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

Commit 7a591bfa authored by Vikas Balapal Maheswarappa's avatar Vikas Balapal Maheswarappa Committed by Marco Nelissen
Browse files

Enable Dolby Vision AV1 support in MPEG4 extractor

Bug: 129367182
Test: build, cts

Change-Id: I2dae1e4cab3d45cd295bf692ba59c3a709ccc3a6
parent 7a0c3c9b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -521,6 +521,7 @@ enum C2Config::profile_t : uint32_t {
    PROFILE_DV_HE_07 = _C2_PL_DV_BASE + 7,      ///< Dolby Vision dvhe.07 profile
    PROFILE_DV_HE_08 = _C2_PL_DV_BASE + 8,      ///< Dolby Vision dvhe.08 profile
    PROFILE_DV_AV_09 = _C2_PL_DV_BASE + 9,      ///< Dolby Vision dvav.09 profile
    PROFILE_DV_AV1_10 = _C2_PL_DV_BASE + 10,    ///< Dolby Vision dav1.10 profile

    // AV1 profiles
    PROFILE_AV1_0 = _C2_PL_AV1_BASE,            ///< AV1 Profile 0 (4:2:0, 8 to 10 bit)
+1 −0
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ ALookup<C2Config::profile_t, int32_t> sDolbyVisionProfiles = {
    { C2Config::PROFILE_DV_HE_07, DolbyVisionProfileDvheDtb },
    { C2Config::PROFILE_DV_HE_08, DolbyVisionProfileDvheSt },
    { C2Config::PROFILE_DV_AV_09, DolbyVisionProfileDvavSe },
    { C2Config::PROFILE_DV_AV1_10, DolbyVisionProfileDvav110 },
};

ALookup<C2Config::level_t, int32_t> sH263Levels = {
+39 −33
Original line number Diff line number Diff line
@@ -343,6 +343,7 @@ static const char *FourCC2MIME(uint32_t fourcc) {
        case FOURCC("dva1"):
        case FOURCC("dvhe"):
        case FOURCC("dvh1"):
        case FOURCC("dav1"):
            return MEDIA_MIMETYPE_VIDEO_DOLBY_VISION;

        case FOURCC("ac-4"):
@@ -1083,7 +1084,7 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
                        const uint8_t bl_compatibility_id = (ptr[4]) >> 4;

                        if (4 == profile || 7 == profile ||
                                (profile >= 8 && profile < 10 && bl_compatibility_id)) {
                                (profile >= 8 && profile < 11 && bl_compatibility_id)) {
                            // we need a backward compatible track
                            ALOGV("Adding new backward compatible track");
                            Track *track_b = new Track;
@@ -1117,6 +1118,9 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
                            } else if (9 == profile) {
                                AMediaFormat_setString(track_b->meta,
                                        AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_AVC);
                            } else if (10 == profile) {
                                AMediaFormat_setString(track_b->meta,
                                        AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_AV1);
                            } // Should never get to else part

                            mLastTrack = track_b;
@@ -1895,6 +1899,7 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
        case FOURCC("dva1"):
        case FOURCC("dvhe"):
        case FOURCC("dvh1"):
        case FOURCC("dav1"):
        case FOURCC("av01"):
        {
            uint8_t buffer[78];
@@ -4226,8 +4231,8 @@ MediaTrackHelper *MPEG4Extractor::getTrack(size_t index) {

        const uint8_t *ptr = (const uint8_t *)data;

        if (size != 24 || ptr[0] != 1 || ptr[1] != 0) {
            // dv_version_major == 1, dv_version_minor == 0;
        // dv_major.dv_minor Should be 1.0 or 2.1
        if (size != 24 || ((ptr[0] != 1 || ptr[1] != 0) && (ptr[0] != 2 || ptr[1] != 1))) {
            return NULL;
        }
   } else if (!strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AV1)) {
@@ -4840,14 +4845,14 @@ MPEG4Source::MPEG4Source(
        const uint8_t *ptr = (const uint8_t *)data;

        CHECK(size == 24);
       CHECK_EQ((unsigned)ptr[0], 1u);  // dv_major_version == 1
       CHECK_EQ((unsigned)ptr[1], 0u);  // dv_minor_version == 0

       const uint8_t profile = ptr[2] >> 1;
        // dv_major.dv_minor Should be 1.0 or 2.1
        CHECK(!((ptr[0] != 1 || ptr[1] != 0) && (ptr[0] != 2 || ptr[1] != 1)));

       // profile == (0,1,9) --> AVC; profile = (2,3,4,5,6,7,8) --> HEVC;
        const uint8_t profile = ptr[2] >> 1;
        // profile == (unknown,1,9) --> AVC; profile = (2,3,4,5,6,7,8) --> HEVC;
        // profile == (10) --> AV1
        if (profile > 1 && profile < 9) {

            CHECK(AMediaFormat_getBuffer(format, AMEDIAFORMAT_KEY_CSD_HEVC, &data, &size));

            const uint8_t *ptr = (const uint8_t *)data;
@@ -4856,8 +4861,9 @@ MPEG4Source::MPEG4Source(
            CHECK_EQ((unsigned)ptr[0], 1u);  // configurationVersion == 1

            mNALLengthSize = 1 + (ptr[14 + 7] & 3);
        } else if (10 == profile) {
            /* AV1 profile nothing to do */
        } else {

            CHECK(AMediaFormat_getBuffer(format, AMEDIAFORMAT_KEY_CSD_AVC, &data, &size));
            const uint8_t *ptr = (const uint8_t *)data;

@@ -5933,7 +5939,7 @@ media_status_t MPEG4Source::read(
        }
    }

    if (!mIsAVC && !mIsHEVC && !mIsDolbyVision && !mIsAC4) {
    if (!mIsAVC && !mIsHEVC && !(mIsDolbyVision && mNALLengthSize) && !mIsAC4) {
        if (newBuffer) {
            if (mIsPcm) {
                // The twos' PCM block reader assumes that all samples has the same size.
@@ -6323,7 +6329,7 @@ media_status_t MPEG4Source::fragmentedRead(
        AMediaFormat_setBuffer(bufmeta, AMEDIAFORMAT_KEY_CRYPTO_IV, iv, ivlength);
    }

    if (!mIsAVC && !mIsHEVC && !mIsDolbyVision) {
    if (!mIsAVC && !mIsHEVC && !(mIsDolbyVision && mNALLengthSize)) {
        if (newBuffer) {
            if (!isInRange((size_t)0u, mBuffer->size(), size)) {
                mBuffer->release();
+6 −2
Original line number Diff line number Diff line
@@ -228,8 +228,9 @@ static void parseAvcProfileLevelFromAvcc(const uint8_t *ptr, size_t size, sp<AMe
}

static void parseDolbyVisionProfileLevelFromDvcc(const uint8_t *ptr, size_t size, sp<AMessage> &format) {
    // dv_major_version == 1, dv_minor_version == 0
    if (size < 4 || ptr[0] != 1 || ptr[1] != 0) {
    // dv_major.dv_minor Should be 1.0 or 2.1
    if (size != 24 || ((ptr[0] != 1 || ptr[1] != 0) && (ptr[0] != 2 || ptr[1] != 1))) {
        ALOGV("Size %zu, dv_major %d, dv_minor %d", size, ptr[0], ptr[1]);
        return;
    }

@@ -254,6 +255,7 @@ static void parseDolbyVisionProfileLevelFromDvcc(const uint8_t *ptr, size_t size
        {7, OMX_VIDEO_DolbyVisionProfileDvheDtb},
        {8, OMX_VIDEO_DolbyVisionProfileDvheSt},
        {9, OMX_VIDEO_DolbyVisionProfileDvavSe},
        {10, OMX_VIDEO_DolbyVisionProfileDvav110},
    };

    const static ALookup<uint8_t, OMX_VIDEO_DOLBYVISIONLEVELTYPE> levels{
@@ -1918,6 +1920,8 @@ void convertMessageToMetaData(const sp<AMessage> &msg, sp<MetaData> &meta) {
                    std::vector<uint8_t> hvcc(csd0size + 1024);
                    size_t outsize = reassembleHVCC(csd0, hvcc.data(), hvcc.size(), 4);
                    meta->setData(kKeyHVCC, kTypeHVCC, hvcc.data(), outsize);
                } else if (DolbyVisionProfileDvav110 == profile) {
                    meta->setData(kKeyAV1C, 0, csd0->data(), csd0->size());
                } else {
                    sp<ABuffer> csd1;
                    if (msg->findBuffer("csd-1", &csd1)) {
+15 −13
Original line number Diff line number Diff line
@@ -512,6 +512,7 @@ constexpr int32_t DolbyVisionProfileDvheDth = 0x40;
constexpr int32_t DolbyVisionProfileDvheDtb = 0x80;
constexpr int32_t DolbyVisionProfileDvheSt  = 0x100;
constexpr int32_t DolbyVisionProfileDvavSe  = 0x200;
constexpr int32_t DolbyVisionProfileDvav110 = 0x400;

inline static const char *asString_DolbyVisionProfile(int32_t i, const char *def = "??") {
    switch (i) {
@@ -525,6 +526,7 @@ inline static const char *asString_DolbyVisionProfile(int32_t i, const char *def
        case DolbyVisionProfileDvheDtb:  return "DvheDtb";
        case DolbyVisionProfileDvheSt:   return "DvheSt";
        case DolbyVisionProfileDvavSe:   return "DvavSe";
        case DolbyVisionProfileDvav110:  return "Dav110";
        default:                         return def;
    }
}