int camera_start_preview(camera_h camera)
{
int ret = CAMERA_ERROR_NONE;
+ int *fds = NULL;
muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
camera_cli_s *pc = (camera_cli_s *)camera;
camera_state_e current_state = CAMERA_STATE_NONE;
CAM_LOG_INFO("Enter : preview format %d, display type %d",
pc->cb_info->preview_format, pc->cb_info->dp_info.type);
- ret = camera_get_state(camera, ¤t_state);
- if (ret != CAMERA_ERROR_NONE) {
- CAM_LOG_ERROR("failed to get current state 0x%x", ret);
- return ret;
- }
-
if (pc->cb_info->preview_format == CAMERA_PIXEL_FORMAT_INVZ &&
pc->cb_info->dp_info.type != CAMERA_DISPLAY_TYPE_NONE) {
CAM_LOG_ERROR("CAMERA_DISPLAY_TYPE_NONE[current %d] should be set with INVZ format",
return CAMERA_ERROR_INVALID_OPERATION;
}
- /* message handler thread for preview callback */
- if (!__create_msg_handler_thread(&pc->cb_info->preview_cb_info,
- CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "camera_msg_handler:preview_cb", pc->cb_info)) {
- CAM_LOG_ERROR("preview_cb_info failed");
- return CAMERA_ERROR_INVALID_OPERATION;
+ ret = camera_get_state(camera, ¤t_state);
+ if (ret != CAMERA_ERROR_NONE) {
+ CAM_LOG_ERROR("failed to get current state 0x%x", ret);
+ return ret;
}
- if (current_state == CAMERA_STATE_CREATED && pc->cb_info->user_buffer_supported) {
- if (__camera_allocate_preview_buffer(camera))
- _camera_msg_send(api, pc->cb_info->fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
- else
- ret = CAMERA_ERROR_INVALID_OPERATION;
- } else {
- _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
- }
+ if (current_state == CAMERA_STATE_CREATED) {
+ if (!__create_msg_handler_thread(&pc->cb_info->preview_cb_info,
+ CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "camera_msg_handler:preview_cb", pc->cb_info)) {
+ CAM_LOG_ERROR("preview_cb_info failed");
+ return CAMERA_ERROR_INVALID_OPERATION;
+ }
- if (ret == CAMERA_ERROR_NONE) {
- if (pc->cb_info->is_evas_render) {
- ret = _camera_start_evas_rendering(camera);
- if (ret != CAMERA_ERROR_NONE) {
- CAM_LOG_ERROR("stop preview because of error");
- _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
+ if (pc->cb_info->user_buffer_supported) {
+ if (!__camera_allocate_preview_buffer(camera)) {
+ ret = CAMERA_ERROR_INVALID_OPERATION;
+ goto _START_FAILED;
}
+
+ fds = pc->cb_info->fds;
}
}
+ _camera_msg_send(api, fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
if (ret != CAMERA_ERROR_NONE)
+ goto _START_FAILED;
+
+ if (pc->cb_info->is_evas_render) {
+ ret = _camera_start_evas_rendering(camera);
+ if (ret != CAMERA_ERROR_NONE) {
+ CAM_LOG_ERROR("stop preview because of error");
+ _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
+ goto _START_FAILED;
+ }
+ }
+
+ CAM_LOG_INFO("done");
+
+ return CAMERA_ERROR_NONE;
+
+_START_FAILED:
+ if (current_state == CAMERA_STATE_CREATED) {
+ if (pc->cb_info->user_buffer_supported)
+ __camera_release_preview_buffer(camera);
+
__destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
+ }
- CAM_LOG_INFO("ret : 0x%x", ret);
+ CAM_LOG_ERROR("failed : 0x%x", ret);
return ret;
}