Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014, 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 "MediaCodecInfo" |
| 19 | #include <utils/Log.h> |
| 20 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 21 | #include <media/MediaCodecInfo.h> |
| 22 | |
| 23 | #include <media/stagefright/foundation/ADebug.h> |
| 24 | #include <media/stagefright/foundation/AMessage.h> |
| 25 | #include <binder/Parcel.h> |
| 26 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 29 | // initialize max supported instances with default value. |
| 30 | int32_t MediaCodecInfo::sMaxSupportedInstances = 0; |
| 31 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 32 | /** This redundant redeclaration is needed for C++ pre 14 */ |
| 33 | constexpr char MediaCodecInfo::Capabilities::FEATURE_ADAPTIVE_PLAYBACK[]; |
| 34 | constexpr char MediaCodecInfo::Capabilities::FEATURE_DYNAMIC_TIMESTAMP[]; |
| 35 | constexpr char MediaCodecInfo::Capabilities::FEATURE_FRAME_PARSING[]; |
| 36 | constexpr char MediaCodecInfo::Capabilities::FEATURE_INTRA_REFRESH[]; |
| 37 | constexpr char MediaCodecInfo::Capabilities::FEATURE_MULTIPLE_FRAMES[]; |
| 38 | constexpr char MediaCodecInfo::Capabilities::FEATURE_SECURE_PLAYBACK[]; |
| 39 | constexpr char MediaCodecInfo::Capabilities::FEATURE_TUNNELED_PLAYBACK[]; |
Lajos Molnar | d55f06f | 2024-04-01 14:49:28 -0700 | [diff] [blame] | 40 | constexpr char MediaCodecInfo::Capabilities::FEATURE_DETACHED_SURFACE[]; |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 41 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 42 | void MediaCodecInfo::Capabilities::getSupportedProfileLevels( |
| 43 | Vector<ProfileLevel> *profileLevels) const { |
| 44 | profileLevels->clear(); |
| 45 | profileLevels->appendVector(mProfileLevels); |
| 46 | } |
| 47 | |
| 48 | void MediaCodecInfo::Capabilities::getSupportedColorFormats( |
| 49 | Vector<uint32_t> *colorFormats) const { |
| 50 | colorFormats->clear(); |
| 51 | colorFormats->appendVector(mColorFormats); |
| 52 | } |
| 53 | |
Lajos Molnar | 2461e0c | 2014-08-12 08:55:25 -0700 | [diff] [blame] | 54 | const sp<AMessage> MediaCodecInfo::Capabilities::getDetails() const { |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 55 | return mDetails; |
| 56 | } |
| 57 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 58 | MediaCodecInfo::Capabilities::Capabilities() { |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 59 | mDetails = new AMessage; |
| 60 | } |
| 61 | |
| 62 | // static |
| 63 | sp<MediaCodecInfo::Capabilities> MediaCodecInfo::Capabilities::FromParcel( |
| 64 | const Parcel &parcel) { |
| 65 | sp<MediaCodecInfo::Capabilities> caps = new Capabilities(); |
| 66 | size_t size = static_cast<size_t>(parcel.readInt32()); |
| 67 | for (size_t i = 0; i < size; i++) { |
| 68 | ProfileLevel profileLevel; |
| 69 | profileLevel.mProfile = static_cast<uint32_t>(parcel.readInt32()); |
| 70 | profileLevel.mLevel = static_cast<uint32_t>(parcel.readInt32()); |
| 71 | if (caps != NULL) { |
| 72 | caps->mProfileLevels.push_back(profileLevel); |
| 73 | } |
| 74 | } |
| 75 | size = static_cast<size_t>(parcel.readInt32()); |
| 76 | for (size_t i = 0; i < size; i++) { |
| 77 | uint32_t color = static_cast<uint32_t>(parcel.readInt32()); |
| 78 | if (caps != NULL) { |
| 79 | caps->mColorFormats.push_back(color); |
| 80 | } |
| 81 | } |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 82 | sp<AMessage> details = AMessage::FromParcel(parcel); |
Pawin Vongmasa | 8dab1730 | 2016-05-02 16:08:39 -0700 | [diff] [blame] | 83 | if (details == NULL) |
| 84 | return NULL; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 85 | if (caps != NULL) { |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 86 | caps->mDetails = details; |
| 87 | } |
| 88 | return caps; |
| 89 | } |
| 90 | |
| 91 | status_t MediaCodecInfo::Capabilities::writeToParcel(Parcel *parcel) const { |
Colin Cross | b8c35f9 | 2017-04-27 16:15:51 -0700 | [diff] [blame] | 92 | CHECK_LE(mProfileLevels.size(), static_cast<size_t>(INT32_MAX)); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 93 | parcel->writeInt32(mProfileLevels.size()); |
| 94 | for (size_t i = 0; i < mProfileLevels.size(); i++) { |
| 95 | parcel->writeInt32(mProfileLevels.itemAt(i).mProfile); |
| 96 | parcel->writeInt32(mProfileLevels.itemAt(i).mLevel); |
| 97 | } |
Colin Cross | b8c35f9 | 2017-04-27 16:15:51 -0700 | [diff] [blame] | 98 | CHECK_LE(mColorFormats.size(), static_cast<size_t>(INT32_MAX)); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 99 | parcel->writeInt32(mColorFormats.size()); |
| 100 | for (size_t i = 0; i < mColorFormats.size(); i++) { |
| 101 | parcel->writeInt32(mColorFormats.itemAt(i)); |
| 102 | } |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 103 | mDetails->writeToParcel(parcel); |
| 104 | return OK; |
| 105 | } |
| 106 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 107 | void MediaCodecInfo::CapabilitiesWriter::addDetail( |
| 108 | const char* key, const char* value) { |
| 109 | mCap->mDetails->setString(key, value); |
| 110 | } |
| 111 | |
| 112 | void MediaCodecInfo::CapabilitiesWriter::addDetail( |
| 113 | const char* key, int32_t value) { |
| 114 | mCap->mDetails->setInt32(key, value); |
| 115 | } |
| 116 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 117 | void MediaCodecInfo::CapabilitiesWriter::removeDetail(const char* key) { |
| 118 | if (mCap->mDetails->removeEntryAt(mCap->mDetails->findEntryByName(key)) == OK) { |
| 119 | ALOGD("successfully removed detail %s", key); |
| 120 | } else { |
| 121 | ALOGD("detail %s wasn't present to remove", key); |
| 122 | } |
| 123 | } |
| 124 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 125 | void MediaCodecInfo::CapabilitiesWriter::addProfileLevel( |
| 126 | uint32_t profile, uint32_t level) { |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 127 | ProfileLevel profileLevel; |
| 128 | profileLevel.mProfile = profile; |
| 129 | profileLevel.mLevel = level; |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 130 | if (mCap->mProfileLevelsSorted.indexOf(profileLevel) < 0) { |
| 131 | mCap->mProfileLevels.push_back(profileLevel); |
| 132 | mCap->mProfileLevelsSorted.add(profileLevel); |
Lajos Molnar | 06e9836 | 2017-08-14 15:57:57 -0700 | [diff] [blame] | 133 | } |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 136 | void MediaCodecInfo::CapabilitiesWriter::addColorFormat(uint32_t format) { |
| 137 | if (mCap->mColorFormatsSorted.indexOf(format) < 0) { |
| 138 | mCap->mColorFormats.push(format); |
| 139 | mCap->mColorFormatsSorted.add(format); |
Lajos Molnar | 06e9836 | 2017-08-14 15:57:57 -0700 | [diff] [blame] | 140 | } |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 143 | MediaCodecInfo::CapabilitiesWriter::CapabilitiesWriter( |
| 144 | MediaCodecInfo::Capabilities* cap) : mCap(cap) { |
Lajos Molnar | 5b05e49 | 2016-02-04 18:57:45 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 147 | MediaCodecInfo::Attributes MediaCodecInfo::getAttributes() const { |
| 148 | return mAttributes; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 151 | uint32_t MediaCodecInfo::getRank() const { |
Wonsik Kim | 78165d3 | 2018-01-24 14:48:03 -0800 | [diff] [blame] | 152 | return mRank; |
| 153 | } |
| 154 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 155 | void MediaCodecInfo::getAliases(Vector<AString> *aliases) const { |
| 156 | *aliases = mAliases; |
| 157 | } |
| 158 | |
| 159 | void MediaCodecInfo::getSupportedMediaTypes(Vector<AString> *mediaTypes) const { |
| 160 | mediaTypes->clear(); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 161 | for (size_t ix = 0; ix < mCaps.size(); ix++) { |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 162 | mediaTypes->push_back(mCaps.keyAt(ix)); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
Lajos Molnar | 2461e0c | 2014-08-12 08:55:25 -0700 | [diff] [blame] | 166 | const sp<MediaCodecInfo::Capabilities> |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 167 | MediaCodecInfo::getCapabilitiesFor(const char *mediaType) const { |
| 168 | ssize_t ix = getCapabilityIndex(mediaType); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 169 | if (ix >= 0) { |
| 170 | return mCaps.valueAt(ix); |
| 171 | } |
| 172 | return NULL; |
| 173 | } |
| 174 | |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 175 | const std::shared_ptr<CodecCapabilities> MediaCodecInfo::getCodecCapsFor( |
| 176 | const char *mediaType) const { |
| 177 | ssize_t ix = getCodecCapIndex(mediaType); |
| 178 | if (ix >= 0) { |
| 179 | return mCodecCaps.valueAt(ix); |
| 180 | } |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 184 | const char *MediaCodecInfo::getCodecName() const { |
| 185 | return mName.c_str(); |
| 186 | } |
| 187 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 188 | const char *MediaCodecInfo::getOwnerName() const { |
| 189 | return mOwner.c_str(); |
| 190 | } |
| 191 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 192 | // static |
| 193 | sp<MediaCodecInfo> MediaCodecInfo::FromParcel(const Parcel &parcel) { |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 194 | sMaxSupportedInstances = parcel.readInt32(); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 195 | AString name = AString::FromParcel(parcel); |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 196 | AString owner = AString::FromParcel(parcel); |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 197 | Attributes attributes = static_cast<Attributes>(parcel.readInt32()); |
Wonsik Kim | 78165d3 | 2018-01-24 14:48:03 -0800 | [diff] [blame] | 198 | uint32_t rank = parcel.readUint32(); |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 199 | sp<MediaCodecInfo> info = new MediaCodecInfo; |
| 200 | info->mName = name; |
| 201 | info->mOwner = owner; |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 202 | info->mAttributes = attributes; |
Wonsik Kim | 78165d3 | 2018-01-24 14:48:03 -0800 | [diff] [blame] | 203 | info->mRank = rank; |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 204 | size_t numAliases = static_cast<size_t>(parcel.readInt32()); |
| 205 | for (size_t i = 0; i < numAliases; i++) { |
| 206 | AString alias = AString::FromParcel(parcel); |
| 207 | info->mAliases.add(alias); |
| 208 | } |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 209 | size_t size = static_cast<size_t>(parcel.readInt32()); |
| 210 | for (size_t i = 0; i < size; i++) { |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 211 | AString mediaType = AString::FromParcel(parcel); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 212 | sp<Capabilities> caps = Capabilities::FromParcel(parcel); |
Pawin Vongmasa | 8dab1730 | 2016-05-02 16:08:39 -0700 | [diff] [blame] | 213 | if (caps == NULL) |
| 214 | return NULL; |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 215 | if (info != NULL) { |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 216 | info->mCaps.add(mediaType, caps); |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 217 | std::shared_ptr<CodecCapabilities> codecCaps |
| 218 | = MediaCodecInfoWriter::BuildCodecCapabilities( |
| 219 | mediaType.c_str(), caps, info->isEncoder()); |
| 220 | info->mCodecCaps.add(mediaType, codecCaps); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | return info; |
| 224 | } |
| 225 | |
| 226 | status_t MediaCodecInfo::writeToParcel(Parcel *parcel) const { |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 227 | parcel->writeInt32(sMaxSupportedInstances); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 228 | mName.writeToParcel(parcel); |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 229 | mOwner.writeToParcel(parcel); |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 230 | parcel->writeInt32(mAttributes); |
Wonsik Kim | 78165d3 | 2018-01-24 14:48:03 -0800 | [diff] [blame] | 231 | parcel->writeUint32(mRank); |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 232 | parcel->writeInt32(mAliases.size()); |
| 233 | for (const AString &alias : mAliases) { |
| 234 | alias.writeToParcel(parcel); |
| 235 | } |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 236 | parcel->writeInt32(mCaps.size()); |
| 237 | for (size_t i = 0; i < mCaps.size(); i++) { |
| 238 | mCaps.keyAt(i).writeToParcel(parcel); |
| 239 | mCaps.valueAt(i)->writeToParcel(parcel); |
| 240 | } |
| 241 | return OK; |
| 242 | } |
| 243 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 244 | ssize_t MediaCodecInfo::getCapabilityIndex(const char *mediaType) const { |
| 245 | if (mediaType) { |
Marco Nelissen | 89b2a0a | 2016-05-03 11:10:42 -0700 | [diff] [blame] | 246 | for (size_t ix = 0; ix < mCaps.size(); ix++) { |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 247 | if (mCaps.keyAt(ix).equalsIgnoreCase(mediaType)) { |
Marco Nelissen | 89b2a0a | 2016-05-03 11:10:42 -0700 | [diff] [blame] | 248 | return ix; |
| 249 | } |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | return -1; |
| 253 | } |
| 254 | |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 255 | ssize_t MediaCodecInfo::getCodecCapIndex(const char *mediaType) const { |
| 256 | if (mediaType == nullptr) { |
| 257 | return -1; |
| 258 | } |
| 259 | |
| 260 | if (mCodecCaps.size() != mCaps.size()) { |
| 261 | ALOGE("Size of mCodecCaps and mCaps do not match, which are %zu and %zu", |
| 262 | mCodecCaps.size(), mCaps.size()); |
| 263 | } |
| 264 | |
| 265 | for (size_t ix = 0; ix < mCodecCaps.size(); ix++) { |
| 266 | if (mCodecCaps.keyAt(ix).equalsIgnoreCase(mediaType)) { |
| 267 | return ix; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return -1; |
| 272 | } |
| 273 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 274 | MediaCodecInfo::MediaCodecInfo() |
| 275 | : mAttributes((MediaCodecInfo::Attributes)0), |
| 276 | mRank(0x100) { |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 279 | void MediaCodecInfoWriter::setName(const char* name) { |
| 280 | mInfo->mName = name; |
| 281 | } |
| 282 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 283 | void MediaCodecInfoWriter::addAlias(const char* name) { |
| 284 | mInfo->mAliases.add(name); |
| 285 | } |
| 286 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 287 | void MediaCodecInfoWriter::setOwner(const char* owner) { |
| 288 | mInfo->mOwner = owner; |
| 289 | } |
| 290 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 291 | void MediaCodecInfoWriter::setAttributes( |
| 292 | typename std::underlying_type<MediaCodecInfo::Attributes>::type attributes) { |
| 293 | mInfo->mAttributes = (MediaCodecInfo::Attributes)attributes; |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Wonsik Kim | 78165d3 | 2018-01-24 14:48:03 -0800 | [diff] [blame] | 296 | void MediaCodecInfoWriter::setRank(uint32_t rank) { |
| 297 | mInfo->mRank = rank; |
| 298 | } |
| 299 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 300 | std::unique_ptr<MediaCodecInfo::CapabilitiesWriter> |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 301 | MediaCodecInfoWriter::addMediaType(const char *mediaType) { |
| 302 | ssize_t ix = mInfo->getCapabilityIndex(mediaType); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 303 | if (ix >= 0) { |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 304 | return std::unique_ptr<MediaCodecInfo::CapabilitiesWriter>( |
| 305 | new MediaCodecInfo::CapabilitiesWriter( |
| 306 | mInfo->mCaps.valueAt(ix).get())); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 307 | } |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 308 | sp<MediaCodecInfo::Capabilities> caps = new MediaCodecInfo::Capabilities(); |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 309 | mInfo->mCaps.add(AString(mediaType), caps); |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 310 | return std::unique_ptr<MediaCodecInfo::CapabilitiesWriter>( |
| 311 | new MediaCodecInfo::CapabilitiesWriter(caps.get())); |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Lajos Molnar | 8d4bdfd | 2018-11-13 14:23:49 -0800 | [diff] [blame] | 314 | bool MediaCodecInfoWriter::removeMediaType(const char *mediaType) { |
| 315 | ssize_t ix = mInfo->getCapabilityIndex(mediaType); |
Lajos Molnar | 6ff58f0 | 2014-08-11 16:46:15 -0700 | [diff] [blame] | 316 | if (ix >= 0) { |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 317 | mInfo->mCaps.removeItemsAt(ix); |
| 318 | return true; |
Lajos Molnar | 6ff58f0 | 2014-08-11 16:46:15 -0700 | [diff] [blame] | 319 | } |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 320 | return false; |
Lajos Molnar | 6ff58f0 | 2014-08-11 16:46:15 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Songyue Han | 45f8194 | 2024-05-02 21:17:51 +0000 | [diff] [blame] | 323 | void MediaCodecInfoWriter::createCodecCaps() { |
| 324 | mInfo->mCodecCaps.clear(); |
| 325 | for (size_t ix = 0; ix < mInfo->mCaps.size(); ix++) { |
| 326 | AString mediaType = mInfo->mCaps.keyAt(ix); |
| 327 | sp<MediaCodecInfo::Capabilities> caps = mInfo->mCaps.valueAt(ix); |
| 328 | mInfo->mCodecCaps.add(mediaType, |
| 329 | BuildCodecCapabilities(mediaType.c_str(), caps, mInfo->isEncoder(), |
| 330 | MediaCodecInfo::sMaxSupportedInstances)); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // static |
| 335 | std::shared_ptr<CodecCapabilities> MediaCodecInfoWriter::BuildCodecCapabilities( |
| 336 | const char *mediaType, sp<MediaCodecInfo::Capabilities> caps, bool isEncoder, |
| 337 | int32_t maxSupportedInstances) { |
| 338 | Vector<ProfileLevel> profileLevels_; |
| 339 | Vector<uint32_t> colorFormats_; |
| 340 | caps->getSupportedProfileLevels(&profileLevels_); |
| 341 | caps->getSupportedColorFormats(&colorFormats_); |
| 342 | |
| 343 | std::vector<ProfileLevel> profileLevels; |
| 344 | std::vector<uint32_t> colorFormats; |
| 345 | for (ProfileLevel pl : profileLevels_) { |
| 346 | profileLevels.push_back(pl); |
| 347 | } |
| 348 | for (uint32_t cf : colorFormats_) { |
| 349 | colorFormats.push_back(cf); |
| 350 | } |
| 351 | |
| 352 | sp<AMessage> defaultFormat = new AMessage(); |
| 353 | defaultFormat->setString("mime", mediaType); |
| 354 | |
| 355 | sp<AMessage> capabilitiesInfo = caps->getDetails(); |
| 356 | |
| 357 | std::shared_ptr<CodecCapabilities> codecCaps = std::make_shared<CodecCapabilities>(); |
| 358 | codecCaps->init(profileLevels, colorFormats, isEncoder, defaultFormat, |
| 359 | capabilitiesInfo, maxSupportedInstances); |
| 360 | |
| 361 | return codecCaps; |
| 362 | } |
| 363 | |
| 364 | // static |
| 365 | void MediaCodecInfoWriter::SetMaxSupportedInstances(int32_t maxSupportedInstances) { |
| 366 | MediaCodecInfo::sMaxSupportedInstances = maxSupportedInstances; |
| 367 | } |
| 368 | |
Pawin Vongmasa | fbe70ae | 2017-07-27 02:21:57 -0700 | [diff] [blame] | 369 | MediaCodecInfoWriter::MediaCodecInfoWriter(MediaCodecInfo* info) : |
| 370 | mInfo(info) { |
Lajos Molnar | 732c6d9 | 2014-08-14 19:54:08 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Lajos Molnar | 60b1c0e | 2014-08-06 16:55:46 -0700 | [diff] [blame] | 373 | } // namespace android |