Loading services/camera/libcameraservice/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ LOCAL_SRC_FILES:= \ CameraClient.cpp \ Camera2Client.cpp \ ProCamera2Client.cpp \ Camera2ClientBase.cpp \ CameraDeviceBase.cpp \ Camera2Device.cpp \ Camera3Device.cpp \ Loading services/camera/libcameraservice/Camera2Client.cpp +38 −114 Original line number Diff line number Diff line Loading @@ -49,9 +49,8 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService, uid_t clientUid, int servicePid, int deviceVersion): Client(cameraService, cameraClient, clientPackageName, Camera2ClientBase(cameraService, cameraClient, clientPackageName, cameraId, cameraFacing, clientPid, clientUid, servicePid), mSharedCameraClient(cameraClient), mParameters(cameraId, cameraFacing) { ATRACE_CALL(); Loading @@ -76,15 +75,6 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService, l.mParameters.state = Parameters::DISCONNECTED; } status_t Camera2Client::checkPid(const char* checkLocation) const { int callingPid = getCallingPid(); if (callingPid == mClientPid) return NO_ERROR; ALOGE("%s: attempt to use a locked camera from a different process" " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid); return PERMISSION_DENIED; } status_t Camera2Client::initialize(camera_module_t *module) { ATRACE_CALL(); Loading Loading @@ -173,7 +163,7 @@ status_t Camera2Client::dump(int fd, const Vector<String16>& args) { String8 result; result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n", mCameraId, getCameraClient()->asBinder().get(), getRemoteCallback()->asBinder().get(), mClientPid); result.append(" State: "); #define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break; Loading Loading @@ -376,25 +366,15 @@ status_t Camera2Client::dump(int fd, const Vector<String16>& args) { mZslProcessor->dump(fd, args); result = " Device dump:\n"; write(fd, result.string(), result.size()); status_t res = mDevice->dump(fd, args); if (res != OK) { result = String8::format(" Error dumping device: %s (%d)", strerror(-res), res); write(fd, result.string(), result.size()); } return dumpDevice(fd, args); #undef CASE_APPEND_ENUM return NO_ERROR; } // ICamera interface void Camera2Client::disconnect() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); // Allow both client and the media server to disconnect at all times int callingPid = getCallingPid(); Loading Loading @@ -444,7 +424,7 @@ void Camera2Client::disconnect() { status_t Camera2Client::connect(const sp<ICameraClient>& client) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if (mClientPid != 0 && getCallingPid() != mClientPid) { ALOGE("%s: Camera %d: Connection attempt from pid %d; " Loading @@ -455,8 +435,8 @@ status_t Camera2Client::connect(const sp<ICameraClient>& client) { mClientPid = getCallingPid(); mCameraClient = client; mSharedCameraClient = client; mRemoteCallback = client; mSharedCameraCallbacks = client; return OK; } Loading @@ -464,7 +444,7 @@ status_t Camera2Client::connect(const sp<ICameraClient>& client) { status_t Camera2Client::lock() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d", __FUNCTION__, mCameraId, getCallingPid(), mClientPid); Loading @@ -485,7 +465,7 @@ status_t Camera2Client::lock() { status_t Camera2Client::unlock() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d", __FUNCTION__, mCameraId, getCallingPid(), mClientPid); Loading @@ -497,8 +477,8 @@ status_t Camera2Client::unlock() { return INVALID_OPERATION; } mClientPid = 0; mCameraClient.clear(); mSharedCameraClient.clear(); mRemoteCallback.clear(); mSharedCameraCallbacks.clear(); return OK; } Loading @@ -511,7 +491,7 @@ status_t Camera2Client::setPreviewDisplay( const sp<Surface>& surface) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading @@ -529,7 +509,7 @@ status_t Camera2Client::setPreviewTexture( const sp<IGraphicBufferProducer>& bufferProducer) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -598,7 +578,7 @@ status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder, void Camera2Client::setPreviewCallbackFlag(int flag) { ATRACE_CALL(); ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return; Loading Loading @@ -637,7 +617,7 @@ void Camera2Client::setPreviewCallbackFlagL(Parameters ¶ms, int flag) { status_t Camera2Client::startPreview() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; SharedParameters::Lock l(mParameters); Loading Loading @@ -753,7 +733,7 @@ status_t Camera2Client::startPreviewL(Parameters ¶ms, bool restart) { void Camera2Client::stopPreview() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return; stopPreviewL(); Loading Loading @@ -801,7 +781,7 @@ void Camera2Client::stopPreviewL() { bool Camera2Client::previewEnabled() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return false; Loading @@ -811,7 +791,7 @@ bool Camera2Client::previewEnabled() { status_t Camera2Client::storeMetaDataInBuffers(bool enabled) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading @@ -836,7 +816,7 @@ status_t Camera2Client::storeMetaDataInBuffers(bool enabled) { status_t Camera2Client::startRecording() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; SharedParameters::Lock l(mParameters); Loading Loading @@ -927,7 +907,7 @@ status_t Camera2Client::startRecordingL(Parameters ¶ms, bool restart) { void Camera2Client::stopRecording() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); SharedParameters::Lock l(mParameters); status_t res; Loading Loading @@ -959,7 +939,7 @@ void Camera2Client::stopRecording() { bool Camera2Client::recordingEnabled() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return false; Loading @@ -976,7 +956,7 @@ bool Camera2Client::recordingEnabledL() { void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return; mStreamingProcessor->releaseRecordingFrame(mem); Loading @@ -984,7 +964,7 @@ void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { status_t Camera2Client::autoFocus() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1022,9 +1002,9 @@ status_t Camera2Client::autoFocus() { * Send immediate notification back to client */ if (notifyImmediately) { SharedCameraClient::Lock l(mSharedCameraClient); if (l.mCameraClient != 0) { l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, notifySuccess ? 1 : 0, 0); } return OK; Loading Loading @@ -1055,7 +1035,7 @@ status_t Camera2Client::autoFocus() { status_t Camera2Client::cancelAutoFocus() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1087,7 +1067,7 @@ status_t Camera2Client::cancelAutoFocus() { status_t Camera2Client::takePicture(int msgType) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1146,7 +1126,7 @@ status_t Camera2Client::takePicture(int msgType) { status_t Camera2Client::setParameters(const String8& params) { ATRACE_CALL(); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading @@ -1163,7 +1143,7 @@ status_t Camera2Client::setParameters(const String8& params) { String8 Camera2Client::getParameters() const { ATRACE_CALL(); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return String8(); SharedParameters::ReadLock l(mParameters); Loading @@ -1173,7 +1153,7 @@ String8 Camera2Client::getParameters() const { status_t Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1348,18 +1328,6 @@ status_t Camera2Client::commandSetVideoBufferCountL(size_t count) { } /** Device-related methods */ void Camera2Client::notifyError(int errorCode, int arg1, int arg2) { ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, arg1, arg2); } void Camera2Client::notifyShutter(int frameNumber, nsecs_t timestamp) { (void)frameNumber; (void)timestamp; ALOGV("%s: Shutter notification for frame %d at time %lld", __FUNCTION__, frameNumber, timestamp); } void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { ALOGV("%s: Autofocus state now %d, last trigger %d", __FUNCTION__, newState, triggerId); Loading Loading @@ -1455,16 +1423,16 @@ void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { } } if (sendMovingMessage) { SharedCameraClient::Lock l(mSharedCameraClient); if (l.mCameraClient != 0) { l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS_MOVE, SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS_MOVE, afInMotion ? 1 : 0, 0); } } if (sendCompletedMessage) { SharedCameraClient::Lock l(mSharedCameraClient); if (l.mCameraClient != 0) { l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, success ? 1 : 0, 0); } } Loading @@ -1476,25 +1444,6 @@ void Camera2Client::notifyAutoExposure(uint8_t newState, int triggerId) { mCaptureSequencer->notifyAutoExposure(newState, triggerId); } void Camera2Client::notifyAutoWhitebalance(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", __FUNCTION__, newState, triggerId); } int Camera2Client::getCameraId() const { return mCameraId; } const sp<CameraDeviceBase>& Camera2Client::getCameraDevice() { return mDevice; } const sp<CameraService>& Camera2Client::getCameraService() { return mCameraService; } camera2::SharedParameters& Camera2Client::getParameters() { return mParameters; } Loading Loading @@ -1533,32 +1482,6 @@ status_t Camera2Client::stopStream() { return mStreamingProcessor->stopStream(); } Camera2Client::SharedCameraClient::Lock::Lock(SharedCameraClient &client): mCameraClient(client.mCameraClient), mSharedClient(client) { mSharedClient.mCameraClientLock.lock(); } Camera2Client::SharedCameraClient::Lock::~Lock() { mSharedClient.mCameraClientLock.unlock(); } Camera2Client::SharedCameraClient::SharedCameraClient(const sp<ICameraClient>&client): mCameraClient(client) { } Camera2Client::SharedCameraClient& Camera2Client::SharedCameraClient::operator=( const sp<ICameraClient>&client) { Mutex::Autolock l(mCameraClientLock); mCameraClient = client; return *this; } void Camera2Client::SharedCameraClient::clear() { Mutex::Autolock l(mCameraClientLock); mCameraClient.clear(); } const int32_t Camera2Client::kPreviewRequestIdStart; const int32_t Camera2Client::kPreviewRequestIdEnd; const int32_t Camera2Client::kRecordingRequestIdStart; Loading Loading @@ -1660,4 +1583,5 @@ status_t Camera2Client::syncWithDevice() { return res; } } // namespace android services/camera/libcameraservice/Camera2Client.h +2 −43 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include "camera2/ZslProcessor.h" #include "camera2/CaptureSequencer.h" #include "camera2/CallbackProcessor.h" #include "Camera2ClientBase.h" namespace android { Loading @@ -35,8 +36,7 @@ class IMemory; * CAMERA_DEVICE_API_VERSION_2_0 and 3_0. */ class Camera2Client : public CameraService::Client, public CameraDeviceBase::NotificationListener public Camera2ClientBase<CameraService::Client> { public: /** Loading Loading @@ -90,19 +90,13 @@ public: * Interface used by CameraDeviceBase */ virtual void notifyError(int errorCode, int arg1, int arg2); virtual void notifyShutter(int frameNumber, nsecs_t timestamp); virtual void notifyAutoFocus(uint8_t newState, int triggerId); virtual void notifyAutoExposure(uint8_t newState, int triggerId); virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId); /** * Interface used by independent components of Camera2Client. */ int getCameraId() const; const sp<CameraDeviceBase>& getCameraDevice(); const sp<CameraService>& getCameraService(); camera2::SharedParameters& getParameters(); int getPreviewStreamId() const; Loading @@ -118,27 +112,6 @@ public: status_t stopStream(); // Simple class to ensure that access to ICameraClient is serialized by // requiring mCameraClientLock to be locked before access to mCameraClient // is possible. class SharedCameraClient { public: class Lock { public: Lock(SharedCameraClient &client); ~Lock(); sp<ICameraClient> &mCameraClient; private: SharedCameraClient &mSharedClient; }; SharedCameraClient(const sp<ICameraClient>& client); SharedCameraClient& operator=(const sp<ICameraClient>& client); void clear(); private: sp<ICameraClient> mCameraClient; mutable Mutex mCameraClientLock; } mSharedCameraClient; static size_t calculateBufferSize(int width, int height, int format, int stride); Loading @@ -153,13 +126,6 @@ public: private: /** ICamera interface-related private members */ // Mutex that must be locked by methods implementing the ICamera interface. // Ensures serialization between incoming ICamera calls. All methods below // that append 'L' to the name assume that mICameraLock is locked when // they're called mutable Mutex mICameraLock; typedef camera2::Parameters Parameters; status_t setPreviewWindowL(const sp<IBinder>& binder, Loading Loading @@ -213,17 +179,10 @@ private: bool mAfInMotion; /** CameraDevice instance, wraps HAL camera device */ sp<CameraDeviceBase> mDevice; /** Utility members */ // Wait until the camera device has received the latest control settings status_t syncWithDevice(); // Verify that caller is the owner of the camera status_t checkPid(const char *checkLocation) const; }; }; // namespace android Loading services/camera/libcameraservice/Camera2ClientBase.cpp 0 → 100644 +315 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "Camera2ClientBase" #define ATRACE_TAG ATRACE_TAG_CAMERA //#define LOG_NDEBUG 0 #include <utils/Log.h> #include <utils/Trace.h> #include <cutils/properties.h> #include <gui/Surface.h> #include <gui/Surface.h> #include "camera2/Parameters.h" #include "Camera2ClientBase.h" #include "camera2/ProFrameProcessor.h" #include "Camera2Device.h" namespace android { using namespace camera2; static int getCallingPid() { return IPCThreadState::self()->getCallingPid(); } // Interface used by CameraService template <typename TClientBase> Camera2ClientBase<TClientBase>::Camera2ClientBase( const sp<CameraService>& cameraService, const sp<TCamCallbacks>& remoteCallback, const String16& clientPackageName, int cameraId, int cameraFacing, int clientPid, uid_t clientUid, int servicePid): TClientBase(cameraService, remoteCallback, clientPackageName, cameraId, cameraFacing, clientPid, clientUid, servicePid), mSharedCameraCallbacks(remoteCallback) { ALOGI("Camera %d: Opened", cameraId); mDevice = new Camera2Device(cameraId); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation) const { int callingPid = getCallingPid(); if (callingPid == TClientBase::mClientPid) return NO_ERROR; ALOGE("%s: attempt to use a locked camera from a different process" " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid); return PERMISSION_DENIED; } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::initialize(camera_module_t *module) { ATRACE_CALL(); ALOGV("%s: Initializing client for camera %d", __FUNCTION__, TClientBase::mCameraId); status_t res; res = mDevice->initialize(module); if (res != OK) { ALOGE("%s: Camera %d: unable to initialize device: %s (%d)", __FUNCTION__, TClientBase::mCameraId, strerror(-res), res); return NO_INIT; } res = mDevice->setNotifyCallback(this); return OK; } template <typename TClientBase> Camera2ClientBase<TClientBase>::~Camera2ClientBase() { ATRACE_CALL(); TClientBase::mDestructionStarted = true; disconnect(); ALOGI("Closed Camera %d", TClientBase::mCameraId); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::dump(int fd, const Vector<String16>& args) { String8 result; result.appendFormat("Camera2ClientBase[%d] (%p) PID: %d, dump:\n", TClientBase::mCameraId, TClientBase::getRemoteCallback()->asBinder().get(), TClientBase::mClientPid); result.append(" State: "); write(fd, result.string(), result.size()); // TODO: print dynamic/request section from most recent requests return dumpDevice(fd, args); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::dumpDevice( int fd, const Vector<String16>& args) { String8 result; result = " Device dump:\n"; write(fd, result.string(), result.size()); if (!mDevice.get()) { result = " *** Device is detached\n"; write(fd, result.string(), result.size()); return NO_ERROR; } status_t res = mDevice->dump(fd, args); if (res != OK) { result = String8::format(" Error dumping device: %s (%d)", strerror(-res), res); write(fd, result.string(), result.size()); } return NO_ERROR; } // ICameraClient2BaseUser interface template <typename TClientBase> void Camera2ClientBase<TClientBase>::disconnect() { ATRACE_CALL(); Mutex::Autolock icl(mBinderSerializationLock); // Allow both client and the media server to disconnect at all times int callingPid = getCallingPid(); if (callingPid != TClientBase::mClientPid && callingPid != TClientBase::mServicePid) return; ALOGV("Camera %d: Shutting down", TClientBase::mCameraId); detachDevice(); TClientBase::disconnect(); ALOGV("Camera %d: Shut down complete complete", TClientBase::mCameraId); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::detachDevice() { if (mDevice == 0) return; mDevice->disconnect(); mDevice.clear(); ALOGV("Camera %d: Detach complete", TClientBase::mCameraId); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::connect( const sp<TCamCallbacks>& client) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mBinderSerializationLock); if (TClientBase::mClientPid != 0 && getCallingPid() != TClientBase::mClientPid) { ALOGE("%s: Camera %d: Connection attempt from pid %d; " "current locked to pid %d", __FUNCTION__, TClientBase::mCameraId, getCallingPid(), TClientBase::mClientPid); return BAD_VALUE; } TClientBase::mClientPid = getCallingPid(); TClientBase::mRemoteCallback = client; mSharedCameraCallbacks = client; return OK; } /** Device-related methods */ template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyError(int errorCode, int arg1, int arg2) { ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, arg1, arg2); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyShutter(int frameNumber, nsecs_t timestamp) { (void)frameNumber; (void)timestamp; ALOGV("%s: Shutter notification for frame %d at time %lld", __FUNCTION__, frameNumber, timestamp); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Autofocus state now %d, last trigger %d", __FUNCTION__, newState, triggerId); typename SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS_MOVE, 1, 0); } if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, 1, 0); } } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Autoexposure state now %d, last trigger %d", __FUNCTION__, newState, triggerId); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", __FUNCTION__, newState, triggerId); } template <typename TClientBase> int Camera2ClientBase<TClientBase>::getCameraId() const { return TClientBase::mCameraId; } template <typename TClientBase> const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() { return mDevice; } template <typename TClientBase> const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() { return TClientBase::mCameraService; } template <typename TClientBase> Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock( SharedCameraCallbacks &client) : mRemoteCallback(client.mRemoteCallback), mSharedClient(client) { mSharedClient.mRemoteCallbackLock.lock(); } template <typename TClientBase> Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() { mSharedClient.mRemoteCallbackLock.unlock(); } template <typename TClientBase> Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks( const sp<TCamCallbacks>&client) : mRemoteCallback(client) { } template <typename TClientBase> typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks& Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=( const sp<TCamCallbacks>&client) { Mutex::Autolock l(mRemoteCallbackLock); mRemoteCallback = client; return *this; } template <typename TClientBase> void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() { Mutex::Autolock l(mRemoteCallbackLock); mRemoteCallback.clear(); } template class Camera2ClientBase<CameraService::ProClient>; template class Camera2ClientBase<CameraService::Client>; } // namespace android services/camera/libcameraservice/Camera2ClientBase.h 0 → 100644 +128 −0 File added.Preview size limit exceeded, changes collapsed. Show changes Loading
services/camera/libcameraservice/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ LOCAL_SRC_FILES:= \ CameraClient.cpp \ Camera2Client.cpp \ ProCamera2Client.cpp \ Camera2ClientBase.cpp \ CameraDeviceBase.cpp \ Camera2Device.cpp \ Camera3Device.cpp \ Loading
services/camera/libcameraservice/Camera2Client.cpp +38 −114 Original line number Diff line number Diff line Loading @@ -49,9 +49,8 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService, uid_t clientUid, int servicePid, int deviceVersion): Client(cameraService, cameraClient, clientPackageName, Camera2ClientBase(cameraService, cameraClient, clientPackageName, cameraId, cameraFacing, clientPid, clientUid, servicePid), mSharedCameraClient(cameraClient), mParameters(cameraId, cameraFacing) { ATRACE_CALL(); Loading @@ -76,15 +75,6 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService, l.mParameters.state = Parameters::DISCONNECTED; } status_t Camera2Client::checkPid(const char* checkLocation) const { int callingPid = getCallingPid(); if (callingPid == mClientPid) return NO_ERROR; ALOGE("%s: attempt to use a locked camera from a different process" " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid); return PERMISSION_DENIED; } status_t Camera2Client::initialize(camera_module_t *module) { ATRACE_CALL(); Loading Loading @@ -173,7 +163,7 @@ status_t Camera2Client::dump(int fd, const Vector<String16>& args) { String8 result; result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n", mCameraId, getCameraClient()->asBinder().get(), getRemoteCallback()->asBinder().get(), mClientPid); result.append(" State: "); #define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break; Loading Loading @@ -376,25 +366,15 @@ status_t Camera2Client::dump(int fd, const Vector<String16>& args) { mZslProcessor->dump(fd, args); result = " Device dump:\n"; write(fd, result.string(), result.size()); status_t res = mDevice->dump(fd, args); if (res != OK) { result = String8::format(" Error dumping device: %s (%d)", strerror(-res), res); write(fd, result.string(), result.size()); } return dumpDevice(fd, args); #undef CASE_APPEND_ENUM return NO_ERROR; } // ICamera interface void Camera2Client::disconnect() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); // Allow both client and the media server to disconnect at all times int callingPid = getCallingPid(); Loading Loading @@ -444,7 +424,7 @@ void Camera2Client::disconnect() { status_t Camera2Client::connect(const sp<ICameraClient>& client) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if (mClientPid != 0 && getCallingPid() != mClientPid) { ALOGE("%s: Camera %d: Connection attempt from pid %d; " Loading @@ -455,8 +435,8 @@ status_t Camera2Client::connect(const sp<ICameraClient>& client) { mClientPid = getCallingPid(); mCameraClient = client; mSharedCameraClient = client; mRemoteCallback = client; mSharedCameraCallbacks = client; return OK; } Loading @@ -464,7 +444,7 @@ status_t Camera2Client::connect(const sp<ICameraClient>& client) { status_t Camera2Client::lock() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d", __FUNCTION__, mCameraId, getCallingPid(), mClientPid); Loading @@ -485,7 +465,7 @@ status_t Camera2Client::lock() { status_t Camera2Client::unlock() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d", __FUNCTION__, mCameraId, getCallingPid(), mClientPid); Loading @@ -497,8 +477,8 @@ status_t Camera2Client::unlock() { return INVALID_OPERATION; } mClientPid = 0; mCameraClient.clear(); mSharedCameraClient.clear(); mRemoteCallback.clear(); mSharedCameraCallbacks.clear(); return OK; } Loading @@ -511,7 +491,7 @@ status_t Camera2Client::setPreviewDisplay( const sp<Surface>& surface) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading @@ -529,7 +509,7 @@ status_t Camera2Client::setPreviewTexture( const sp<IGraphicBufferProducer>& bufferProducer) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -598,7 +578,7 @@ status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder, void Camera2Client::setPreviewCallbackFlag(int flag) { ATRACE_CALL(); ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return; Loading Loading @@ -637,7 +617,7 @@ void Camera2Client::setPreviewCallbackFlagL(Parameters ¶ms, int flag) { status_t Camera2Client::startPreview() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; SharedParameters::Lock l(mParameters); Loading Loading @@ -753,7 +733,7 @@ status_t Camera2Client::startPreviewL(Parameters ¶ms, bool restart) { void Camera2Client::stopPreview() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return; stopPreviewL(); Loading Loading @@ -801,7 +781,7 @@ void Camera2Client::stopPreviewL() { bool Camera2Client::previewEnabled() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return false; Loading @@ -811,7 +791,7 @@ bool Camera2Client::previewEnabled() { status_t Camera2Client::storeMetaDataInBuffers(bool enabled) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading @@ -836,7 +816,7 @@ status_t Camera2Client::storeMetaDataInBuffers(bool enabled) { status_t Camera2Client::startRecording() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; SharedParameters::Lock l(mParameters); Loading Loading @@ -927,7 +907,7 @@ status_t Camera2Client::startRecordingL(Parameters ¶ms, bool restart) { void Camera2Client::stopRecording() { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); SharedParameters::Lock l(mParameters); status_t res; Loading Loading @@ -959,7 +939,7 @@ void Camera2Client::stopRecording() { bool Camera2Client::recordingEnabled() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return false; Loading @@ -976,7 +956,7 @@ bool Camera2Client::recordingEnabledL() { void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return; mStreamingProcessor->releaseRecordingFrame(mem); Loading @@ -984,7 +964,7 @@ void Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) { status_t Camera2Client::autoFocus() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1022,9 +1002,9 @@ status_t Camera2Client::autoFocus() { * Send immediate notification back to client */ if (notifyImmediately) { SharedCameraClient::Lock l(mSharedCameraClient); if (l.mCameraClient != 0) { l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, notifySuccess ? 1 : 0, 0); } return OK; Loading Loading @@ -1055,7 +1035,7 @@ status_t Camera2Client::autoFocus() { status_t Camera2Client::cancelAutoFocus() { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1087,7 +1067,7 @@ status_t Camera2Client::cancelAutoFocus() { status_t Camera2Client::takePicture(int msgType) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1146,7 +1126,7 @@ status_t Camera2Client::takePicture(int msgType) { status_t Camera2Client::setParameters(const String8& params) { ATRACE_CALL(); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading @@ -1163,7 +1143,7 @@ status_t Camera2Client::setParameters(const String8& params) { String8 Camera2Client::getParameters() const { ATRACE_CALL(); ALOGV("%s: Camera %d", __FUNCTION__, mCameraId); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); if ( checkPid(__FUNCTION__) != OK) return String8(); SharedParameters::ReadLock l(mParameters); Loading @@ -1173,7 +1153,7 @@ String8 Camera2Client::getParameters() const { status_t Camera2Client::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) { ATRACE_CALL(); Mutex::Autolock icl(mICameraLock); Mutex::Autolock icl(mBinderSerializationLock); status_t res; if ( (res = checkPid(__FUNCTION__) ) != OK) return res; Loading Loading @@ -1348,18 +1328,6 @@ status_t Camera2Client::commandSetVideoBufferCountL(size_t count) { } /** Device-related methods */ void Camera2Client::notifyError(int errorCode, int arg1, int arg2) { ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, arg1, arg2); } void Camera2Client::notifyShutter(int frameNumber, nsecs_t timestamp) { (void)frameNumber; (void)timestamp; ALOGV("%s: Shutter notification for frame %d at time %lld", __FUNCTION__, frameNumber, timestamp); } void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { ALOGV("%s: Autofocus state now %d, last trigger %d", __FUNCTION__, newState, triggerId); Loading Loading @@ -1455,16 +1423,16 @@ void Camera2Client::notifyAutoFocus(uint8_t newState, int triggerId) { } } if (sendMovingMessage) { SharedCameraClient::Lock l(mSharedCameraClient); if (l.mCameraClient != 0) { l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS_MOVE, SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS_MOVE, afInMotion ? 1 : 0, 0); } } if (sendCompletedMessage) { SharedCameraClient::Lock l(mSharedCameraClient); if (l.mCameraClient != 0) { l.mCameraClient->notifyCallback(CAMERA_MSG_FOCUS, SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, success ? 1 : 0, 0); } } Loading @@ -1476,25 +1444,6 @@ void Camera2Client::notifyAutoExposure(uint8_t newState, int triggerId) { mCaptureSequencer->notifyAutoExposure(newState, triggerId); } void Camera2Client::notifyAutoWhitebalance(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", __FUNCTION__, newState, triggerId); } int Camera2Client::getCameraId() const { return mCameraId; } const sp<CameraDeviceBase>& Camera2Client::getCameraDevice() { return mDevice; } const sp<CameraService>& Camera2Client::getCameraService() { return mCameraService; } camera2::SharedParameters& Camera2Client::getParameters() { return mParameters; } Loading Loading @@ -1533,32 +1482,6 @@ status_t Camera2Client::stopStream() { return mStreamingProcessor->stopStream(); } Camera2Client::SharedCameraClient::Lock::Lock(SharedCameraClient &client): mCameraClient(client.mCameraClient), mSharedClient(client) { mSharedClient.mCameraClientLock.lock(); } Camera2Client::SharedCameraClient::Lock::~Lock() { mSharedClient.mCameraClientLock.unlock(); } Camera2Client::SharedCameraClient::SharedCameraClient(const sp<ICameraClient>&client): mCameraClient(client) { } Camera2Client::SharedCameraClient& Camera2Client::SharedCameraClient::operator=( const sp<ICameraClient>&client) { Mutex::Autolock l(mCameraClientLock); mCameraClient = client; return *this; } void Camera2Client::SharedCameraClient::clear() { Mutex::Autolock l(mCameraClientLock); mCameraClient.clear(); } const int32_t Camera2Client::kPreviewRequestIdStart; const int32_t Camera2Client::kPreviewRequestIdEnd; const int32_t Camera2Client::kRecordingRequestIdStart; Loading Loading @@ -1660,4 +1583,5 @@ status_t Camera2Client::syncWithDevice() { return res; } } // namespace android
services/camera/libcameraservice/Camera2Client.h +2 −43 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include "camera2/ZslProcessor.h" #include "camera2/CaptureSequencer.h" #include "camera2/CallbackProcessor.h" #include "Camera2ClientBase.h" namespace android { Loading @@ -35,8 +36,7 @@ class IMemory; * CAMERA_DEVICE_API_VERSION_2_0 and 3_0. */ class Camera2Client : public CameraService::Client, public CameraDeviceBase::NotificationListener public Camera2ClientBase<CameraService::Client> { public: /** Loading Loading @@ -90,19 +90,13 @@ public: * Interface used by CameraDeviceBase */ virtual void notifyError(int errorCode, int arg1, int arg2); virtual void notifyShutter(int frameNumber, nsecs_t timestamp); virtual void notifyAutoFocus(uint8_t newState, int triggerId); virtual void notifyAutoExposure(uint8_t newState, int triggerId); virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId); /** * Interface used by independent components of Camera2Client. */ int getCameraId() const; const sp<CameraDeviceBase>& getCameraDevice(); const sp<CameraService>& getCameraService(); camera2::SharedParameters& getParameters(); int getPreviewStreamId() const; Loading @@ -118,27 +112,6 @@ public: status_t stopStream(); // Simple class to ensure that access to ICameraClient is serialized by // requiring mCameraClientLock to be locked before access to mCameraClient // is possible. class SharedCameraClient { public: class Lock { public: Lock(SharedCameraClient &client); ~Lock(); sp<ICameraClient> &mCameraClient; private: SharedCameraClient &mSharedClient; }; SharedCameraClient(const sp<ICameraClient>& client); SharedCameraClient& operator=(const sp<ICameraClient>& client); void clear(); private: sp<ICameraClient> mCameraClient; mutable Mutex mCameraClientLock; } mSharedCameraClient; static size_t calculateBufferSize(int width, int height, int format, int stride); Loading @@ -153,13 +126,6 @@ public: private: /** ICamera interface-related private members */ // Mutex that must be locked by methods implementing the ICamera interface. // Ensures serialization between incoming ICamera calls. All methods below // that append 'L' to the name assume that mICameraLock is locked when // they're called mutable Mutex mICameraLock; typedef camera2::Parameters Parameters; status_t setPreviewWindowL(const sp<IBinder>& binder, Loading Loading @@ -213,17 +179,10 @@ private: bool mAfInMotion; /** CameraDevice instance, wraps HAL camera device */ sp<CameraDeviceBase> mDevice; /** Utility members */ // Wait until the camera device has received the latest control settings status_t syncWithDevice(); // Verify that caller is the owner of the camera status_t checkPid(const char *checkLocation) const; }; }; // namespace android Loading
services/camera/libcameraservice/Camera2ClientBase.cpp 0 → 100644 +315 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "Camera2ClientBase" #define ATRACE_TAG ATRACE_TAG_CAMERA //#define LOG_NDEBUG 0 #include <utils/Log.h> #include <utils/Trace.h> #include <cutils/properties.h> #include <gui/Surface.h> #include <gui/Surface.h> #include "camera2/Parameters.h" #include "Camera2ClientBase.h" #include "camera2/ProFrameProcessor.h" #include "Camera2Device.h" namespace android { using namespace camera2; static int getCallingPid() { return IPCThreadState::self()->getCallingPid(); } // Interface used by CameraService template <typename TClientBase> Camera2ClientBase<TClientBase>::Camera2ClientBase( const sp<CameraService>& cameraService, const sp<TCamCallbacks>& remoteCallback, const String16& clientPackageName, int cameraId, int cameraFacing, int clientPid, uid_t clientUid, int servicePid): TClientBase(cameraService, remoteCallback, clientPackageName, cameraId, cameraFacing, clientPid, clientUid, servicePid), mSharedCameraCallbacks(remoteCallback) { ALOGI("Camera %d: Opened", cameraId); mDevice = new Camera2Device(cameraId); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::checkPid(const char* checkLocation) const { int callingPid = getCallingPid(); if (callingPid == TClientBase::mClientPid) return NO_ERROR; ALOGE("%s: attempt to use a locked camera from a different process" " (old pid %d, new pid %d)", checkLocation, TClientBase::mClientPid, callingPid); return PERMISSION_DENIED; } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::initialize(camera_module_t *module) { ATRACE_CALL(); ALOGV("%s: Initializing client for camera %d", __FUNCTION__, TClientBase::mCameraId); status_t res; res = mDevice->initialize(module); if (res != OK) { ALOGE("%s: Camera %d: unable to initialize device: %s (%d)", __FUNCTION__, TClientBase::mCameraId, strerror(-res), res); return NO_INIT; } res = mDevice->setNotifyCallback(this); return OK; } template <typename TClientBase> Camera2ClientBase<TClientBase>::~Camera2ClientBase() { ATRACE_CALL(); TClientBase::mDestructionStarted = true; disconnect(); ALOGI("Closed Camera %d", TClientBase::mCameraId); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::dump(int fd, const Vector<String16>& args) { String8 result; result.appendFormat("Camera2ClientBase[%d] (%p) PID: %d, dump:\n", TClientBase::mCameraId, TClientBase::getRemoteCallback()->asBinder().get(), TClientBase::mClientPid); result.append(" State: "); write(fd, result.string(), result.size()); // TODO: print dynamic/request section from most recent requests return dumpDevice(fd, args); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::dumpDevice( int fd, const Vector<String16>& args) { String8 result; result = " Device dump:\n"; write(fd, result.string(), result.size()); if (!mDevice.get()) { result = " *** Device is detached\n"; write(fd, result.string(), result.size()); return NO_ERROR; } status_t res = mDevice->dump(fd, args); if (res != OK) { result = String8::format(" Error dumping device: %s (%d)", strerror(-res), res); write(fd, result.string(), result.size()); } return NO_ERROR; } // ICameraClient2BaseUser interface template <typename TClientBase> void Camera2ClientBase<TClientBase>::disconnect() { ATRACE_CALL(); Mutex::Autolock icl(mBinderSerializationLock); // Allow both client and the media server to disconnect at all times int callingPid = getCallingPid(); if (callingPid != TClientBase::mClientPid && callingPid != TClientBase::mServicePid) return; ALOGV("Camera %d: Shutting down", TClientBase::mCameraId); detachDevice(); TClientBase::disconnect(); ALOGV("Camera %d: Shut down complete complete", TClientBase::mCameraId); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::detachDevice() { if (mDevice == 0) return; mDevice->disconnect(); mDevice.clear(); ALOGV("Camera %d: Detach complete", TClientBase::mCameraId); } template <typename TClientBase> status_t Camera2ClientBase<TClientBase>::connect( const sp<TCamCallbacks>& client) { ATRACE_CALL(); ALOGV("%s: E", __FUNCTION__); Mutex::Autolock icl(mBinderSerializationLock); if (TClientBase::mClientPid != 0 && getCallingPid() != TClientBase::mClientPid) { ALOGE("%s: Camera %d: Connection attempt from pid %d; " "current locked to pid %d", __FUNCTION__, TClientBase::mCameraId, getCallingPid(), TClientBase::mClientPid); return BAD_VALUE; } TClientBase::mClientPid = getCallingPid(); TClientBase::mRemoteCallback = client; mSharedCameraCallbacks = client; return OK; } /** Device-related methods */ template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyError(int errorCode, int arg1, int arg2) { ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, arg1, arg2); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyShutter(int frameNumber, nsecs_t timestamp) { (void)frameNumber; (void)timestamp; ALOGV("%s: Shutter notification for frame %d at time %lld", __FUNCTION__, frameNumber, timestamp); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyAutoFocus(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Autofocus state now %d, last trigger %d", __FUNCTION__, newState, triggerId); typename SharedCameraCallbacks::Lock l(mSharedCameraCallbacks); if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS_MOVE, 1, 0); } if (l.mRemoteCallback != 0) { l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS, 1, 0); } } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyAutoExposure(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Autoexposure state now %d, last trigger %d", __FUNCTION__, newState, triggerId); } template <typename TClientBase> void Camera2ClientBase<TClientBase>::notifyAutoWhitebalance(uint8_t newState, int triggerId) { (void)newState; (void)triggerId; ALOGV("%s: Auto-whitebalance state now %d, last trigger %d", __FUNCTION__, newState, triggerId); } template <typename TClientBase> int Camera2ClientBase<TClientBase>::getCameraId() const { return TClientBase::mCameraId; } template <typename TClientBase> const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() { return mDevice; } template <typename TClientBase> const sp<CameraService>& Camera2ClientBase<TClientBase>::getCameraService() { return TClientBase::mCameraService; } template <typename TClientBase> Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::Lock( SharedCameraCallbacks &client) : mRemoteCallback(client.mRemoteCallback), mSharedClient(client) { mSharedClient.mRemoteCallbackLock.lock(); } template <typename TClientBase> Camera2ClientBase<TClientBase>::SharedCameraCallbacks::Lock::~Lock() { mSharedClient.mRemoteCallbackLock.unlock(); } template <typename TClientBase> Camera2ClientBase<TClientBase>::SharedCameraCallbacks::SharedCameraCallbacks( const sp<TCamCallbacks>&client) : mRemoteCallback(client) { } template <typename TClientBase> typename Camera2ClientBase<TClientBase>::SharedCameraCallbacks& Camera2ClientBase<TClientBase>::SharedCameraCallbacks::operator=( const sp<TCamCallbacks>&client) { Mutex::Autolock l(mRemoteCallbackLock); mRemoteCallback = client; return *this; } template <typename TClientBase> void Camera2ClientBase<TClientBase>::SharedCameraCallbacks::clear() { Mutex::Autolock l(mRemoteCallbackLock); mRemoteCallback.clear(); } template class Camera2ClientBase<CameraService::ProClient>; template class Camera2ClientBase<CameraService::Client>; } // namespace android
services/camera/libcameraservice/Camera2ClientBase.h 0 → 100644 +128 −0 File added.Preview size limit exceeded, changes collapsed. Show changes