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

Commit 555cca11 authored by Shuzhen Wang's avatar Shuzhen Wang Committed by Automerger Merge Worker
Browse files

Merge "Camera: Call corresponding unlock for every lockAsync" am: 2ac8ac5a

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2029166

Change-Id: I2a845dca254076ca8504fb91d3f9b9bcc4d192ce
parents 20e893dd 2ac8ac5a
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -117,6 +117,41 @@ protected:
    // Composite streams should behave accordingly.
    // Composite streams should behave accordingly.
    void enableErrorState();
    void enableErrorState();


    // Utility class to lock and unlock a GraphicBuffer
    class GraphicBufferLocker {
    public:
        GraphicBufferLocker(sp<GraphicBuffer> buffer) : _buffer(buffer) {}

        status_t lockAsync(void** dstBuffer, int fenceFd) {
            if (_buffer == nullptr) return BAD_VALUE;

            status_t res = OK;
            if (!_locked) {
                status_t res =  _buffer->lockAsync(GRALLOC_USAGE_SW_WRITE_OFTEN,
                        dstBuffer, fenceFd);
                if (res == OK) {
                    _locked = true;
                }
            }
            return res;
        }

        ~GraphicBufferLocker() {
            if (_locked && _buffer != nullptr) {
                auto res = _buffer->unlock();
                if (res != OK) {
                    ALOGE("%s: Error trying to unlock buffer: %s (%d)", __FUNCTION__,
                            strerror(-res), res);
                }
            }
        }

    private:
        sp<GraphicBuffer> _buffer;
        bool _locked = false;
    };


    wp<CameraDeviceBase>   mDevice;
    wp<CameraDeviceBase>   mDevice;
    wp<camera3::StatusTracker> mStatusTracker;
    wp<camera3::StatusTracker> mStatusTracker;
    wp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
    wp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
+2 −1
Original line number Original line Diff line number Diff line
@@ -297,7 +297,8 @@ status_t DepthCompositeStream::processInputFrame(nsecs_t ts, const InputFrame &i
    }
    }


    sp<GraphicBuffer> gb = GraphicBuffer::from(anb);
    sp<GraphicBuffer> gb = GraphicBuffer::from(anb);
    res = gb->lockAsync(GRALLOC_USAGE_SW_WRITE_OFTEN, &dstBuffer, fenceFd);
    GraphicBufferLocker gbLocker(gb);
    res = gbLocker.lockAsync(&dstBuffer, fenceFd);
    if (res != OK) {
    if (res != OK) {
        ALOGE("%s: Error trying to lock output buffer fence: %s (%d)", __FUNCTION__,
        ALOGE("%s: Error trying to lock output buffer fence: %s (%d)", __FUNCTION__,
                strerror(-res), res);
                strerror(-res), res);
+2 −1
Original line number Original line Diff line number Diff line
@@ -1130,7 +1130,8 @@ status_t HeicCompositeStream::processCompletedInputFrame(int64_t frameNumber,
    // Copy the content of the file to memory.
    // Copy the content of the file to memory.
    sp<GraphicBuffer> gb = GraphicBuffer::from(inputFrame.anb);
    sp<GraphicBuffer> gb = GraphicBuffer::from(inputFrame.anb);
    void* dstBuffer;
    void* dstBuffer;
    auto res = gb->lockAsync(GRALLOC_USAGE_SW_WRITE_OFTEN, &dstBuffer, inputFrame.fenceFd);
    GraphicBufferLocker gbLocker(gb);
    auto res = gbLocker.lockAsync(&dstBuffer, inputFrame.fenceFd);
    if (res != OK) {
    if (res != OK) {
        ALOGE("%s: Error trying to lock output buffer fence: %s (%d)", __FUNCTION__,
        ALOGE("%s: Error trying to lock output buffer fence: %s (%d)", __FUNCTION__,
                strerror(-res), res);
                strerror(-res), res);