diff options
author | Alex Ray <aray@google.com> | 2013-07-17 14:23:04 -0700 |
---|---|---|
committer | Alex Ray <aray@google.com> | 2013-07-26 16:36:43 -0700 |
commit | 0f82f5a73a9ea6462706c807dc1a5a2cf2333ea1 (patch) | |
tree | 1388dda744ecaa72ef27135eb13d001afb015883 | |
parent | ba9c8badb7683f76eaa3f40f3b930410682bab69 (diff) | |
download | hardware_libhardware-0f82f5a73a9ea6462706c807dc1a5a2cf2333ea1.zip hardware_libhardware-0f82f5a73a9ea6462706c807dc1a5a2cf2333ea1.tar.gz hardware_libhardware-0f82f5a73a9ea6462706c807dc1a5a2cf2333ea1.tar.bz2 |
modules: camera: Separate locking for static characteristics
Static camera characteristics can be queried on any device at any time.
Separate the locking for it from the rest of the device to eliminate any
contention between operations on the device and static characteristic
initialization.
Change-Id: I8076378699f274e70c6318e537df4758972de9db
-rw-r--r-- | modules/camera/Camera.cpp | 65 | ||||
-rw-r--r-- | modules/camera/Camera.h | 5 |
2 files changed, 36 insertions, 34 deletions
diff --git a/modules/camera/Camera.cpp b/modules/camera/Camera.cpp index 2fe7395..973380e 100644 --- a/modules/camera/Camera.cpp +++ b/modules/camera/Camera.cpp @@ -59,8 +59,8 @@ Camera::Camera(int id) mNumStreams(0), mSettings(NULL) { - pthread_mutex_init(&mMutex, - NULL); // No pthread mutex attributes. + pthread_mutex_init(&mMutex, NULL); + pthread_mutex_init(&mStaticInfoMutex, NULL); memset(&mDevice, 0, sizeof(mDevice)); mDevice.common.tag = HARDWARE_DEVICE_TAG; @@ -72,6 +72,8 @@ Camera::Camera(int id) Camera::~Camera() { + pthread_mutex_destroy(&mMutex); + pthread_mutex_destroy(&mStaticInfoMutex); } int Camera::open(const hw_module_t *module, hw_device_t **device) @@ -96,21 +98,19 @@ int Camera::open(const hw_module_t *module, hw_device_t **device) int Camera::getInfo(struct camera_info *info) { - int ret = 0; - info->facing = CAMERA_FACING_FRONT; info->orientation = 0; info->device_version = mDevice.common.version; - pthread_mutex_lock(&mMutex); + pthread_mutex_lock(&mStaticInfoMutex); if (mStaticInfo == NULL) { - ret = initStaticInfo(); + mStaticInfo = initStaticInfo(); } - pthread_mutex_unlock(&mMutex); + pthread_mutex_unlock(&mStaticInfoMutex); info->static_camera_characteristics = mStaticInfo; - return ret; + return 0; } int Camera::close() @@ -161,49 +161,50 @@ int Camera::initialize(const camera3_callback_ops_t *callback_ops) return 0; } -int Camera::initStaticInfo() +camera_metadata_t *Camera::initStaticInfo() { /* * Setup static camera info. This will have to customized per camera * device. */ + Metadata m; /* android.control */ int32_t android_control_ae_available_target_fps_ranges[] = {30, 30}; - mMetadata.addInt32(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, + m.addInt32(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, ARRAY_SIZE(android_control_ae_available_target_fps_ranges), android_control_ae_available_target_fps_ranges); int32_t android_control_ae_compensation_range[] = {-4, 4}; - mMetadata.addInt32(ANDROID_CONTROL_AE_COMPENSATION_RANGE, + m.addInt32(ANDROID_CONTROL_AE_COMPENSATION_RANGE, ARRAY_SIZE(android_control_ae_compensation_range), android_control_ae_compensation_range); camera_metadata_rational_t android_control_ae_compensation_step[] = {{2,1}}; - mMetadata.addRational(ANDROID_CONTROL_AE_COMPENSATION_STEP, + m.addRational(ANDROID_CONTROL_AE_COMPENSATION_STEP, ARRAY_SIZE(android_control_ae_compensation_step), android_control_ae_compensation_step); int32_t android_control_max_regions[] = {1}; - mMetadata.addInt32(ANDROID_CONTROL_MAX_REGIONS, + m.addInt32(ANDROID_CONTROL_MAX_REGIONS, ARRAY_SIZE(android_control_max_regions), android_control_max_regions); /* android.jpeg */ int32_t android_jpeg_available_thumbnail_sizes[] = {0, 0, 128, 96}; - mMetadata.addInt32(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, + m.addInt32(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, ARRAY_SIZE(android_jpeg_available_thumbnail_sizes), android_jpeg_available_thumbnail_sizes); /* android.lens */ float android_lens_info_available_focal_lengths[] = {1.0}; - mMetadata.addFloat(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, + m.addFloat(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, ARRAY_SIZE(android_lens_info_available_focal_lengths), android_lens_info_available_focal_lengths); /* android.request */ int32_t android_request_max_num_output_streams[] = {0, 3, 1}; - mMetadata.addInt32(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, + m.addInt32(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, ARRAY_SIZE(android_request_max_num_output_streams), android_request_max_num_output_streams); @@ -217,83 +218,81 @@ int Camera::initStaticInfo() // HAL_PIXEL_FORMAT_YV12, // HAL_PIXEL_FORMAT_YCrCb_420_SP, HAL_PIXEL_FORMAT_YCbCr_420_888}; - mMetadata.addInt32(ANDROID_SCALER_AVAILABLE_FORMATS, + m.addInt32(ANDROID_SCALER_AVAILABLE_FORMATS, ARRAY_SIZE(android_scaler_available_formats), android_scaler_available_formats); int64_t android_scaler_available_jpeg_min_durations[] = {1}; - mMetadata.addInt64(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS, + m.addInt64(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS, ARRAY_SIZE(android_scaler_available_jpeg_min_durations), android_scaler_available_jpeg_min_durations); int32_t android_scaler_available_jpeg_sizes[] = {640, 480}; - mMetadata.addInt32(ANDROID_SCALER_AVAILABLE_JPEG_SIZES, + m.addInt32(ANDROID_SCALER_AVAILABLE_JPEG_SIZES, ARRAY_SIZE(android_scaler_available_jpeg_sizes), android_scaler_available_jpeg_sizes); float android_scaler_available_max_digital_zoom[] = {1}; - mMetadata.addFloat(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, + m.addFloat(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, ARRAY_SIZE(android_scaler_available_max_digital_zoom), android_scaler_available_max_digital_zoom); int64_t android_scaler_available_processed_min_durations[] = {1}; - mMetadata.addInt64(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS, + m.addInt64(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS, ARRAY_SIZE(android_scaler_available_processed_min_durations), android_scaler_available_processed_min_durations); int32_t android_scaler_available_processed_sizes[] = {640, 480}; - mMetadata.addInt32(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES, + m.addInt32(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES, ARRAY_SIZE(android_scaler_available_processed_sizes), android_scaler_available_processed_sizes); int64_t android_scaler_available_raw_min_durations[] = {1}; - mMetadata.addInt64(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, + m.addInt64(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, ARRAY_SIZE(android_scaler_available_raw_min_durations), android_scaler_available_raw_min_durations); int32_t android_scaler_available_raw_sizes[] = {640, 480}; - mMetadata.addInt32(ANDROID_SCALER_AVAILABLE_RAW_SIZES, + m.addInt32(ANDROID_SCALER_AVAILABLE_RAW_SIZES, ARRAY_SIZE(android_scaler_available_raw_sizes), android_scaler_available_raw_sizes); /* android.sensor */ int32_t android_sensor_info_active_array_size[] = {0, 0, 640, 480}; - mMetadata.addInt32(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, + m.addInt32(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, ARRAY_SIZE(android_sensor_info_active_array_size), android_sensor_info_active_array_size); int32_t android_sensor_info_sensitivity_range[] = {100, 1600}; - mMetadata.addInt32(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, + m.addInt32(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE, ARRAY_SIZE(android_sensor_info_sensitivity_range), android_sensor_info_sensitivity_range); int64_t android_sensor_info_max_frame_duration[] = {30000000000}; - mMetadata.addInt64(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, + m.addInt64(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, ARRAY_SIZE(android_sensor_info_max_frame_duration), android_sensor_info_max_frame_duration); float android_sensor_info_physical_size[] = {3.2, 2.4}; - mMetadata.addFloat(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, + m.addFloat(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, ARRAY_SIZE(android_sensor_info_physical_size), android_sensor_info_physical_size); int32_t android_sensor_info_pixel_array_size[] = {640, 480}; - mMetadata.addInt32(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, + m.addInt32(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, ARRAY_SIZE(android_sensor_info_pixel_array_size), android_sensor_info_pixel_array_size); int32_t android_sensor_orientation[] = {0}; - mMetadata.addInt32(ANDROID_SENSOR_ORIENTATION, + m.addInt32(ANDROID_SENSOR_ORIENTATION, ARRAY_SIZE(android_sensor_orientation), android_sensor_orientation); /* End of static camera characteristics */ - mStaticInfo = mMetadata.generate(); - - return 0; + return clone_camera_metadata(m.generate()); } int Camera::configureStreams(camera3_stream_configuration_t *stream_config) diff --git a/modules/camera/Camera.h b/modules/camera/Camera.h index 16e1439..be672f9 100644 --- a/modules/camera/Camera.h +++ b/modules/camera/Camera.h @@ -54,7 +54,7 @@ class Camera { private: // Separate initialization method for static metadata - int initStaticInfo(); + camera_metadata_t *initStaticInfo(); // Reuse a stream already created by this device Stream *reuseStream(camera3_stream_t *astream); // Destroy all streams in a stream array, and the array itself @@ -89,6 +89,9 @@ class Camera { const camera3_callback_ops_t *mCallbackOps; // Lock protecting the Camera object for modifications pthread_mutex_t mMutex; + // Lock protecting only static camera characteristics, which may + // be accessed without the camera device open + pthread_mutex_t mStaticInfoMutex; // Array of handles to streams currently in use by the device Stream **mStreams; // Number of streams in mStreams |