Loading services/camera/libcameraservice/CameraService.cpp +38 −4 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ */ #define LOG_TAG "CameraService" #define LOG_TAG "CameraService" #define ATRACE_TAG ATRACE_TAG_CAMERA //#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0 #include <algorithm> #include <algorithm> Loading Loading @@ -156,7 +157,6 @@ void CameraService::onFirstRef() } } mModule = new CameraModule(rawModule); mModule = new CameraModule(rawModule); ALOGI("Loaded \"%s\" camera module", mModule->getModuleName()); err = mModule->init(); err = mModule->init(); if (err != OK) { if (err != OK) { ALOGE("Could not initialize camera HAL module: %d (%s)", err, ALOGE("Could not initialize camera HAL module: %d (%s)", err, Loading @@ -168,6 +168,7 @@ void CameraService::onFirstRef() mModule = nullptr; mModule = nullptr; return; return; } } ALOGI("Loaded \"%s\" camera module", mModule->getModuleName()); mNumberOfCameras = mModule->getNumberOfCameras(); mNumberOfCameras = mModule->getNumberOfCameras(); mNumberOfNormalCameras = mNumberOfCameras; mNumberOfNormalCameras = mNumberOfCameras; Loading Loading @@ -403,10 +404,12 @@ void CameraService::onTorchStatusChangedLocked(const String8& cameraId, } } int32_t CameraService::getNumberOfCameras() { int32_t CameraService::getNumberOfCameras() { ATRACE_CALL(); return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE); return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE); } } int32_t CameraService::getNumberOfCameras(int type) { int32_t CameraService::getNumberOfCameras(int type) { ATRACE_CALL(); switch (type) { switch (type) { case CAMERA_TYPE_BACKWARD_COMPATIBLE: case CAMERA_TYPE_BACKWARD_COMPATIBLE: return mNumberOfNormalCameras; return mNumberOfNormalCameras; Loading @@ -421,6 +424,7 @@ int32_t CameraService::getNumberOfCameras(int type) { status_t CameraService::getCameraInfo(int cameraId, status_t CameraService::getCameraInfo(int cameraId, struct CameraInfo* cameraInfo) { struct CameraInfo* cameraInfo) { ATRACE_CALL(); if (!mModule) { if (!mModule) { return -ENODEV; return -ENODEV; } } Loading Loading @@ -448,6 +452,7 @@ int CameraService::cameraIdToInt(const String8& cameraId) { } } status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) { status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) { ATRACE_CALL(); status_t ret = OK; status_t ret = OK; struct CameraInfo info; struct CameraInfo info; if ((ret = getCameraInfo(cameraId, &info)) != OK) { if ((ret = getCameraInfo(cameraId, &info)) != OK) { Loading Loading @@ -534,6 +539,7 @@ status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata status_t CameraService::getCameraCharacteristics(int cameraId, status_t CameraService::getCameraCharacteristics(int cameraId, CameraMetadata* cameraInfo) { CameraMetadata* cameraInfo) { ATRACE_CALL(); if (!cameraInfo) { if (!cameraInfo) { ALOGE("%s: cameraInfo is NULL", __FUNCTION__); ALOGE("%s: cameraInfo is NULL", __FUNCTION__); return BAD_VALUE; return BAD_VALUE; Loading Loading @@ -611,6 +617,7 @@ int CameraService::getCameraPriorityFromProcState(int procState) { } } status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) { status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) { ATRACE_CALL(); if (!mModule) { if (!mModule) { ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__); ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__); return -ENODEV; return -ENODEV; Loading @@ -621,6 +628,7 @@ status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescript } } int CameraService::getDeviceVersion(int cameraId, int* facing) { int CameraService::getDeviceVersion(int cameraId, int* facing) { ATRACE_CALL(); struct camera_info info; struct camera_info info; if (mModule->getCameraInfo(cameraId, &info) != OK) { if (mModule->getCameraInfo(cameraId, &info) != OK) { return -1; return -1; Loading Loading @@ -652,6 +660,7 @@ status_t CameraService::filterGetInfoErrorCode(status_t err) { } } bool CameraService::setUpVendorTags() { bool CameraService::setUpVendorTags() { ATRACE_CALL(); vendor_tag_ops_t vOps = vendor_tag_ops_t(); vendor_tag_ops_t vOps = vendor_tag_ops_t(); // Check if vendor operations have been implemented // Check if vendor operations have been implemented Loading @@ -660,9 +669,7 @@ bool CameraService::setUpVendorTags() { return false; return false; } } ATRACE_BEGIN("camera3->get_metadata_vendor_tag_ops"); mModule->getVendorTagOps(&vOps); mModule->getVendorTagOps(&vOps); ATRACE_END(); // Ensure all vendor operations are present // Ensure all vendor operations are present if (vOps.get_tag_count == NULL || vOps.get_all_tags == NULL || if (vOps.get_tag_count == NULL || vOps.get_all_tags == NULL || Loading Loading @@ -962,7 +969,7 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien /*out*/ /*out*/ sp<BasicClient>* client, sp<BasicClient>* client, std::shared_ptr<resource_policy::ClientDescriptor<String8, sp<BasicClient>>>* partial) { std::shared_ptr<resource_policy::ClientDescriptor<String8, sp<BasicClient>>>* partial) { ATRACE_CALL(); status_t ret = NO_ERROR; status_t ret = NO_ERROR; std::vector<DescriptorPtr> evictedClients; std::vector<DescriptorPtr> evictedClients; DescriptorPtr clientDescriptor; DescriptorPtr clientDescriptor; Loading Loading @@ -1151,6 +1158,7 @@ status_t CameraService::connect( /*out*/ /*out*/ sp<ICamera>& device) { sp<ICamera>& device) { ATRACE_CALL(); status_t ret = NO_ERROR; status_t ret = NO_ERROR; String8 id = String8::format("%d", cameraId); String8 id = String8::format("%d", cameraId); sp<Client> client = nullptr; sp<Client> client = nullptr; Loading @@ -1175,6 +1183,7 @@ status_t CameraService::connectLegacy( /*out*/ /*out*/ sp<ICamera>& device) { sp<ICamera>& device) { ATRACE_CALL(); String8 id = String8::format("%d", cameraId); String8 id = String8::format("%d", cameraId); int apiVersion = mModule->getModuleApiVersion(); int apiVersion = mModule->getModuleApiVersion(); if (halVersion != CAMERA_HAL_API_VERSION_UNSPECIFIED && if (halVersion != CAMERA_HAL_API_VERSION_UNSPECIFIED && Loading Loading @@ -1215,6 +1224,7 @@ status_t CameraService::connectDevice( /*out*/ /*out*/ sp<ICameraDeviceUser>& device) { sp<ICameraDeviceUser>& device) { ATRACE_CALL(); status_t ret = NO_ERROR; status_t ret = NO_ERROR; String8 id = String8::format("%d", cameraId); String8 id = String8::format("%d", cameraId); sp<CameraDeviceClient> client = nullptr; sp<CameraDeviceClient> client = nullptr; Loading @@ -1234,6 +1244,8 @@ status_t CameraService::connectDevice( status_t CameraService::setTorchMode(const String16& cameraId, bool enabled, status_t CameraService::setTorchMode(const String16& cameraId, bool enabled, const sp<IBinder>& clientBinder) { const sp<IBinder>& clientBinder) { ATRACE_CALL(); if (enabled && clientBinder == nullptr) { if (enabled && clientBinder == nullptr) { ALOGE("%s: torch client binder is NULL", __FUNCTION__); ALOGE("%s: torch client binder is NULL", __FUNCTION__); return -EINVAL; return -EINVAL; Loading Loading @@ -1322,6 +1334,8 @@ status_t CameraService::setTorchMode(const String16& cameraId, bool enabled, } } void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) { void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) { ATRACE_CALL(); switch(eventId) { switch(eventId) { case ICameraService::USER_SWITCHED: { case ICameraService::USER_SWITCHED: { doUserSwitch(/*newUserIds*/args, /*length*/length); doUserSwitch(/*newUserIds*/args, /*length*/length); Loading @@ -1337,6 +1351,8 @@ void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size } } status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) { status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) { ATRACE_CALL(); ALOGV("%s: Add listener %p", __FUNCTION__, listener.get()); ALOGV("%s: Add listener %p", __FUNCTION__, listener.get()); if (listener == nullptr) { if (listener == nullptr) { Loading Loading @@ -1385,6 +1401,8 @@ status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) } } status_t CameraService::removeListener(const sp<ICameraServiceListener>& listener) { status_t CameraService::removeListener(const sp<ICameraServiceListener>& listener) { ATRACE_CALL(); ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get()); ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get()); if (listener == 0) { if (listener == 0) { Loading @@ -1411,6 +1429,8 @@ status_t CameraService::removeListener(const sp<ICameraServiceListener>& listene } } status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) { status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) { ATRACE_CALL(); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); if (parameters == NULL) { if (parameters == NULL) { Loading @@ -1435,6 +1455,8 @@ status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* param } } status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) { status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) { ATRACE_CALL(); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); switch (apiVersion) { switch (apiVersion) { Loading Loading @@ -1802,6 +1824,8 @@ MediaPlayer* CameraService::newMediaPlayer(const char *file) { } } void CameraService::loadSound() { void CameraService::loadSound() { ATRACE_CALL(); Mutex::Autolock lock(mSoundLock); Mutex::Autolock lock(mSoundLock); LOG1("CameraService::loadSound ref=%d", mSoundRef); LOG1("CameraService::loadSound ref=%d", mSoundRef); if (mSoundRef++) return; if (mSoundRef++) return; Loading @@ -1824,6 +1848,8 @@ void CameraService::releaseSound() { } } void CameraService::playSound(sound_kind kind) { void CameraService::playSound(sound_kind kind) { ATRACE_CALL(); LOG1("playSound(%d)", kind); LOG1("playSound(%d)", kind); Mutex::Autolock lock(mSoundLock); Mutex::Autolock lock(mSoundLock); sp<MediaPlayer> player = mSoundPlayer[kind]; sp<MediaPlayer> player = mSoundPlayer[kind]; Loading Loading @@ -1933,6 +1959,8 @@ bool CameraService::BasicClient::canCastToApiClient(apiLevel level) const { } } status_t CameraService::BasicClient::startCameraOps() { status_t CameraService::BasicClient::startCameraOps() { ATRACE_CALL(); int32_t res; int32_t res; // Notify app ops that the camera is not available // Notify app ops that the camera is not available mOpsCallback = new OpsCallback(this); mOpsCallback = new OpsCallback(this); Loading Loading @@ -1974,6 +2002,8 @@ status_t CameraService::BasicClient::startCameraOps() { } } status_t CameraService::BasicClient::finishCameraOps() { status_t CameraService::BasicClient::finishCameraOps() { ATRACE_CALL(); // Check if startCameraOps succeeded, and if so, finish the camera op // Check if startCameraOps succeeded, and if so, finish the camera op if (mOpsActive) { if (mOpsActive) { // Notify app ops that the camera is available again // Notify app ops that the camera is available again Loading Loading @@ -2006,6 +2036,8 @@ status_t CameraService::BasicClient::finishCameraOps() { } } void CameraService::BasicClient::opChanged(int32_t op, const String16& packageName) { void CameraService::BasicClient::opChanged(int32_t op, const String16& packageName) { ATRACE_CALL(); String8 name(packageName); String8 name(packageName); String8 myName(mClientPackageName); String8 myName(mClientPackageName); Loading Loading @@ -2229,6 +2261,8 @@ static bool tryLock(Mutex& mutex) } } status_t CameraService::dump(int fd, const Vector<String16>& args) { status_t CameraService::dump(int fd, const Vector<String16>& args) { ATRACE_CALL(); String8 result("Dump of the Camera Service:\n"); String8 result("Dump of the Camera Service:\n"); if (checkCallingPermission(String16("android.permission.DUMP")) == false) { if (checkCallingPermission(String16("android.permission.DUMP")) == false) { result.appendFormat("Permission Denial: " result.appendFormat("Permission Denial: " Loading services/camera/libcameraservice/common/CameraModule.cpp +46 −10 Original line number Original line Diff line number Diff line Loading @@ -15,14 +15,18 @@ */ */ #define LOG_TAG "CameraModule" #define LOG_TAG "CameraModule" #define ATRACE_TAG ATRACE_TAG_CAMERA //#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0 #include <utils/Trace.h> #include "CameraModule.h" #include "CameraModule.h" namespace android { namespace android { void CameraModule::deriveCameraCharacteristicsKeys( void CameraModule::deriveCameraCharacteristicsKeys( uint32_t deviceVersion, CameraMetadata &chars) { uint32_t deviceVersion, CameraMetadata &chars) { ATRACE_CALL(); // HAL1 devices should not reach here // HAL1 devices should not reach here if (deviceVersion < CAMERA_DEVICE_API_VERSION_2_0) { if (deviceVersion < CAMERA_DEVICE_API_VERSION_2_0) { ALOGV("%s: Cannot derive keys for HAL version < 2.0"); ALOGV("%s: Cannot derive keys for HAL version < 2.0"); Loading Loading @@ -150,9 +154,7 @@ CameraModule::CameraModule(camera_module_t *module) { ALOGE("%s: camera hardware module must not be null", __FUNCTION__); ALOGE("%s: camera hardware module must not be null", __FUNCTION__); assert(0); assert(0); } } mModule = module; mModule = module; mCameraInfoMap.setCapacity(getNumberOfCameras()); } } CameraModule::~CameraModule() CameraModule::~CameraModule() Loading @@ -168,14 +170,20 @@ CameraModule::~CameraModule() } } int CameraModule::init() { int CameraModule::init() { ATRACE_CALL(); int res = OK; if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 && if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 && mModule->init != NULL) { mModule->init != NULL) { return mModule->init(); ATRACE_BEGIN("camera_module->init"); res = mModule->init(); ATRACE_END(); } } return OK; mCameraInfoMap.setCapacity(getNumberOfCameras()); return res; } } int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { ATRACE_CALL(); Mutex::Autolock lock(mCameraInfoLock); Mutex::Autolock lock(mCameraInfoLock); if (cameraId < 0) { if (cameraId < 0) { ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId); ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId); Loading @@ -185,14 +193,20 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { // Only override static_camera_characteristics for API2 devices // Only override static_camera_characteristics for API2 devices int apiVersion = mModule->common.module_api_version; int apiVersion = mModule->common.module_api_version; if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) { if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) { return mModule->get_camera_info(cameraId, info); int ret; ATRACE_BEGIN("camera_module->get_camera_info"); ret = mModule->get_camera_info(cameraId, info); ATRACE_END(); return ret; } } ssize_t index = mCameraInfoMap.indexOfKey(cameraId); ssize_t index = mCameraInfoMap.indexOfKey(cameraId); if (index == NAME_NOT_FOUND) { if (index == NAME_NOT_FOUND) { // Get camera info from raw module and cache it // Get camera info from raw module and cache it camera_info rawInfo, cameraInfo; camera_info rawInfo, cameraInfo; ATRACE_BEGIN("camera_module->get_camera_info"); int ret = mModule->get_camera_info(cameraId, &rawInfo); int ret = mModule->get_camera_info(cameraId, &rawInfo); ATRACE_END(); if (ret != 0) { if (ret != 0) { return ret; return ret; } } Loading @@ -217,20 +231,36 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { } } int CameraModule::open(const char* id, struct hw_device_t** device) { int CameraModule::open(const char* id, struct hw_device_t** device) { return filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device)); int res; ATRACE_BEGIN("camera_module->open"); res = filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device)); ATRACE_END(); return res; } } int CameraModule::openLegacy( int CameraModule::openLegacy( const char* id, uint32_t halVersion, struct hw_device_t** device) { const char* id, uint32_t halVersion, struct hw_device_t** device) { return mModule->open_legacy(&mModule->common, id, halVersion, device); int res; ATRACE_BEGIN("camera_module->open_legacy"); res = mModule->open_legacy(&mModule->common, id, halVersion, device); ATRACE_END(); return res; } } int CameraModule::getNumberOfCameras() { int CameraModule::getNumberOfCameras() { return mModule->get_number_of_cameras(); int numCameras; ATRACE_BEGIN("camera_module->get_number_of_cameras"); numCameras = mModule->get_number_of_cameras(); ATRACE_END(); return numCameras; } } int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) { int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) { return mModule->set_callbacks(callbacks); int res; ATRACE_BEGIN("camera_module->set_callbacks"); res = mModule->set_callbacks(callbacks); ATRACE_END(); return res; } } bool CameraModule::isVendorTagDefined() { bool CameraModule::isVendorTagDefined() { Loading @@ -239,12 +269,18 @@ bool CameraModule::isVendorTagDefined() { void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) { void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) { if (mModule->get_vendor_tag_ops) { if (mModule->get_vendor_tag_ops) { ATRACE_BEGIN("camera_module->get_vendor_tag_ops"); mModule->get_vendor_tag_ops(ops); mModule->get_vendor_tag_ops(ops); ATRACE_END(); } } } } int CameraModule::setTorchMode(const char* camera_id, bool enable) { int CameraModule::setTorchMode(const char* camera_id, bool enable) { return mModule->set_torch_mode(camera_id, enable); int res; ATRACE_BEGIN("camera_module->set_torch_mode"); res = mModule->set_torch_mode(camera_id, enable); ATRACE_END(); return res; } } status_t CameraModule::filterOpenErrorCode(status_t err) { status_t CameraModule::filterOpenErrorCode(status_t err) { Loading Loading
services/camera/libcameraservice/CameraService.cpp +38 −4 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ */ #define LOG_TAG "CameraService" #define LOG_TAG "CameraService" #define ATRACE_TAG ATRACE_TAG_CAMERA //#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0 #include <algorithm> #include <algorithm> Loading Loading @@ -156,7 +157,6 @@ void CameraService::onFirstRef() } } mModule = new CameraModule(rawModule); mModule = new CameraModule(rawModule); ALOGI("Loaded \"%s\" camera module", mModule->getModuleName()); err = mModule->init(); err = mModule->init(); if (err != OK) { if (err != OK) { ALOGE("Could not initialize camera HAL module: %d (%s)", err, ALOGE("Could not initialize camera HAL module: %d (%s)", err, Loading @@ -168,6 +168,7 @@ void CameraService::onFirstRef() mModule = nullptr; mModule = nullptr; return; return; } } ALOGI("Loaded \"%s\" camera module", mModule->getModuleName()); mNumberOfCameras = mModule->getNumberOfCameras(); mNumberOfCameras = mModule->getNumberOfCameras(); mNumberOfNormalCameras = mNumberOfCameras; mNumberOfNormalCameras = mNumberOfCameras; Loading Loading @@ -403,10 +404,12 @@ void CameraService::onTorchStatusChangedLocked(const String8& cameraId, } } int32_t CameraService::getNumberOfCameras() { int32_t CameraService::getNumberOfCameras() { ATRACE_CALL(); return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE); return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE); } } int32_t CameraService::getNumberOfCameras(int type) { int32_t CameraService::getNumberOfCameras(int type) { ATRACE_CALL(); switch (type) { switch (type) { case CAMERA_TYPE_BACKWARD_COMPATIBLE: case CAMERA_TYPE_BACKWARD_COMPATIBLE: return mNumberOfNormalCameras; return mNumberOfNormalCameras; Loading @@ -421,6 +424,7 @@ int32_t CameraService::getNumberOfCameras(int type) { status_t CameraService::getCameraInfo(int cameraId, status_t CameraService::getCameraInfo(int cameraId, struct CameraInfo* cameraInfo) { struct CameraInfo* cameraInfo) { ATRACE_CALL(); if (!mModule) { if (!mModule) { return -ENODEV; return -ENODEV; } } Loading Loading @@ -448,6 +452,7 @@ int CameraService::cameraIdToInt(const String8& cameraId) { } } status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) { status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) { ATRACE_CALL(); status_t ret = OK; status_t ret = OK; struct CameraInfo info; struct CameraInfo info; if ((ret = getCameraInfo(cameraId, &info)) != OK) { if ((ret = getCameraInfo(cameraId, &info)) != OK) { Loading Loading @@ -534,6 +539,7 @@ status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata status_t CameraService::getCameraCharacteristics(int cameraId, status_t CameraService::getCameraCharacteristics(int cameraId, CameraMetadata* cameraInfo) { CameraMetadata* cameraInfo) { ATRACE_CALL(); if (!cameraInfo) { if (!cameraInfo) { ALOGE("%s: cameraInfo is NULL", __FUNCTION__); ALOGE("%s: cameraInfo is NULL", __FUNCTION__); return BAD_VALUE; return BAD_VALUE; Loading Loading @@ -611,6 +617,7 @@ int CameraService::getCameraPriorityFromProcState(int procState) { } } status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) { status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) { ATRACE_CALL(); if (!mModule) { if (!mModule) { ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__); ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__); return -ENODEV; return -ENODEV; Loading @@ -621,6 +628,7 @@ status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescript } } int CameraService::getDeviceVersion(int cameraId, int* facing) { int CameraService::getDeviceVersion(int cameraId, int* facing) { ATRACE_CALL(); struct camera_info info; struct camera_info info; if (mModule->getCameraInfo(cameraId, &info) != OK) { if (mModule->getCameraInfo(cameraId, &info) != OK) { return -1; return -1; Loading Loading @@ -652,6 +660,7 @@ status_t CameraService::filterGetInfoErrorCode(status_t err) { } } bool CameraService::setUpVendorTags() { bool CameraService::setUpVendorTags() { ATRACE_CALL(); vendor_tag_ops_t vOps = vendor_tag_ops_t(); vendor_tag_ops_t vOps = vendor_tag_ops_t(); // Check if vendor operations have been implemented // Check if vendor operations have been implemented Loading @@ -660,9 +669,7 @@ bool CameraService::setUpVendorTags() { return false; return false; } } ATRACE_BEGIN("camera3->get_metadata_vendor_tag_ops"); mModule->getVendorTagOps(&vOps); mModule->getVendorTagOps(&vOps); ATRACE_END(); // Ensure all vendor operations are present // Ensure all vendor operations are present if (vOps.get_tag_count == NULL || vOps.get_all_tags == NULL || if (vOps.get_tag_count == NULL || vOps.get_all_tags == NULL || Loading Loading @@ -962,7 +969,7 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien /*out*/ /*out*/ sp<BasicClient>* client, sp<BasicClient>* client, std::shared_ptr<resource_policy::ClientDescriptor<String8, sp<BasicClient>>>* partial) { std::shared_ptr<resource_policy::ClientDescriptor<String8, sp<BasicClient>>>* partial) { ATRACE_CALL(); status_t ret = NO_ERROR; status_t ret = NO_ERROR; std::vector<DescriptorPtr> evictedClients; std::vector<DescriptorPtr> evictedClients; DescriptorPtr clientDescriptor; DescriptorPtr clientDescriptor; Loading Loading @@ -1151,6 +1158,7 @@ status_t CameraService::connect( /*out*/ /*out*/ sp<ICamera>& device) { sp<ICamera>& device) { ATRACE_CALL(); status_t ret = NO_ERROR; status_t ret = NO_ERROR; String8 id = String8::format("%d", cameraId); String8 id = String8::format("%d", cameraId); sp<Client> client = nullptr; sp<Client> client = nullptr; Loading @@ -1175,6 +1183,7 @@ status_t CameraService::connectLegacy( /*out*/ /*out*/ sp<ICamera>& device) { sp<ICamera>& device) { ATRACE_CALL(); String8 id = String8::format("%d", cameraId); String8 id = String8::format("%d", cameraId); int apiVersion = mModule->getModuleApiVersion(); int apiVersion = mModule->getModuleApiVersion(); if (halVersion != CAMERA_HAL_API_VERSION_UNSPECIFIED && if (halVersion != CAMERA_HAL_API_VERSION_UNSPECIFIED && Loading Loading @@ -1215,6 +1224,7 @@ status_t CameraService::connectDevice( /*out*/ /*out*/ sp<ICameraDeviceUser>& device) { sp<ICameraDeviceUser>& device) { ATRACE_CALL(); status_t ret = NO_ERROR; status_t ret = NO_ERROR; String8 id = String8::format("%d", cameraId); String8 id = String8::format("%d", cameraId); sp<CameraDeviceClient> client = nullptr; sp<CameraDeviceClient> client = nullptr; Loading @@ -1234,6 +1244,8 @@ status_t CameraService::connectDevice( status_t CameraService::setTorchMode(const String16& cameraId, bool enabled, status_t CameraService::setTorchMode(const String16& cameraId, bool enabled, const sp<IBinder>& clientBinder) { const sp<IBinder>& clientBinder) { ATRACE_CALL(); if (enabled && clientBinder == nullptr) { if (enabled && clientBinder == nullptr) { ALOGE("%s: torch client binder is NULL", __FUNCTION__); ALOGE("%s: torch client binder is NULL", __FUNCTION__); return -EINVAL; return -EINVAL; Loading Loading @@ -1322,6 +1334,8 @@ status_t CameraService::setTorchMode(const String16& cameraId, bool enabled, } } void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) { void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) { ATRACE_CALL(); switch(eventId) { switch(eventId) { case ICameraService::USER_SWITCHED: { case ICameraService::USER_SWITCHED: { doUserSwitch(/*newUserIds*/args, /*length*/length); doUserSwitch(/*newUserIds*/args, /*length*/length); Loading @@ -1337,6 +1351,8 @@ void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size } } status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) { status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) { ATRACE_CALL(); ALOGV("%s: Add listener %p", __FUNCTION__, listener.get()); ALOGV("%s: Add listener %p", __FUNCTION__, listener.get()); if (listener == nullptr) { if (listener == nullptr) { Loading Loading @@ -1385,6 +1401,8 @@ status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) } } status_t CameraService::removeListener(const sp<ICameraServiceListener>& listener) { status_t CameraService::removeListener(const sp<ICameraServiceListener>& listener) { ATRACE_CALL(); ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get()); ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get()); if (listener == 0) { if (listener == 0) { Loading @@ -1411,6 +1429,8 @@ status_t CameraService::removeListener(const sp<ICameraServiceListener>& listene } } status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) { status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) { ATRACE_CALL(); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); if (parameters == NULL) { if (parameters == NULL) { Loading @@ -1435,6 +1455,8 @@ status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* param } } status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) { status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) { ATRACE_CALL(); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId); switch (apiVersion) { switch (apiVersion) { Loading Loading @@ -1802,6 +1824,8 @@ MediaPlayer* CameraService::newMediaPlayer(const char *file) { } } void CameraService::loadSound() { void CameraService::loadSound() { ATRACE_CALL(); Mutex::Autolock lock(mSoundLock); Mutex::Autolock lock(mSoundLock); LOG1("CameraService::loadSound ref=%d", mSoundRef); LOG1("CameraService::loadSound ref=%d", mSoundRef); if (mSoundRef++) return; if (mSoundRef++) return; Loading @@ -1824,6 +1848,8 @@ void CameraService::releaseSound() { } } void CameraService::playSound(sound_kind kind) { void CameraService::playSound(sound_kind kind) { ATRACE_CALL(); LOG1("playSound(%d)", kind); LOG1("playSound(%d)", kind); Mutex::Autolock lock(mSoundLock); Mutex::Autolock lock(mSoundLock); sp<MediaPlayer> player = mSoundPlayer[kind]; sp<MediaPlayer> player = mSoundPlayer[kind]; Loading Loading @@ -1933,6 +1959,8 @@ bool CameraService::BasicClient::canCastToApiClient(apiLevel level) const { } } status_t CameraService::BasicClient::startCameraOps() { status_t CameraService::BasicClient::startCameraOps() { ATRACE_CALL(); int32_t res; int32_t res; // Notify app ops that the camera is not available // Notify app ops that the camera is not available mOpsCallback = new OpsCallback(this); mOpsCallback = new OpsCallback(this); Loading Loading @@ -1974,6 +2002,8 @@ status_t CameraService::BasicClient::startCameraOps() { } } status_t CameraService::BasicClient::finishCameraOps() { status_t CameraService::BasicClient::finishCameraOps() { ATRACE_CALL(); // Check if startCameraOps succeeded, and if so, finish the camera op // Check if startCameraOps succeeded, and if so, finish the camera op if (mOpsActive) { if (mOpsActive) { // Notify app ops that the camera is available again // Notify app ops that the camera is available again Loading Loading @@ -2006,6 +2036,8 @@ status_t CameraService::BasicClient::finishCameraOps() { } } void CameraService::BasicClient::opChanged(int32_t op, const String16& packageName) { void CameraService::BasicClient::opChanged(int32_t op, const String16& packageName) { ATRACE_CALL(); String8 name(packageName); String8 name(packageName); String8 myName(mClientPackageName); String8 myName(mClientPackageName); Loading Loading @@ -2229,6 +2261,8 @@ static bool tryLock(Mutex& mutex) } } status_t CameraService::dump(int fd, const Vector<String16>& args) { status_t CameraService::dump(int fd, const Vector<String16>& args) { ATRACE_CALL(); String8 result("Dump of the Camera Service:\n"); String8 result("Dump of the Camera Service:\n"); if (checkCallingPermission(String16("android.permission.DUMP")) == false) { if (checkCallingPermission(String16("android.permission.DUMP")) == false) { result.appendFormat("Permission Denial: " result.appendFormat("Permission Denial: " Loading
services/camera/libcameraservice/common/CameraModule.cpp +46 −10 Original line number Original line Diff line number Diff line Loading @@ -15,14 +15,18 @@ */ */ #define LOG_TAG "CameraModule" #define LOG_TAG "CameraModule" #define ATRACE_TAG ATRACE_TAG_CAMERA //#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0 #include <utils/Trace.h> #include "CameraModule.h" #include "CameraModule.h" namespace android { namespace android { void CameraModule::deriveCameraCharacteristicsKeys( void CameraModule::deriveCameraCharacteristicsKeys( uint32_t deviceVersion, CameraMetadata &chars) { uint32_t deviceVersion, CameraMetadata &chars) { ATRACE_CALL(); // HAL1 devices should not reach here // HAL1 devices should not reach here if (deviceVersion < CAMERA_DEVICE_API_VERSION_2_0) { if (deviceVersion < CAMERA_DEVICE_API_VERSION_2_0) { ALOGV("%s: Cannot derive keys for HAL version < 2.0"); ALOGV("%s: Cannot derive keys for HAL version < 2.0"); Loading Loading @@ -150,9 +154,7 @@ CameraModule::CameraModule(camera_module_t *module) { ALOGE("%s: camera hardware module must not be null", __FUNCTION__); ALOGE("%s: camera hardware module must not be null", __FUNCTION__); assert(0); assert(0); } } mModule = module; mModule = module; mCameraInfoMap.setCapacity(getNumberOfCameras()); } } CameraModule::~CameraModule() CameraModule::~CameraModule() Loading @@ -168,14 +170,20 @@ CameraModule::~CameraModule() } } int CameraModule::init() { int CameraModule::init() { ATRACE_CALL(); int res = OK; if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 && if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 && mModule->init != NULL) { mModule->init != NULL) { return mModule->init(); ATRACE_BEGIN("camera_module->init"); res = mModule->init(); ATRACE_END(); } } return OK; mCameraInfoMap.setCapacity(getNumberOfCameras()); return res; } } int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { ATRACE_CALL(); Mutex::Autolock lock(mCameraInfoLock); Mutex::Autolock lock(mCameraInfoLock); if (cameraId < 0) { if (cameraId < 0) { ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId); ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId); Loading @@ -185,14 +193,20 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { // Only override static_camera_characteristics for API2 devices // Only override static_camera_characteristics for API2 devices int apiVersion = mModule->common.module_api_version; int apiVersion = mModule->common.module_api_version; if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) { if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) { return mModule->get_camera_info(cameraId, info); int ret; ATRACE_BEGIN("camera_module->get_camera_info"); ret = mModule->get_camera_info(cameraId, info); ATRACE_END(); return ret; } } ssize_t index = mCameraInfoMap.indexOfKey(cameraId); ssize_t index = mCameraInfoMap.indexOfKey(cameraId); if (index == NAME_NOT_FOUND) { if (index == NAME_NOT_FOUND) { // Get camera info from raw module and cache it // Get camera info from raw module and cache it camera_info rawInfo, cameraInfo; camera_info rawInfo, cameraInfo; ATRACE_BEGIN("camera_module->get_camera_info"); int ret = mModule->get_camera_info(cameraId, &rawInfo); int ret = mModule->get_camera_info(cameraId, &rawInfo); ATRACE_END(); if (ret != 0) { if (ret != 0) { return ret; return ret; } } Loading @@ -217,20 +231,36 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { } } int CameraModule::open(const char* id, struct hw_device_t** device) { int CameraModule::open(const char* id, struct hw_device_t** device) { return filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device)); int res; ATRACE_BEGIN("camera_module->open"); res = filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device)); ATRACE_END(); return res; } } int CameraModule::openLegacy( int CameraModule::openLegacy( const char* id, uint32_t halVersion, struct hw_device_t** device) { const char* id, uint32_t halVersion, struct hw_device_t** device) { return mModule->open_legacy(&mModule->common, id, halVersion, device); int res; ATRACE_BEGIN("camera_module->open_legacy"); res = mModule->open_legacy(&mModule->common, id, halVersion, device); ATRACE_END(); return res; } } int CameraModule::getNumberOfCameras() { int CameraModule::getNumberOfCameras() { return mModule->get_number_of_cameras(); int numCameras; ATRACE_BEGIN("camera_module->get_number_of_cameras"); numCameras = mModule->get_number_of_cameras(); ATRACE_END(); return numCameras; } } int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) { int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) { return mModule->set_callbacks(callbacks); int res; ATRACE_BEGIN("camera_module->set_callbacks"); res = mModule->set_callbacks(callbacks); ATRACE_END(); return res; } } bool CameraModule::isVendorTagDefined() { bool CameraModule::isVendorTagDefined() { Loading @@ -239,12 +269,18 @@ bool CameraModule::isVendorTagDefined() { void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) { void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) { if (mModule->get_vendor_tag_ops) { if (mModule->get_vendor_tag_ops) { ATRACE_BEGIN("camera_module->get_vendor_tag_ops"); mModule->get_vendor_tag_ops(ops); mModule->get_vendor_tag_ops(ops); ATRACE_END(); } } } } int CameraModule::setTorchMode(const char* camera_id, bool enable) { int CameraModule::setTorchMode(const char* camera_id, bool enable) { return mModule->set_torch_mode(camera_id, enable); int res; ATRACE_BEGIN("camera_module->set_torch_mode"); res = mModule->set_torch_mode(camera_id, enable); ATRACE_END(); return res; } } status_t CameraModule::filterOpenErrorCode(status_t err) { status_t CameraModule::filterOpenErrorCode(status_t err) { Loading