/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * 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. */ #include #include #include #include #include #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_CAMERA" //LCOV_EXCL_START int __set_level(camera_h camera, muse_camera_api_e api, int level) { int ret = CAMERA_ERROR_NONE; camera_cli_s *pc = (camera_cli_s *)camera; camera_msg_param param; if (!pc || !pc->cb_info) { CAM_LOG_ERROR("NULL handle - api[%d]", api); return CAMERA_ERROR_INVALID_PARAMETER; } CAM_LOG_INFO("Enter - api[%d], level[%d]", api, level); CAMERA_MSG_PARAM_SET(param, INT, level); _camera_msg_send_param1(api, pc->cb_info, &ret, ¶m, CAMERA_CB_TIMEOUT); CAM_LOG_INFO("ret : 0x%x", ret); return ret; } int camera_start_evas_rendering(camera_h camera) { return _camera_start_evas_rendering(camera); } int camera_stop_evas_rendering(camera_h camera, bool keep_screen) { return _camera_stop_evas_rendering(camera, keep_screen); } int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window) { return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window); } //LCOV_EXCL_STOP void camera_create_preview_frame(void *stream, int num_buffer_fd, void *buffer_bo_handle, void *data_bo_handle, camera_preview_data_s *frame) { int total_size = 0; unsigned char *buf_pos = NULL; MMCamcorderVideoStreamDataType *_stream = (MMCamcorderVideoStreamDataType *)stream; tbm_bo_handle *_buffer_bo_handle = (tbm_bo_handle *)buffer_bo_handle; tbm_bo_handle *_data_bo_handle = (tbm_bo_handle *)data_bo_handle; if (!_stream || !_buffer_bo_handle || !frame) { CAM_LOG_ERROR("invalid param %p,%p,%p", _stream, _buffer_bo_handle, frame); return; } /* set frame info */ if (_stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY) frame->format = MM_PIXEL_FORMAT_UYVY; else frame->format = _stream->format; frame->width = _stream->width; frame->height = _stream->height; frame->timestamp = _stream->timestamp; frame->num_of_planes = _stream->num_planes; if (num_buffer_fd == 0) { //LCOV_EXCL_START /* non-zero copy */ if (!_data_bo_handle || !_data_bo_handle->ptr) { CAM_LOG_ERROR("NULL pointer"); return; } buf_pos = _data_bo_handle->ptr; switch (_stream->format) { case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */ case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */ case MM_PIXEL_FORMAT_ENCODED_VP8: /* fall through */ case MM_PIXEL_FORMAT_ENCODED_VP9: frame->data.encoded_plane.data = buf_pos; frame->data.encoded_plane.size = _stream->data.encoded.length_data; frame->data.encoded_plane.is_delta_frame = (bool)_stream->data.encoded.is_delta_frame; total_size = _stream->data.encoded.length_data; break; case MM_PIXEL_FORMAT_INVZ: frame->data.depth_plane.data = buf_pos; frame->data.depth_plane.size = _stream->data.depth.length_data; total_size = _stream->data.depth.length_data; break; case MM_PIXEL_FORMAT_RGBA: /* fall through */ case MM_PIXEL_FORMAT_ARGB: frame->data.rgb_plane.data = buf_pos; frame->data.rgb_plane.size = _stream->data.rgb.length_data; total_size = _stream->data.rgb.length_data; break; default: switch (_stream->num_planes) { case 1: frame->data.single_plane.yuv = buf_pos; frame->data.single_plane.size = _stream->data.yuv420.length_yuv; total_size = _stream->data.yuv420.length_yuv; break; case 2: frame->data.double_plane.y = buf_pos; frame->data.double_plane.y_size = _stream->data.yuv420sp.length_y; buf_pos += _stream->data.yuv420sp.length_y; frame->data.double_plane.uv = buf_pos; frame->data.double_plane.uv_size = _stream->data.yuv420sp.length_uv; total_size = _stream->data.yuv420sp.length_y + \ _stream->data.yuv420sp.length_uv; break; case 3: frame->data.triple_plane.y = buf_pos; frame->data.triple_plane.y_size = _stream->data.yuv420p.length_y; buf_pos += _stream->data.yuv420p.length_y; frame->data.triple_plane.u = buf_pos; frame->data.triple_plane.u_size = _stream->data.yuv420p.length_u; buf_pos += _stream->data.yuv420p.length_u; frame->data.triple_plane.v = buf_pos; frame->data.triple_plane.v_size = _stream->data.yuv420p.length_v; total_size = _stream->data.yuv420p.length_y + \ _stream->data.yuv420p.length_u + \ _stream->data.yuv420p.length_v; break; default: break; } break; } //LCOV_EXCL_STOP } else { /* zero copy */ switch (_stream->num_planes) { //LCOV_EXCL_START case 1: if (_stream->data_type == MM_CAM_STREAM_DATA_ENCODED) { frame->data.encoded_plane.data = _buffer_bo_handle[0].ptr; frame->data.encoded_plane.size = _stream->data.encoded.length_data; frame->data.encoded_plane.is_delta_frame = (bool)_stream->data.encoded.is_delta_frame; total_size = _stream->data.encoded.length_data; } else { frame->data.single_plane.yuv = _buffer_bo_handle[0].ptr; frame->data.single_plane.size = _stream->data.yuv420.length_yuv; total_size = _stream->data.yuv420.length_yuv; } break; //LCOV_EXCL_STOP case 2: frame->data.double_plane.y = _buffer_bo_handle[0].ptr; if (_stream->num_planes == (unsigned int)num_buffer_fd) frame->data.double_plane.uv = _buffer_bo_handle[1].ptr; else frame->data.double_plane.uv = _buffer_bo_handle[0].ptr + _stream->data.yuv420sp.length_y; frame->data.double_plane.y_size = _stream->data.yuv420sp.length_y; frame->data.double_plane.uv_size = _stream->data.yuv420sp.length_uv; total_size = _stream->data.yuv420sp.length_y + \ _stream->data.yuv420sp.length_uv; break; case 3: //LCOV_EXCL_START frame->data.triple_plane.y = _buffer_bo_handle[0].ptr; if (_stream->num_planes == (unsigned int)num_buffer_fd) { frame->data.triple_plane.u = _buffer_bo_handle[1].ptr; frame->data.triple_plane.v = _buffer_bo_handle[2].ptr; } else { frame->data.triple_plane.u = _buffer_bo_handle[0].ptr + _stream->data.yuv420p.length_y; frame->data.triple_plane.v = frame->data.triple_plane.u + _stream->data.yuv420p.length_u; } frame->data.triple_plane.y_size = _stream->data.yuv420p.length_y; frame->data.triple_plane.u_size = _stream->data.yuv420p.length_u; frame->data.triple_plane.v_size = _stream->data.yuv420p.length_v; total_size = _stream->data.yuv420p.length_y + \ _stream->data.yuv420p.length_u + \ _stream->data.yuv420p.length_v; break; //LCOV_EXCL_STOP default: break; } } CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]", frame->format, frame->width, frame->height, total_size, frame->num_of_planes); } //LCOV_EXCL_START int camera_attr_set_flash_brightness(camera_h camera, int level) { return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_BRIGHTNESS, level); } int camera_attr_get_flash_brightness(camera_h camera, int *level) { return _camera_attr_get_level(camera, MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS, MUSE_CAMERA_GET_INT_FLASH_BRIGHTNESS, level); } int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max) { return _camera_attr_get_range(camera, MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS_RANGE, MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE, min, max); } int camera_set_extra_preview_device(camera_h camera, int stream_id, camera_device_e device) { int ret = CAMERA_ERROR_NONE; char *msg = NULL; camera_cli_s *pc = (camera_cli_s *)camera; muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_DEVICE; CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER); CAM_LOG_INFO("Enter - stream[%d], device[%d]", stream_id, device); msg = muse_core_msg_new(api, MUSE_TYPE_INT, "stream_id", stream_id, MUSE_TYPE_INT, "device", device, NULL); _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret); return ret; } int camera_request_codec_config(camera_h camera) { int ret = CAMERA_ERROR_NONE; camera_cli_s *pc = (camera_cli_s *)camera; muse_camera_api_e api = MUSE_CAMERA_API_REQUEST_CODEC_CONFIG; if (!pc || !pc->cb_info) { CAM_LOG_ERROR("NULL pointer %p", pc); return CAMERA_ERROR_INVALID_PARAMETER; } CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); CAM_LOG_INFO("ret : 0x%x", ret); return ret; } int camera_attr_get_preview_frame_timestamp(camera_h camera, unsigned long long *timestamp) { camera_cli_s *pc = (camera_cli_s *)camera; if (!pc || !pc->cb_info || !timestamp) { CAM_LOG_ERROR("NULL pointer %p %p", pc, timestamp); return CAMERA_ERROR_INVALID_PARAMETER; } if (!pc->cb_info->stream_data) { CAM_LOG_ERROR("no stream data, maybe it's not in preview callback"); return CAMERA_ERROR_INVALID_OPERATION; } *timestamp = pc->cb_info->stream_data->timestamp_nsec; CAM_LOG_DEBUG("frame timestamp[%llu]", *timestamp); return CAMERA_ERROR_NONE; } int camera_attr_get_preview_frame_meta(camera_h camera, camera_frame_meta_s *frame_meta) { camera_cli_s *pc = (camera_cli_s *)camera; MMCamcorderVideoStreamDataType *stream = NULL; if (!pc || !pc->cb_info || !frame_meta) { CAM_LOG_ERROR("NULL pointer %p %p", pc, frame_meta); return CAMERA_ERROR_INVALID_PARAMETER; } stream = pc->cb_info->stream_data; if (!stream) { CAM_LOG_ERROR("no stream data, maybe it's not in preview callback"); return CAMERA_ERROR_INVALID_OPERATION; } frame_meta->ts_soe = stream->frame_meta.ts_soe; frame_meta->ts_eoe = stream->frame_meta.ts_eoe; frame_meta->ts_sof = stream->frame_meta.ts_sof; frame_meta->ts_eof = stream->frame_meta.ts_eof; frame_meta->ts_hal = stream->frame_meta.ts_hal; frame_meta->ts_qmf = stream->frame_meta.ts_qmf; frame_meta->ts_gst = stream->frame_meta.ts_gst; frame_meta->td_exp = stream->frame_meta.td_exp; frame_meta->ts_aux = stream->frame_meta.ts_aux; frame_meta->td_aux = stream->frame_meta.td_aux; frame_meta->seqnum = stream->frame_meta.seqnum; frame_meta->flags = stream->frame_meta.flags; frame_meta->lux_index = stream->frame_meta.lux_index; return CAMERA_ERROR_NONE; } int camera_attr_get_preview_frame_status_auto_exposure(camera_h camera, camera_status_auto_exposure_e *status) { camera_cli_s *pc = (camera_cli_s *)camera; MMCamcorderVideoStreamDataType *stream = NULL; if (!pc || !pc->cb_info || !status) { CAM_LOG_ERROR("NULL pointer %p %p", pc, status); return CAMERA_ERROR_INVALID_PARAMETER; } stream = pc->cb_info->stream_data; if (!stream) { CAM_LOG_ERROR("no stream data, maybe it's not in preview callback"); return CAMERA_ERROR_INVALID_OPERATION; } *status = stream->status_ae; CAM_LOG_DEBUG("status: auto exposure[%d]", *status); return CAMERA_ERROR_NONE; } int camera_attr_get_preview_frame_status_auto_white_balance(camera_h camera, camera_status_auto_white_balance_e *status) { camera_cli_s *pc = (camera_cli_s *)camera; MMCamcorderVideoStreamDataType *stream = NULL; if (!pc || !pc->cb_info || !status) { CAM_LOG_ERROR("NULL pointer %p %p", pc, status); return CAMERA_ERROR_INVALID_PARAMETER; } stream = pc->cb_info->stream_data; if (!stream) { CAM_LOG_ERROR("no stream data, maybe it's not in preview callback"); return CAMERA_ERROR_INVALID_OPERATION; } *status = stream->status_awb; CAM_LOG_DEBUG("status: auto white balance[%d]", *status); return CAMERA_ERROR_NONE; } bool camera_is_supported_media_packet_preview_internal_cb(camera_h camera) { return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_INTERNAL_CB); } int camera_set_media_packet_preview_internal_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data) { int ret = CAMERA_ERROR_NONE; camera_cli_s *pc = (camera_cli_s *)camera; muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_INTERNAL_CB; CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER); if (camera_is_supported_media_packet_preview_internal_cb(camera) == false) { CAM_LOG_ERROR("NOT SUPPORTED"); return CAMERA_ERROR_NOT_SUPPORTED; } if (callback == NULL) { CAM_LOG_ERROR("NULL callback"); return CAMERA_ERROR_INVALID_PARAMETER; } CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); if (ret == CAMERA_ERROR_NONE) { g_mutex_lock(&pc->cb_info->user_cb_lock[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL]); pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL] = callback; pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL] = user_data; g_mutex_unlock(&pc->cb_info->user_cb_lock[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL]); } CAM_LOG_INFO("ret : 0x%x", ret); return ret; } int camera_unset_media_packet_preview_internal_cb(camera_h camera) { int ret = CAMERA_ERROR_NONE; camera_cli_s *pc = (camera_cli_s *)camera; muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_INTERNAL_CB; CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER); if (camera_is_supported_media_packet_preview_internal_cb(camera) == false) { CAM_LOG_ERROR("NOT SUPPORTED"); return CAMERA_ERROR_NOT_SUPPORTED; } CAM_LOG_INFO("Enter"); _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT); if (ret == CAMERA_ERROR_NONE) { g_mutex_lock(&pc->cb_info->user_cb_lock[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL]); pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL] = NULL; pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL] = NULL; g_mutex_unlock(&pc->cb_info->user_cb_lock[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW_INTERNAL]); } CAM_LOG_INFO("ret : 0x%x", ret); return ret; } //LCOV_EXCL_STOP