Loading camera/libcameraservice/CameraHardwareStub.cpp +14 −23 Original line number Diff line number Diff line Loading @@ -29,8 +29,7 @@ namespace android { CameraHardwareStub::CameraHardwareStub() : mParameters(), mPreviewHeap(0), mRawHeap(0), mHeap(0), mFakeCamera(0), mPreviewFrameSize(0), mRawPictureCallback(0), Loading Loading @@ -63,17 +62,13 @@ void CameraHardwareStub::initDefaultParameters() void CameraHardwareStub::initHeapLocked() { // Create raw heap. int picture_width, picture_height; mParameters.getPictureSize(&picture_width, &picture_height); mRawHeap = new MemoryHeapBase(picture_width * 2 * picture_height); int width, height; mParameters.getPreviewSize(&width, &height); int preview_width, preview_height; mParameters.getPreviewSize(&preview_width, &preview_height); LOGD("initHeapLocked: preview size=%dx%d", preview_width, preview_height); LOGD("initHeapLocked: preview size=%dx%d", width, height); // Note that we enforce yuv422 in setParameters(). int how_big = preview_width * preview_height * 2; int how_big = width * height * 2; // If we are being reinitialized to the same size as before, no // work needs to be done. Loading @@ -84,15 +79,15 @@ void CameraHardwareStub::initHeapLocked() // Make a new mmap'ed heap that can be shared across processes. // use code below to test with pmem mPreviewHeap = new MemoryHeapBase(mPreviewFrameSize * kBufferCount); mHeap = new MemoryHeapBase(mPreviewFrameSize * kBufferCount); // Make an IMemory for each frame so that we can reuse them in callbacks. for (int i = 0; i < kBufferCount; i++) { mBuffers[i] = new MemoryBase(mPreviewHeap, i * mPreviewFrameSize, mPreviewFrameSize); mBuffers[i] = new MemoryBase(mHeap, i * mPreviewFrameSize, mPreviewFrameSize); } // Recreate the fake camera to reflect the current size. delete mFakeCamera; mFakeCamera = new FakeCamera(preview_width, preview_height); mFakeCamera = new FakeCamera(width, height); } CameraHardwareStub::~CameraHardwareStub() Loading @@ -104,12 +99,7 @@ CameraHardwareStub::~CameraHardwareStub() sp<IMemoryHeap> CameraHardwareStub::getPreviewHeap() const { return mPreviewHeap; } sp<IMemoryHeap> CameraHardwareStub::getRawHeap() const { return mRawHeap; return mHeap; } // --------------------------------------------------------------------------- Loading @@ -124,7 +114,7 @@ int CameraHardwareStub::previewThread() // Find the offset within the heap of the current buffer. ssize_t offset = mCurrentPreviewFrame * mPreviewFrameSize; sp<MemoryHeapBase> heap = mPreviewHeap; sp<MemoryHeapBase> heap = mHeap; // this assumes the internal state of fake camera doesn't change // (or is thread safe) Loading Loading @@ -265,9 +255,10 @@ int CameraHardwareStub::pictureThread() // In the meantime just make another fake camera picture. int w, h; mParameters.getPictureSize(&w, &h); sp<MemoryBase> mem = new MemoryBase(mRawHeap, 0, w * 2 * h); sp<MemoryHeapBase> heap = new MemoryHeapBase(w * 2 * h); sp<MemoryBase> mem = new MemoryBase(heap, 0, w * 2 * h); FakeCamera cam(w, h); cam.getNextFrameAsYuv422((uint8_t *)mRawHeap->base()); cam.getNextFrameAsYuv422((uint8_t *)heap->base()); if (mRawPictureCallback) mRawPictureCallback(mem, mPictureCallbackCookie); } Loading camera/libcameraservice/CameraHardwareStub.h +1 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ namespace android { class CameraHardwareStub : public CameraHardwareInterface { public: virtual sp<IMemoryHeap> getPreviewHeap() const; virtual sp<IMemoryHeap> getRawHeap() const; virtual status_t startPreview(preview_callback cb, void* user); virtual void stopPreview(); Loading Loading @@ -94,8 +93,7 @@ private: CameraParameters mParameters; sp<MemoryHeapBase> mPreviewHeap; sp<MemoryHeapBase> mRawHeap; sp<MemoryHeapBase> mHeap; sp<MemoryBase> mBuffers[kBufferCount]; FakeCamera *mFakeCamera; Loading camera/libcameraservice/CameraService.cpp +21 −27 Original line number Diff line number Diff line Loading @@ -684,33 +684,13 @@ status_t CameraService::Client::takePicture() return INVALID_OPERATION; } if (mSurface != NULL && !mUseOverlay) mSurface->unregisterBuffers(); Mutex::Autolock buffer_lock(mBufferLock); result = mHardware->takePicture(shutterCallback, return mHardware->takePicture(shutterCallback, yuvPictureCallback, jpegPictureCallback, mCameraService.get()); // It takes quite some time before yuvPicture callback to be called. // Register the buffer for raw image here to reduce latency. // But yuvPictureCallback is called from libcamera. So do not call into a // libcamera function here that gets another lock, which may cause deadlock. if (mSurface != 0 && !mUseOverlay) { int w, h; CameraParameters params(mHardware->getParameters()); params.getPictureSize(&w, &h); mSurface->unregisterBuffers(); uint32_t transform = 0; if (params.getOrientation() == CameraParameters::CAMERA_ORIENTATION_PORTRAIT) { LOGV("portrait mode"); transform = ISurface::BufferHeap::ROT_90; } ISurface::BufferHeap buffers(w, h, w, h, PIXEL_FORMAT_YCbCr_420_SP, transform, 0, mHardware->getRawHeap()); mSurface->registerBuffers(buffers); } return result; } // picture callback - snapshot taken Loading Loading @@ -752,9 +732,23 @@ void CameraService::Client::yuvPictureCallback(const sp<IMemory>& mem, #endif // Put the YUV version of the snapshot in the preview display. // Use lock to make sure buffer has been registered. Mutex::Autolock clientLock(client->mBufferLock); int w, h; CameraParameters params(client->mHardware->getParameters()); params.getPictureSize(&w, &h); // Mutex::Autolock clientLock(client->mLock); if (client->mSurface != 0 && !client->mUseOverlay) { client->mSurface->unregisterBuffers(); uint32_t transform = 0; if (params.getOrientation() == CameraParameters::CAMERA_ORIENTATION_PORTRAIT) { LOGV("portrait mode"); transform = ISurface::BufferHeap::ROT_90; } ISurface::BufferHeap buffers(w, h, w, h, PIXEL_FORMAT_YCbCr_420_SP, transform, 0, heap); client->mSurface->registerBuffers(buffers); client->mSurface->postBuffer(offset); } Loading camera/libcameraservice/CameraService.h +0 −3 Original line number Diff line number Diff line Loading @@ -172,9 +172,6 @@ private: // for a callback from CameraHardwareInterface. If this // happens, it will cause a deadlock. mutable Mutex mSurfaceLock; // mBufferLock synchronizes buffer registration between takePicture() // and yuvPictureCallback(). mutable Mutex mBufferLock; mutable Condition mReady; sp<CameraService> mCameraService; sp<ISurface> mSurface; Loading include/ui/CameraHardwareInterface.h +0 −3 Original line number Diff line number Diff line Loading @@ -87,9 +87,6 @@ public: /** Return the IMemoryHeap for the preview image heap */ virtual sp<IMemoryHeap> getPreviewHeap() const = 0; /** Return the IMemoryHeap for the raw image heap */ virtual sp<IMemoryHeap> getRawHeap() const = 0; /** * Start preview mode. When a preview image is available * preview_callback is called with the user parameter. The Loading Loading
camera/libcameraservice/CameraHardwareStub.cpp +14 −23 Original line number Diff line number Diff line Loading @@ -29,8 +29,7 @@ namespace android { CameraHardwareStub::CameraHardwareStub() : mParameters(), mPreviewHeap(0), mRawHeap(0), mHeap(0), mFakeCamera(0), mPreviewFrameSize(0), mRawPictureCallback(0), Loading Loading @@ -63,17 +62,13 @@ void CameraHardwareStub::initDefaultParameters() void CameraHardwareStub::initHeapLocked() { // Create raw heap. int picture_width, picture_height; mParameters.getPictureSize(&picture_width, &picture_height); mRawHeap = new MemoryHeapBase(picture_width * 2 * picture_height); int width, height; mParameters.getPreviewSize(&width, &height); int preview_width, preview_height; mParameters.getPreviewSize(&preview_width, &preview_height); LOGD("initHeapLocked: preview size=%dx%d", preview_width, preview_height); LOGD("initHeapLocked: preview size=%dx%d", width, height); // Note that we enforce yuv422 in setParameters(). int how_big = preview_width * preview_height * 2; int how_big = width * height * 2; // If we are being reinitialized to the same size as before, no // work needs to be done. Loading @@ -84,15 +79,15 @@ void CameraHardwareStub::initHeapLocked() // Make a new mmap'ed heap that can be shared across processes. // use code below to test with pmem mPreviewHeap = new MemoryHeapBase(mPreviewFrameSize * kBufferCount); mHeap = new MemoryHeapBase(mPreviewFrameSize * kBufferCount); // Make an IMemory for each frame so that we can reuse them in callbacks. for (int i = 0; i < kBufferCount; i++) { mBuffers[i] = new MemoryBase(mPreviewHeap, i * mPreviewFrameSize, mPreviewFrameSize); mBuffers[i] = new MemoryBase(mHeap, i * mPreviewFrameSize, mPreviewFrameSize); } // Recreate the fake camera to reflect the current size. delete mFakeCamera; mFakeCamera = new FakeCamera(preview_width, preview_height); mFakeCamera = new FakeCamera(width, height); } CameraHardwareStub::~CameraHardwareStub() Loading @@ -104,12 +99,7 @@ CameraHardwareStub::~CameraHardwareStub() sp<IMemoryHeap> CameraHardwareStub::getPreviewHeap() const { return mPreviewHeap; } sp<IMemoryHeap> CameraHardwareStub::getRawHeap() const { return mRawHeap; return mHeap; } // --------------------------------------------------------------------------- Loading @@ -124,7 +114,7 @@ int CameraHardwareStub::previewThread() // Find the offset within the heap of the current buffer. ssize_t offset = mCurrentPreviewFrame * mPreviewFrameSize; sp<MemoryHeapBase> heap = mPreviewHeap; sp<MemoryHeapBase> heap = mHeap; // this assumes the internal state of fake camera doesn't change // (or is thread safe) Loading Loading @@ -265,9 +255,10 @@ int CameraHardwareStub::pictureThread() // In the meantime just make another fake camera picture. int w, h; mParameters.getPictureSize(&w, &h); sp<MemoryBase> mem = new MemoryBase(mRawHeap, 0, w * 2 * h); sp<MemoryHeapBase> heap = new MemoryHeapBase(w * 2 * h); sp<MemoryBase> mem = new MemoryBase(heap, 0, w * 2 * h); FakeCamera cam(w, h); cam.getNextFrameAsYuv422((uint8_t *)mRawHeap->base()); cam.getNextFrameAsYuv422((uint8_t *)heap->base()); if (mRawPictureCallback) mRawPictureCallback(mem, mPictureCallbackCookie); } Loading
camera/libcameraservice/CameraHardwareStub.h +1 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ namespace android { class CameraHardwareStub : public CameraHardwareInterface { public: virtual sp<IMemoryHeap> getPreviewHeap() const; virtual sp<IMemoryHeap> getRawHeap() const; virtual status_t startPreview(preview_callback cb, void* user); virtual void stopPreview(); Loading Loading @@ -94,8 +93,7 @@ private: CameraParameters mParameters; sp<MemoryHeapBase> mPreviewHeap; sp<MemoryHeapBase> mRawHeap; sp<MemoryHeapBase> mHeap; sp<MemoryBase> mBuffers[kBufferCount]; FakeCamera *mFakeCamera; Loading
camera/libcameraservice/CameraService.cpp +21 −27 Original line number Diff line number Diff line Loading @@ -684,33 +684,13 @@ status_t CameraService::Client::takePicture() return INVALID_OPERATION; } if (mSurface != NULL && !mUseOverlay) mSurface->unregisterBuffers(); Mutex::Autolock buffer_lock(mBufferLock); result = mHardware->takePicture(shutterCallback, return mHardware->takePicture(shutterCallback, yuvPictureCallback, jpegPictureCallback, mCameraService.get()); // It takes quite some time before yuvPicture callback to be called. // Register the buffer for raw image here to reduce latency. // But yuvPictureCallback is called from libcamera. So do not call into a // libcamera function here that gets another lock, which may cause deadlock. if (mSurface != 0 && !mUseOverlay) { int w, h; CameraParameters params(mHardware->getParameters()); params.getPictureSize(&w, &h); mSurface->unregisterBuffers(); uint32_t transform = 0; if (params.getOrientation() == CameraParameters::CAMERA_ORIENTATION_PORTRAIT) { LOGV("portrait mode"); transform = ISurface::BufferHeap::ROT_90; } ISurface::BufferHeap buffers(w, h, w, h, PIXEL_FORMAT_YCbCr_420_SP, transform, 0, mHardware->getRawHeap()); mSurface->registerBuffers(buffers); } return result; } // picture callback - snapshot taken Loading Loading @@ -752,9 +732,23 @@ void CameraService::Client::yuvPictureCallback(const sp<IMemory>& mem, #endif // Put the YUV version of the snapshot in the preview display. // Use lock to make sure buffer has been registered. Mutex::Autolock clientLock(client->mBufferLock); int w, h; CameraParameters params(client->mHardware->getParameters()); params.getPictureSize(&w, &h); // Mutex::Autolock clientLock(client->mLock); if (client->mSurface != 0 && !client->mUseOverlay) { client->mSurface->unregisterBuffers(); uint32_t transform = 0; if (params.getOrientation() == CameraParameters::CAMERA_ORIENTATION_PORTRAIT) { LOGV("portrait mode"); transform = ISurface::BufferHeap::ROT_90; } ISurface::BufferHeap buffers(w, h, w, h, PIXEL_FORMAT_YCbCr_420_SP, transform, 0, heap); client->mSurface->registerBuffers(buffers); client->mSurface->postBuffer(offset); } Loading
camera/libcameraservice/CameraService.h +0 −3 Original line number Diff line number Diff line Loading @@ -172,9 +172,6 @@ private: // for a callback from CameraHardwareInterface. If this // happens, it will cause a deadlock. mutable Mutex mSurfaceLock; // mBufferLock synchronizes buffer registration between takePicture() // and yuvPictureCallback(). mutable Mutex mBufferLock; mutable Condition mReady; sp<CameraService> mCameraService; sp<ISurface> mSurface; Loading
include/ui/CameraHardwareInterface.h +0 −3 Original line number Diff line number Diff line Loading @@ -87,9 +87,6 @@ public: /** Return the IMemoryHeap for the preview image heap */ virtual sp<IMemoryHeap> getPreviewHeap() const = 0; /** Return the IMemoryHeap for the raw image heap */ virtual sp<IMemoryHeap> getRawHeap() const = 0; /** * Start preview mode. When a preview image is available * preview_callback is called with the user parameter. The Loading