}
+static int _camera_switch_device(camera_s *handle, camera_device_e device)
+{
+ int ret = MM_ERROR_NONE;
+ MMCamAttrsInfo info;
+
+ camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER);
+
+ ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_SWITCH_DEVICE, &info);
+ if (ret != MM_ERROR_NONE)
+ return __convert_camera_error_code(__func__, ret);
+
+ if (info.int_array.count == 0) {
+ /* NOTE: Return INVALID_STATE here.
+ - The camera_change_device() API should return INVALID_STATE if it's not CREATED state.
+ - The current state is PREVIEW now. */
+ CAM_LOG_ERROR("not support switch device");
+ return CAMERA_ERROR_INVALID_STATE;
+ }
+
+ ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
+ MMCAM_CAMERA_SWITCH_DEVICE, device,
+ NULL);
+
+ return __convert_camera_error_code(__func__, ret);
+}
+
+
int legacy_camera_change_device(camera_h *camera, camera_device_e device)
{
int ret = MM_ERROR_NONE;
old_handle = (camera_s *)*camera;
- camera_return_val_if_fail(old_handle->is_used_in_recorder == false, CAMERA_ERROR_INVALID_OPERATION);
- camera_return_val_if_fail(old_handle->device_type != device, CAMERA_ERROR_NONE);
-
/* check current state */
legacy_camera_get_state(*camera, &capi_state);
+ if (capi_state == CAMERA_STATE_PREVIEW)
+ return _camera_switch_device(old_handle, device);
+
+ camera_return_val_if_fail(old_handle->device_type != device, CAMERA_ERROR_NONE);
camera_return_val_if_fail(capi_state == CAMERA_STATE_CREATED, CAMERA_ERROR_INVALID_STATE);
+ camera_return_val_if_fail(!old_handle->is_used_in_recorder, CAMERA_ERROR_INVALID_OPERATION);
+
/* get reuse element */
ret = mm_camcorder_get_attributes(old_handle->mm_handle, NULL,
MMCAM_DISPLAY_REUSE_ELEMENT, &reuse_element, &element_size,