2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <camera_internal.h>
24 #include <camera_private.h>
29 #define LOG_TAG "TIZEN_N_CAMERA"
33 int __set_level(camera_h camera, muse_camera_api_e api, int level)
35 int ret = CAMERA_ERROR_NONE;
36 camera_cli_s *pc = (camera_cli_s *)camera;
37 camera_msg_param param;
39 if (!pc || !pc->cb_info) {
40 CAM_LOG_ERROR("NULL handle - api[%d]", api);
41 return CAMERA_ERROR_INVALID_PARAMETER;
44 CAM_LOG_INFO("Enter - api[%d], level[%d]", api, level);
46 CAMERA_MSG_PARAM_SET(param, INT, level);
48 _camera_msg_send_param1(api, pc->cb_info, &ret, ¶m, CAMERA_CB_TIMEOUT);
50 CAM_LOG_INFO("ret : 0x%x", ret);
56 int camera_start_evas_rendering(camera_h camera)
58 return _camera_start_evas_rendering(camera);
62 int camera_stop_evas_rendering(camera_h camera, bool keep_screen)
64 return _camera_stop_evas_rendering(camera, keep_screen);
68 int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window)
70 return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window);
75 void camera_create_preview_frame(MMCamcorderVideoStreamDataType *stream, int num_buffer_fd,
76 tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame)
79 unsigned char *buf_pos = NULL;
81 if (!stream || !buffer_bo_handle || !frame) {
82 CAM_LOG_ERROR("invalid param %p,%p,%p", stream, buffer_bo_handle, frame);
87 if (stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY)
88 frame->format = MM_PIXEL_FORMAT_UYVY;
90 frame->format = stream->format;
92 frame->width = stream->width;
93 frame->height = stream->height;
94 frame->timestamp = stream->timestamp;
95 frame->num_of_planes = stream->num_planes;
97 if (num_buffer_fd == 0) {
100 if (!data_bo_handle || !data_bo_handle->ptr) {
101 CAM_LOG_ERROR("NULL pointer");
105 buf_pos = data_bo_handle->ptr;
107 switch (stream->format) {
108 case MM_PIXEL_FORMAT_ENCODED_H264:
110 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
112 case MM_PIXEL_FORMAT_ENCODED_VP8:
114 case MM_PIXEL_FORMAT_ENCODED_VP9:
115 frame->data.encoded_plane.data = buf_pos;
116 frame->data.encoded_plane.size = stream->data.encoded.length_data;
117 frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
118 total_size = stream->data.encoded.length_data;
121 case MM_PIXEL_FORMAT_INVZ:
122 frame->data.depth_plane.data = buf_pos;
123 frame->data.depth_plane.size = stream->data.depth.length_data;
124 total_size = stream->data.depth.length_data;
127 case MM_PIXEL_FORMAT_RGBA:
129 case MM_PIXEL_FORMAT_ARGB:
130 frame->data.rgb_plane.data = buf_pos;
131 frame->data.rgb_plane.size = stream->data.rgb.length_data;
132 total_size = stream->data.rgb.length_data;
136 switch (stream->num_planes) {
138 frame->data.single_plane.yuv = buf_pos;
139 frame->data.single_plane.size = stream->data.yuv420.length_yuv;
140 total_size = stream->data.yuv420.length_yuv;
143 frame->data.double_plane.y = buf_pos;
144 frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
145 buf_pos += stream->data.yuv420sp.length_y;
146 frame->data.double_plane.uv = buf_pos;
147 frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
148 total_size = stream->data.yuv420sp.length_y + \
149 stream->data.yuv420sp.length_uv;
152 frame->data.triple_plane.y = buf_pos;
153 frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
154 buf_pos += stream->data.yuv420p.length_y;
155 frame->data.triple_plane.u = buf_pos;
156 frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
157 buf_pos += stream->data.yuv420p.length_u;
158 frame->data.triple_plane.v = buf_pos;
159 frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
160 total_size = stream->data.yuv420p.length_y + \
161 stream->data.yuv420p.length_u + \
162 stream->data.yuv420p.length_v;
172 switch (stream->num_planes) {
175 if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED) {
176 frame->data.encoded_plane.data = buffer_bo_handle[0].ptr;
177 frame->data.encoded_plane.size = stream->data.encoded.length_data;
178 frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
179 total_size = stream->data.encoded.length_data;
181 frame->data.single_plane.yuv = buffer_bo_handle[0].ptr;
182 frame->data.single_plane.size = stream->data.yuv420.length_yuv;
183 total_size = stream->data.yuv420.length_yuv;
188 frame->data.double_plane.y = buffer_bo_handle[0].ptr;
189 if (stream->num_planes == (unsigned int)num_buffer_fd)
190 frame->data.double_plane.uv = buffer_bo_handle[1].ptr;
192 frame->data.double_plane.uv = buffer_bo_handle[0].ptr + stream->data.yuv420sp.length_y;
193 frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
194 frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
195 total_size = stream->data.yuv420sp.length_y + \
196 stream->data.yuv420sp.length_uv;
200 frame->data.triple_plane.y = buffer_bo_handle[0].ptr;
201 if (stream->num_planes == (unsigned int)num_buffer_fd) {
202 frame->data.triple_plane.u = buffer_bo_handle[1].ptr;
203 frame->data.triple_plane.v = buffer_bo_handle[2].ptr;
205 frame->data.triple_plane.u = buffer_bo_handle[0].ptr + stream->data.yuv420p.length_y;
206 frame->data.triple_plane.v = frame->data.triple_plane.u + stream->data.yuv420p.length_u;
208 frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
209 frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
210 frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
211 total_size = stream->data.yuv420p.length_y + \
212 stream->data.yuv420p.length_u + \
213 stream->data.yuv420p.length_v;
221 CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
222 frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
227 int camera_attr_set_flash_brightness(camera_h camera, int level)
229 return __set_level(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_BRIGHTNESS, level);
233 int camera_attr_get_flash_brightness(camera_h camera, int *level)
235 int ret = CAMERA_ERROR_NONE;
236 camera_cli_s *pc = (camera_cli_s *)camera;
237 muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS;
239 if (!pc || !pc->cb_info || !level) {
240 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
241 return CAMERA_ERROR_INVALID_PARAMETER;
244 CAM_LOG_INFO("Enter");
246 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
248 if (ret == CAMERA_ERROR_NONE)
249 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_BRIGHTNESS];
251 CAM_LOG_INFO("ret : 0x%x", ret);
257 int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max)
259 int ret = CAMERA_ERROR_NONE;
260 camera_cli_s *pc = (camera_cli_s *)camera;
261 muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS_RANGE;
263 if (!pc || !pc->cb_info || !min || !max) {
264 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
265 return CAMERA_ERROR_INVALID_PARAMETER;
268 CAM_LOG_INFO("Enter");
270 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
272 if (ret == CAMERA_ERROR_NONE) {
273 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][0];
274 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][1];
277 CAM_LOG_INFO("ret : 0x%x", ret);
283 int camera_attr_set_focus_level(camera_h camera, int level)
285 return __set_level(camera, MUSE_CAMERA_API_ATTR_SET_FOCUS_LEVEL, level);
289 int camera_attr_get_focus_level(camera_h camera, int *level)
291 int ret = CAMERA_ERROR_NONE;
292 camera_cli_s *pc = (camera_cli_s *)camera;
293 muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL;
295 if (!pc || !pc->cb_info || !level) {
296 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
297 return CAMERA_ERROR_INVALID_PARAMETER;
300 CAM_LOG_INFO("Enter");
302 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
304 if (ret == CAMERA_ERROR_NONE)
305 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FOCUS_LEVEL];
307 CAM_LOG_INFO("ret : 0x%x", ret);
313 int camera_attr_get_focus_level_range(camera_h camera, int *min, int *max)
315 int ret = CAMERA_ERROR_NONE;
316 camera_cli_s *pc = (camera_cli_s *)camera;
317 muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL_RANGE;
319 if (!pc || !pc->cb_info || !min || !max) {
320 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
321 return CAMERA_ERROR_INVALID_PARAMETER;
324 CAM_LOG_INFO("Enter");
326 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
328 if (ret == CAMERA_ERROR_NONE) {
329 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][0];
330 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][1];
333 CAM_LOG_INFO("ret : 0x%x", ret);
339 int camera_set_extra_preview_device(camera_h camera, int stream_id, camera_device_e device)
341 int ret = CAMERA_ERROR_NONE;
343 camera_cli_s *pc = (camera_cli_s *)camera;
344 muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_DEVICE;
346 CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
348 CAM_LOG_INFO("Enter - stream[%d], device[%d]", stream_id, device);
350 msg = muse_core_msg_new(api,
351 MUSE_TYPE_INT, "stream_id", stream_id,
352 MUSE_TYPE_INT, "device", device,
355 _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
361 int camera_request_codec_config(camera_h camera)
363 int ret = CAMERA_ERROR_NONE;
364 camera_cli_s *pc = (camera_cli_s *)camera;
365 muse_camera_api_e api = MUSE_CAMERA_API_REQUEST_CODEC_CONFIG;
367 if (!pc || !pc->cb_info) {
368 CAM_LOG_ERROR("NULL pointer %p", pc);
369 return CAMERA_ERROR_INVALID_PARAMETER;
372 CAM_LOG_INFO("Enter");
374 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
376 CAM_LOG_INFO("ret : 0x%x", ret);
382 int camera_attr_get_preview_frame_timestamp(camera_h camera, unsigned long *timestamp)
384 camera_cli_s *pc = (camera_cli_s *)camera;
386 if (!pc || !pc->cb_info || !timestamp) {
387 CAM_LOG_ERROR("NULL pointer %p %p", pc, timestamp);
388 return CAMERA_ERROR_INVALID_PARAMETER;
391 if (!pc->cb_info->stream_data) {
392 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
393 return CAMERA_ERROR_INVALID_OPERATION;
396 *timestamp = pc->cb_info->stream_data->timestamp_nsec;
398 CAM_LOG_DEBUG("frame timestamp[%lu]", *timestamp);
400 return CAMERA_ERROR_NONE;
404 int camera_attr_get_preview_frame_meta_timestamp(camera_h camera, camera_meta_timestamp_s *meta_timestamp)
406 camera_cli_s *pc = (camera_cli_s *)camera;
407 MMCamcorderVideoStreamDataType *stream = NULL;
409 if (!pc || !pc->cb_info || !meta_timestamp) {
410 CAM_LOG_ERROR("NULL pointer %p %p", pc, meta_timestamp);
411 return CAMERA_ERROR_INVALID_PARAMETER;
414 stream = pc->cb_info->stream_data;
416 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
417 return CAMERA_ERROR_INVALID_OPERATION;
420 meta_timestamp->ts_soe = stream->frame_meta.ts_soe;
421 meta_timestamp->ts_eoe = stream->frame_meta.ts_eoe;
422 meta_timestamp->ts_sof = stream->frame_meta.ts_sof;
423 meta_timestamp->ts_eof = stream->frame_meta.ts_eof;
424 meta_timestamp->ts_hal = stream->frame_meta.ts_hal;
425 meta_timestamp->ts_qmf = stream->frame_meta.ts_qmf;
426 meta_timestamp->ts_gst = stream->frame_meta.ts_gst;
427 meta_timestamp->td_exp = stream->frame_meta.td_exp;
428 meta_timestamp->ts_aux = stream->frame_meta.ts_aux;
429 meta_timestamp->td_aux = stream->frame_meta.td_aux;
431 return CAMERA_ERROR_NONE;
435 int camera_attr_get_preview_frame_meta(camera_h camera, camera_frame_meta_s *frame_meta)
437 camera_cli_s *pc = (camera_cli_s *)camera;
438 MMCamcorderVideoStreamDataType *stream = NULL;
440 if (!pc || !pc->cb_info || !frame_meta) {
441 CAM_LOG_ERROR("NULL pointer %p %p", pc, frame_meta);
442 return CAMERA_ERROR_INVALID_PARAMETER;
445 stream = pc->cb_info->stream_data;
447 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
448 return CAMERA_ERROR_INVALID_OPERATION;
451 frame_meta->ts_soe = stream->frame_meta.ts_soe;
452 frame_meta->ts_eoe = stream->frame_meta.ts_eoe;
453 frame_meta->ts_sof = stream->frame_meta.ts_sof;
454 frame_meta->ts_eof = stream->frame_meta.ts_eof;
455 frame_meta->ts_hal = stream->frame_meta.ts_hal;
456 frame_meta->ts_qmf = stream->frame_meta.ts_qmf;
457 frame_meta->ts_gst = stream->frame_meta.ts_gst;
458 frame_meta->td_exp = stream->frame_meta.td_exp;
459 frame_meta->ts_aux = stream->frame_meta.ts_aux;
460 frame_meta->td_aux = stream->frame_meta.td_aux;
461 frame_meta->seqnum = stream->frame_meta.seqnum;
462 frame_meta->flags = stream->frame_meta.flags;
464 return CAMERA_ERROR_NONE;