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

Commit 0ed1dcaa authored by Girish's avatar Girish
Browse files

mediacodec: remove codec resources upon stop

Remove the codec hal resources upon stopping the codec

Bug: 382739177
Test: ccodec_unit_test
      atest CtsMediaMiscTestCases:android.media.misc.cts.ResourceManagerTest
Flag: EXEMPT bugfix
Change-Id: I3732e08b7dd70ed00fd666fcd59c6bdaa51686d9
parent 105003fc
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -418,6 +418,7 @@ struct MediaCodec::ResourceManagerServiceProxy :
    void addResource(const MediaResourceParcel &resource);
    void addResource(const std::vector<MediaResourceParcel>& resources);
    void removeResource(const MediaResourceParcel &resource);
    void removeResource(const std::vector<MediaResourceParcel>& resources);
    void removeClient();
    void markClientForPendingRemoval();
    bool reclaimResource(const std::vector<MediaResourceParcel> &resources);
@@ -649,17 +650,24 @@ void MediaCodec::ResourceManagerServiceProxy::addResource(

void MediaCodec::ResourceManagerServiceProxy::removeResource(
        const MediaResourceParcel &resource) {
    std::vector<MediaResourceParcel> resources;
    resources.push_back(resource);
    removeResource(resources);
}

void MediaCodec::ResourceManagerServiceProxy::removeResource(
        const std::vector<MediaResourceParcel>& resources) {
    std::scoped_lock lock{mLock};
    std::shared_ptr<IResourceManagerService> service = getService_l();
    if (service == nullptr) {
        ALOGW("Service isn't available");
        return;
    }
    std::vector<MediaResourceParcel> resources;
    resources.push_back(resource);
    service->removeResource(getClientInfo(), resources);
    for (const MediaResourceParcel& resource : resources) {
        mMediaResourceParcel.erase(resource);
    }
}

void MediaCodec::ResourceManagerServiceProxy::removeClient() {
    std::scoped_lock lock{mLock};
@@ -4549,6 +4557,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {

                    CHECK_EQ(mState, STARTING);

                    // Add the codec resources upon start.
                    std::vector<MediaResourceParcel> resources;
                    if (mDomain == DOMAIN_VIDEO || mDomain == DOMAIN_IMAGE) {
                        resources.push_back(
@@ -4863,6 +4872,21 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                        mVideoRenderQualityTracker.resetForDiscontinuity();
                    }

                    // Remove the codec resources upon stop.
                    std::vector<MediaResourceParcel> resources;
                    if (android::media::codec::codec_availability() &&
                        android::media::codec::codec_availability_support()) {
                        Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(
                                mRequiredResourceInfo);
                        std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked;
                        for (const InstanceResourceInfo& resource : requiredResourceInfo) {
                            resources.push_back(getMediaResourceParcel(resource));
                        }
                    }
                    if (!resources.empty()) {
                        mResourceManagerProxy->removeResource(resources);
                    }

                    // Notify the RM that the codec has been stopped.
                    ClientConfigParcel clientConfig;
                    initClientConfigParcel(clientConfig);