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

Commit ead5bb7e authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change Ic8093c11 into eclair

* changes:
  Hold a lock while we access the preview heap.
parents d086c1cd 23c21baf
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -1215,20 +1215,27 @@ void CameraService::Client::copyFrameAndPostCopiedFrame(const sp<ICameraClient>&
    // the callback. For efficiency, reuse the same MemoryHeapBase
    // provided it's big enough. Don't allocate the memory or
    // perform the copy if there's no callback.

    // hold the lock while we grab a reference to the preview buffer
    sp<MemoryHeapBase> previewBuffer;
    {
        Mutex::Autolock lock(mLock);
        if (mPreviewBuffer == 0) {
            mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
        } else if (size > mPreviewBuffer->virtualSize()) {
            mPreviewBuffer.clear();
            mPreviewBuffer = new MemoryHeapBase(size, 0, NULL);
        }
        if (mPreviewBuffer == 0) {
            LOGE("failed to allocate space for preview buffer");
            return;
        }
        previewBuffer = mPreviewBuffer;
    }
    memcpy(mPreviewBuffer->base(),
    memcpy(previewBuffer->base(),
           (uint8_t *)heap->base() + offset, size);

    sp<MemoryBase> frame = new MemoryBase(mPreviewBuffer, 0, size);
    sp<MemoryBase> frame = new MemoryBase(previewBuffer, 0, size);
    if (frame == 0) {
        LOGE("failed to allocate space for frame callback");
        return;