Loading services/camera/libcameraservice/CameraService.cpp +40 −18 Original line number Diff line number Diff line Loading @@ -410,6 +410,7 @@ status_t CameraService::Client::checkPidAndHardware() const { status_t CameraService::Client::lock() { int callingPid = getCallingPid(); LOG1("lock (pid %d)", callingPid); Mutex::Autolock ilock(mICameraLock); Mutex::Autolock lock(mLock); // lock camera to this client if the the camera is unlocked Loading @@ -425,6 +426,7 @@ status_t CameraService::Client::lock() { status_t CameraService::Client::unlock() { int callingPid = getCallingPid(); LOG1("unlock (pid %d)", callingPid); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); // allow anyone to use camera (after they lock the camera) Loading @@ -447,6 +449,7 @@ status_t CameraService::Client::unlock() { status_t CameraService::Client::connect(const sp<ICameraClient>& client) { int callingPid = getCallingPid(); LOG1("connect E (pid %d)", callingPid); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (mClientPid != 0 && checkPid() != NO_ERROR) { Loading Loading @@ -482,6 +485,7 @@ static void disconnectWindow(const sp<ANativeWindow>& window) { void CameraService::Client::disconnect() { int callingPid = getCallingPid(); LOG1("disconnect E (pid %d)", callingPid); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPid() != NO_ERROR) { Loading Loading @@ -526,6 +530,7 @@ void CameraService::Client::disconnect() { status_t CameraService::Client::setPreviewWindow(const sp<IBinder>& binder, const sp<ANativeWindow>& window) { Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading Loading @@ -597,6 +602,7 @@ status_t CameraService::Client::setPreviewTexture( // preview are handled. void CameraService::Client::setPreviewCallbackFlag(int callback_flag) { LOG1("setPreviewCallbackFlag(%d) (pid %d)", callback_flag, getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; Loading @@ -623,6 +629,7 @@ status_t CameraService::Client::startRecording() { // start preview or recording status_t CameraService::Client::startCameraMode(camera_mode mode) { LOG1("startCameraMode(%d)", mode); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading Loading @@ -696,6 +703,7 @@ status_t CameraService::Client::startRecordingMode() { // stop preview mode void CameraService::Client::stopPreview() { LOG1("stopPreview (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; Loading @@ -709,6 +717,7 @@ void CameraService::Client::stopPreview() { // stop recording mode void CameraService::Client::stopRecording() { LOG1("stopRecording (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; Loading @@ -721,6 +730,7 @@ void CameraService::Client::stopRecording() { // release a recording frame void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem) { Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; mHardware->releaseRecordingFrame(mem); Loading @@ -729,6 +739,7 @@ void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem) { status_t CameraService::Client::storeMetaDataInBuffers(bool enabled) { LOG1("storeMetaDataInBuffers: %s", enabled? "true": "false"); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) { return UNKNOWN_ERROR; Loading @@ -739,6 +750,7 @@ status_t CameraService::Client::storeMetaDataInBuffers(bool enabled) bool CameraService::Client::previewEnabled() { LOG1("previewEnabled (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return false; return mHardware->previewEnabled(); Loading @@ -747,6 +759,7 @@ bool CameraService::Client::previewEnabled() { bool CameraService::Client::recordingEnabled() { LOG1("recordingEnabled (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return false; return mHardware->recordingEnabled(); Loading @@ -755,6 +768,7 @@ bool CameraService::Client::recordingEnabled() { status_t CameraService::Client::autoFocus() { LOG1("autoFocus (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -765,6 +779,7 @@ status_t CameraService::Client::autoFocus() { status_t CameraService::Client::cancelAutoFocus() { LOG1("cancelAutoFocus (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -776,6 +791,9 @@ status_t CameraService::Client::cancelAutoFocus() { status_t CameraService::Client::takePicture(int msgType) { LOG1("takePicture (pid %d): 0x%x", getCallingPid(), msgType); Mutex::Autolock iLock(mICameraLock); int picMsgType = 0; { // scope for lock Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -789,13 +807,14 @@ status_t CameraService::Client::takePicture(int msgType) { // We only accept picture related message types // and ignore other types of messages for takePicture(). int picMsgType = msgType picMsgType = msgType & (CAMERA_MSG_SHUTTER | CAMERA_MSG_POSTVIEW_FRAME | CAMERA_MSG_RAW_IMAGE | CAMERA_MSG_RAW_IMAGE_NOTIFY | CAMERA_MSG_COMPRESSED_IMAGE); } enableMsgType(picMsgType); return mHardware->takePicture(); Loading @@ -805,6 +824,7 @@ status_t CameraService::Client::takePicture(int msgType) { status_t CameraService::Client::setParameters(const String8& params) { LOG1("setParameters (pid %d) (%s)", getCallingPid(), params.string()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -815,6 +835,7 @@ status_t CameraService::Client::setParameters(const String8& params) { // get preview/capture parameters - key/value pairs String8 CameraService::Client::getParameters() const { Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return String8(); Loading Loading @@ -855,6 +876,7 @@ status_t CameraService::Client::enableShutterSound(bool enable) { status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) { LOG1("sendCommand (pid %d)", getCallingPid()); int orientation; Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading services/camera/libcameraservice/CameraService.h +5 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,11 @@ private: // Ensures atomicity among the public methods mutable Mutex mLock; // A lock to synchronize access through the ICamera binder // interface. The entire binder call should be done with mICameraLock // locked, to serialize ICamera access, even when mLock is disabled for // calls to the HAL. mutable Mutex mICameraLock; // This is a binder of Surface or SurfaceTexture. sp<IBinder> mSurface; sp<ANativeWindow> mPreviewWindow; Loading Loading
services/camera/libcameraservice/CameraService.cpp +40 −18 Original line number Diff line number Diff line Loading @@ -410,6 +410,7 @@ status_t CameraService::Client::checkPidAndHardware() const { status_t CameraService::Client::lock() { int callingPid = getCallingPid(); LOG1("lock (pid %d)", callingPid); Mutex::Autolock ilock(mICameraLock); Mutex::Autolock lock(mLock); // lock camera to this client if the the camera is unlocked Loading @@ -425,6 +426,7 @@ status_t CameraService::Client::lock() { status_t CameraService::Client::unlock() { int callingPid = getCallingPid(); LOG1("unlock (pid %d)", callingPid); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); // allow anyone to use camera (after they lock the camera) Loading @@ -447,6 +449,7 @@ status_t CameraService::Client::unlock() { status_t CameraService::Client::connect(const sp<ICameraClient>& client) { int callingPid = getCallingPid(); LOG1("connect E (pid %d)", callingPid); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (mClientPid != 0 && checkPid() != NO_ERROR) { Loading Loading @@ -482,6 +485,7 @@ static void disconnectWindow(const sp<ANativeWindow>& window) { void CameraService::Client::disconnect() { int callingPid = getCallingPid(); LOG1("disconnect E (pid %d)", callingPid); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPid() != NO_ERROR) { Loading Loading @@ -526,6 +530,7 @@ void CameraService::Client::disconnect() { status_t CameraService::Client::setPreviewWindow(const sp<IBinder>& binder, const sp<ANativeWindow>& window) { Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading Loading @@ -597,6 +602,7 @@ status_t CameraService::Client::setPreviewTexture( // preview are handled. void CameraService::Client::setPreviewCallbackFlag(int callback_flag) { LOG1("setPreviewCallbackFlag(%d) (pid %d)", callback_flag, getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; Loading @@ -623,6 +629,7 @@ status_t CameraService::Client::startRecording() { // start preview or recording status_t CameraService::Client::startCameraMode(camera_mode mode) { LOG1("startCameraMode(%d)", mode); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading Loading @@ -696,6 +703,7 @@ status_t CameraService::Client::startRecordingMode() { // stop preview mode void CameraService::Client::stopPreview() { LOG1("stopPreview (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; Loading @@ -709,6 +717,7 @@ void CameraService::Client::stopPreview() { // stop recording mode void CameraService::Client::stopRecording() { LOG1("stopRecording (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; Loading @@ -721,6 +730,7 @@ void CameraService::Client::stopRecording() { // release a recording frame void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem) { Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return; mHardware->releaseRecordingFrame(mem); Loading @@ -729,6 +739,7 @@ void CameraService::Client::releaseRecordingFrame(const sp<IMemory>& mem) { status_t CameraService::Client::storeMetaDataInBuffers(bool enabled) { LOG1("storeMetaDataInBuffers: %s", enabled? "true": "false"); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) { return UNKNOWN_ERROR; Loading @@ -739,6 +750,7 @@ status_t CameraService::Client::storeMetaDataInBuffers(bool enabled) bool CameraService::Client::previewEnabled() { LOG1("previewEnabled (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return false; return mHardware->previewEnabled(); Loading @@ -747,6 +759,7 @@ bool CameraService::Client::previewEnabled() { bool CameraService::Client::recordingEnabled() { LOG1("recordingEnabled (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return false; return mHardware->recordingEnabled(); Loading @@ -755,6 +768,7 @@ bool CameraService::Client::recordingEnabled() { status_t CameraService::Client::autoFocus() { LOG1("autoFocus (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -765,6 +779,7 @@ status_t CameraService::Client::autoFocus() { status_t CameraService::Client::cancelAutoFocus() { LOG1("cancelAutoFocus (pid %d)", getCallingPid()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -776,6 +791,9 @@ status_t CameraService::Client::cancelAutoFocus() { status_t CameraService::Client::takePicture(int msgType) { LOG1("takePicture (pid %d): 0x%x", getCallingPid(), msgType); Mutex::Autolock iLock(mICameraLock); int picMsgType = 0; { // scope for lock Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -789,13 +807,14 @@ status_t CameraService::Client::takePicture(int msgType) { // We only accept picture related message types // and ignore other types of messages for takePicture(). int picMsgType = msgType picMsgType = msgType & (CAMERA_MSG_SHUTTER | CAMERA_MSG_POSTVIEW_FRAME | CAMERA_MSG_RAW_IMAGE | CAMERA_MSG_RAW_IMAGE_NOTIFY | CAMERA_MSG_COMPRESSED_IMAGE); } enableMsgType(picMsgType); return mHardware->takePicture(); Loading @@ -805,6 +824,7 @@ status_t CameraService::Client::takePicture(int msgType) { status_t CameraService::Client::setParameters(const String8& params) { LOG1("setParameters (pid %d) (%s)", getCallingPid(), params.string()); Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading @@ -815,6 +835,7 @@ status_t CameraService::Client::setParameters(const String8& params) { // get preview/capture parameters - key/value pairs String8 CameraService::Client::getParameters() const { Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); if (checkPidAndHardware() != NO_ERROR) return String8(); Loading Loading @@ -855,6 +876,7 @@ status_t CameraService::Client::enableShutterSound(bool enable) { status_t CameraService::Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) { LOG1("sendCommand (pid %d)", getCallingPid()); int orientation; Mutex::Autolock iLock(mICameraLock); Mutex::Autolock lock(mLock); status_t result = checkPidAndHardware(); if (result != NO_ERROR) return result; Loading
services/camera/libcameraservice/CameraService.h +5 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,11 @@ private: // Ensures atomicity among the public methods mutable Mutex mLock; // A lock to synchronize access through the ICamera binder // interface. The entire binder call should be done with mICameraLock // locked, to serialize ICamera access, even when mLock is disabled for // calls to the HAL. mutable Mutex mICameraLock; // This is a binder of Surface or SurfaceTexture. sp<IBinder> mSurface; sp<ANativeWindow> mPreviewWindow; Loading