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

Commit d4bbb765 authored by Harish Mahendrakar's avatar Harish Mahendrakar
Browse files

c2 av1, vp9: Add support for P010 format

Updated VP9 and AV1 decoder plugins to support P010 output.
Plugins now advertise P010 as supported color format and return
P010 output for 10 bit clips.

Bug: 178229371
Test: atest CtsMediaDecoderTestCases:ImageReaderDecoderTest -- \
 --module-arg \
 CtsMediaDecoderTestCases:instrumentation-arg:codec-prefix:=c2.android.
Test: atest android.mediav2.cts.CodecDecoderSurfaceTest \
 android.mediav2.cts.AdaptivePlaybackTest \
 android.mediav2.cts.CodecDecoderTest -- --module-arg \
 CtsMediaV2TestCases:instrumentation-arg:codec-prefix:=c2.android.

Change-Id: I4c2ad2f45d51337b44de4a5a5a44281c4a7640ad
parent 508d01b8
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -32,6 +32,13 @@ namespace android {
constexpr uint8_t kNeutralUVBitDepth8 = 128;
constexpr uint16_t kNeutralUVBitDepth10 = 512;

bool isAtLeastT() {
    char deviceCodeName[PROP_VALUE_MAX];
    __system_property_get("ro.build.version.codename", deviceCodeName);
    return android_get_device_api_level() >= __ANDROID_API_T__ ||
           !strcmp(deviceCodeName, "Tiramisu");
}

void convertYUV420Planar8ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, const uint8_t *srcY,
                                const uint8_t *srcU, const uint8_t *srcV, size_t srcYStride,
                                size_t srcUStride, size_t srcVStride, size_t dstYStride,
@@ -767,9 +774,9 @@ int SimpleC2Component::getHalPixelFormatForBitDepth10(bool allowRGBA1010102) {
    // Save supported hal pixel formats for bit depth of 10, the first time this is called
    if (!mBitDepth10HalPixelFormats.size()) {
        std::vector<int> halPixelFormats;
        // TODO(b/178229371) Enable HAL_PIXEL_FORMAT_YCBCR_P010 once framework supports it
        // halPixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010);

        if (isAtLeastT()) {
            halPixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010);
        }
        // since allowRGBA1010102 can chance in each call, but mBitDepth10HalPixelFormats
        // is populated only once, allowRGBA1010102 is not considered at this stage.
        halPixelFormats.push_back(HAL_PIXEL_FORMAT_RGBA_1010102);
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
#include <media/stagefright/foundation/Mutexed.h>

namespace android {

bool isAtLeastT();
void convertYUV420Planar8ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, const uint8_t *srcY,
                                const uint8_t *srcU, const uint8_t *srcV, size_t srcYStride,
                                size_t srcUStride, size_t srcVStride, size_t dstYStride,
+30 −4
Original line number Diff line number Diff line
@@ -189,10 +189,17 @@ class C2SoftGav1Dec::IntfImpl : public SimpleInterface<void>::BaseParams {
              .withSetter(ColorAspectsSetter, mDefaultColorAspects, mCodedColorAspects)
              .build());

    std::vector<uint32_t> pixelFormats = {HAL_PIXEL_FORMAT_YCBCR_420_888};
    if (isAtLeastT()) {
        pixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010);
    }
    // TODO: support more formats?
    addParameter(DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT)
                     .withConstValue(new C2StreamPixelFormatInfo::output(
    addParameter(
            DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT)
            .withDefault(new C2StreamPixelFormatInfo::output(
                              0u, HAL_PIXEL_FORMAT_YCBCR_420_888))
            .withFields({C2F(mPixelFormat, value).oneOf(pixelFormats)})
            .withSetter((Setter<decltype(*mPixelFormat)>::StrictValueWithNoDeps))
            .build());
  }

@@ -402,6 +409,7 @@ static int GetCPUCoreCount() {
bool C2SoftGav1Dec::initDecoder() {
  mSignalledError = false;
  mSignalledOutputEos = false;
  mHalPixelFormat = HAL_PIXEL_FORMAT_YV12;
  mCodecCtx.reset(new libgav1::Decoder());

  if (mCodecCtx == nullptr) {
@@ -647,6 +655,24 @@ bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
      return false;
    }
  }

  if (mHalPixelFormat != format) {
    C2StreamPixelFormatInfo::output pixelFormat(0u, format);
    std::vector<std::unique_ptr<C2SettingResult>> failures;
    c2_status_t err = mIntf->config({&pixelFormat }, C2_MAY_BLOCK, &failures);
    if (err == C2_OK) {
      work->worklets.front()->output.configUpdate.push_back(
          C2Param::Copy(pixelFormat));
    } else {
      ALOGE("Config update pixelFormat failed");
      mSignalledError = true;
      work->workletsProcessed = 1u;
      work->result = C2_CORRUPTED;
      return UNKNOWN_ERROR;
    }
    mHalPixelFormat = format;
  }

  C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};

  c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, format,
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ struct C2SoftGav1Dec : public SimpleC2Component {
  std::shared_ptr<IntfImpl> mIntf;
  std::unique_ptr<libgav1::Decoder> mCodecCtx;

  uint32_t mHalPixelFormat;
  uint32_t mWidth;
  uint32_t mHeight;
  bool mSignalledOutputEos;
+30 −4
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#include <log/log.h>

#include <algorithm>

#include <media/stagefright/foundation/AUtils.h>
#include <media/stagefright/foundation/MediaDefs.h>

@@ -218,11 +217,20 @@ public:
                .build());

        // TODO: support more formats?
        std::vector<uint32_t> pixelFormats = {HAL_PIXEL_FORMAT_YCBCR_420_888};
#ifdef VP9
        if (isAtLeastT()) {
            pixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010);
        }
#endif
        addParameter(
                DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT)
                .withConstValue(new C2StreamPixelFormatInfo::output(
                .withDefault(new C2StreamPixelFormatInfo::output(
                                  0u, HAL_PIXEL_FORMAT_YCBCR_420_888))
                .withFields({C2F(mPixelFormat, value).oneOf(pixelFormats)})
                .withSetter((Setter<decltype(*mPixelFormat)>::StrictValueWithNoDeps))
                .build());

    }

    static C2R SizeSetter(bool mayBlock, const C2P<C2StreamPictureSizeInfo::output> &oldMe,
@@ -424,7 +432,7 @@ status_t C2SoftVpxDec::initDecoder() {
#else
    mMode = MODE_VP8;
#endif

    mHalPixelFormat = HAL_PIXEL_FORMAT_YV12;
    mWidth = 320;
    mHeight = 240;
    mFrameParallelMode = false;
@@ -690,6 +698,24 @@ status_t C2SoftVpxDec::outputBuffer(
        }
        format = getHalPixelFormatForBitDepth10(allowRGBA1010102);
    }

    if (mHalPixelFormat != format) {
        C2StreamPixelFormatInfo::output pixelFormat(0u, format);
        std::vector<std::unique_ptr<C2SettingResult>> failures;
        c2_status_t err = mIntf->config({&pixelFormat }, C2_MAY_BLOCK, &failures);
        if (err == C2_OK) {
            work->worklets.front()->output.configUpdate.push_back(
                C2Param::Copy(pixelFormat));
        } else {
            ALOGE("Config update pixelFormat failed");
            mSignalledError = true;
            work->workletsProcessed = 1u;
            work->result = C2_CORRUPTED;
            return UNKNOWN_ERROR;
        }
        mHalPixelFormat = format;
    }

    C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
    c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, format, usage, &block);
    if (err != C2_OK) {
Loading