ImageReader format is overridden on some devices

I have an ImageReader that is used to get the preview frame data (an array of bytes). It is configured with the recommended image format YUV_420_888 as follows:

 mPreviewImageReader = ImageReader.newInstance(width, height, ImageFormat.YUV_420_888, 2); 

When the listener set in mPreviewImageReader.setOnImageAvailableListener(); I get an image:

 Image image = reader.acquireLatestImage(); 

On some phones, I see the following listing in the log with the ImageReader_JNI tag:

ImageReader_imageSetup: Overriding the buffer format YUV_420_888 to 32315659.

I searched and it seems the format is being redefined on YV12 . I tried to look at the C ++ ImageReader code and found where this happens:

 int bufFmt = buffer->format; if (imgReaderFmt == HAL_PIXEL_FORMAT_YCbCr_420_888) { bufFmt = buffer->flexFormat; } if (imgReaderFmt != bufFmt) { if (imgReaderFmt == HAL_PIXEL_FORMAT_YCbCr_420_888 && (bufFmt == HAL_PIXEL_FORMAT_YCrCb_420_SP || bufFmt == HAL_PIXEL_FORMAT_YV12)) { // Special casing for when producer switches to a format compatible with flexible YUV // (HAL_PIXEL_FORMAT_YCbCr_420_888). ctx->setBufferFormat(bufFmt); ALOGD("%s: Overriding buffer format YUV_420_888 to %x.", __FUNCTION__, bufFmt); } // ... rest of the code 

So, the buffer format is YV12 , and the ImageReader format is YUV_420_888 , as I installed it.

This leads me to two questions regarding this situation, which correspond to the two parameters that I have (as far as I can see):

  • Why is the format of the YV12 buffer where it is installed, and can I change this?
  • I can add support for YV12 , but I need to know that this override has occurred. But when calling image.getFormat() I get 35, which means YUV_420_888 . Is there any way to know if this override has occurred?

Any other ideas are welcome.

+5
source share

Source: https://habr.com/ru/post/1012446/


All Articles