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

Commit 86a97eb8 authored by Sham Rathod's avatar Sham Rathod
Browse files

Set Profile and level for APV codec

Parse CSD of APV as per syntax of APV configuration
box and set profile and level in MediaFormat.

Test: atest CtsMediaMuxerTestCases
Change-Id: I36427062cfab503deff2c2ed602b5efbbb333943
parent bc74e235
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -736,6 +736,39 @@ static void parseAV1ProfileLevelFromCsd(const sp<ABuffer> &csd, sp<AMessage> &fo
    }
}

static void parseAPVProfileLevelFromCsd(const sp<ABuffer>& csd, sp<AMessage>& format) {
    // Parse CSD structure to extract profile level information
    // https://github.com/openapv/openapv/blob/main/readme/apv_isobmff.md#syntax-1
    const uint8_t* data = csd->data();
    size_t csdSize = csd->size();
    if (csdSize < 21 || data[5] != 0x01) {  // configurationVersion == 1
        return;
    }
    uint8_t profileData = data[9];           // profile_idc
    uint8_t levelData = data[10];            // level_idc
    uint8_t band = data[11];                 // band_idc
    uint8_t bitDepth = (data[20] >> 4) + 8;  // bit_depth_minus8
    const static ALookup<std::pair<uint8_t, uint8_t>, int32_t> profiles{
            {{33, 10}, APVProfile422_10},
            {{44, 12}, APVProfile422_10HDR10Plus},
    };
    int32_t profile;
    if (profiles.map(std::make_pair(profileData, bitDepth), &profile)) {
        // bump to HDR profile
        if (isHdr10or10Plus(format) && profile == APVProfile422_10) {
            if (format->contains("hdr-static-info")) {
                profile = APVProfile422_10HDR10;
            }
        }
        format->setInt32("profile", profile);
    }
    int level_num = (levelData / 30) * 2;
    if (levelData % 30 == 0) {
        level_num -= 1;
    }
    int32_t level = ((0x100 << (level_num - 1)) | (1 << band));
    format->setInt32("level", level);
}

static std::vector<std::pair<const char *, uint32_t>> stringMappings {
    {
@@ -1456,6 +1489,7 @@ status_t convertMetaDataToMessage(
        buffer->meta()->setInt32("csd", true);
        buffer->meta()->setInt64("timeUs", 0);
        msg->setBuffer("csd-0", buffer);
        parseAPVProfileLevelFromCsd(buffer, msg);
    } else if (meta->findData(kKeyESDS, &type, &data, &size)) {
        ESDS esds((const char *)data, size);
        if (esds.InitCheck() != (status_t)OK) {