Ejemplo n.º 1
0
void CameraClient::copyFrameAndPostCopiedFrame(
        int32_t msgType, const sp<ICameraClient>& client,
        const sp<IMemoryHeap>& heap, size_t offset, size_t size,
        camera_frame_metadata_t *metadata) {
    LOG2("copyFrameAndPostCopiedFrame");
    // It is necessary to copy out of pmem before sending this to
    // 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 preview lock while we grab a reference to the preview buffer
    sp<MemoryHeapBase> previewBuffer;

    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) {
        ALOGE("failed to allocate space for preview buffer");
        mLock.unlock();
        return;
    }
    previewBuffer = mPreviewBuffer;

    void* previewBufferBase = previewBuffer->base();
    void* heapBase = heap->base();

    if (heapBase == MAP_FAILED) {
        ALOGE("%s: Failed to mmap heap for preview frame.", __FUNCTION__);
        mLock.unlock();
        return;
    } else if (previewBufferBase == MAP_FAILED) {
        ALOGE("%s: Failed to mmap preview buffer for preview frame.", __FUNCTION__);
        mLock.unlock();
        return;
    }

    memcpy(previewBufferBase, (uint8_t *) heapBase + offset, size);

    sp<MemoryBase> frame = new MemoryBase(previewBuffer, 0, size);
    if (frame == 0) {
        ALOGE("failed to allocate space for frame callback");
        mLock.unlock();
        return;
    }

    mLock.unlock();
    client->dataCallback(msgType, frame, metadata);
}
		void CameraService::Client::copyFrameAndPostCopiedFrame(
																const sp<ICameraClient>& client, const sp<IMemoryHeap>& heap,
																size_t offset, size_t size) {
			LOG2("copyFrameAndPostCopiedFrame");
			// It is necessary to copy out of pmem before sending this to
			// 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 preview lock while we grab a reference to the preview buffer
			sp<MemoryHeapBase> previewBuffer;
			
			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");
				mLock.unlock();
				return;
			}
			previewBuffer = mPreviewBuffer;
			
			memcpy(previewBuffer->base(), (uint8_t *)heap->base() + offset, size);
			
			sp<MemoryBase> frame = new MemoryBase(previewBuffer, 0, size);
			if (frame == 0) {
				LOGE("failed to allocate space for frame callback");
				mLock.unlock();
				return;
			}
			
			mLock.unlock();
			client->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame);
		}