Add RGBA_8888 support to V4L2 camera HAL
Actually returns GBR data for now, based on available formats for
RPi3 camera, but claims it's RGB.
BUG: b/31829804
TEST: test program runs, can handle format 0x1 (RGBA_8888)
Change-Id: I41c9ced5c1fa25d1254530d3d0a1446d2d514a1f
diff --git a/modules/camera/3_4/stream_format.cpp b/modules/camera/3_4/stream_format.cpp
index 43f4cae..5940b71 100644
--- a/modules/camera/3_4/stream_format.cpp
+++ b/modules/camera/3_4/stream_format.cpp
@@ -62,7 +62,8 @@
switch (v4l2_pixel_format_) {
case V4L2_PIX_FMT_JPEG:
return kFormatCategoryStalling;
- case V4L2_PIX_FMT_YUV420:
+ case V4L2_PIX_FMT_YUV420: // Fall through.
+ case V4L2_PIX_FMT_BGR32:
return kFormatCategoryNonStalling;
default:
// Note: currently no supported RAW formats.
@@ -92,8 +93,12 @@
case V4L2_PIX_FMT_YUV420:
hal_pixel_format = HAL_PIXEL_FORMAT_YCbCr_420_888;
break;
+ case V4L2_PIX_FMT_BGR32:
+ hal_pixel_format = HAL_PIXEL_FORMAT_RGBA_8888;
+ break;
default:
// Unrecognized format.
+ HAL_LOGV("Unrecognized v4l2 pixel format %u", v4l2_pixel_format);
break;
}
return hal_pixel_format;
@@ -104,6 +109,11 @@
uint32_t v4l2_pixel_format = 0;
switch (hal_pixel_format) {
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: // fall-through.
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ // Should be RGB32, but RPi doesn't support that.
+ // For now we accept that the colors will be off.
+ v4l2_pixel_format = V4L2_PIX_FMT_BGR32;
+ break;
case HAL_PIXEL_FORMAT_YCbCr_420_888:
v4l2_pixel_format = V4L2_PIX_FMT_YUV420;
break;
@@ -112,6 +122,7 @@
break;
default:
// Unrecognized format.
+ HAL_LOGV("Unrecognized HAL pixel format %d", hal_pixel_format);
break;
}
return v4l2_pixel_format;
diff --git a/modules/camera/3_4/v4l2_gralloc.cpp b/modules/camera/3_4/v4l2_gralloc.cpp
index 5812649..64fa306 100644
--- a/modules/camera/3_4/v4l2_gralloc.cpp
+++ b/modules/camera/3_4/v4l2_gralloc.cpp
@@ -25,6 +25,7 @@
#include <system/graphics.h>
#include "common.h"
+#include "stream_format.h"
namespace v4l2_camera_hal {
@@ -96,9 +97,9 @@
buffer_handle_t buffer = *camera_buffer->buffer;
void* data;
camera3_stream_t* stream = camera_buffer->stream;
- switch(stream->format) {
+ switch(StreamFormat::HalToV4L2PixelFormat(stream->format)) {
// TODO(b/30119452): support more YCbCr formats.
- case HAL_PIXEL_FORMAT_YCbCr_420_888:
+ case V4L2_PIX_FMT_YUV420:
android_ycbcr yuv_data;
mModule->lock_ycbcr(mModule, buffer, stream->usage, 0, 0,
stream->width, stream->height, &yuv_data);
@@ -127,10 +128,15 @@
buffer_data->transform_dest.reset(new android_ycbcr(yuv_data));
}
break;
- case HAL_PIXEL_FORMAT_BLOB:
+ case V4L2_PIX_FMT_JPEG:
// Jpeg buffers are just contiguous blobs; lock length * 1.
mModule->lock(mModule, buffer, stream->usage, 0, 0, device_buffer->length, 1, &data);
break;
+ case V4L2_PIX_FMT_BGR32: // Fall-through.
+ case V4L2_PIX_FMT_RGB32:
+ // RGB formats have nice agreed upon representation. Unless using android flex formats.
+ mModule->lock(mModule, buffer, stream->usage, 0, 0, stream->width, stream->height, &data);
+ break;
default:
return -EINVAL;
}