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

Commit b07a4f29 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "MediaCodec: define available/required resources APIs" into main am: 566be6ef

parents 3e89b3db 566be6ef
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -1189,6 +1189,19 @@ sp<PersistentSurface> MediaCodec::CreatePersistentInputSurface() {
    return new PersistentSurface(bufferProducer, bufferSource);
}

//static
status_t MediaCodec::getGloballyAvailableResources(std::vector<GlobalResourceInfo>& resources) {
    resources.clear();
    // Make sure codec availability feature is on.
    if (!android::media::codec::codec_availability()) {
        return ERROR_UNSUPPORTED;
    }
    // TODO: For now this is just an empty function.
    // The actual implementation should use component store to query the
    // available resources from hal, and fill in resources with the same.
    return ERROR_UNSUPPORTED;
}

// GenerateCodecId generates a 64bit Random ID for each codec that is created.
// The Codec ID is generated as:
//   - A process-unique random high 32bits
@@ -2553,6 +2566,31 @@ status_t MediaCodec::configure(
    return err;
}

status_t MediaCodec::getRequiredResources(std::vector<InstanceResourceInfo>& resources) {
    resources.clear();
    // Make sure codec availability feature is on.
    if (!android::media::codec::codec_availability()) {
        return ERROR_UNSUPPORTED;
    }
    // Make sure that the codec was configured already.
    if (mState != CONFIGURED && mState != STARTING && mState != STARTED &&
        mState != FLUSHING && mState != FLUSHED) {
        ALOGE("Codec wasn't configured yet!");
        return INVALID_OPERATION;
    }

    if (!mRequiredResourceInfo.empty()) {
        resources = mRequiredResourceInfo;
        return OK;
    }

    // TODO: For now this is just an empty function.
    // The actual implementation should use component interface
    // (for example, through mCodec->getRequiredDeviceResources) to query the
    // the required resources for this configuration, and fill in resources with the same.
    return ERROR_UNSUPPORTED;
}

// Media Format Shaping support
//

@@ -7041,6 +7079,18 @@ void MediaCodec::onOutputFormatChanged() {
    }
}

void MediaCodec::onRequiredResourcesChanged(
        const std::vector<InstanceResourceInfo>& resourceInfo) {
    mRequiredResourceInfo = resourceInfo;
    // Make sure codec availability feature is on.
    if (mCallback != nullptr && android::media::codec::codec_availability()) {
        // Post the callback
        sp<AMessage> msg = mCallback->dup();
        msg->setInt32("callbackID", CB_REQUIRED_RESOURCES_CHANGED);
        msg->post();
    }
}

void MediaCodec::postActivityNotificationIfPossible() {
    if (mActivityNotify == NULL) {
        return;
+88 −0
Original line number Diff line number Diff line
@@ -130,6 +130,11 @@ struct MediaCodec : public AHandler {
         * Object at the "metrics" key.
         */
        CB_METRICS_FLUSHED = 8,

        /** Callback ID to notify the change in resource requirement
         * for the codec component.
         */
        CB_REQUIRED_RESOURCES_CHANGED = 9,
    };

    static const pid_t kNoPid = -1;
@@ -149,6 +154,73 @@ struct MediaCodec : public AHandler {

    static sp<PersistentSurface> CreatePersistentInputSurface();

    /**
     * Abstraction for the Global Codec resources.
     * This encapsulates all the available codec resources on the device.
     */
    struct GlobalResourceInfo {
        /**
         * Name of the Resource type.
         */
        std::string mName;
        /**
         * Total count/capacity of resources of this type.
         */
        int mCapacity;
        /**
         * Available count of this resource type.
         */
        int mAvailable;

        GlobalResourceInfo(const std::string& name, int capacity, int available) :
                mName(name),
                mCapacity(capacity),
                mAvailable(available) {}

        GlobalResourceInfo(const GlobalResourceInfo& info) :
                mName(info.mName),
                mCapacity(info.mCapacity),
                mAvailable(info.mAvailable) {}
    };

    /**
     * Abstraction for the resources associated with a codec instance.
     * This encapsulates the required codec resources for a configured codec instance.
     */
    struct InstanceResourceInfo {
        /**
         * Name of the Resource type.
         */
        std::string mName;
        /**
         * Required resource count of this type.
         */
        int mStaticCount;
        /**
         * Per frame resource requirement of this resource type.
         */
        int mPerFrameCount;

        InstanceResourceInfo(const std::string& name, int staticCount, int perFrameCount) :
                mName(name),
                mStaticCount(staticCount),
                mPerFrameCount(perFrameCount) {}

        InstanceResourceInfo(const InstanceResourceInfo& info) :
                mName(info.mName),
                mStaticCount(info.mStaticCount),
                mPerFrameCount(info.mPerFrameCount) {}
    };

    /**
     * Get a list of Globally available device codec resources.
     *
     * It will return INVALID_OPERATION if:
     *  - HAL does not implement codec availability API
     *  - codec_availability feature flag isn't defined.
     */
    static status_t getGloballyAvailableResources(std::vector<GlobalResourceInfo>& resources);

    status_t configure(
            const sp<AMessage> &format,
            const sp<Surface> &nativeWindow,
@@ -162,6 +234,19 @@ struct MediaCodec : public AHandler {
            const sp<IDescrambler> &descrambler,
            uint32_t flags);

    /**
     * Get a list of required codec resources.
     *
     * This may only be called after configuring the codec.
     *
     * Calling this while the codec wasn't configured, will result in
     * returning INVALID_OPERATION error code.
     * It will also return INVALID_OPERATION if:
     *  - HAL does not implement codec availability API
     *  - codec_availability feature flag isn't defined.
     */
    status_t getRequiredResources(std::vector<InstanceResourceInfo>& resources);

    status_t releaseCrypto();

    status_t setCallback(const sp<AMessage> &callback);
@@ -688,6 +773,7 @@ private:
    void onCryptoError(const sp<AMessage> &msg);
    void onError(status_t err, int32_t actionCode, const char *detail = NULL);
    void onOutputFormatChanged();
    void onRequiredResourcesChanged(const std::vector<InstanceResourceInfo>& resourceInfo);

    status_t onSetParameters(const sp<AMessage> &params);

@@ -787,6 +873,8 @@ private:
    friend class MediaTestHelper;

    CodecErrorLog mErrorLog;
    // Required resource info for this codec.
    std::vector<InstanceResourceInfo> mRequiredResourceInfo;

    DISALLOW_EVIL_CONSTRUCTORS(MediaCodec);
};