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.
21 #include <camera_internal.h>
22 #include <camera_private.h>
27 #define LOG_TAG "TIZEN_N_CAMERA"
31 int __set_level(camera_h camera, muse_camera_api_e api, int level)
33 int ret = CAMERA_ERROR_NONE;
34 camera_cli_s *pc = (camera_cli_s *)camera;
35 camera_msg_param param;
37 if (!pc || !pc->cb_info) {
38 CAM_LOG_ERROR("NULL handle - api[%d]", api);
39 return CAMERA_ERROR_INVALID_PARAMETER;
42 CAM_LOG_INFO("Enter - api[%d], level[%d]", api, level);
44 CAMERA_MSG_PARAM_SET(param, INT, level);
46 _camera_msg_send_param1(api, pc->cb_info, &ret, ¶m, CAMERA_CB_TIMEOUT);
48 CAM_LOG_INFO("ret : 0x%x", ret);
54 int camera_start_evas_rendering(camera_h camera)
56 return _camera_start_evas_rendering(camera);
60 int camera_stop_evas_rendering(camera_h camera, bool keep_screen)
62 return _camera_stop_evas_rendering(camera, keep_screen);
66 int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window)
68 return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window);
73 void camera_create_preview_frame(void *stream, int num_buffer_fd,
74 void *buffer_bo_handle, void *data_bo_handle, camera_preview_data_s *frame)
77 unsigned char *buf_pos = NULL;
78 MMCamcorderVideoStreamDataType *_stream = (MMCamcorderVideoStreamDataType *)stream;
79 tbm_bo_handle *_buffer_bo_handle = (tbm_bo_handle *)buffer_bo_handle;
80 tbm_bo_handle *_data_bo_handle = (tbm_bo_handle *)data_bo_handle;
82 if (!_stream || !_buffer_bo_handle || !frame) {
83 CAM_LOG_ERROR("invalid param %p,%p,%p", _stream, _buffer_bo_handle, frame);
88 if (_stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY)
89 frame->format = MM_PIXEL_FORMAT_UYVY;
91 frame->format = _stream->format;
93 frame->width = _stream->width;
94 frame->height = _stream->height;
95 frame->timestamp = _stream->timestamp;
96 frame->num_of_planes = _stream->num_planes;
98 if (num_buffer_fd == 0) {
101 if (!_data_bo_handle || !_data_bo_handle->ptr) {
102 CAM_LOG_ERROR("NULL pointer");
106 buf_pos = _data_bo_handle->ptr;
108 switch (_stream->format) {
109 case MM_PIXEL_FORMAT_ENCODED_H264:
111 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
113 case MM_PIXEL_FORMAT_ENCODED_VP8:
115 case MM_PIXEL_FORMAT_ENCODED_VP9:
116 frame->data.encoded_plane.data = buf_pos;
117 frame->data.encoded_plane.size = _stream->data.encoded.length_data;
118 frame->data.encoded_plane.is_delta_frame = (bool)_stream->data.encoded.is_delta_frame;
119 total_size = _stream->data.encoded.length_data;
122 case MM_PIXEL_FORMAT_INVZ:
123 frame->data.depth_plane.data = buf_pos;
124 frame->data.depth_plane.size = _stream->data.depth.length_data;
125 total_size = _stream->data.depth.length_data;
128 case MM_PIXEL_FORMAT_RGBA:
130 case MM_PIXEL_FORMAT_ARGB:
131 frame->data.rgb_plane.data = buf_pos;
132 frame->data.rgb_plane.size = _stream->data.rgb.length_data;
133 total_size = _stream->data.rgb.length_data;
137 switch (_stream->num_planes) {
139 frame->data.single_plane.yuv = buf_pos;
140 frame->data.single_plane.size = _stream->data.yuv420.length_yuv;
141 total_size = _stream->data.yuv420.length_yuv;
144 frame->data.double_plane.y = buf_pos;
145 frame->data.double_plane.y_size = _stream->data.yuv420sp.length_y;
146 buf_pos += _stream->data.yuv420sp.length_y;
147 frame->data.double_plane.uv = buf_pos;
148 frame->data.double_plane.uv_size = _stream->data.yuv420sp.length_uv;
149 total_size = _stream->data.yuv420sp.length_y + \
150 _stream->data.yuv420sp.length_uv;
153 frame->data.triple_plane.y = buf_pos;
154 frame->data.triple_plane.y_size = _stream->data.yuv420p.length_y;
155 buf_pos += _stream->data.yuv420p.length_y;
156 frame->data.triple_plane.u = buf_pos;
157 frame->data.triple_plane.u_size = _stream->data.yuv420p.length_u;
158 buf_pos += _stream->data.yuv420p.length_u;
159 frame->data.triple_plane.v = buf_pos;
160 frame->data.triple_plane.v_size = _stream->data.yuv420p.length_v;
161 total_size = _stream->data.yuv420p.length_y + \
162 _stream->data.yuv420p.length_u + \
163 _stream->data.yuv420p.length_v;
173 switch (_stream->num_planes) {
176 if (_stream->data_type == MM_CAM_STREAM_DATA_ENCODED) {
177 frame->data.encoded_plane.data = _buffer_bo_handle[0].ptr;
178 frame->data.encoded_plane.size = _stream->data.encoded.length_data;
179 frame->data.encoded_plane.is_delta_frame = (bool)_stream->data.encoded.is_delta_frame;
180 total_size = _stream->data.encoded.length_data;
182 frame->data.single_plane.yuv = _buffer_bo_handle[0].ptr;
183 frame->data.single_plane.size = _stream->data.yuv420.length_yuv;
184 total_size = _stream->data.yuv420.length_yuv;
189 frame->data.double_plane.y = _buffer_bo_handle[0].ptr;
190 if (_stream->num_planes == (unsigned int)num_buffer_fd)
191 frame->data.double_plane.uv = _buffer_bo_handle[1].ptr;
193 frame->data.double_plane.uv = _buffer_bo_handle[0].ptr + _stream->data.yuv420sp.length_y;
194 frame->data.double_plane.y_size = _stream->data.yuv420sp.length_y;
195 frame->data.double_plane.uv_size = _stream->data.yuv420sp.length_uv;
196 total_size = _stream->data.yuv420sp.length_y + \
197 _stream->data.yuv420sp.length_uv;
201 frame->data.triple_plane.y = _buffer_bo_handle[0].ptr;
202 if (_stream->num_planes == (unsigned int)num_buffer_fd) {
203 frame->data.triple_plane.u = _buffer_bo_handle[1].ptr;
204 frame->data.triple_plane.v = _buffer_bo_handle[2].ptr;
206 frame->data.triple_plane.u = _buffer_bo_handle[0].ptr + _stream->data.yuv420p.length_y;
207 frame->data.triple_plane.v = frame->data.triple_plane.u + _stream->data.yuv420p.length_u;
209 frame->data.triple_plane.y_size = _stream->data.yuv420p.length_y;
210 frame->data.triple_plane.u_size = _stream->data.yuv420p.length_u;
211 frame->data.triple_plane.v_size = _stream->data.yuv420p.length_v;
212 total_size = _stream->data.yuv420p.length_y + \
213 _stream->data.yuv420p.length_u + \
214 _stream->data.yuv420p.length_v;
222 CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
223 frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
228 int camera_attr_set_flash_brightness(camera_h camera, int level)
230 return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_BRIGHTNESS, level);
234 int camera_attr_get_flash_brightness(camera_h camera, int *level)
236 return _camera_attr_get_level(camera,
237 MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS,
238 MUSE_CAMERA_GET_INT_FLASH_BRIGHTNESS,
243 int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max)
245 return _camera_attr_get_range(camera,
246 MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS_RANGE,
247 MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE,
252 int camera_set_extra_preview_device(camera_h camera, int stream_id, camera_device_e device)
254 int ret = CAMERA_ERROR_NONE;
256 camera_cli_s *pc = (camera_cli_s *)camera;
257 muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_DEVICE;
259 CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
261 CAM_LOG_INFO("Enter - stream[%d], device[%d]", stream_id, device);
263 msg = muse_core_msg_new(api,
264 MUSE_TYPE_INT, "stream_id", stream_id,
265 MUSE_TYPE_INT, "device", device,
268 _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
274 int camera_request_codec_config(camera_h camera)
276 int ret = CAMERA_ERROR_NONE;
277 camera_cli_s *pc = (camera_cli_s *)camera;
278 muse_camera_api_e api = MUSE_CAMERA_API_REQUEST_CODEC_CONFIG;
280 if (!pc || !pc->cb_info) {
281 CAM_LOG_ERROR("NULL pointer %p", pc);
282 return CAMERA_ERROR_INVALID_PARAMETER;
285 CAM_LOG_INFO("Enter");
287 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
289 CAM_LOG_INFO("ret : 0x%x", ret);
295 int camera_attr_get_preview_frame_timestamp(camera_h camera, unsigned long long *timestamp)
297 camera_cli_s *pc = (camera_cli_s *)camera;
299 if (!pc || !pc->cb_info || !timestamp) {
300 CAM_LOG_ERROR("NULL pointer %p %p", pc, timestamp);
301 return CAMERA_ERROR_INVALID_PARAMETER;
304 if (!pc->cb_info->stream_data) {
305 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
306 return CAMERA_ERROR_INVALID_OPERATION;
309 *timestamp = pc->cb_info->stream_data->timestamp_nsec;
311 CAM_LOG_DEBUG("frame timestamp[%llu]", *timestamp);
313 return CAMERA_ERROR_NONE;
317 int camera_attr_get_preview_frame_meta(camera_h camera, camera_frame_meta_s *frame_meta)
319 camera_cli_s *pc = (camera_cli_s *)camera;
320 MMCamcorderVideoStreamDataType *stream = NULL;
322 if (!pc || !pc->cb_info || !frame_meta) {
323 CAM_LOG_ERROR("NULL pointer %p %p", pc, frame_meta);
324 return CAMERA_ERROR_INVALID_PARAMETER;
327 stream = pc->cb_info->stream_data;
329 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
330 return CAMERA_ERROR_INVALID_OPERATION;
333 frame_meta->ts_soe = stream->frame_meta.ts_soe;
334 frame_meta->ts_eoe = stream->frame_meta.ts_eoe;
335 frame_meta->ts_sof = stream->frame_meta.ts_sof;
336 frame_meta->ts_eof = stream->frame_meta.ts_eof;
337 frame_meta->ts_hal = stream->frame_meta.ts_hal;
338 frame_meta->ts_qmf = stream->frame_meta.ts_qmf;
339 frame_meta->ts_gst = stream->frame_meta.ts_gst;
340 frame_meta->td_exp = stream->frame_meta.td_exp;
341 frame_meta->ts_aux = stream->frame_meta.ts_aux;
342 frame_meta->td_aux = stream->frame_meta.td_aux;
343 frame_meta->seqnum = stream->frame_meta.seqnum;
344 frame_meta->flags = stream->frame_meta.flags;
346 return CAMERA_ERROR_NONE;
350 int camera_attr_get_preview_frame_status_auto_exposure(camera_h camera, camera_status_auto_exposure_e *status)
352 camera_cli_s *pc = (camera_cli_s *)camera;
353 MMCamcorderVideoStreamDataType *stream = NULL;
355 if (!pc || !pc->cb_info || !status) {
356 CAM_LOG_ERROR("NULL pointer %p %p", pc, status);
357 return CAMERA_ERROR_INVALID_PARAMETER;
360 stream = pc->cb_info->stream_data;
362 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
363 return CAMERA_ERROR_INVALID_OPERATION;
366 *status = stream->status_ae;
368 CAM_LOG_DEBUG("status: auto exposure[%d]", *status);
370 return CAMERA_ERROR_NONE;
374 int camera_attr_get_preview_frame_status_auto_white_balance(camera_h camera, camera_status_auto_white_balance_e *status)
376 camera_cli_s *pc = (camera_cli_s *)camera;
377 MMCamcorderVideoStreamDataType *stream = NULL;
379 if (!pc || !pc->cb_info || !status) {
380 CAM_LOG_ERROR("NULL pointer %p %p", pc, status);
381 return CAMERA_ERROR_INVALID_PARAMETER;
384 stream = pc->cb_info->stream_data;
386 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
387 return CAMERA_ERROR_INVALID_OPERATION;
390 *status = stream->status_awb;
392 CAM_LOG_DEBUG("status: auto white balance[%d]", *status);
394 return CAMERA_ERROR_NONE;