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

Commit 74bda72d authored by Lajos Molnar's avatar Lajos Molnar Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherrypicker-L42600000954628703:N10500001267021915" into tm-dev

* changes:
  CCodec: configure hdr-format for HDR encoder profiles
  codec2: add HDR format info
parents 24eb57be e9707b37
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ struct C2Config {
    enum drc_effect_type_t : int32_t;       ///< DRC effect type
    enum drc_album_mode_t : int32_t;        ///< DRC album mode
    enum hdr_dynamic_metadata_type_t : uint32_t;  ///< HDR dynamic metadata type
    enum hdr_format_t : uint32_t;           ///< HDR format
    enum intra_refresh_mode_t : uint32_t;   ///< intra refresh modes
    enum level_t : uint32_t;                ///< coding level
    enum ordinal_key_t : uint32_t;          ///< work ordering keys
@@ -192,10 +193,9 @@ enum C2ParamIndexKind : C2Param::type_index_t {
    kParamIndexPictureType,
    // deprecated
    kParamIndexHdr10PlusMetadata,

    kParamIndexPictureQuantization,

    kParamIndexHdrDynamicMetadata,
    kParamIndexHdrFormat,

    /* ------------------------------------ video components ------------------------------------ */

@@ -1667,6 +1667,34 @@ typedef C2StreamParam<C2Info, C2HdrDynamicMetadataStruct, kParamIndexHdrDynamicM
constexpr char C2_PARAMKEY_INPUT_HDR_DYNAMIC_INFO[] = "input.hdr-dynamic-info";
constexpr char C2_PARAMKEY_OUTPUT_HDR_DYNAMIC_INFO[] = "output.hdr-dynamic-info";

/**
 * HDR Format
 */
C2ENUM(C2Config::hdr_format_t, uint32_t,
    UNKNOWN,     ///< HDR format not known (default)
    SDR,         ///< not HDR (SDR)
    HLG,         ///< HLG
    HDR10,       ///< HDR10
    HDR10_PLUS,  ///< HDR10+
);

/**
 * HDR Format Info
 *
 * This information may be present during configuration to allow encoders to
 * prepare encoding certain HDR formats. When this information is not present
 * before start, encoders should determine the HDR format based on the available
 * HDR metadata on the first input frame.
 *
 * While this information is optional, it is not a hint. When present, encoders
 * that do not support dynamic reconfiguration do not need to switch to the HDR
 * format based on the metadata on the first input frame.
 */
typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2EasyEnum<C2Config::hdr_format_t>>,
                kParamIndexHdrFormat>
        C2StreamHdrFormatInfo;
constexpr char C2_PARAMKEY_HDR_FORMAT[] = "coded.hdr-format";

/* ------------------------------------ block-based coding ----------------------------------- */

/**
+24 −0
Original line number Diff line number Diff line
@@ -513,6 +513,9 @@ void CCodecConfig::initializeStandardParams() {
    add(ConfigMapper("cta861.max-fall", C2_PARAMKEY_HDR_STATIC_INFO, "max-fall")
        .limitTo((D::VIDEO | D::IMAGE) & D::RAW));

    add(ConfigMapper(C2_PARAMKEY_HDR_FORMAT, C2_PARAMKEY_HDR_FORMAT, "value")
        .limitTo((D::VIDEO | D::IMAGE) & D::CODED & D::CONFIG));

    add(ConfigMapper(std::string(KEY_FEATURE_) + FEATURE_SecurePlayback,
                     C2_PARAMKEY_SECURE_MODE, "value"));

@@ -1624,6 +1627,27 @@ ReflectedParamUpdater::Dict CCodecConfig::getReflectedFormat(
                params->setFloat(C2_PARAMKEY_INPUT_TIME_STRETCH, captureRate / frameRate);
            }
        }

        // add HDR format for video encoding
        if (configDomain == IS_CONFIG) {
            // don't assume here that transfer is set for HDR, only require it for HLG
            int transfer = 0;
            params->findInt32(KEY_COLOR_TRANSFER, &transfer);

            int profile;
            if (params->findInt32(KEY_PROFILE, &profile)) {
                std::shared_ptr<C2Mapper::ProfileLevelMapper> mapper =
                    C2Mapper::GetProfileLevelMapper(mCodingMediaType);
                C2Config::hdr_format_t c2 = C2Config::hdr_format_t::UNKNOWN;
                if (mapper && mapper->mapHdrFormat(profile, &c2)) {
                    if (c2 == C2Config::hdr_format_t::HLG &&
                        transfer != COLOR_TRANSFER_HLG) {
                        c2 = C2Config::hdr_format_t::UNKNOWN;
                    }
                    params->setInt32(C2_PARAMKEY_HDR_FORMAT, c2);
                }
            }
        }
    }

    {   // reflect temporal layering into a binary blob
+51 −0
Original line number Diff line number Diff line
@@ -276,6 +276,13 @@ ALookup<C2Config::profile_t, int32_t> sHevcHdr10PlusProfiles = {
    { C2Config::PROFILE_HEVC_MAIN_10, HEVCProfileMain10HDR10Plus },
};

ALookup<C2Config::hdr_format_t, int32_t> sHevcHdrFormats = {
    { C2Config::hdr_format_t::SDR, HEVCProfileMain },
    { C2Config::hdr_format_t::HLG, HEVCProfileMain10 },
    { C2Config::hdr_format_t::HDR10, HEVCProfileMain10HDR10 },
    { C2Config::hdr_format_t::HDR10_PLUS, HEVCProfileMain10HDR10Plus },
};

ALookup<C2Config::level_t, int32_t> sMpeg2Levels = {
    { C2Config::LEVEL_MP2V_LOW,         MPEG2LevelLL },
    { C2Config::LEVEL_MP2V_MAIN,        MPEG2LevelML },
@@ -365,6 +372,17 @@ ALookup<C2Config::profile_t, int32_t> sVp9Hdr10PlusProfiles = {
    { C2Config::PROFILE_VP9_3, VP9Profile3HDR10Plus },
};

ALookup<C2Config::hdr_format_t, int32_t> sVp9HdrFormats = {
    { C2Config::hdr_format_t::SDR, VP9Profile0 },
    { C2Config::hdr_format_t::SDR, VP9Profile1 },
    { C2Config::hdr_format_t::HLG, VP9Profile2 },
    { C2Config::hdr_format_t::HLG, VP9Profile3 },
    { C2Config::hdr_format_t::HDR10, VP9Profile2HDR },
    { C2Config::hdr_format_t::HDR10, VP9Profile3HDR },
    { C2Config::hdr_format_t::HDR10_PLUS, VP9Profile2HDR10Plus },
    { C2Config::hdr_format_t::HDR10_PLUS, VP9Profile3HDR10Plus },
};

ALookup<C2Config::level_t, int32_t> sAv1Levels = {
    { C2Config::LEVEL_AV1_2,    AV1Level2  },
    { C2Config::LEVEL_AV1_2_1,  AV1Level21 },
@@ -411,6 +429,13 @@ ALookup<C2Config::profile_t, int32_t> sAv1Hdr10PlusProfiles = {
    { C2Config::PROFILE_AV1_0, AV1ProfileMain10HDR10Plus },
};

ALookup<C2Config::hdr_format_t, int32_t> sAv1HdrFormats = {
    { C2Config::hdr_format_t::SDR, AV1ProfileMain8 },
    { C2Config::hdr_format_t::HLG, AV1ProfileMain10 },
    { C2Config::hdr_format_t::HDR10, AV1ProfileMain10HDR10 },
    { C2Config::hdr_format_t::HDR10_PLUS, AV1ProfileMain10HDR10Plus },
};

// HAL_PIXEL_FORMAT_* -> COLOR_Format*
ALookup<uint32_t, int32_t> sPixelFormats = {
    { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, COLOR_FormatSurface },
@@ -487,6 +512,10 @@ struct AacProfileLevelMapper : ProfileLevelMapperHelper {
    virtual bool simpleMap(int32_t from, C2Config::profile_t *to) {
        return sAacProfiles.map(from, to);
    }
    // AAC does not have HDR format
    virtual bool mapHdrFormat(int32_t, C2Config::hdr_format_t*) override {
        return false;
    }
};

struct AvcProfileLevelMapper : ProfileLevelMapperHelper {
@@ -517,6 +546,12 @@ struct DolbyVisionProfileLevelMapper : ProfileLevelMapperHelper {
    virtual bool simpleMap(int32_t from, C2Config::profile_t *to) {
        return sDolbyVisionProfiles.map(from, to);
    }
    // Dolby Vision is always HDR and the profile is fully expressive so use unknown
    // HDR format
    virtual bool mapHdrFormat(int32_t, C2Config::hdr_format_t *to) override {
        *to = C2Config::hdr_format_t::UNKNOWN;
        return true;
    }
};

struct H263ProfileLevelMapper : ProfileLevelMapperHelper {
@@ -555,6 +590,9 @@ struct HevcProfileLevelMapper : ProfileLevelMapperHelper {
                     mIsHdr ? sHevcHdrProfiles.map(from, to) :
                              sHevcProfiles.map(from, to);
    }
    virtual bool mapHdrFormat(int32_t from, C2Config::hdr_format_t *to) override {
        return sHevcHdrFormats.map(from, to);
    }

private:
    bool mIsHdr;
@@ -633,6 +671,9 @@ struct Vp9ProfileLevelMapper : ProfileLevelMapperHelper {
                     mIsHdr ? sVp9HdrProfiles.map(from, to) :
                              sVp9Profiles.map(from, to);
    }
    virtual bool mapHdrFormat(int32_t from, C2Config::hdr_format_t *to) override {
        return sVp9HdrFormats.map(from, to);
    }

private:
    bool mIsHdr;
@@ -662,6 +703,9 @@ struct Av1ProfileLevelMapper : ProfileLevelMapperHelper {
                          mIsHdr ? sAv1HdrProfiles.map(from, to) :
                                   sAv1Profiles.map(from, to);
    }
    virtual bool mapHdrFormat(int32_t from, C2Config::hdr_format_t *to) override {
        return sAv1HdrFormats.map(from, to);
    }

private:
    bool mIsHdr;
@@ -671,6 +715,13 @@ private:

} // namespace

// the default mapper is used for media types that do not support HDR
bool C2Mapper::ProfileLevelMapper::mapHdrFormat(int32_t, C2Config::hdr_format_t *to) {
    // by default map all (including vendor) profiles to SDR
    *to = C2Config::hdr_format_t::SDR;
    return true;
}

// static
std::shared_ptr<C2Mapper::ProfileLevelMapper>
C2Mapper::GetProfileLevelMapper(std::string mediaType) {
+10 −0
Original line number Diff line number Diff line
@@ -34,6 +34,16 @@ namespace android {
            virtual bool mapProfile(int32_t, C2Config::profile_t*) = 0;
            virtual bool mapLevel(C2Config::level_t, int32_t*) = 0;
            virtual bool mapLevel(int32_t, C2Config::level_t*) = 0;

            /**
             * Mapper method that maps a MediaCodec profile to the supported
             * HDR format for that profile. Since 10-bit profiles are used for
             * HLG, this method will return HLG for all 10-bit profiles, but
             * the caller should also verify that the transfer function is
             * indeed HLG.
             */
            // not an abstract method as we have a default implementation for SDR
            virtual bool mapHdrFormat(int32_t, C2Config::hdr_format_t *hdr);
            virtual ~ProfileLevelMapper() = default;
        };