160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar/*
260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * Copyright 2014, The Android Open Source Project
360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar *
460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * you may not use this file except in compliance with the License.
660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * You may obtain a copy of the License at
760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar *
860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar *     http://www.apache.org/licenses/LICENSE-2.0
960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar *
1060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * Unless required by applicable law or agreed to in writing, software
1160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * See the License for the specific language governing permissions and
1460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar * limitations under the License.
1560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar */
1660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
1760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar//#define LOG_NDEBUG 0
1860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#define LOG_TAG "MediaCodecInfo"
1960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <utils/Log.h>
2060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
2160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <media/IOMX.h>
2260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
2360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <media/MediaCodecInfo.h>
2460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
2560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <media/stagefright/foundation/ADebug.h>
2660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <media/stagefright/foundation/AMessage.h>
2760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <binder/Parcel.h>
2860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
2960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar#include <media/stagefright/OMXCodec.h>
3060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
3160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarnamespace android {
3260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
3360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::Capabilities::getSupportedProfileLevels(
3460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        Vector<ProfileLevel> *profileLevels) const {
3560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    profileLevels->clear();
3660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    profileLevels->appendVector(mProfileLevels);
3760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
3860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
3960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::Capabilities::getSupportedColorFormats(
4060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        Vector<uint32_t> *colorFormats) const {
4160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    colorFormats->clear();
4260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    colorFormats->appendVector(mColorFormats);
4360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
4460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
4560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnaruint32_t MediaCodecInfo::Capabilities::getFlags() const {
4660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return mFlags;
4760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
4860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
492461e0cf6ae3fe5c9b52ce9e3ac764f4aff5e5ebLajos Molnarconst sp<AMessage> MediaCodecInfo::Capabilities::getDetails() const {
5060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return mDetails;
5160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
5260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
5360b1c0e79d12a1c70758bc8d060156924635f8baLajos MolnarMediaCodecInfo::Capabilities::Capabilities()
5460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar  : mFlags(0) {
5560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mDetails = new AMessage;
5660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
5760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
5860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar// static
5960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarsp<MediaCodecInfo::Capabilities> MediaCodecInfo::Capabilities::FromParcel(
6060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        const Parcel &parcel) {
6160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    sp<MediaCodecInfo::Capabilities> caps = new Capabilities();
6260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    size_t size = static_cast<size_t>(parcel.readInt32());
6360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < size; i++) {
6460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        ProfileLevel profileLevel;
6560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        profileLevel.mProfile = static_cast<uint32_t>(parcel.readInt32());
6660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        profileLevel.mLevel = static_cast<uint32_t>(parcel.readInt32());
6760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        if (caps != NULL) {
6860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar            caps->mProfileLevels.push_back(profileLevel);
6960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        }
7060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
7160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    size = static_cast<size_t>(parcel.readInt32());
7260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < size; i++) {
7360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        uint32_t color = static_cast<uint32_t>(parcel.readInt32());
7460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        if (caps != NULL) {
7560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar            caps->mColorFormats.push_back(color);
7660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        }
7760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
7860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    uint32_t flags = static_cast<uint32_t>(parcel.readInt32());
7960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    sp<AMessage> details = AMessage::FromParcel(parcel);
8060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    if (caps != NULL) {
8160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        caps->mFlags = flags;
8260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        caps->mDetails = details;
8360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
8460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return caps;
8560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
8660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
8760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarstatus_t MediaCodecInfo::Capabilities::writeToParcel(Parcel *parcel) const {
8860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    CHECK_LE(mProfileLevels.size(), INT32_MAX);
8960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    parcel->writeInt32(mProfileLevels.size());
9060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < mProfileLevels.size(); i++) {
9160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        parcel->writeInt32(mProfileLevels.itemAt(i).mProfile);
9260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        parcel->writeInt32(mProfileLevels.itemAt(i).mLevel);
9360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
9460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    CHECK_LE(mColorFormats.size(), INT32_MAX);
9560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    parcel->writeInt32(mColorFormats.size());
9660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < mColorFormats.size(); i++) {
9760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        parcel->writeInt32(mColorFormats.itemAt(i));
9860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
9960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    parcel->writeInt32(mFlags);
10060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mDetails->writeToParcel(parcel);
10160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return OK;
10260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
10360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
10460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarbool MediaCodecInfo::isEncoder() const {
10560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return mIsEncoder;
10660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
10760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
10860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarbool MediaCodecInfo::hasQuirk(const char *name) const {
10960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t ix = 0; ix < mQuirks.size(); ix++) {
11060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        if (mQuirks.itemAt(ix).equalsIgnoreCase(name)) {
11160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar            return true;
11260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        }
11360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
11460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return false;
11560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
11660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
11760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::getSupportedMimes(Vector<AString> *mimes) const {
11860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mimes->clear();
11960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t ix = 0; ix < mCaps.size(); ix++) {
12060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mimes->push_back(mCaps.keyAt(ix));
12160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
12260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
12360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
1242461e0cf6ae3fe5c9b52ce9e3ac764f4aff5e5ebLajos Molnarconst sp<MediaCodecInfo::Capabilities>
12560b1c0e79d12a1c70758bc8d060156924635f8baLajos MolnarMediaCodecInfo::getCapabilitiesFor(const char *mime) const {
12660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    ssize_t ix = getCapabilityIndex(mime);
12760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    if (ix >= 0) {
12860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        return mCaps.valueAt(ix);
12960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
13060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return NULL;
13160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
13260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
13360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarconst char *MediaCodecInfo::getCodecName() const {
13460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return mName.c_str();
13560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
13660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
13760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar// static
13860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarsp<MediaCodecInfo> MediaCodecInfo::FromParcel(const Parcel &parcel) {
13960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    AString name = AString::FromParcel(parcel);
14060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    bool isEncoder = static_cast<bool>(parcel.readInt32());
14160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    sp<MediaCodecInfo> info = new MediaCodecInfo(name, isEncoder, NULL);
14260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    size_t size = static_cast<size_t>(parcel.readInt32());
14360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < size; i++) {
14460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        AString quirk = AString::FromParcel(parcel);
14560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        if (info != NULL) {
14660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar            info->mQuirks.push_back(quirk);
14760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        }
14860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
14960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    size = static_cast<size_t>(parcel.readInt32());
15060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < size; i++) {
15160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        AString mime = AString::FromParcel(parcel);
15260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        sp<Capabilities> caps = Capabilities::FromParcel(parcel);
15360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        if (info != NULL) {
15460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar            info->mCaps.add(mime, caps);
15560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        }
15660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
15760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return info;
15860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
15960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
16060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarstatus_t MediaCodecInfo::writeToParcel(Parcel *parcel) const {
16160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mName.writeToParcel(parcel);
16260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    parcel->writeInt32(mIsEncoder);
16360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    parcel->writeInt32(mQuirks.size());
16460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < mQuirks.size(); i++) {
16560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mQuirks.itemAt(i).writeToParcel(parcel);
16660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
16760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    parcel->writeInt32(mCaps.size());
16860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < mCaps.size(); i++) {
16960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCaps.keyAt(i).writeToParcel(parcel);
17060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCaps.valueAt(i)->writeToParcel(parcel);
17160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
17260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return OK;
17360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
17460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
17560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarssize_t MediaCodecInfo::getCapabilityIndex(const char *mime) const {
17660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t ix = 0; ix < mCaps.size(); ix++) {
17760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        if (mCaps.keyAt(ix).equalsIgnoreCase(mime)) {
17860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar            return ix;
17960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        }
18060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
18160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return -1;
18260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
18360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
18460b1c0e79d12a1c70758bc8d060156924635f8baLajos MolnarMediaCodecInfo::MediaCodecInfo(AString name, bool encoder, const char *mime)
18560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    : mName(name),
18660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar      mIsEncoder(encoder),
18760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar      mHasSoleMime(false) {
18860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    if (mime != NULL) {
18960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        addMime(mime);
19060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mHasSoleMime = true;
19160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
19260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
19360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
19460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarstatus_t MediaCodecInfo::addMime(const char *mime) {
19560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    if (mHasSoleMime) {
19660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        ALOGE("Codec '%s' already had its type specified", mName.c_str());
19760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        return -EINVAL;
19860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
19960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    ssize_t ix = getCapabilityIndex(mime);
20060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    if (ix >= 0) {
20160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCurrentCaps = mCaps.valueAt(ix);
20260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    } else {
20360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCurrentCaps = new Capabilities();
20460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCaps.add(AString(mime), mCurrentCaps);
20560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
20660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return OK;
20760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
20860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
2096ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnarvoid MediaCodecInfo::removeMime(const char *mime) {
2106ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar    ssize_t ix = getCapabilityIndex(mime);
2116ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar    if (ix >= 0) {
2126ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar        mCaps.removeItemsAt(ix);
2136ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar        // mCurrentCaps will be removed when completed
2146ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar    }
2156ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar}
2166ff58f04f78886b07c72c0118eb71a78d08f5651Lajos Molnar
21760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarstatus_t MediaCodecInfo::initializeCapabilities(const CodecCapabilities &caps) {
21860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps->mProfileLevels.clear();
21960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps->mColorFormats.clear();
22060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
22160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < caps.mProfileLevels.size(); ++i) {
22260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        const CodecProfileLevel &src = caps.mProfileLevels.itemAt(i);
22360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
22460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        ProfileLevel profileLevel;
22560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        profileLevel.mProfile = src.mProfile;
22660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        profileLevel.mLevel = src.mLevel;
22760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCurrentCaps->mProfileLevels.push_back(profileLevel);
22860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
22960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
23060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    for (size_t i = 0; i < caps.mColorFormats.size(); ++i) {
23160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mCurrentCaps->mColorFormats.push_back(caps.mColorFormats.itemAt(i));
23260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
23360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
23460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps->mFlags = caps.mFlags;
23560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps->mDetails = new AMessage;
23660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
23760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    return OK;
23860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
23960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
24060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::addQuirk(const char *name) {
24160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    if (!hasQuirk(name)) {
24260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar        mQuirks.push(name);
24360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    }
24460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
24560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
24660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::complete() {
24760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps = NULL;
24860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
24960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
25060b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::addDetail(const AString &key, const AString &value) {
25160b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps->mDetails->setString(key.c_str(), value.c_str());
25260b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
25360b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
25460b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnarvoid MediaCodecInfo::addFeature(const AString &key, int32_t value) {
25560b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    AString tag = "feature-";
25660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    tag.append(key);
25760b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar    mCurrentCaps->mDetails->setInt32(tag.c_str(), value);
25860b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}
25960b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar
260732c6d955524ead6c31e6e1bafbd41ea4cee525dLajos Molnarvoid MediaCodecInfo::addFeature(const AString &key, const char *value) {
261732c6d955524ead6c31e6e1bafbd41ea4cee525dLajos Molnar    AString tag = "feature-";
262732c6d955524ead6c31e6e1bafbd41ea4cee525dLajos Molnar    tag.append(key);
263732c6d955524ead6c31e6e1bafbd41ea4cee525dLajos Molnar    mCurrentCaps->mDetails->setString(tag.c_str(), value);
264732c6d955524ead6c31e6e1bafbd41ea4cee525dLajos Molnar}
265732c6d955524ead6c31e6e1bafbd41ea4cee525dLajos Molnar
26660b1c0e79d12a1c70758bc8d060156924635f8baLajos Molnar}  // namespace android
267