| /* |
| ** |
| ** Copyright 2013, Samsung Electronics Co. LTD |
| ** |
| ** 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_NDEBUG 0 */ |
| #define LOG_TAG "ExynosCameraInterface" |
| #include <cutils/log.h> |
| |
| #include "ExynosCameraInterface.h" |
| #include "ExynosCameraAutoTimer.h" |
| |
| #ifdef SAMSUNG_TN_FEATURE |
| #include "SecCameraVendorTags.h" |
| #endif |
| |
| namespace android { |
| |
| static int HAL_camera_device_open( |
| const struct hw_module_t* module, |
| const char *id, |
| struct hw_device_t** device) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| int cameraId = atoi(id); |
| |
| #ifdef BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA |
| if (cameraId == 0) { |
| return HAL_ext_camera_device_open_wrapper(module, id, device); |
| } |
| #endif |
| |
| #ifdef BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA |
| if (cameraId == 1) { |
| return HAL_ext_camera_device_open_wrapper(module, id, device); |
| } |
| #endif |
| |
| #if (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) |
| #else |
| enum CAMERA_STATE state; |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| if (cameraId < 0 || cameraId >= HAL_getNumberOfCameras()) { |
| ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id); |
| return -EINVAL; |
| } |
| |
| state = CAMERA_OPENED; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", __FUNCTION__, cameraId, state); |
| return -1; |
| } |
| |
| if ((unsigned int)cameraId < (sizeof(sCameraInfo) / sizeof(sCameraInfo[0]))) { |
| if (g_cam_device[cameraId]) { |
| ALOGE("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id); |
| *device = (hw_device_t *)g_cam_device[cameraId]; |
| goto done; |
| } |
| |
| g_cam_device[cameraId] = (camera_device_t *)malloc(sizeof(camera_device_t)); |
| if (!g_cam_device[cameraId]) |
| return -ENOMEM; |
| |
| g_cam_openLock[cameraId].lock(); |
| g_cam_device[cameraId]->common.tag = HARDWARE_DEVICE_TAG; |
| g_cam_device[cameraId]->common.version = 1; |
| g_cam_device[cameraId]->common.module = const_cast<hw_module_t *>(module); |
| g_cam_device[cameraId]->common.close = HAL_camera_device_close; |
| |
| g_cam_device[cameraId]->ops = &camera_device_ops; |
| |
| ALOGD("DEBUG(%s):open camera %s", __FUNCTION__, id); |
| g_cam_device[cameraId]->priv = new ExynosCamera(cameraId, g_cam_device[cameraId]); |
| *device = (hw_device_t *)g_cam_device[cameraId]; |
| ALOGI("INFO(%s[%d]):camera(%d) out from new g_cam_device[%d]->priv()", |
| __FUNCTION__, __LINE__, cameraId, cameraId); |
| |
| g_cam_openLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| } else { |
| ALOGE("DEBUG(%s):camera(%s) open fail - must front camera open first", |
| __FUNCTION__, id); |
| return -EINVAL; |
| } |
| |
| done: |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId); |
| #endif /* (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) */ |
| |
| return 0; |
| } |
| |
| static int HAL_camera_device_close(struct hw_device_t* device) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| uint32_t cameraId; |
| enum CAMERA_STATE state; |
| |
| #if (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) |
| #else |
| ALOGI("INFO(%s[%d]): in", __FUNCTION__, __LINE__); |
| |
| if (device) { |
| camera_device_t *cam_device = (camera_device_t *)device; |
| cameraId = obj(cam_device)->getCameraId(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d)", __FUNCTION__, __LINE__, cameraId); |
| |
| state = CAMERA_CLOSED; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", |
| __FUNCTION__, cameraId, state); |
| return -1; |
| } |
| |
| g_cam_openLock[cameraId].lock(); |
| ALOGI("INFO(%s[%d]):camera(%d) locked..", __FUNCTION__, __LINE__, cameraId); |
| g_cam_device[cameraId] = NULL; |
| g_cam_openLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| |
| delete static_cast<ExynosCamera *>(cam_device->priv); |
| free(cam_device); |
| |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d)", __FUNCTION__, __LINE__, cameraId); |
| } |
| |
| ALOGI("INFO(%s[%d]): out", __FUNCTION__, __LINE__); |
| #endif /* (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) */ |
| |
| return 0; |
| } |
| |
| static int HAL_camera_device_set_preview_window( |
| struct camera_device *dev, |
| struct preview_stream_ops *buf) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| static int ret; |
| uint32_t cameraId = obj(dev)->getCameraId(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| ret = obj(dev)->setPreviewWindow(buf); |
| ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId); |
| return ret; |
| } |
| |
| static void HAL_camera_device_set_callbacks(struct camera_device *dev, |
| camera_notify_callback notify_cb, |
| camera_data_callback data_cb, |
| camera_data_timestamp_callback data_cb_timestamp, |
| camera_request_memory get_memory, |
| void* user) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| obj(dev)->setCallbacks(notify_cb, data_cb, data_cb_timestamp, |
| get_memory, |
| user); |
| } |
| |
| static void HAL_camera_device_enable_msg_type( |
| struct camera_device *dev, |
| int32_t msg_type) |
| { |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| obj(dev)->enableMsgType(msg_type); |
| } |
| |
| static void HAL_camera_device_disable_msg_type( |
| struct camera_device *dev, |
| int32_t msg_type) |
| { |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| obj(dev)->disableMsgType(msg_type); |
| } |
| |
| static int HAL_camera_device_msg_type_enabled( |
| struct camera_device *dev, |
| int32_t msg_type) |
| { |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->msgTypeEnabled(msg_type); |
| } |
| |
| static int HAL_camera_device_start_preview(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| static int ret; |
| uint32_t cameraId = obj(dev)->getCameraId(); |
| enum CAMERA_STATE state; |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| |
| state = CAMERA_PREVIEW; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", |
| __FUNCTION__, cameraId, state); |
| return -1; |
| } |
| |
| g_cam_previewLock[cameraId].lock(); |
| |
| ret = obj(dev)->startPreview(); |
| ALOGI("INFO(%s[%d]):camera(%d) out from startPreview()", |
| __FUNCTION__, __LINE__, cameraId); |
| |
| g_cam_previewLock[cameraId].unlock(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| |
| if (ret == OK) { |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) out (startPreview succeeded)", |
| __FUNCTION__, __LINE__, cameraId); |
| } else { |
| ALOGI("INFO(%s[%d]):camera(%d) out (startPreview FAILED)", |
| __FUNCTION__, __LINE__, cameraId); |
| } |
| return ret; |
| } |
| |
| static void HAL_camera_device_stop_preview(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| uint32_t cameraId = obj(dev)->getCameraId(); |
| enum CAMERA_STATE state; |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| /* HACK : If camera in recording state, */ |
| /* CameraService have to call the stop_recording before the stop_preview */ |
| #if 1 |
| if (cam_state[cameraId] == CAMERA_RECORDING) { |
| ALOGE("ERR(%s[%d]):camera(%d) in RECORDING RUNNING state ---- INVALID ----", |
| __FUNCTION__, __LINE__, cameraId); |
| ALOGE("ERR(%s[%d]):camera(%d) The stop_recording must be called " |
| "before the stop_preview ---- INVALID ----", |
| __FUNCTION__, __LINE__, cameraId); |
| HAL_camera_device_stop_recording(dev); |
| ALOGE("ERR(%s[%d]):cameraId=%d out from stop_recording ---- INVALID ----", |
| __FUNCTION__, __LINE__, cameraId); |
| |
| for (int i=0; i<30; i++) { |
| ALOGE("ERR(%s[%d]):camera(%d) The stop_recording must be called " |
| "before the stop_preview ---- INVALID ----", |
| __FUNCTION__, __LINE__, cameraId); |
| } |
| ALOGE("ERR(%s[%d]):camera(%d) sleep 500ms for ---- INVALID ---- state", |
| __FUNCTION__, __LINE__, cameraId); |
| usleep(500000); /* to notify, sleep 500ms */ |
| } |
| #endif |
| state = CAMERA_PREVIEWSTOPPED; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", __FUNCTION__, cameraId, state); |
| return; |
| } |
| |
| g_cam_previewLock[cameraId].lock(); |
| |
| obj(dev)->stopPreview(); |
| ALOGI("INFO(%s[%d]):camera(%d) out from stopPreview()", |
| __FUNCTION__, __LINE__, cameraId); |
| |
| g_cam_previewLock[cameraId].unlock(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId); |
| } |
| |
| static int HAL_camera_device_preview_enabled(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->previewEnabled(); |
| } |
| |
| static int HAL_camera_device_store_meta_data_in_buffers( |
| struct camera_device *dev, |
| int enable) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->storeMetaDataInBuffers(enable); |
| } |
| |
| static int HAL_camera_device_start_recording(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| static int ret; |
| uint32_t cameraId = obj(dev)->getCameraId(); |
| enum CAMERA_STATE state; |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| |
| state = CAMERA_RECORDING; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", |
| __FUNCTION__, cameraId, state); |
| return -1; |
| } |
| |
| g_cam_recordingLock[cameraId].lock(); |
| |
| ret = obj(dev)->startRecording(); |
| ALOGI("INFO(%s[%d]):camera(%d) out from startRecording()", |
| __FUNCTION__, __LINE__, cameraId); |
| |
| g_cam_recordingLock[cameraId].unlock(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| |
| if (ret == OK) { |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) out (startRecording succeeded)", |
| __FUNCTION__, __LINE__, cameraId); |
| } else { |
| ALOGI("INFO(%s[%d]):camera(%d) out (startRecording FAILED)", |
| __FUNCTION__, __LINE__, cameraId); |
| } |
| return ret; |
| } |
| |
| static void HAL_camera_device_stop_recording(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| uint32_t cameraId = obj(dev)->getCameraId(); |
| enum CAMERA_STATE state; |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| |
| state = CAMERA_RECORDINGSTOPPED; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", __FUNCTION__, cameraId, state); |
| return; |
| } |
| |
| g_cam_recordingLock[cameraId].lock(); |
| |
| obj(dev)->stopRecording(); |
| ALOGI("INFO(%s[%d]):camera(%d) out from stopRecording()", |
| __FUNCTION__, __LINE__, cameraId); |
| |
| g_cam_recordingLock[cameraId].unlock(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId); |
| } |
| |
| static int HAL_camera_device_recording_enabled(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->recordingEnabled(); |
| } |
| |
| static void HAL_camera_device_release_recording_frame(struct camera_device *dev, |
| const void *opaque) |
| { |
| /* ExynosCameraAutoTimer autoTimer(__FUNCTION__); */ |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| obj(dev)->releaseRecordingFrame(opaque); |
| } |
| |
| static int HAL_camera_device_auto_focus(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->autoFocus(); |
| } |
| |
| static int HAL_camera_device_cancel_auto_focus(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->cancelAutoFocus(); |
| } |
| |
| static int HAL_camera_device_take_picture(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->takePicture(); |
| } |
| |
| static int HAL_camera_device_cancel_picture(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->cancelPicture(); |
| } |
| |
| static int HAL_camera_device_set_parameters( |
| struct camera_device *dev, |
| const char *parms) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| String8 str(parms); |
| CameraParameters p(str); |
| return obj(dev)->setParameters(p); |
| } |
| |
| char *HAL_camera_device_get_parameters(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| String8 str; |
| |
| /* HACK : to avoid compile error */ |
| #if (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) |
| ALOGE("ERR(%s[%d]):invalid opertion on external camera", __FUNCTION__, __LINE__); |
| #else |
| CameraParameters parms = obj(dev)->getParameters(); |
| str = parms.flatten(); |
| #endif |
| return strdup(str.string()); |
| } |
| |
| static void HAL_camera_device_put_parameters( |
| __unused struct camera_device *dev, |
| char *parms) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| free(parms); |
| } |
| |
| static int HAL_camera_device_send_command( |
| struct camera_device *dev, |
| int32_t cmd, |
| int32_t arg1, |
| int32_t arg2) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->sendCommand(cmd, arg1, arg2); |
| } |
| |
| static void HAL_camera_device_release(struct camera_device *dev) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| uint32_t cameraId = obj(dev)->getCameraId(); |
| enum CAMERA_STATE state; |
| |
| ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId); |
| |
| state = CAMERA_RELEASED; |
| if (check_camera_state(state, cameraId) == false) { |
| ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", |
| __FUNCTION__, cameraId, state); |
| return; |
| } |
| |
| g_cam_openLock[cameraId].lock(); |
| |
| obj(dev)->release(); |
| ALOGI("INFO(%s[%d]):camera(%d) out from release()", |
| __FUNCTION__, __LINE__, cameraId); |
| |
| g_cam_openLock[cameraId].unlock(); |
| |
| ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId); |
| |
| cam_stateLock[cameraId].lock(); |
| cam_state[cameraId] = state; |
| cam_stateLock[cameraId].unlock(); |
| ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId); |
| } |
| |
| static int HAL_camera_device_dump(struct camera_device *dev, int fd) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return obj(dev)->dump(fd); |
| } |
| |
| static int HAL_getNumberOfCameras() |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return sizeof(sCameraInfo) / sizeof(sCameraInfo[0]); |
| } |
| |
| static int HAL_set_callbacks(__unused const camera_module_callbacks_t *callbacks) |
| { |
| ALOGW("WRN(%s): not supported API level 1.0", __FUNCTION__); |
| return 0; |
| } |
| |
| static int HAL_getCameraInfo(int cameraId, struct camera_info *info) |
| { |
| ExynosCameraAutoTimer autoTimer(__FUNCTION__); |
| |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| if (cameraId < 0 || cameraId >= HAL_getNumberOfCameras()) { |
| ALOGE("ERR(%s):Invalid camera ID %d", __FUNCTION__, cameraId); |
| return -EINVAL; |
| } |
| |
| info->facing = sCameraInfo[cameraId][0]; |
| info->orientation = sCameraInfo[cameraId][1]; |
| info->device_version = HARDWARE_DEVICE_API_VERSION(1, 0); |
| |
| return NO_ERROR; |
| } |
| |
| static int HAL_open_legacy(__unused const struct hw_module_t* module, __unused const char* id, __unused uint32_t halVersion, __unused struct hw_device_t** device) |
| { |
| ALOGV("DEBUG(%s):", __FUNCTION__); |
| return NO_ERROR; |
| } |
| |
| static void HAL_get_vendor_tag_ops(__unused vendor_tag_ops_t* ops) |
| { |
| ALOGV("INFO(%s):", __FUNCTION__); |
| |
| #ifdef SAMSUNG_TN_FEATURE |
| SecCameraVendorTags::Ops = ops; |
| |
| ops->get_all_tags = SecCameraVendorTags::get_ext_all_tags; |
| ops->get_tag_count = SecCameraVendorTags::get_ext_tag_count; |
| ops->get_tag_type = SecCameraVendorTags::get_ext_tag_type; |
| ops->get_tag_name = SecCameraVendorTags::get_ext_tag_name; |
| ops->get_section_name = SecCameraVendorTags::get_ext_section_name; |
| ops->reserved[0] = NULL; |
| #endif |
| } |
| |
| }; /* namespace android */ |