Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11b60d2b authored by James Zern's avatar James Zern Committed by Cherrypicker Worker
Browse files

gav1: support 444 and 422 for 10bit (RGBA1010102 path)

This will enable 444, 422 and monochrome support for AVIF images as
well.

I?10ToAB30Matrix were added in:
  7ed0473 Update external/libyuv to r1837
and upstream in version 1780.

To keep this compatible with mainline LIBYUV_VERSION checks are added
around the new code. libyuv is not a part of mainline and is currently
at libyuv version 1732.

Bug: 261112792
Test: decode videos through files app on oriole device (no P010)
Test: compile pre/post libyuv update
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b1461a809fde572d565454eb3c3fdd0d74c83b4e)
Merged-In: I40ace4a68bf09886bd54049ac5d9d9c4d6e9f444
Change-Id: I40ace4a68bf09886bd54049ac5d9d9c4d6e9f444
parent 0958b8ba
Loading
Loading
Loading
Loading
+45 −5
Original line number Diff line number Diff line
@@ -29,6 +29,14 @@
#include <media/stagefright/foundation/AUtils.h>
#include <media/stagefright/foundation/MediaDefs.h>

// libyuv version required for I410ToAB30Matrix and I210ToAB30Matrix.
#if LIBYUV_VERSION >= 1780
#include <algorithm>
#define HAVE_LIBYUV_I410_I210_TO_AB30 1
#else
#define HAVE_LIBYUV_I410_I210_TO_AB30 0
#endif

namespace android {

// codecname set and passed in as a compile flag from Android.bp
@@ -818,6 +826,7 @@ bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
      allowRGBA1010102 = true;
    }
    format = getHalPixelFormatForBitDepth10(allowRGBA1010102);
#if !HAVE_LIBYUV_I410_I210_TO_AB30
    if ((format == HAL_PIXEL_FORMAT_RGBA_1010102) &&
        (buffer->image_format != libgav1::kImageFormatYuv420)) {
        ALOGE("Only YUV420 output is supported when targeting RGBA_1010102");
@@ -826,6 +835,7 @@ bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
      work->workletsProcessed = 1u;
      return false;
    }
#endif
  }

  if (mHalPixelFormat != format) {
@@ -889,11 +899,41 @@ bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
    size_t srcVStride = buffer->stride[2] / 2;

    if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
        bool processed = false;
#if HAVE_LIBYUV_I410_I210_TO_AB30
        if (buffer->image_format == libgav1::kImageFormatYuv444) {
            libyuv::I410ToAB30Matrix(srcY, srcYStride, srcU, srcUStride, srcV, srcVStride,
                                     dstY, dstYStride, &libyuv::kYuvV2020Constants,
                                     mWidth, mHeight);
            processed = true;
        } else if (buffer->image_format == libgav1::kImageFormatYuv422) {
            libyuv::I210ToAB30Matrix(srcY, srcYStride, srcU, srcUStride, srcV, srcVStride,
                                     dstY, dstYStride, &libyuv::kYuvV2020Constants,
                                     mWidth, mHeight);
            processed = true;
        }
#endif  // HAVE_LIBYUV_I410_I210_TO_AB30
        if (!processed) {
            if (isMonochrome) {
                const size_t tmpSize = mWidth;
                const bool needFill = tmpSize > mTmpFrameBufferSize;
                if (!allocTmpFrameBuffer(tmpSize)) {
                    ALOGE("Error allocating temp conversion buffer (%zu bytes)", tmpSize);
                    setError(work, C2_NO_MEMORY);
                    return false;
                }
                srcU = srcV = mTmpFrameBuffer.get();
                srcUStride = srcVStride = 0;
                if (needFill) {
                    std::fill_n(mTmpFrameBuffer.get(), tmpSize, 512);
                }
            }
            convertYUV420Planar16ToY410OrRGBA1010102(
                    (uint32_t *)dstY, srcY, srcU, srcV, srcYStride,
                    srcUStride, srcVStride,
                    dstYStride / sizeof(uint32_t), mWidth, mHeight,
                    std::static_pointer_cast<const C2ColorAspectsStruct>(codedColorAspects));
        }
    } else if (format == HAL_PIXEL_FORMAT_YCBCR_P010) {
        dstYStride /= 2;
        dstUStride /= 2;