Loading media/codec2/core/include/C2Config.h +30 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -192,10 +193,9 @@ enum C2ParamIndexKind : C2Param::type_index_t { kParamIndexPictureType, // deprecated kParamIndexHdr10PlusMetadata, kParamIndexPictureQuantization, kParamIndexHdrDynamicMetadata, kParamIndexHdrFormat, /* ------------------------------------ video components ------------------------------------ */ Loading Loading @@ -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 ----------------------------------- */ /** Loading media/codec2/sfplugin/CCodecConfig.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -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")); Loading Loading @@ -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 Loading media/codec2/sfplugin/utils/Codec2Mapper.cpp +51 −0 Original line number Diff line number Diff line Loading @@ -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 }, Loading Loading @@ -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 }, Loading Loading @@ -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 }, Loading Loading @@ -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 { Loading Loading @@ -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 { Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading @@ -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) { Loading media/codec2/sfplugin/utils/Codec2Mapper.h +10 −0 Original line number Diff line number Diff line Loading @@ -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; }; Loading media/libaaudio/src/flowgraph/FlowgraphUtilities.h +2 −2 Original line number Diff line number Diff line Loading @@ -39,9 +39,9 @@ static int32_t clamp32FromFloat(float f) static const float limneg = -1.; if (f <= limneg) { return -0x80000000; /* or 0x80000000 */ return INT32_MIN; } else if (f >= limpos) { return 0x7fffffff; return INT32_MAX; } f *= scale; /* integer conversion is through truncation (though int to float is not). Loading Loading
media/codec2/core/include/C2Config.h +30 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -192,10 +193,9 @@ enum C2ParamIndexKind : C2Param::type_index_t { kParamIndexPictureType, // deprecated kParamIndexHdr10PlusMetadata, kParamIndexPictureQuantization, kParamIndexHdrDynamicMetadata, kParamIndexHdrFormat, /* ------------------------------------ video components ------------------------------------ */ Loading Loading @@ -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 ----------------------------------- */ /** Loading
media/codec2/sfplugin/CCodecConfig.cpp +24 −0 Original line number Diff line number Diff line Loading @@ -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")); Loading Loading @@ -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 Loading
media/codec2/sfplugin/utils/Codec2Mapper.cpp +51 −0 Original line number Diff line number Diff line Loading @@ -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 }, Loading Loading @@ -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 }, Loading Loading @@ -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 }, Loading Loading @@ -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 { Loading Loading @@ -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 { Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading @@ -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) { Loading
media/codec2/sfplugin/utils/Codec2Mapper.h +10 −0 Original line number Diff line number Diff line Loading @@ -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; }; Loading
media/libaaudio/src/flowgraph/FlowgraphUtilities.h +2 −2 Original line number Diff line number Diff line Loading @@ -39,9 +39,9 @@ static int32_t clamp32FromFloat(float f) static const float limneg = -1.; if (f <= limneg) { return -0x80000000; /* or 0x80000000 */ return INT32_MIN; } else if (f >= limpos) { return 0x7fffffff; return INT32_MAX; } f *= scale; /* integer conversion is through truncation (though int to float is not). Loading