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

Commit e9ba1054 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "C2BqPool: Invalidate when the client died" into main

parents 2853e09e 03cfa625
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -222,6 +222,21 @@ c2_status_t Component::status() const {
    return mInit;
}

void Component::onDeathReceived() {
    {
        std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
        mClientDied = true;
        for (auto it = mBlockPools.begin(); it != mBlockPools.end(); ++it) {
            if (it->second->getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) {
                std::shared_ptr<C2BufferQueueBlockPool> bqPool =
                        std::static_pointer_cast<C2BufferQueueBlockPool>(it->second);
                bqPool->invalidate();
            }
        }
    }
    release();
}

// Methods from ::android::hardware::media::c2::V1_0::IComponent
Return<Status> Component::queue(const WorkBundle& workBundle) {
    std::list<std::unique_ptr<C2Work>> c2works;
@@ -409,9 +424,19 @@ Return<void> Component::createBlockPool(
        blockPool = nullptr;
    }
    if (blockPool) {
        bool emplaced = false;
        {
            mBlockPoolsMutex.lock();
            if (!mClientDied) {
                mBlockPools.emplace(blockPool->getLocalId(), blockPool);
                emplaced = true;
            }
            mBlockPoolsMutex.unlock();
        }
        if (!emplaced) {
            blockPool.reset();
            status = C2_BAD_STATE;
        }
    } else if (status == C2_OK) {
        status = C2_CORRUPTED;
    }
@@ -494,8 +519,8 @@ void Component::initListener(const sp<Component>& self) {
                ) override {
            auto strongComponent = mComponent.promote();
            if (strongComponent) {
                LOG(INFO) << "Client died ! release the component !!";
                strongComponent->release();
                LOG(INFO) << "Client died ! notify and release the component !!";
                strongComponent->onDeathReceived();
            } else {
                LOG(ERROR) << "Client died ! no component to release !!";
            }
+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ struct Component : public IComponent,
            const sp<::android::hardware::media::bufferpool::V2_0::
                IClientManager>& clientPoolManager);
    c2_status_t status() const;
    // Receives a death notification of the client.
    void onDeathReceived();

    typedef ::android::hardware::graphics::bufferqueue::V1_0::
            IGraphicBufferProducer HGraphicBufferProducer1;
@@ -135,6 +137,7 @@ protected:

    using HwDeathRecipient = ::android::hardware::hidl_death_recipient;
    sp<HwDeathRecipient> mDeathRecipient;
    bool mClientDied{false};
};

}  // namespace utils
+30 −5
Original line number Diff line number Diff line
@@ -222,6 +222,21 @@ c2_status_t Component::status() const {
    return mInit;
}

void Component::onDeathReceived() {
    {
        std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
        mClientDied = true;
        for (auto it = mBlockPools.begin(); it != mBlockPools.end(); ++it) {
            if (it->second->getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) {
                std::shared_ptr<C2BufferQueueBlockPool> bqPool =
                        std::static_pointer_cast<C2BufferQueueBlockPool>(it->second);
                bqPool->invalidate();
            }
        }
    }
    release();
}

// Methods from ::android::hardware::media::c2::V1_1::IComponent
Return<Status> Component::queue(const WorkBundle& workBundle) {
    std::list<std::unique_ptr<C2Work>> c2works;
@@ -409,9 +424,19 @@ Return<void> Component::createBlockPool(
        blockPool = nullptr;
    }
    if (blockPool) {
        bool emplaced = false;
        {
            mBlockPoolsMutex.lock();
            if (!mClientDied) {
                mBlockPools.emplace(blockPool->getLocalId(), blockPool);
                emplaced = true;
            }
            mBlockPoolsMutex.unlock();
        }
        if (!emplaced) {
            blockPool.reset();
            status = C2_BAD_STATE;
        }
    } else if (status == C2_OK) {
        status = C2_CORRUPTED;
    }
@@ -501,8 +526,8 @@ void Component::initListener(const sp<Component>& self) {
                ) override {
            auto strongComponent = component.promote();
            if (strongComponent) {
                LOG(INFO) << "Client died ! release the component !!";
                strongComponent->release();
                LOG(INFO) << "Client died ! notify and release the component !!";
                strongComponent->onDeathReceived();
            } else {
                LOG(ERROR) << "Client died ! no component to release !!";
            }
+3 −0
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ struct Component : public IComponent,
            const sp<::android::hardware::media::bufferpool::V2_0::
                IClientManager>& clientPoolManager);
    c2_status_t status() const;
    // Receives a death notification of the client.
    void onDeathReceived();

    typedef ::android::hardware::graphics::bufferqueue::V1_0::
            IGraphicBufferProducer HGraphicBufferProducer1;
@@ -140,6 +142,7 @@ protected:

    using HwDeathRecipient = ::android::hardware::hidl_death_recipient;
    sp<HwDeathRecipient> mDeathRecipient;
    bool mClientDied{false};
};

} // namespace utils
+30 −5
Original line number Diff line number Diff line
@@ -222,6 +222,21 @@ c2_status_t Component::status() const {
    return mInit;
}

void Component::onDeathReceived() {
    {
        std::lock_guard<std::mutex> lock(mBlockPoolsMutex);
        mClientDied = true;
        for (auto it = mBlockPools.begin(); it != mBlockPools.end(); ++it) {
            if (it->second->getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) {
                std::shared_ptr<C2BufferQueueBlockPool> bqPool =
                        std::static_pointer_cast<C2BufferQueueBlockPool>(it->second);
                bqPool->invalidate();
            }
        }
    }
    release();
}

// Methods from ::android::hardware::media::c2::V1_1::IComponent
Return<Status> Component::queue(const WorkBundle& workBundle) {
    std::list<std::unique_ptr<C2Work>> c2works;
@@ -409,9 +424,19 @@ Return<void> Component::createBlockPool(
        blockPool = nullptr;
    }
    if (blockPool) {
        bool emplaced = false;
        {
            mBlockPoolsMutex.lock();
            if (!mClientDied) {
                mBlockPools.emplace(blockPool->getLocalId(), blockPool);
                emplaced = true;
            }
            mBlockPoolsMutex.unlock();
        }
        if (!emplaced) {
            blockPool.reset();
            status = C2_BAD_STATE;
        }
    } else if (status == C2_OK) {
        status = C2_CORRUPTED;
    }
@@ -532,8 +557,8 @@ void Component::initListener(const sp<Component>& self) {
                ) override {
            auto strongComponent = component.promote();
            if (strongComponent) {
                LOG(INFO) << "Client died ! release the component !!";
                strongComponent->release();
                LOG(INFO) << "Client died ! notify and release the component !!";
                strongComponent->onDeathReceived();
            } else {
                LOG(ERROR) << "Client died ! no component to release !!";
            }
Loading