gav1: Support 444 and 422 for 8bit using libyuv
The android platform includes libyuv and we can use that to support
444 and 422 av1 content using the software decoder. This will enable
444 and 422 support for AVIF images as well.
Bug: 261112792
Change-Id: I2e08fa4b760fcb772a97be6ee62259d8762b2c12
Test: decode images on an oriole device
diff --git a/media/codec2/components/gav1/Android.bp b/media/codec2/components/gav1/Android.bp
index 162339f..9781b6d 100644
--- a/media/codec2/components/gav1/Android.bp
+++ b/media/codec2/components/gav1/Android.bp
@@ -21,7 +21,10 @@
],
srcs: ["C2SoftGav1Dec.cpp"],
- static_libs: ["libgav1"],
+ static_libs: [
+ "libgav1",
+ "libyuv_static",
+ ],
apex_available: [
"//apex_available:platform",
diff --git a/media/codec2/components/gav1/C2SoftGav1Dec.cpp b/media/codec2/components/gav1/C2SoftGav1Dec.cpp
index 9c5ce9f..77296a4 100644
--- a/media/codec2/components/gav1/C2SoftGav1Dec.cpp
+++ b/media/codec2/components/gav1/C2SoftGav1Dec.cpp
@@ -24,6 +24,7 @@
#include <Codec2CommonUtils.h>
#include <Codec2Mapper.h>
#include <SimpleC2Interface.h>
+#include <libyuv.h>
#include <log/log.h>
#include <media/stagefright/foundation/AUtils.h>
#include <media/stagefright/foundation/MediaDefs.h>
@@ -771,14 +772,16 @@
getHDRStaticParams(buffer, work);
getHDR10PlusInfoData(buffer, work);
- if (!(buffer->image_format == libgav1::kImageFormatYuv420 ||
+ if (buffer->bitdepth == 10 &&
+ !(buffer->image_format == libgav1::kImageFormatYuv420 ||
buffer->image_format == libgav1::kImageFormatMonochrome400)) {
- ALOGE("image_format %d not supported", buffer->image_format);
+ ALOGE("image_format %d not supported for 10bit", buffer->image_format);
mSignalledError = true;
work->workletsProcessed = 1u;
work->result = C2_CORRUPTED;
return false;
}
+
const bool isMonochrome =
buffer->image_format == libgav1::kImageFormatMonochrome400;
@@ -884,9 +887,20 @@
const uint8_t *srcY = (const uint8_t *)buffer->plane[0];
const uint8_t *srcU = (const uint8_t *)buffer->plane[1];
const uint8_t *srcV = (const uint8_t *)buffer->plane[2];
- convertYUV420Planar8ToYV12(dstY, dstU, dstV, srcY, srcU, srcV, srcYStride, srcUStride,
- srcVStride, dstYStride, dstUStride, dstVStride, mWidth, mHeight,
- isMonochrome);
+
+ if (buffer->image_format == libgav1::kImageFormatYuv444) {
+ libyuv::I444ToI420(srcY, srcYStride, srcU, srcUStride, srcV, srcVStride,
+ dstY, dstYStride, dstU, dstUStride, dstV, dstVStride,
+ mWidth, mHeight);
+ } else if (buffer->image_format == libgav1::kImageFormatYuv422) {
+ libyuv::I422ToI420(srcY, srcYStride, srcU, srcUStride, srcV, srcVStride,
+ dstY, dstYStride, dstU, dstUStride, dstV, dstVStride,
+ mWidth, mHeight);
+ } else {
+ convertYUV420Planar8ToYV12(dstY, dstU, dstV, srcY, srcU, srcV, srcYStride, srcUStride,
+ srcVStride, dstYStride, dstUStride, dstVStride, mWidth, mHeight,
+ isMonochrome);
+ }
}
finishWork(buffer->user_private_data, work, std::move(block));
block = nullptr;