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

Commit 0fafb401 authored by Chong Zhang's avatar Chong Zhang
Browse files

save codec info during codec construction

Save the codec info used to create the codec for use
when get caps is called.

bug: 74073607
Change-Id: Id12a5b96f5a00226f8cf1e71f32655a14aeac014
parent cb9be977
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -6346,9 +6346,6 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

    sp<AMessage> notify = new AMessage(kWhatOMXDied, mCodec);

    Vector<AString> matchingCodecs;
    Vector<AString> owners;

    AString componentName;
    CHECK(msg->findString("componentName", &componentName));

@@ -6424,7 +6421,7 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

    mCodec->mOMX = omx;
    mCodec->mOMXNode = omxNode;
    mCodec->mCallback->onComponentAllocated(mCodec->mComponentName.c_str());
    mCodec->mCallback->onComponentAllocated(mCodec->mComponentName.c_str(), info);
    mCodec->changeState(mCodec->mLoadedState);

    return true;
+40 −5
Original line number Diff line number Diff line
@@ -278,7 +278,8 @@ public:
    virtual void onReleaseCompleted() override;
    virtual void onFlushCompleted() override;
    virtual void onError(status_t err, enum ActionCode actionCode) override;
    virtual void onComponentAllocated(const char *componentName) override;
    virtual void onComponentAllocated(
            const char *componentName, const sp<MediaCodecInfo> &codecInfo) override;
    virtual void onComponentConfigured(
            const sp<AMessage> &inputFormat, const sp<AMessage> &outputFormat) override;
    virtual void onInputSurfaceCreated(
@@ -338,10 +339,14 @@ void CodecCallback::onError(status_t err, enum ActionCode actionCode) {
    notify->post();
}

void CodecCallback::onComponentAllocated(const char *componentName) {
void CodecCallback::onComponentAllocated(
        const char *componentName, const sp<MediaCodecInfo> &codecInfo) {
    sp<AMessage> notify(mNotify->dup());
    notify->setInt32("what", kWhatComponentAllocated);
    notify->setString("componentName", componentName);
    if (codecInfo != nullptr) {
        notify->setObject("codecInfo", codecInfo);
    }
    notify->post();
}

@@ -422,14 +427,12 @@ sp<MediaCodec> MediaCodec::CreateByType(
        const sp<ALooper> &looper, const AString &mime, bool encoder, status_t *err, pid_t pid,
        uid_t uid) {
    Vector<AString> matchingCodecs;
    Vector<AString> owners;

    MediaCodecList::findMatchingCodecs(
            mime.c_str(),
            encoder,
            0,
            &matchingCodecs,
            &owners);
            &matchingCodecs);

    if (err != NULL) {
        *err = NAME_NOT_FOUND;
@@ -1205,6 +1208,22 @@ status_t MediaCodec::getName(AString *name) const {
    return OK;
}

status_t MediaCodec::getCodecInfo(sp<MediaCodecInfo> *codecInfo) const {
    sp<AMessage> msg = new AMessage(kWhatGetCodecInfo, this);

    sp<AMessage> response;
    status_t err;
    if ((err = PostAndAwaitResponse(msg, &response)) != OK) {
        return err;
    }

    sp<RefBase> obj;
    CHECK(response->findObject("codecInfo", &obj));
    *codecInfo = static_cast<MediaCodecInfo *>(obj.get());

    return OK;
}

status_t MediaCodec::getMetrics(MediaAnalyticsItem * &reply) {

    reply = NULL;
@@ -1588,6 +1607,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {

                    CHECK(msg->findString("componentName", &mComponentName));

                    sp<RefBase> obj;
                    if (msg->findObject("codecInfo", &obj)) {
                        mCodecInfo = static_cast<MediaCodecInfo *>(obj.get());
                    }

                    if (mComponentName.c_str()) {
                        mAnalyticsItem->setCString(kCodecCodec, mComponentName.c_str());
                    }
@@ -2595,6 +2619,17 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
            break;
        }

        case kWhatGetCodecInfo:
        {
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
            response->setObject("codecInfo", mCodecInfo);
            response->postReply(replyID);
            break;
        }

        case kWhatSetParameters:
        {
            sp<AReplyToken> replyID;
+1 −7
Original line number Diff line number Diff line
@@ -307,11 +307,8 @@ static int compareSoftwareCodecsFirst(const AString *name1, const AString *name2
//static
void MediaCodecList::findMatchingCodecs(
        const char *mime, bool encoder, uint32_t flags,
        Vector<AString> *matches, Vector<AString> *owners) {
        Vector<AString> *matches) {
    matches->clear();
    if (owners != nullptr) {
        owners->clear();
    }

    const sp<IMediaCodecList> list = getInstance();
    if (list == nullptr) {
@@ -337,9 +334,6 @@ void MediaCodecList::findMatchingCodecs(
            ALOGV("skipping SW codec '%s'", componentName.c_str());
        } else {
            matches->push(componentName);
            if (owners != nullptr) {
                owners->push(AString(info->getOwnerName()));
            }
            ALOGV("matching '%s'", componentName.c_str());
        }
    }
+4 −1
Original line number Diff line number Diff line
@@ -95,8 +95,11 @@ struct CodecBase : public AHandler, /* static */ ColorUtils {
         *
         * @param componentName the unique name of the component specified in
         *                      MediaCodecList.
         * @param codecInfo the associated codec info if available.
         */
        virtual void onComponentAllocated(const char *componentName) = 0;
        virtual void onComponentAllocated(
                const char *componentName,
                const sp<MediaCodecInfo> &codecInfo = nullptr) = 0;
        /**
         * Notify MediaCodec that the underlying component is configured.
         *
+4 −0
Original line number Diff line number Diff line
@@ -184,6 +184,8 @@ struct MediaCodec : public AHandler {

    status_t getName(AString *componentName) const;

    status_t getCodecInfo(sp<MediaCodecInfo> *codecInfo) const;

    status_t getMetrics(MediaAnalyticsItem * &reply);

    status_t setParameters(const sp<AMessage> &params);
@@ -248,6 +250,7 @@ private:
        kWhatRequestIDRFrame                = 'ridr',
        kWhatRequestActivityNotification    = 'racN',
        kWhatGetName                        = 'getN',
        kWhatGetCodecInfo                   = 'gCoI',
        kWhatSetParameters                  = 'setP',
        kWhatSetCallback                    = 'setC',
        kWhatSetNotification                = 'setN',
@@ -308,6 +311,7 @@ private:
    sp<ALooper> mCodecLooper;
    sp<CodecBase> mCodec;
    AString mComponentName;
    sp<MediaCodecInfo> mCodecInfo;
    sp<AReplyToken> mReplyID;
    uint32_t mFlags;
    status_t mStickyError;
Loading