Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "Codec2InfoBuilder" |
| 19 | #include <log/log.h> |
| 20 | |
| 21 | #include <strings.h> |
| 22 | |
Arun Johnson | 71cd000 | 2024-03-04 08:25:27 +0000 | [diff] [blame] | 23 | #include <com_android_media_codec_flags.h> |
Arun Johnson | abfac48 | 2024-02-22 07:17:20 +0000 | [diff] [blame] | 24 | #include <android_media_codec.h> |
| 25 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 26 | #include <C2Component.h> |
| 27 | #include <C2Config.h> |
| 28 | #include <C2Debug.h> |
| 29 | #include <C2PlatformSupport.h> |
| 30 | #include <Codec2Mapper.h> |
| 31 | |
| 32 | #include <OMX_Audio.h> |
| 33 | #include <OMX_AudioExt.h> |
| 34 | #include <OMX_IndexExt.h> |
| 35 | #include <OMX_Types.h> |
| 36 | #include <OMX_Video.h> |
| 37 | #include <OMX_VideoExt.h> |
| 38 | #include <OMX_AsString.h> |
Harish Mahendrakar | 2c0fc8f | 2022-05-24 15:48:34 -0700 | [diff] [blame] | 39 | #include <SurfaceFlingerProperties.sysprop.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 40 | |
| 41 | #include <android/hardware/media/omx/1.0/IOmx.h> |
| 42 | #include <android/hardware/media/omx/1.0/IOmxObserver.h> |
| 43 | #include <android/hardware/media/omx/1.0/IOmxNode.h> |
| 44 | #include <android/hardware/media/omx/1.0/types.h> |
| 45 | |
| 46 | #include <android-base/properties.h> |
| 47 | #include <codec2/hidl/client.h> |
| 48 | #include <cutils/native_handle.h> |
| 49 | #include <media/omx/1.0/WOmxNode.h> |
Pawin Vongmasa | 1f21336 | 2019-01-24 06:59:16 -0800 | [diff] [blame] | 50 | #include <media/stagefright/foundation/ALookup.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 51 | #include <media/stagefright/foundation/MediaDefs.h> |
| 52 | #include <media/stagefright/omx/OMXUtils.h> |
| 53 | #include <media/stagefright/xmlparser/MediaCodecsXmlParser.h> |
Wonsik Kim | 155d5cb | 2019-10-09 12:49:49 -0700 | [diff] [blame] | 54 | #include <media/stagefright/Codec2InfoBuilder.h> |
| 55 | #include <media/stagefright/MediaCodecConstants.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 56 | |
| 57 | namespace android { |
| 58 | |
| 59 | using Traits = C2Component::Traits; |
| 60 | |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 61 | // HAL pixel format -> framework color format |
| 62 | typedef std::map<uint32_t, int32_t> PixelFormatMap; |
| 63 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 64 | namespace /* unnamed */ { |
| 65 | |
| 66 | bool hasPrefix(const std::string& s, const char* prefix) { |
| 67 | size_t prefixLen = strlen(prefix); |
| 68 | return s.compare(0, prefixLen, prefix) == 0; |
| 69 | } |
| 70 | |
| 71 | bool hasSuffix(const std::string& s, const char* suffix) { |
| 72 | size_t suffixLen = strlen(suffix); |
| 73 | return suffixLen > s.size() ? false : |
| 74 | s.compare(s.size() - suffixLen, suffixLen, suffix) == 0; |
| 75 | } |
| 76 | |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 77 | std::optional<int32_t> findFrameworkColorFormat( |
| 78 | const C2FlexiblePixelFormatDescriptorStruct &desc) { |
| 79 | switch (desc.bitDepth) { |
| 80 | case 8u: |
| 81 | if (desc.layout == C2Color::PLANAR_PACKED |
| 82 | || desc.layout == C2Color::SEMIPLANAR_PACKED) { |
| 83 | return COLOR_FormatYUV420Flexible; |
| 84 | } |
| 85 | break; |
| 86 | case 10u: |
| 87 | if (desc.layout == C2Color::SEMIPLANAR_PACKED) { |
| 88 | return COLOR_FormatYUVP010; |
| 89 | } |
| 90 | break; |
| 91 | default: |
| 92 | break; |
| 93 | } |
| 94 | return std::nullopt; |
| 95 | } |
| 96 | |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 97 | // returns true if component advertised supported profile level(s) |
| 98 | bool addSupportedProfileLevels( |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 99 | std::shared_ptr<Codec2Client::Interface> intf, |
| 100 | MediaCodecInfo::CapabilitiesWriter *caps, |
| 101 | const Traits& trait, const std::string &mediaType) { |
| 102 | std::shared_ptr<C2Mapper::ProfileLevelMapper> mapper = |
| 103 | C2Mapper::GetProfileLevelMapper(trait.mediaType); |
| 104 | // if we don't know the media type, pass through all values unmapped |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 105 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 106 | // TODO: we cannot find levels that are local 'maxima' without knowing the coding |
| 107 | // e.g. H.263 level 45 and level 30 could be two values for highest level as |
| 108 | // they don't include one another. For now we use the last supported value. |
| 109 | bool encoder = trait.kind == C2Component::KIND_ENCODER; |
| 110 | C2StreamProfileLevelInfo pl(encoder /* output */, 0u); |
| 111 | std::vector<C2FieldSupportedValuesQuery> profileQuery = { |
| 112 | C2FieldSupportedValuesQuery::Possible(C2ParamField(&pl, &pl.profile)) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 115 | c2_status_t err = intf->querySupportedValues(profileQuery, C2_DONT_BLOCK); |
| 116 | ALOGV("query supported profiles -> %s | %s", asString(err), asString(profileQuery[0].status)); |
| 117 | if (err != C2_OK || profileQuery[0].status != C2_OK) { |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 118 | return false; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 121 | // we only handle enumerated values |
| 122 | if (profileQuery[0].values.type != C2FieldSupportedValues::VALUES) { |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 123 | return false; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Wonsik Kim | 4b7bb0a | 2021-11-03 11:43:48 -0700 | [diff] [blame] | 126 | // determine if codec supports HDR; imply 10-bit support |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 127 | bool supportsHdr = false; |
Wonsik Kim | 4b7bb0a | 2021-11-03 11:43:48 -0700 | [diff] [blame] | 128 | // determine if codec supports HDR10Plus; imply 10-bit support |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 129 | bool supportsHdr10Plus = false; |
Wonsik Kim | 4b7bb0a | 2021-11-03 11:43:48 -0700 | [diff] [blame] | 130 | // determine if codec supports 10-bit format |
| 131 | bool supports10Bit = false; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 132 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 133 | std::vector<std::shared_ptr<C2ParamDescriptor>> paramDescs; |
| 134 | c2_status_t err1 = intf->querySupportedParams(¶mDescs); |
| 135 | if (err1 == C2_OK) { |
| 136 | for (const std::shared_ptr<C2ParamDescriptor> &desc : paramDescs) { |
Lajos Molnar | 739fe73 | 2021-02-07 13:06:10 -0800 | [diff] [blame] | 137 | C2Param::Type type = desc->index(); |
| 138 | // only consider supported parameters on raw ports |
| 139 | if (!(encoder ? type.forInput() : type.forOutput())) { |
| 140 | continue; |
| 141 | } |
| 142 | switch (type.coreIndex()) { |
Taehwan Kim | 2d222b8 | 2022-05-12 14:19:26 +0900 | [diff] [blame] | 143 | case C2StreamHdrDynamicMetadataInfo::CORE_INDEX: |
| 144 | [[fallthrough]]; |
| 145 | case C2StreamHdr10PlusInfo::CORE_INDEX: // will be deprecated |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 146 | supportsHdr10Plus = true; |
| 147 | break; |
Lajos Molnar | 739fe73 | 2021-02-07 13:06:10 -0800 | [diff] [blame] | 148 | case C2StreamHdrStaticInfo::CORE_INDEX: |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 149 | supportsHdr = true; |
| 150 | break; |
| 151 | default: |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 152 | break; |
| 153 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Lajos Molnar | b857cde | 2022-05-25 10:20:37 -0700 | [diff] [blame] | 157 | // VP9 does not support HDR metadata in the bitstream and static metadata |
| 158 | // can always be carried by the framework. (The framework does not propagate |
| 159 | // dynamic metadata as that needs to be frame accurate.) |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 160 | supportsHdr |= (mediaType == MIMETYPE_VIDEO_VP9); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 161 | |
Wonsik Kim | a2d68d9 | 2022-06-23 14:56:51 -0700 | [diff] [blame] | 162 | // HDR support implies 10-bit support. AV1 codecs are also required to |
| 163 | // support 10-bit per CDD. |
Wonsik Kim | 4b7bb0a | 2021-11-03 11:43:48 -0700 | [diff] [blame] | 164 | // TODO: directly check this from the component interface |
Wonsik Kim | a2d68d9 | 2022-06-23 14:56:51 -0700 | [diff] [blame] | 165 | supports10Bit = (supportsHdr || supportsHdr10Plus) || (mediaType == MIMETYPE_VIDEO_AV1); |
Wonsik Kim | 4b7bb0a | 2021-11-03 11:43:48 -0700 | [diff] [blame] | 166 | |
Harish Mahendrakar | 2c0fc8f | 2022-05-24 15:48:34 -0700 | [diff] [blame] | 167 | // If the device doesn't support HDR display, then no codec on the device |
| 168 | // can advertise support for HDR profiles. |
| 169 | // Default to true to maintain backward compatibility |
| 170 | auto ret = sysprop::SurfaceFlingerProperties::has_HDR_display(); |
| 171 | bool hasHDRDisplay = ret.has_value() ? *ret : true; |
| 172 | |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 173 | bool added = false; |
| 174 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 175 | for (C2Value::Primitive profile : profileQuery[0].values.values) { |
| 176 | pl.profile = (C2Config::profile_t)profile.ref<uint32_t>(); |
| 177 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 178 | err = intf->config({&pl}, C2_DONT_BLOCK, &failures); |
| 179 | ALOGV("set profile to %u -> %s", pl.profile, asString(err)); |
| 180 | std::vector<C2FieldSupportedValuesQuery> levelQuery = { |
| 181 | C2FieldSupportedValuesQuery::Current(C2ParamField(&pl, &pl.level)) |
| 182 | }; |
| 183 | err = intf->querySupportedValues(levelQuery, C2_DONT_BLOCK); |
| 184 | ALOGV("query supported levels -> %s | %s", asString(err), asString(levelQuery[0].status)); |
| 185 | if (err != C2_OK || levelQuery[0].status != C2_OK |
| 186 | || levelQuery[0].values.type != C2FieldSupportedValues::VALUES |
| 187 | || levelQuery[0].values.values.size() == 0) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 188 | continue; |
| 189 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 190 | |
| 191 | C2Value::Primitive level = levelQuery[0].values.values.back(); |
| 192 | pl.level = (C2Config::level_t)level.ref<uint32_t>(); |
| 193 | ALOGV("supporting level: %u", pl.level); |
| 194 | int32_t sdkProfile, sdkLevel; |
| 195 | if (mapper && mapper->mapProfile(pl.profile, &sdkProfile) |
| 196 | && mapper->mapLevel(pl.level, &sdkLevel)) { |
| 197 | caps->addProfileLevel((uint32_t)sdkProfile, (uint32_t)sdkLevel); |
Harish Mahendrakar | 2c0fc8f | 2022-05-24 15:48:34 -0700 | [diff] [blame] | 198 | // also list HDR profiles if component supports HDR and device has HDR display |
| 199 | if (supportsHdr && hasHDRDisplay) { |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 200 | auto hdrMapper = C2Mapper::GetHdrProfileLevelMapper(trait.mediaType); |
| 201 | if (hdrMapper && hdrMapper->mapProfile(pl.profile, &sdkProfile)) { |
| 202 | caps->addProfileLevel((uint32_t)sdkProfile, (uint32_t)sdkLevel); |
| 203 | } |
| 204 | if (supportsHdr10Plus) { |
| 205 | hdrMapper = C2Mapper::GetHdrProfileLevelMapper( |
| 206 | trait.mediaType, true /*isHdr10Plus*/); |
| 207 | if (hdrMapper && hdrMapper->mapProfile(pl.profile, &sdkProfile)) { |
| 208 | caps->addProfileLevel((uint32_t)sdkProfile, (uint32_t)sdkLevel); |
| 209 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 210 | } |
| 211 | } |
Wonsik Kim | 4b7bb0a | 2021-11-03 11:43:48 -0700 | [diff] [blame] | 212 | if (supports10Bit) { |
| 213 | auto bitnessMapper = C2Mapper::GetBitDepthProfileLevelMapper(trait.mediaType, 10); |
| 214 | if (bitnessMapper && bitnessMapper->mapProfile(pl.profile, &sdkProfile)) { |
| 215 | caps->addProfileLevel((uint32_t)sdkProfile, (uint32_t)sdkLevel); |
| 216 | } |
| 217 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 218 | } else if (!mapper) { |
| 219 | caps->addProfileLevel(pl.profile, pl.level); |
| 220 | } |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 221 | added = true; |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 222 | |
| 223 | // for H.263 also advertise the second highest level if the |
| 224 | // codec supports level 45, as level 45 only covers level 10 |
| 225 | // TODO: move this to some form of a setting so it does not |
| 226 | // have to be here |
| 227 | if (mediaType == MIMETYPE_VIDEO_H263) { |
| 228 | C2Config::level_t nextLevel = C2Config::LEVEL_UNUSED; |
| 229 | for (C2Value::Primitive v : levelQuery[0].values.values) { |
| 230 | C2Config::level_t level = (C2Config::level_t)v.ref<uint32_t>(); |
| 231 | if (level < C2Config::LEVEL_H263_45 && level > nextLevel) { |
| 232 | nextLevel = level; |
| 233 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 234 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 235 | if (nextLevel != C2Config::LEVEL_UNUSED |
| 236 | && nextLevel != pl.level |
| 237 | && mapper |
| 238 | && mapper->mapProfile(pl.profile, &sdkProfile) |
| 239 | && mapper->mapLevel(nextLevel, &sdkLevel)) { |
| 240 | caps->addProfileLevel( |
| 241 | (uint32_t)sdkProfile, (uint32_t)sdkLevel); |
| 242 | } |
| 243 | } |
| 244 | } |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 245 | return added; |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void addSupportedColorFormats( |
| 249 | std::shared_ptr<Codec2Client::Interface> intf, |
| 250 | MediaCodecInfo::CapabilitiesWriter *caps, |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 251 | const Traits& trait, const std::string &mediaType, |
| 252 | const PixelFormatMap &pixelFormatMap) { |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 253 | // TODO: get this from intf() as well, but how do we map them to |
| 254 | // MediaCodec color formats? |
| 255 | bool encoder = trait.kind == C2Component::KIND_ENCODER; |
Wonsik Kim | 1622326 | 2019-06-14 14:40:57 -0700 | [diff] [blame] | 256 | if (mediaType.find("video") != std::string::npos |
| 257 | || mediaType.find("image") != std::string::npos) { |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 258 | |
| 259 | std::vector<C2FieldSupportedValuesQuery> query; |
| 260 | if (encoder) { |
| 261 | C2StreamPixelFormatInfo::input pixelFormat; |
| 262 | query.push_back(C2FieldSupportedValuesQuery::Possible( |
| 263 | C2ParamField::Make(pixelFormat, pixelFormat.value))); |
| 264 | } else { |
| 265 | C2StreamPixelFormatInfo::output pixelFormat; |
| 266 | query.push_back(C2FieldSupportedValuesQuery::Possible( |
| 267 | C2ParamField::Make(pixelFormat, pixelFormat.value))); |
| 268 | } |
| 269 | std::list<int32_t> supportedColorFormats; |
| 270 | if (intf->querySupportedValues(query, C2_DONT_BLOCK) == C2_OK) { |
| 271 | if (query[0].status == C2_OK) { |
| 272 | const C2FieldSupportedValues &fsv = query[0].values; |
| 273 | if (fsv.type == C2FieldSupportedValues::VALUES) { |
| 274 | for (C2Value::Primitive value : fsv.values) { |
| 275 | auto it = pixelFormatMap.find(value.u32); |
| 276 | if (it != pixelFormatMap.end()) { |
| 277 | auto it2 = std::find( |
| 278 | supportedColorFormats.begin(), |
| 279 | supportedColorFormats.end(), |
| 280 | it->second); |
| 281 | if (it2 == supportedColorFormats.end()) { |
| 282 | supportedColorFormats.push_back(it->second); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | auto addDefaultColorFormat = [caps, &supportedColorFormats](int32_t colorFormat) { |
| 290 | caps->addColorFormat(colorFormat); |
| 291 | auto it = std::find( |
| 292 | supportedColorFormats.begin(), supportedColorFormats.end(), colorFormat); |
| 293 | if (it != supportedColorFormats.end()) { |
| 294 | supportedColorFormats.erase(it); |
| 295 | } |
| 296 | }; |
| 297 | |
My Name | 298764f | 2022-03-25 15:07:51 -0700 | [diff] [blame] | 298 | // The color format is ordered by preference. The intention here is to advertise: |
| 299 | // c2.android.* codecs: YUV420s, Surface, <the rest> |
| 300 | // all other codecs: Surface, YUV420s, <the rest> |
| 301 | // TODO: get this preference via Codec2 API |
| 302 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 303 | // vendor video codecs prefer opaque format |
| 304 | if (trait.name.find("android") == std::string::npos) { |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 305 | addDefaultColorFormat(COLOR_FormatSurface); |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 306 | } |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 307 | addDefaultColorFormat(COLOR_FormatYUV420Flexible); |
| 308 | addDefaultColorFormat(COLOR_FormatYUV420Planar); |
| 309 | addDefaultColorFormat(COLOR_FormatYUV420SemiPlanar); |
| 310 | addDefaultColorFormat(COLOR_FormatYUV420PackedPlanar); |
| 311 | addDefaultColorFormat(COLOR_FormatYUV420PackedSemiPlanar); |
My Name | 298764f | 2022-03-25 15:07:51 -0700 | [diff] [blame] | 312 | // Android video codecs prefer CPU-readable formats |
| 313 | if (trait.name.find("android") != std::string::npos) { |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 314 | addDefaultColorFormat(COLOR_FormatSurface); |
| 315 | } |
Wonsik Kim | 1e16eb3 | 2022-06-03 16:32:19 -0700 | [diff] [blame] | 316 | |
| 317 | static const int kVendorSdkVersion = ::android::base::GetIntProperty( |
| 318 | "ro.vendor.build.version.sdk", android_get_device_api_level()); |
| 319 | if (kVendorSdkVersion >= __ANDROID_API_T__) { |
| 320 | for (int32_t colorFormat : supportedColorFormats) { |
| 321 | caps->addColorFormat(colorFormat); |
| 322 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 327 | class Switch { |
| 328 | enum Flags : uint8_t { |
| 329 | // flags |
| 330 | IS_ENABLED = (1 << 0), |
| 331 | BY_DEFAULT = (1 << 1), |
| 332 | }; |
| 333 | |
| 334 | constexpr Switch(uint8_t flags) : mFlags(flags) {} |
| 335 | |
| 336 | uint8_t mFlags; |
| 337 | |
| 338 | public: |
| 339 | // have to create class due to this bool conversion operator... |
| 340 | constexpr operator bool() const { |
| 341 | return mFlags & IS_ENABLED; |
| 342 | } |
| 343 | |
| 344 | constexpr Switch operator!() const { |
| 345 | return Switch(mFlags ^ IS_ENABLED); |
| 346 | } |
| 347 | |
| 348 | static constexpr Switch DISABLED() { return 0; }; |
| 349 | static constexpr Switch ENABLED() { return IS_ENABLED; }; |
| 350 | static constexpr Switch DISABLED_BY_DEFAULT() { return BY_DEFAULT; }; |
| 351 | static constexpr Switch ENABLED_BY_DEFAULT() { return IS_ENABLED | BY_DEFAULT; }; |
| 352 | |
| 353 | const char *toString(const char *def = "??") const { |
| 354 | switch (mFlags) { |
| 355 | case 0: return "0"; |
| 356 | case IS_ENABLED: return "1"; |
| 357 | case BY_DEFAULT: return "(0)"; |
| 358 | case IS_ENABLED | BY_DEFAULT: return "(1)"; |
| 359 | default: return def; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | }; |
| 364 | |
| 365 | const char *asString(const Switch &s, const char *def = "??") { |
| 366 | return s.toString(def); |
| 367 | } |
| 368 | |
| 369 | Switch isSettingEnabled( |
| 370 | std::string setting, const MediaCodecsXmlParser::AttributeMap &settings, |
| 371 | Switch def = Switch::DISABLED_BY_DEFAULT()) { |
| 372 | const auto enablement = settings.find(setting); |
| 373 | if (enablement == settings.end()) { |
| 374 | return def; |
| 375 | } |
| 376 | return enablement->second == "1" ? Switch::ENABLED() : Switch::DISABLED(); |
| 377 | } |
| 378 | |
| 379 | Switch isVariantEnabled( |
| 380 | std::string variant, const MediaCodecsXmlParser::AttributeMap &settings) { |
| 381 | return isSettingEnabled("variant-" + variant, settings); |
| 382 | } |
| 383 | |
| 384 | Switch isVariantExpressionEnabled( |
| 385 | std::string exp, const MediaCodecsXmlParser::AttributeMap &settings) { |
| 386 | if (!exp.empty() && exp.at(0) == '!') { |
| 387 | return !isVariantEnabled(exp.substr(1, exp.size() - 1), settings); |
| 388 | } |
| 389 | return isVariantEnabled(exp, settings); |
| 390 | } |
| 391 | |
| 392 | Switch isDomainEnabled( |
| 393 | std::string domain, const MediaCodecsXmlParser::AttributeMap &settings) { |
| 394 | return isSettingEnabled("domain-" + domain, settings); |
| 395 | } |
| 396 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 397 | } // unnamed namespace |
| 398 | |
| 399 | status_t Codec2InfoBuilder::buildMediaCodecList(MediaCodecListWriter* writer) { |
| 400 | // TODO: Remove run-time configurations once all codecs are working |
| 401 | // properly. (Assume "full" behavior eventually.) |
| 402 | // |
| 403 | // debug.stagefright.ccodec supports 5 values. |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 404 | // 0 - No Codec 2.0 components are available. |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 405 | // 1 - Audio decoders and encoders with prefix "c2.android." are available |
| 406 | // and ranked first. |
| 407 | // All other components with prefix "c2.android." are available with |
| 408 | // their normal ranks. |
| 409 | // Components with prefix "c2.vda." are available with their normal |
| 410 | // ranks. |
| 411 | // All other components with suffix ".avc.decoder" or ".avc.encoder" |
| 412 | // are available but ranked last. |
| 413 | // 2 - Components with prefix "c2.android." are available and ranked |
| 414 | // first. |
| 415 | // Components with prefix "c2.vda." are available with their normal |
| 416 | // ranks. |
| 417 | // All other components with suffix ".avc.decoder" or ".avc.encoder" |
| 418 | // are available but ranked last. |
| 419 | // 3 - Components with prefix "c2.android." are available and ranked |
| 420 | // first. |
| 421 | // All other components are available with their normal ranks. |
| 422 | // 4 - All components are available with their normal ranks. |
| 423 | // |
| 424 | // The default value (boot time) is 1. |
| 425 | // |
| 426 | // Note: Currently, OMX components have default rank 0x100, while all |
| 427 | // Codec2.0 software components have default rank 0x200. |
Lajos Molnar | 8635fc8 | 2019-05-17 17:35:10 +0000 | [diff] [blame] | 428 | int option = ::android::base::GetIntProperty("debug.stagefright.ccodec", 4); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 429 | |
| 430 | // Obtain Codec2Client |
| 431 | std::vector<Traits> traits = Codec2Client::ListComponents(); |
| 432 | |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 433 | // parse APEX XML first, followed by vendor XML. |
| 434 | // Note: APEX XML names do not depend on ro.media.xml_variant.* properties. |
Lajos Molnar | da66689 | 2019-04-08 17:25:34 -0700 | [diff] [blame] | 435 | MediaCodecsXmlParser parser; |
| 436 | parser.parseXmlFilesInSearchDirs( |
Pawin Vongmasa | 7f5e10e | 2020-03-07 04:09:55 -0800 | [diff] [blame] | 437 | { "media_codecs.xml", "media_codecs_performance.xml" }, |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 438 | { "/apex/com.android.media.swcodec/etc" }); |
| 439 | |
| 440 | // TODO: remove these c2-specific files once product moved to default file names |
| 441 | parser.parseXmlFilesInSearchDirs( |
Lajos Molnar | da66689 | 2019-04-08 17:25:34 -0700 | [diff] [blame] | 442 | { "media_codecs_c2.xml", "media_codecs_performance_c2.xml" }); |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 443 | |
| 444 | // parse default XML files |
| 445 | parser.parseXmlFilesInSearchDirs(); |
| 446 | |
Ray Essick | 8c4e9c7 | 2021-03-15 15:25:21 -0700 | [diff] [blame] | 447 | // The mainline modules for media may optionally include some codec shaping information. |
| 448 | // Based on vendor partition SDK, and the brand/product/device information |
| 449 | // (expect to be empty in almost always) |
| 450 | // |
| 451 | { |
| 452 | // get build info so we know what file to search |
| 453 | // ro.vendor.build.fingerprint |
| 454 | std::string fingerprint = base::GetProperty("ro.vendor.build.fingerprint", |
| 455 | "brand/product/device:"); |
| 456 | ALOGV("property_get for ro.vendor.build.fingerprint == '%s'", fingerprint.c_str()); |
| 457 | |
| 458 | // ro.vendor.build.version.sdk |
| 459 | std::string sdk = base::GetProperty("ro.vendor.build.version.sdk", "0"); |
| 460 | ALOGV("property_get for ro.vendor.build.version.sdk == '%s'", sdk.c_str()); |
| 461 | |
| 462 | std::string brand; |
| 463 | std::string product; |
| 464 | std::string device; |
| 465 | size_t pos1; |
| 466 | pos1 = fingerprint.find('/'); |
| 467 | if (pos1 != std::string::npos) { |
| 468 | brand = fingerprint.substr(0, pos1); |
| 469 | size_t pos2 = fingerprint.find('/', pos1+1); |
| 470 | if (pos2 != std::string::npos) { |
| 471 | product = fingerprint.substr(pos1+1, pos2 - pos1 - 1); |
| 472 | size_t pos3 = fingerprint.find('/', pos2+1); |
| 473 | if (pos3 != std::string::npos) { |
| 474 | device = fingerprint.substr(pos2+1, pos3 - pos2 - 1); |
| 475 | size_t pos4 = device.find(':'); |
| 476 | if (pos4 != std::string::npos) { |
| 477 | device.resize(pos4); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | ALOGV("parsed: sdk '%s' brand '%s' product '%s' device '%s'", |
| 484 | sdk.c_str(), brand.c_str(), product.c_str(), device.c_str()); |
| 485 | |
| 486 | std::string base = "/apex/com.android.media/etc/formatshaper"; |
| 487 | |
| 488 | // looking in these directories within the apex |
| 489 | const std::vector<std::string> modulePathnames = { |
| 490 | base + "/" + sdk + "/" + brand + "/" + product + "/" + device, |
| 491 | base + "/" + sdk + "/" + brand + "/" + product, |
| 492 | base + "/" + sdk + "/" + brand, |
| 493 | base + "/" + sdk, |
| 494 | base |
| 495 | }; |
| 496 | |
| 497 | parser.parseXmlFilesInSearchDirs( { "media_codecs_shaping.xml" }, modulePathnames); |
| 498 | } |
| 499 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 500 | if (parser.getParsingStatus() != OK) { |
| 501 | ALOGD("XML parser no good"); |
| 502 | return OK; |
| 503 | } |
| 504 | |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 505 | MediaCodecsXmlParser::AttributeMap settings = parser.getServiceAttributeMap(); |
| 506 | for (const auto &v : settings) { |
| 507 | if (!hasPrefix(v.first, "media-type-") |
| 508 | && !hasPrefix(v.first, "domain-") |
| 509 | && !hasPrefix(v.first, "variant-")) { |
| 510 | writer->addGlobalSetting(v.first.c_str(), v.second.c_str()); |
| 511 | } |
| 512 | } |
| 513 | |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 514 | std::map<std::string, PixelFormatMap> nameToPixelFormatMap; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 515 | for (const Traits& trait : traits) { |
| 516 | C2Component::rank_t rank = trait.rank; |
| 517 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 518 | // Interface must be accessible for us to list the component, and there also |
| 519 | // must be an XML entry for the codec. Codec aliases listed in the traits |
| 520 | // allow additional XML entries to be specified for each alias. These will |
| 521 | // be listed as separate codecs. If no XML entry is specified for an alias, |
| 522 | // those will be treated as an additional alias specified in the XML entry |
| 523 | // for the interface name. |
| 524 | std::vector<std::string> nameAndAliases = trait.aliases; |
| 525 | nameAndAliases.insert(nameAndAliases.begin(), trait.name); |
| 526 | for (const std::string &nameOrAlias : nameAndAliases) { |
| 527 | bool isAlias = trait.name != nameOrAlias; |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 528 | std::shared_ptr<Codec2Client> client; |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 529 | std::shared_ptr<Codec2Client::Interface> intf = |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 530 | Codec2Client::CreateInterfaceByName(nameOrAlias.c_str(), &client); |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 531 | if (!intf) { |
| 532 | ALOGD("could not create interface for %s'%s'", |
| 533 | isAlias ? "alias " : "", |
| 534 | nameOrAlias.c_str()); |
| 535 | continue; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 536 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 537 | if (parser.getCodecMap().count(nameOrAlias) == 0) { |
| 538 | if (isAlias) { |
| 539 | std::unique_ptr<MediaCodecInfoWriter> baseCodecInfo = |
| 540 | writer->findMediaCodecInfo(trait.name.c_str()); |
| 541 | if (!baseCodecInfo) { |
| 542 | ALOGD("alias '%s' not found in xml but canonical codec info '%s' missing", |
| 543 | nameOrAlias.c_str(), |
| 544 | trait.name.c_str()); |
| 545 | } else { |
| 546 | ALOGD("alias '%s' not found in xml; use an XML <Alias> tag for this", |
| 547 | nameOrAlias.c_str()); |
| 548 | // merge alias into existing codec |
| 549 | baseCodecInfo->addAlias(nameOrAlias.c_str()); |
| 550 | } |
| 551 | } else { |
| 552 | ALOGD("component '%s' not found in xml", trait.name.c_str()); |
| 553 | } |
| 554 | continue; |
| 555 | } |
| 556 | std::string canonName = trait.name; |
| 557 | |
| 558 | // TODO: Remove this block once all codecs are enabled by default. |
| 559 | switch (option) { |
| 560 | case 0: |
| 561 | continue; |
| 562 | case 1: |
| 563 | if (hasPrefix(canonName, "c2.vda.")) { |
| 564 | break; |
| 565 | } |
| 566 | if (hasPrefix(canonName, "c2.android.")) { |
| 567 | if (trait.domain == C2Component::DOMAIN_AUDIO) { |
| 568 | rank = 1; |
| 569 | break; |
| 570 | } |
| 571 | break; |
| 572 | } |
| 573 | if (hasSuffix(canonName, ".avc.decoder") || |
| 574 | hasSuffix(canonName, ".avc.encoder")) { |
| 575 | rank = std::numeric_limits<decltype(rank)>::max(); |
| 576 | break; |
| 577 | } |
| 578 | continue; |
| 579 | case 2: |
| 580 | if (hasPrefix(canonName, "c2.vda.")) { |
| 581 | break; |
| 582 | } |
| 583 | if (hasPrefix(canonName, "c2.android.")) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 584 | rank = 1; |
| 585 | break; |
| 586 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 587 | if (hasSuffix(canonName, ".avc.decoder") || |
| 588 | hasSuffix(canonName, ".avc.encoder")) { |
| 589 | rank = std::numeric_limits<decltype(rank)>::max(); |
| 590 | break; |
| 591 | } |
| 592 | continue; |
| 593 | case 3: |
| 594 | if (hasPrefix(canonName, "c2.android.")) { |
| 595 | rank = 1; |
| 596 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 597 | break; |
| 598 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 599 | |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 600 | const MediaCodecsXmlParser::CodecProperties &codec = |
| 601 | parser.getCodecMap().at(nameOrAlias); |
| 602 | |
| 603 | // verify that either the codec is explicitly enabled, or one of its domains is |
| 604 | bool codecEnabled = codec.quirkSet.find("attribute::disabled") == codec.quirkSet.end(); |
| 605 | if (!codecEnabled) { |
| 606 | for (const std::string &domain : codec.domainSet) { |
| 607 | const Switch enabled = isDomainEnabled(domain, settings); |
| 608 | ALOGV("codec entry '%s' is in domain '%s' that is '%s'", |
| 609 | nameOrAlias.c_str(), domain.c_str(), asString(enabled)); |
| 610 | if (enabled) { |
| 611 | codecEnabled = true; |
| 612 | break; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | // if codec has variants, also check that at least one of them is enabled |
| 617 | bool variantEnabled = codec.variantSet.empty(); |
| 618 | for (const std::string &variant : codec.variantSet) { |
| 619 | const Switch enabled = isVariantExpressionEnabled(variant, settings); |
| 620 | ALOGV("codec entry '%s' has a variant '%s' that is '%s'", |
| 621 | nameOrAlias.c_str(), variant.c_str(), asString(enabled)); |
| 622 | if (enabled) { |
| 623 | variantEnabled = true; |
| 624 | break; |
| 625 | } |
| 626 | } |
| 627 | if (!codecEnabled || !variantEnabled) { |
| 628 | ALOGD("codec entry for '%s' is disabled", nameOrAlias.c_str()); |
| 629 | continue; |
| 630 | } |
| 631 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 632 | ALOGV("adding codec entry for '%s'", nameOrAlias.c_str()); |
| 633 | std::unique_ptr<MediaCodecInfoWriter> codecInfo = writer->addMediaCodecInfo(); |
| 634 | codecInfo->setName(nameOrAlias.c_str()); |
| 635 | codecInfo->setOwner(("codec2::" + trait.owner).c_str()); |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 636 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 637 | bool encoder = trait.kind == C2Component::KIND_ENCODER; |
| 638 | typename std::underlying_type<MediaCodecInfo::Attributes>::type attrs = 0; |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 639 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 640 | if (encoder) { |
| 641 | attrs |= MediaCodecInfo::kFlagIsEncoder; |
| 642 | } |
| 643 | if (trait.owner == "software") { |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 644 | attrs |= MediaCodecInfo::kFlagIsSoftwareOnly; |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 645 | } else { |
| 646 | attrs |= MediaCodecInfo::kFlagIsVendor; |
| 647 | if (trait.owner == "vendor-software") { |
| 648 | attrs |= MediaCodecInfo::kFlagIsSoftwareOnly; |
| 649 | } else if (codec.quirkSet.find("attribute::software-codec") |
| 650 | == codec.quirkSet.end()) { |
| 651 | attrs |= MediaCodecInfo::kFlagIsHardwareAccelerated; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 652 | } |
| 653 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 654 | codecInfo->setAttributes(attrs); |
| 655 | if (!codec.rank.empty()) { |
| 656 | uint32_t xmlRank; |
| 657 | char dummy; |
| 658 | if (sscanf(codec.rank.c_str(), "%u%c", &xmlRank, &dummy) == 1) { |
| 659 | rank = xmlRank; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 660 | } |
| 661 | } |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 662 | ALOGV("rank: %u", (unsigned)rank); |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 663 | codecInfo->setRank(rank); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 664 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 665 | for (const std::string &alias : codec.aliases) { |
| 666 | ALOGV("adding alias '%s'", alias.c_str()); |
| 667 | codecInfo->addAlias(alias.c_str()); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 670 | for (auto typeIt = codec.typeMap.begin(); typeIt != codec.typeMap.end(); ++typeIt) { |
| 671 | const std::string &mediaType = typeIt->first; |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 672 | const Switch typeEnabled = isSettingEnabled( |
| 673 | "media-type-" + mediaType, settings, Switch::ENABLED_BY_DEFAULT()); |
| 674 | const Switch domainTypeEnabled = isSettingEnabled( |
| 675 | "media-type-" + mediaType + (encoder ? "-encoder" : "-decoder"), |
| 676 | settings, Switch::ENABLED_BY_DEFAULT()); |
| 677 | ALOGV("type '%s-%s' is '%s/%s'", |
| 678 | mediaType.c_str(), (encoder ? "encoder" : "decoder"), |
| 679 | asString(typeEnabled), asString(domainTypeEnabled)); |
| 680 | if (!typeEnabled || !domainTypeEnabled) { |
| 681 | ALOGD("media type '%s' for codec entry '%s' is disabled", mediaType.c_str(), |
| 682 | nameOrAlias.c_str()); |
| 683 | continue; |
| 684 | } |
| 685 | |
| 686 | ALOGI("adding type '%s'", typeIt->first.c_str()); |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 687 | const MediaCodecsXmlParser::AttributeMap &attrMap = typeIt->second; |
| 688 | std::unique_ptr<MediaCodecInfo::CapabilitiesWriter> caps = |
| 689 | codecInfo->addMediaType(mediaType.c_str()); |
Lajos Molnar | 424cfb5 | 2019-04-08 17:48:00 -0700 | [diff] [blame] | 690 | for (const auto &v : attrMap) { |
| 691 | std::string key = v.first; |
| 692 | std::string value = v.second; |
| 693 | |
| 694 | size_t variantSep = key.find(":::"); |
| 695 | if (variantSep != std::string::npos) { |
| 696 | std::string variant = key.substr(0, variantSep); |
| 697 | const Switch enabled = isVariantExpressionEnabled(variant, settings); |
| 698 | ALOGV("variant '%s' is '%s'", variant.c_str(), asString(enabled)); |
| 699 | if (!enabled) { |
| 700 | continue; |
| 701 | } |
| 702 | key = key.substr(variantSep + 3); |
| 703 | } |
| 704 | |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 705 | if (key.find("feature-") == 0 && key.find("feature-bitrate-modes") != 0) { |
| 706 | int32_t intValue = 0; |
| 707 | // Ignore trailing bad characters and default to 0. |
| 708 | (void)sscanf(value.c_str(), "%d", &intValue); |
| 709 | caps->addDetail(key.c_str(), intValue); |
| 710 | } else { |
| 711 | caps->addDetail(key.c_str(), value.c_str()); |
| 712 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 713 | } |
Lajos Molnar | db5751f | 2019-01-31 17:01:49 -0800 | [diff] [blame] | 714 | |
Lajos Molnar | 59f4a4e | 2021-07-09 18:23:54 -0700 | [diff] [blame] | 715 | if (!addSupportedProfileLevels(intf, caps.get(), trait, mediaType)) { |
| 716 | // TODO(b/193279646) This will get fixed in C2InterfaceHelper |
| 717 | // Some components may not advertise supported values if they use a const |
| 718 | // param for profile/level (they support only one profile). For now cover |
| 719 | // only VP8 here until it is fixed. |
| 720 | if (mediaType == MIMETYPE_VIDEO_VP8) { |
| 721 | caps->addProfileLevel(VP8ProfileMain, VP8Level_Version0); |
| 722 | } |
| 723 | } |
Wonsik Kim | f87cbc4 | 2022-01-24 09:49:12 -0800 | [diff] [blame] | 724 | |
| 725 | auto it = nameToPixelFormatMap.find(client->getServiceName()); |
| 726 | if (it == nameToPixelFormatMap.end()) { |
| 727 | it = nameToPixelFormatMap.try_emplace(client->getServiceName()).first; |
| 728 | PixelFormatMap &pixelFormatMap = it->second; |
| 729 | pixelFormatMap[HAL_PIXEL_FORMAT_YCBCR_420_888] = COLOR_FormatYUV420Flexible; |
| 730 | pixelFormatMap[HAL_PIXEL_FORMAT_YCBCR_P010] = COLOR_FormatYUVP010; |
| 731 | pixelFormatMap[HAL_PIXEL_FORMAT_RGBA_1010102] = COLOR_Format32bitABGR2101010; |
| 732 | pixelFormatMap[HAL_PIXEL_FORMAT_RGBA_FP16] = COLOR_Format64bitABGRFloat; |
| 733 | |
| 734 | std::shared_ptr<C2StoreFlexiblePixelFormatDescriptorsInfo> pixelFormatInfo; |
| 735 | std::vector<std::unique_ptr<C2Param>> heapParams; |
| 736 | if (client->query( |
| 737 | {}, |
| 738 | {C2StoreFlexiblePixelFormatDescriptorsInfo::PARAM_TYPE}, |
| 739 | C2_MAY_BLOCK, |
| 740 | &heapParams) == C2_OK |
| 741 | && heapParams.size() == 1u) { |
| 742 | pixelFormatInfo.reset(C2StoreFlexiblePixelFormatDescriptorsInfo::From( |
| 743 | heapParams[0].release())); |
| 744 | } |
| 745 | if (pixelFormatInfo && *pixelFormatInfo) { |
| 746 | for (size_t i = 0; i < pixelFormatInfo->flexCount(); ++i) { |
| 747 | C2FlexiblePixelFormatDescriptorStruct &desc = |
| 748 | pixelFormatInfo->m.values[i]; |
| 749 | std::optional<int32_t> colorFormat = findFrameworkColorFormat(desc); |
| 750 | if (colorFormat) { |
| 751 | pixelFormatMap[desc.pixelFormat] = *colorFormat; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | addSupportedColorFormats( |
| 757 | intf, caps.get(), trait, mediaType, it->second); |
Arun Johnson | abfac48 | 2024-02-22 07:17:20 +0000 | [diff] [blame] | 758 | |
Arun Johnson | 71cd000 | 2024-03-04 08:25:27 +0000 | [diff] [blame] | 759 | if (com::android::media::codec::flags::provider_->large_audio_frame() |
| 760 | && android::media::codec::provider_->large_audio_frame_finish()) { |
Arun Johnson | abfac48 | 2024-02-22 07:17:20 +0000 | [diff] [blame] | 761 | // Adding feature-multiple-frames when C2LargeFrame param is present |
| 762 | if (trait.domain == C2Component::DOMAIN_AUDIO) { |
| 763 | std::vector<std::shared_ptr<C2ParamDescriptor>> params; |
| 764 | c2_status_t err = intf->querySupportedParams(¶ms); |
| 765 | if (err == C2_OK) { |
| 766 | for (const auto ¶mDesc : params) { |
| 767 | if (C2LargeFrame::output::PARAM_TYPE == paramDesc->index()) { |
| 768 | std::string featureMultipleFrames = |
| 769 | std::string(KEY_FEATURE_) + FEATURE_MultipleFrames; |
| 770 | caps->addDetail(featureMultipleFrames.c_str(), 0); |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | } |
| 780 | return OK; |
| 781 | } |
| 782 | |
| 783 | } // namespace android |
| 784 | |
| 785 | extern "C" android::MediaCodecListBuilderBase *CreateBuilder() { |
| 786 | return new android::Codec2InfoBuilder; |
| 787 | } |