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

Commit 41ec2ab4 authored by Wonsik Kim's avatar Wonsik Kim Committed by Android (Google) Code Review
Browse files

Merge "CCodec: handle vendor parameters"

parents 36cf3947 8a6ed374
Loading
Loading
Loading
Loading
+12 −4
Original line number Original line Diff line number Diff line
@@ -668,7 +668,7 @@ void CCodec::allocate(const sp<MediaCodecInfo> &codecInfo) {
    // initialize config here in case setParameters is called prior to configure
    // initialize config here in case setParameters is called prior to configure
    Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig);
    Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig);
    const std::unique_ptr<Config> &config = *configLocked;
    const std::unique_ptr<Config> &config = *configLocked;
    status_t err = config->initialize(mClient, comp);
    status_t err = config->initialize(mClient->getParamReflector(), comp);
    if (err != OK) {
    if (err != OK) {
        ALOGW("Failed to initialize configuration support");
        ALOGW("Failed to initialize configuration support");
        // TODO: report error once we complete implementation.
        // TODO: report error once we complete implementation.
@@ -884,6 +884,13 @@ void CCodec::configure(const sp<AMessage> &msg) {
            }
            }
        }
        }


        int32_t subscribeToAllVendorParams;
        if (msg->findInt32("x-*", &subscribeToAllVendorParams) && subscribeToAllVendorParams) {
            if (config->subscribeToAllVendorParams(comp, C2_MAY_BLOCK) != OK) {
                ALOGD("[%s] Failed to subscribe to all vendor params", comp->getName().c_str());
            }
        }

        std::vector<std::unique_ptr<C2Param>> configUpdate;
        std::vector<std::unique_ptr<C2Param>> configUpdate;
        // NOTE: We used to ignore "video-bitrate" at configure; replicate
        // NOTE: We used to ignore "video-bitrate" at configure; replicate
        //       the behavior here.
        //       the behavior here.
@@ -1192,7 +1199,7 @@ status_t CCodec::setupInputSurface(const std::shared_ptr<InputSurfaceWrapper> &s


    // we are now using surface - apply default color aspects to input format - as well as
    // we are now using surface - apply default color aspects to input format - as well as
    // get dataspace
    // get dataspace
    bool inputFormatChanged = config->updateFormats(config->IS_INPUT);
    bool inputFormatChanged = config->updateFormats(Config::IS_INPUT);
    ALOGD("input format %s to %s",
    ALOGD("input format %s to %s",
            inputFormatChanged ? "changed" : "unchanged",
            inputFormatChanged ? "changed" : "unchanged",
            config->mInputFormat->debugString().c_str());
            config->mInputFormat->debugString().c_str());
@@ -1207,7 +1214,7 @@ status_t CCodec::setupInputSurface(const std::shared_ptr<InputSurfaceWrapper> &s
    if (err != OK) {
    if (err != OK) {
        // undo input format update
        // undo input format update
        config->mUsingSurface = false;
        config->mUsingSurface = false;
        (void)config->updateFormats(config->IS_INPUT);
        (void)config->updateFormats(Config::IS_INPUT);
        return err;
        return err;
    }
    }
    config->mInputSurface = surface;
    config->mInputSurface = surface;
@@ -1628,7 +1635,8 @@ void CCodec::signalSetParameters(const sp<AMessage> &msg) {
     * Handle input surface parameters
     * Handle input surface parameters
     */
     */
    if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))
    if ((config->mDomain & (Config::IS_VIDEO | Config::IS_IMAGE))
            && (config->mDomain & Config::IS_ENCODER) && config->mInputSurface && config->mISConfig) {
            && (config->mDomain & Config::IS_ENCODER)
            && config->mInputSurface && config->mISConfig) {
        (void)params->findInt64(PARAMETER_KEY_OFFSET_TIME, &config->mISConfig->mTimeOffsetUs);
        (void)params->findInt64(PARAMETER_KEY_OFFSET_TIME, &config->mISConfig->mTimeOffsetUs);


        if (params->findInt64("skip-frames-before", &config->mISConfig->mStartAtUs)) {
        if (params->findInt64("skip-frames-before", &config->mISConfig->mStartAtUs)) {
+105 −49
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@
#include <log/log.h>
#include <log/log.h>


#include <C2Component.h>
#include <C2Component.h>
#include <C2Debug.h>
#include <C2Param.h>
#include <C2Param.h>
#include <util/C2InterfaceHelper.h>
#include <util/C2InterfaceHelper.h>


@@ -51,6 +50,27 @@ namespace android {


namespace {
namespace {


void C2ValueToMessageItem(const C2Value &value, AMessage::ItemData &item) {
    int32_t int32Value;
    uint32_t uint32Value;
    int64_t int64Value;
    uint64_t uint64Value;
    float floatValue;
    if (value.get(&int32Value)) {
        item.set(int32Value);
    } else if (value.get(&uint32Value) && uint32Value <= uint32_t(INT32_MAX)) {
        // SDK does not support unsigned values
        item.set((int32_t)uint32Value);
    } else if (value.get(&int64Value)) {
        item.set(int64Value);
    } else if (value.get(&uint64Value) && uint64Value <= uint64_t(INT64_MAX)) {
        // SDK does not support unsigned values
        item.set((int64_t)uint64Value);
    } else if (value.get(&floatValue)) {
        item.set(floatValue);
    }
}

/**
/**
 * mapping between SDK and Codec 2.0 configurations.
 * mapping between SDK and Codec 2.0 configurations.
 */
 */
@@ -140,27 +160,10 @@ struct ConfigMapper {
    /// Maps from a C2Value to an SDK value in an AMessage.
    /// Maps from a C2Value to an SDK value in an AMessage.
    AMessage::ItemData mapToMessage(C2Value value) const {
    AMessage::ItemData mapToMessage(C2Value value) const {
        AMessage::ItemData item;
        AMessage::ItemData item;
        int32_t int32Value;
        uint32_t uint32Value;
        int64_t int64Value;
        uint64_t uint64Value;
        float floatValue;
        if (value.type() != C2Value::NO_INIT && mReverse) {
        if (value.type() != C2Value::NO_INIT && mReverse) {
            value = mReverse(value);
            value = mReverse(value);
        }
        }
        if (value.get(&int32Value)) {
        C2ValueToMessageItem(value, item);
            item.set(int32Value);
        } else if (value.get(&uint32Value) && uint32Value <= uint32_t(INT32_MAX)) {
            // SDK does not support unsigned values
            item.set((int32_t)uint32Value);
        } else if (value.get(&int64Value)) {
            item.set(int64Value);
        } else if (value.get(&uint64Value) && uint64Value <= uint64_t(INT64_MAX)) {
            // SDK does not support unsigned values
            item.set((int64_t)uint64Value);
        } else if (value.get(&floatValue)) {
            item.set(floatValue);
        }
        return item;
        return item;
    }
    }


@@ -181,10 +184,10 @@ private:


template <typename PORT, typename STREAM>
template <typename PORT, typename STREAM>
AString QueryMediaTypeImpl(
AString QueryMediaTypeImpl(
        const std::shared_ptr<Codec2Client::Component> &component) {
        const std::shared_ptr<Codec2Client::Configurable> &configurable) {
    AString mediaType;
    AString mediaType;
    std::vector<std::unique_ptr<C2Param>> queried;
    std::vector<std::unique_ptr<C2Param>> queried;
    c2_status_t c2err = component->query(
    c2_status_t c2err = configurable->query(
            {}, { PORT::PARAM_TYPE, STREAM::PARAM_TYPE }, C2_DONT_BLOCK, &queried);
            {}, { PORT::PARAM_TYPE, STREAM::PARAM_TYPE }, C2_DONT_BLOCK, &queried);
    if (c2err != C2_OK && queried.size() == 0) {
    if (c2err != C2_OK && queried.size() == 0) {
        ALOGD("Query media type failed => %s", asString(c2err));
        ALOGD("Query media type failed => %s", asString(c2err));
@@ -209,13 +212,13 @@ AString QueryMediaTypeImpl(
}
}


AString QueryMediaType(
AString QueryMediaType(
        bool input, const std::shared_ptr<Codec2Client::Component> &component) {
        bool input, const std::shared_ptr<Codec2Client::Configurable> &configurable) {
    typedef C2PortMediaTypeSetting P;
    typedef C2PortMediaTypeSetting P;
    typedef C2StreamMediaTypeSetting S;
    typedef C2StreamMediaTypeSetting S;
    if (input) {
    if (input) {
        return QueryMediaTypeImpl<P::input, S::input>(component);
        return QueryMediaTypeImpl<P::input, S::input>(configurable);
    } else {
    } else {
        return QueryMediaTypeImpl<P::output, S::output>(component);
        return QueryMediaTypeImpl<P::output, S::output>(configurable);
    }
    }
}
}


@@ -912,27 +915,27 @@ void CCodecConfig::initializeStandardParams() {
}
}


status_t CCodecConfig::initialize(
status_t CCodecConfig::initialize(
        const std::shared_ptr<Codec2Client> &client,
        const std::shared_ptr<C2ParamReflector> &reflector,
        const std::shared_ptr<Codec2Client::Component> &component) {
        const std::shared_ptr<Codec2Client::Configurable> &configurable) {
    C2ComponentDomainSetting domain(C2Component::DOMAIN_OTHER);
    C2ComponentDomainSetting domain(C2Component::DOMAIN_OTHER);
    C2ComponentKindSetting kind(C2Component::KIND_OTHER);
    C2ComponentKindSetting kind(C2Component::KIND_OTHER);


    std::vector<std::unique_ptr<C2Param>> queried;
    std::vector<std::unique_ptr<C2Param>> queried;
    c2_status_t c2err = component->query({ &domain, &kind }, {}, C2_DONT_BLOCK, &queried);
    c2_status_t c2err = configurable->query({ &domain, &kind }, {}, C2_DONT_BLOCK, &queried);
    if (c2err != C2_OK) {
    if (c2err != C2_OK) {
        ALOGD("Query domain & kind failed => %s", asString(c2err));
        ALOGD("Query domain & kind failed => %s", asString(c2err));
        // TEMP: determine kind from component name
        // TEMP: determine kind from component name
        if (kind.value == C2Component::KIND_OTHER) {
        if (kind.value == C2Component::KIND_OTHER) {
            if (component->getName().find("encoder") != std::string::npos) {
            if (configurable->getName().find("encoder") != std::string::npos) {
                kind.value = C2Component::KIND_ENCODER;
                kind.value = C2Component::KIND_ENCODER;
            } else if (component->getName().find("decoder") != std::string::npos) {
            } else if (configurable->getName().find("decoder") != std::string::npos) {
                kind.value = C2Component::KIND_DECODER;
                kind.value = C2Component::KIND_DECODER;
            }
            }
        }
        }


        // TEMP: determine domain from media type (port (preferred) or stream #0)
        // TEMP: determine domain from media type (port (preferred) or stream #0)
        if (domain.value == C2Component::DOMAIN_OTHER) {
        if (domain.value == C2Component::DOMAIN_OTHER) {
            AString mediaType = QueryMediaType(true /* input */, component);
            AString mediaType = QueryMediaType(true /* input */, configurable);
            if (mediaType.startsWith("audio/")) {
            if (mediaType.startsWith("audio/")) {
                domain.value = C2Component::DOMAIN_AUDIO;
                domain.value = C2Component::DOMAIN_AUDIO;
            } else if (mediaType.startsWith("video/")) {
            } else if (mediaType.startsWith("video/")) {
@@ -957,16 +960,16 @@ status_t CCodecConfig::initialize(
    std::vector<C2Param::Index> paramIndices;
    std::vector<C2Param::Index> paramIndices;
    switch (kind.value) {
    switch (kind.value) {
    case C2Component::KIND_DECODER:
    case C2Component::KIND_DECODER:
        mCodingMediaType = QueryMediaType(true /* input */, component).c_str();
        mCodingMediaType = QueryMediaType(true /* input */, configurable).c_str();
        break;
        break;
    case C2Component::KIND_ENCODER:
    case C2Component::KIND_ENCODER:
        mCodingMediaType = QueryMediaType(false /* input */, component).c_str();
        mCodingMediaType = QueryMediaType(false /* input */, configurable).c_str();
        break;
        break;
    default:
    default:
        mCodingMediaType = "";
        mCodingMediaType = "";
    }
    }


    c2err = component->querySupportedParams(&mParamDescs);
    c2err = configurable->querySupportedParams(&mParamDescs);
    if (c2err != C2_OK) {
    if (c2err != C2_OK) {
        ALOGD("Query supported params failed after returning %zu values => %s",
        ALOGD("Query supported params failed after returning %zu values => %s",
                mParamDescs.size(), asString(c2err));
                mParamDescs.size(), asString(c2err));
@@ -976,9 +979,9 @@ status_t CCodecConfig::initialize(
        mSupportedIndices.emplace(desc->index());
        mSupportedIndices.emplace(desc->index());
    }
    }


    mReflector = client->getParamReflector();
    mReflector = reflector;
    if (mReflector == nullptr) {
    if (mReflector == nullptr) {
        ALOGE("Failed to get param reflector");
        ALOGE("Null param reflector");
        return UNKNOWN_ERROR;
        return UNKNOWN_ERROR;
    }
    }


@@ -1032,11 +1035,21 @@ status_t CCodecConfig::initialize(
    // init data (CSD)
    // init data (CSD)
    mSubscribedIndices.emplace(C2StreamInitDataInfo::output::PARAM_TYPE);
    mSubscribedIndices.emplace(C2StreamInitDataInfo::output::PARAM_TYPE);


    for (const std::shared_ptr<C2ParamDescriptor> &desc : mParamDescs) {
        if (desc->index().isVendor()) {
            std::vector<std::string> keys;
            mParamUpdater->getKeysForParamIndex(desc->index(), &keys);
            for (const std::string &key : keys) {
                mVendorParamIndices.insert_or_assign(key, desc->index());
            }
        }
    }

    return OK;
    return OK;
}
}


status_t CCodecConfig::subscribeToConfigUpdate(
status_t CCodecConfig::subscribeToConfigUpdate(
        const std::shared_ptr<Codec2Client::Component> &component,
        const std::shared_ptr<Codec2Client::Configurable> &configurable,
        const std::vector<C2Param::Index> &indices,
        const std::vector<C2Param::Index> &indices,
        c2_blocking_t blocking) {
        c2_blocking_t blocking) {
    mSubscribedIndices.insert(indices.begin(), indices.end());
    mSubscribedIndices.insert(indices.begin(), indices.end());
@@ -1049,7 +1062,7 @@ status_t CCodecConfig::subscribeToConfigUpdate(
        std::unique_ptr<C2SubscribedParamIndicesTuning> subscribeTuning =
        std::unique_ptr<C2SubscribedParamIndicesTuning> subscribeTuning =
            C2SubscribedParamIndicesTuning::AllocUnique(indices);
            C2SubscribedParamIndicesTuning::AllocUnique(indices);
        std::vector<std::unique_ptr<C2SettingResult>> results;
        std::vector<std::unique_ptr<C2SettingResult>> results;
        c2_status_t c2Err = component->config({ subscribeTuning.get() }, blocking, &results);
        c2_status_t c2Err = configurable->config({ subscribeTuning.get() }, blocking, &results);
        if (c2Err != C2_OK && c2Err != C2_BAD_INDEX) {
        if (c2Err != C2_OK && c2Err != C2_BAD_INDEX) {
            ALOGD("Failed to subscribe to parameters => %s", asString(c2Err));
            ALOGD("Failed to subscribe to parameters => %s", asString(c2Err));
            // TODO: error
            // TODO: error
@@ -1061,11 +1074,11 @@ status_t CCodecConfig::subscribeToConfigUpdate(
}
}


status_t CCodecConfig::queryConfiguration(
status_t CCodecConfig::queryConfiguration(
        const std::shared_ptr<Codec2Client::Component> &component) {
        const std::shared_ptr<Codec2Client::Configurable> &configurable) {
    // query all subscribed parameters
    // query all subscribed parameters
    std::vector<C2Param::Index> indices(mSubscribedIndices.begin(), mSubscribedIndices.end());
    std::vector<C2Param::Index> indices(mSubscribedIndices.begin(), mSubscribedIndices.end());
    std::vector<std::unique_ptr<C2Param>> queried;
    std::vector<std::unique_ptr<C2Param>> queried;
    c2_status_t c2Err = component->query({}, indices, C2_MAY_BLOCK, &queried);
    c2_status_t c2Err = configurable->query({}, indices, C2_MAY_BLOCK, &queried);
    if (c2Err != OK) {
    if (c2Err != OK) {
        ALOGI("query failed after returning %zu values (%s)", queried.size(), asString(c2Err));
        ALOGI("query failed after returning %zu values (%s)", queried.size(), asString(c2Err));
        // TODO: error
        // TODO: error
@@ -1135,7 +1148,7 @@ bool CCodecConfig::updateFormats(Domain domain) {
    if (domain & mInputDomain) {
    if (domain & mInputDomain) {
        sp<AMessage> oldFormat = mInputFormat;
        sp<AMessage> oldFormat = mInputFormat;
        mInputFormat = mInputFormat->dup(); // trigger format changed
        mInputFormat = mInputFormat->dup(); // trigger format changed
        mInputFormat->extend(getSdkFormatForDomain(reflected, mInputDomain));
        mInputFormat->extend(getFormatForDomain(reflected, mInputDomain));
        if (mInputFormat->countEntries() != oldFormat->countEntries()
        if (mInputFormat->countEntries() != oldFormat->countEntries()
                || mInputFormat->changesFrom(oldFormat)->countEntries() > 0) {
                || mInputFormat->changesFrom(oldFormat)->countEntries() > 0) {
            changed = true;
            changed = true;
@@ -1146,7 +1159,7 @@ bool CCodecConfig::updateFormats(Domain domain) {
    if (domain & mOutputDomain) {
    if (domain & mOutputDomain) {
        sp<AMessage> oldFormat = mOutputFormat;
        sp<AMessage> oldFormat = mOutputFormat;
        mOutputFormat = mOutputFormat->dup(); // trigger output format changed
        mOutputFormat = mOutputFormat->dup(); // trigger output format changed
        mOutputFormat->extend(getSdkFormatForDomain(reflected, mOutputDomain));
        mOutputFormat->extend(getFormatForDomain(reflected, mOutputDomain));
        if (mOutputFormat->countEntries() != oldFormat->countEntries()
        if (mOutputFormat->countEntries() != oldFormat->countEntries()
                || mOutputFormat->changesFrom(oldFormat)->countEntries() > 0) {
                || mOutputFormat->changesFrom(oldFormat)->countEntries() > 0) {
            changed = true;
            changed = true;
@@ -1158,8 +1171,9 @@ bool CCodecConfig::updateFormats(Domain domain) {
    return changed;
    return changed;
}
}


sp<AMessage> CCodecConfig::getSdkFormatForDomain(
sp<AMessage> CCodecConfig::getFormatForDomain(
        const ReflectedParamUpdater::Dict &reflected, Domain portDomain) const {
        const ReflectedParamUpdater::Dict &reflected,
        Domain portDomain) const {
    sp<AMessage> msg = new AMessage;
    sp<AMessage> msg = new AMessage;
    for (const std::pair<std::string, std::vector<ConfigMapper>> &el : mStandardParams->getKeys()) {
    for (const std::pair<std::string, std::vector<ConfigMapper>> &el : mStandardParams->getKeys()) {
        for (const ConfigMapper &cm : el.second) {
        for (const ConfigMapper &cm : el.second) {
@@ -1190,6 +1204,39 @@ sp<AMessage> CCodecConfig::getSdkFormatForDomain(
        }
        }
    }
    }


    bool input = (portDomain & Domain::IS_INPUT);
    std::vector<std::string> vendorKeys;
    for (const std::pair<std::string, ReflectedParamUpdater::Value> &entry : reflected) {
        auto it = mVendorParamIndices.find(entry.first);
        if (it == mVendorParamIndices.end()) {
            continue;
        }
        if (mSubscribedIndices.count(it->second) == 0) {
            continue;
        }
        // For vendor parameters, we only care about direction
        if ((input && !it->second.forInput())
                || (!input && !it->second.forOutput())) {
            continue;
        }
        const ReflectedParamUpdater::Value &value = entry.second;
        C2Value c2Value;
        sp<ABuffer> bufValue;
        AString strValue;
        AMessage::ItemData item;
        if (value.find(&c2Value)) {
            C2ValueToMessageItem(c2Value, item);
        } else if (value.find(&bufValue)) {
            item.set(bufValue);
        } else if (value.find(&strValue)) {
            item.set(strValue);
        } else {
            ALOGD("unexpected untyped query value for key: %s", entry.first.c_str());
            continue;
        }
        msg->setItem(entry.first.c_str(), item);
    }

    { // convert from Codec 2.0 rect to MediaFormat rect and add crop rect if not present
    { // convert from Codec 2.0 rect to MediaFormat rect and add crop rect if not present
        int32_t left, top, width, height;
        int32_t left, top, width, height;
        if (msg->findInt32("crop-left", &left) && msg->findInt32("crop-width", &width)
        if (msg->findInt32("crop-left", &left) && msg->findInt32("crop-width", &width)
@@ -1597,7 +1644,7 @@ ReflectedParamUpdater::Dict CCodecConfig::getReflectedFormat(
}
}


status_t CCodecConfig::getConfigUpdateFromSdkParams(
status_t CCodecConfig::getConfigUpdateFromSdkParams(
        std::shared_ptr<Codec2Client::Component> component,
        std::shared_ptr<Codec2Client::Configurable> configurable,
        const sp<AMessage> &sdkParams, Domain configDomain,
        const sp<AMessage> &sdkParams, Domain configDomain,
        c2_blocking_t blocking,
        c2_blocking_t blocking,
        std::vector<std::unique_ptr<C2Param>> *configUpdate) const {
        std::vector<std::unique_ptr<C2Param>> *configUpdate) const {
@@ -1624,7 +1671,7 @@ status_t CCodecConfig::getConfigUpdateFromSdkParams(
        }
        }
    }
    }


    c2_status_t err = component->query({ }, supportedIndices, blocking, configUpdate);
    c2_status_t err = configurable->query({ }, supportedIndices, blocking, configUpdate);
    if (err != C2_OK) {
    if (err != C2_OK) {
        ALOGD("query failed after returning %zu params => %s", configUpdate->size(), asString(err));
        ALOGD("query failed after returning %zu params => %s", configUpdate->size(), asString(err));
    }
    }
@@ -1636,7 +1683,7 @@ status_t CCodecConfig::getConfigUpdateFromSdkParams(
}
}


status_t CCodecConfig::setParameters(
status_t CCodecConfig::setParameters(
        std::shared_ptr<Codec2Client::Component> component,
        std::shared_ptr<Codec2Client::Configurable> configurable,
        std::vector<std::unique_ptr<C2Param>> &configUpdate,
        std::vector<std::unique_ptr<C2Param>> &configUpdate,
        c2_blocking_t blocking) {
        c2_blocking_t blocking) {
    status_t result = OK;
    status_t result = OK;
@@ -1672,10 +1719,10 @@ status_t CCodecConfig::setParameters(
        }
        }
    }
    }
    // update subscribed param indices
    // update subscribed param indices
    subscribeToConfigUpdate(component, indices, blocking);
    subscribeToConfigUpdate(configurable, indices, blocking);


    std::vector<std::unique_ptr<C2SettingResult>> failures;
    std::vector<std::unique_ptr<C2SettingResult>> failures;
    c2_status_t err = component->config(paramVector, blocking, &failures);
    c2_status_t err = configurable->config(paramVector, blocking, &failures);
    if (err != C2_OK) {
    if (err != C2_OK) {
        ALOGD("config failed => %s", asString(err));
        ALOGD("config failed => %s", asString(err));
        // This is non-fatal.
        // This is non-fatal.
@@ -1695,7 +1742,7 @@ status_t CCodecConfig::setParameters(
    // Re-query parameter values in case config could not update them and update the current
    // Re-query parameter values in case config could not update them and update the current
    // configuration.
    // configuration.
    configUpdate.clear();
    configUpdate.clear();
    err = component->query({}, indices, blocking, &configUpdate);
    err = configurable->query({}, indices, blocking, &configUpdate);
    if (err != C2_OK) {
    if (err != C2_OK) {
        ALOGD("query failed after returning %zu params => %s", configUpdate.size(), asString(err));
        ALOGD("query failed after returning %zu params => %s", configUpdate.size(), asString(err));
    }
    }
@@ -1714,4 +1761,13 @@ const C2Param *CCodecConfig::getConfigParameterValue(C2Param::Index index) const
    }
    }
}
}


status_t CCodecConfig::subscribeToAllVendorParams(
        const std::shared_ptr<Codec2Client::Configurable> &configurable,
        c2_blocking_t blocking) {
    for (const std::pair<std::string, C2Param::Index> &entry : mVendorParamIndices) {
        mSubscribedIndices.insert(entry.second);
    }
    return subscribeToConfigUpdate(configurable, {}, blocking);
}

}  // namespace android
}  // namespace android
+20 −11
Original line number Original line Diff line number Diff line
@@ -23,8 +23,10 @@
#include <vector>
#include <vector>


#include <C2Component.h>
#include <C2Component.h>
#include <codec2/hidl/client.h>
#include <C2Config.h>
#include <C2Debug.h>


#include <codec2/hidl/client.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>


#include "InputSurfaceWrapper.h"
#include "InputSurfaceWrapper.h"
@@ -39,7 +41,6 @@ struct StandardParams;
 * Struct managing the codec configuration for CCodec.
 * Struct managing the codec configuration for CCodec.
 */
 */
struct CCodecConfig {
struct CCodecConfig {

    /**
    /**
     * Domain consists of a bitmask divided into fields, and specifiers work by excluding other
     * Domain consists of a bitmask divided into fields, and specifiers work by excluding other
     * values in those domains.
     * values in those domains.
@@ -135,6 +136,9 @@ struct CCodecConfig {
    /// For now support a validation function.
    /// For now support a validation function.
    std::map<C2Param::Index, LocalParamValidator> mLocalParams;
    std::map<C2Param::Index, LocalParamValidator> mLocalParams;


    /// Vendor field name -> index map.
    std::map<std::string, C2Param::Index> mVendorParamIndices;

    std::set<std::string> mLastConfig;
    std::set<std::string> mLastConfig;


    CCodecConfig();
    CCodecConfig();
@@ -143,9 +147,8 @@ struct CCodecConfig {
    /// reflected param helper, domain, standard params, and subscribes to standard
    /// reflected param helper, domain, standard params, and subscribes to standard
    /// indices.
    /// indices.
    status_t initialize(
    status_t initialize(
            const std::shared_ptr<Codec2Client> &client,
            const std::shared_ptr<C2ParamReflector> &client,
            const std::shared_ptr<Codec2Client::Component> &component);
            const std::shared_ptr<Codec2Client::Configurable> &configurable);



    /**
    /**
     * Adds a locally maintained parameter. This is used for output configuration that can be
     * Adds a locally maintained parameter. This is used for output configuration that can be
@@ -238,7 +241,7 @@ struct CCodecConfig {
     * \param blocking blocking mode to use with the component
     * \param blocking blocking mode to use with the component
     */
     */
    status_t getConfigUpdateFromSdkParams(
    status_t getConfigUpdateFromSdkParams(
            std::shared_ptr<Codec2Client::Component> component,
            std::shared_ptr<Codec2Client::Configurable> configurable,
            const sp<AMessage> &sdkParams, Domain domain,
            const sp<AMessage> &sdkParams, Domain domain,
            c2_blocking_t blocking,
            c2_blocking_t blocking,
            std::vector<std::unique_ptr<C2Param>> *configUpdate) const;
            std::vector<std::unique_ptr<C2Param>> *configUpdate) const;
@@ -250,19 +253,24 @@ struct CCodecConfig {
     * \param blocking blocking mode to use with the component
     * \param blocking blocking mode to use with the component
     */
     */
    status_t setParameters(
    status_t setParameters(
            std::shared_ptr<Codec2Client::Component> component,
            std::shared_ptr<Codec2Client::Configurable> configurable,
            std::vector<std::unique_ptr<C2Param>> &configUpdate,
            std::vector<std::unique_ptr<C2Param>> &configUpdate,
            c2_blocking_t blocking);
            c2_blocking_t blocking);


    /// Queries subscribed indices (which contains all SDK-exposed values) and updates
    /// Queries subscribed indices (which contains all SDK-exposed values) and updates
    /// input/output formats.
    /// input/output formats.
    status_t queryConfiguration(
    status_t queryConfiguration(
            const std::shared_ptr<Codec2Client::Component> &component);
            const std::shared_ptr<Codec2Client::Configurable> &configurable);


    /// Queries a configuration parameter value. Returns nullptr if the parameter is not
    /// Queries a configuration parameter value. Returns nullptr if the parameter is not
    /// part of the current configuration
    /// part of the current configuration
    const C2Param *getConfigParameterValue(C2Param::Index index) const;
    const C2Param *getConfigParameterValue(C2Param::Index index) const;


    /// Subscribe to all vendor parameters.
    status_t subscribeToAllVendorParams(
            const std::shared_ptr<Codec2Client::Configurable> &configurable,
            c2_blocking_t blocking);

    /**
    /**
     * Object that can be used to access configuration parameters and if they change.
     * Object that can be used to access configuration parameters and if they change.
     */
     */
@@ -321,14 +329,15 @@ private:
    /// Adds indices to the subscribed indices, and updated subscription to component
    /// Adds indices to the subscribed indices, and updated subscription to component
    /// \param blocking blocking mode to use with the component
    /// \param blocking blocking mode to use with the component
    status_t subscribeToConfigUpdate(
    status_t subscribeToConfigUpdate(
            const std::shared_ptr<Codec2Client::Component> &component,
            const std::shared_ptr<Codec2Client::Configurable> &configurable,
            const std::vector<C2Param::Index> &indices,
            const std::vector<C2Param::Index> &indices,
            c2_blocking_t blocking = C2_DONT_BLOCK);
            c2_blocking_t blocking = C2_DONT_BLOCK);


    /// Gets SDK format from codec 2.0 reflected configuration
    /// Gets SDK format from codec 2.0 reflected configuration
    /// \param domain input/output bitmask
    /// \param domain input/output bitmask
    sp<AMessage> getSdkFormatForDomain(
    sp<AMessage> getFormatForDomain(
            const ReflectedParamUpdater::Dict &reflected, Domain domain) const;
            const ReflectedParamUpdater::Dict &reflected,
            Domain domain) const;


    /**
    /**
     * Converts a set of configuration parameters in an AMessage to a list of path-based Codec
     * Converts a set of configuration parameters in an AMessage to a list of path-based Codec
+14 −12
Original line number Original line Diff line number Diff line
@@ -125,18 +125,6 @@ void ReflectedParamUpdater::addParamDesc(
        }
        }
        addParamDesc(desc, *structDesc, reflector, true /* markVendor */);
        addParamDesc(desc, *structDesc, reflector, true /* markVendor */);
    }
    }

    // TEMP: also add vendor parameters as non-vendor
    for (const std::shared_ptr<C2ParamDescriptor> &desc : paramDescs) {
        if (!desc->index().isVendor()) {
            continue;
        }
        std::unique_ptr<C2StructDescriptor> structDesc = reflector->describe(
                desc->index().coreIndex());
        if (structDesc) {
            addParamDesc(desc, *structDesc, reflector, false /* markVendor */);
        }
    }
}
}


void ReflectedParamUpdater::addParamStructDesc(
void ReflectedParamUpdater::addParamStructDesc(
@@ -286,6 +274,20 @@ void ReflectedParamUpdater::getParamIndicesForKeys(
    }
    }
}
}


void ReflectedParamUpdater::getKeysForParamIndex(
        const C2Param::Index &index,
        std::vector<std::string> *keys /* nonnull */) const {
    CHECK(keys != nullptr);
    keys->clear();
    for (const std::pair<const std::string, FieldDesc> &kv : mMap) {
        const std::string &name = kv.first;
        const FieldDesc &desc = kv.second;
        if (desc.paramDesc->index() == index) {
            keys->push_back(name);
        }
    }
}

void ReflectedParamUpdater::updateParamsFromMessage(
void ReflectedParamUpdater::updateParamsFromMessage(
        const Dict &params,
        const Dict &params,
        std::vector<std::unique_ptr<C2Param>> *vec /* nonnull */) const {
        std::vector<std::unique_ptr<C2Param>> *vec /* nonnull */) const {
+10 −0
Original line number Original line Diff line number Diff line
@@ -165,6 +165,16 @@ public:
            const std::vector<std::string> &keys,
            const std::vector<std::string> &keys,
            std::vector<C2Param::Index> *vec /* nonnull */) const;
            std::vector<C2Param::Index> *vec /* nonnull */) const;


    /**
     * Get list of field names for the given param index.
     *
     * \param index[in]   param index
     * \param keys[out]   vector to store the field names
     */
    void getKeysForParamIndex(
            const C2Param::Index &index,
            std::vector<std::string> *keys /* nonnull */) const;

    /**
    /**
     * Update C2Param objects from field name and value in AMessage object.
     * Update C2Param objects from field name and value in AMessage object.
     *
     *
Loading