Add new internal APIs for extra preview stream format
[platform/core/api/camera.git] / src / camera_internal.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <mm.h>
22 #include <mm_types.h>
23 #include <camera_internal.h>
24 #include <camera_private.h>
25 #include <dlog.h>
26 #include <dlfcn.h>
27
28 #ifdef LOG_TAG
29 #undef LOG_TAG
30 #endif
31 #define LOG_TAG "TIZEN_N_CAMERA"
32
33 #define LIB_CAMERA_DEVICE_MANAGER PATH_LIBDIR"/libcamera_device_manager.so"
34
35 typedef struct _cdm_symbol_table {
36         void **func_ptr;
37         const char *func_name;
38 } cdm_symbol_table;
39
40
41 //LCOV_EXCL_START
42 int camera_start_evas_rendering(camera_h camera)
43 {
44         return _camera_start_evas_rendering(camera);
45 }
46
47
48 int camera_stop_evas_rendering(camera_h camera, bool keep_screen)
49 {
50         return _camera_stop_evas_rendering(camera, keep_screen);
51 }
52
53
54 int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window)
55 {
56         return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window);
57 }
58 //LCOV_EXCL_STOP
59
60
61 void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd,
62         tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame)
63 {
64         int total_size = 0;
65         unsigned char *buf_pos = NULL;
66
67         if (!stream || !buffer_bo_handle || !frame) {
68                 CAM_LOG_ERROR("invalid param %p,%p,%p", stream, buffer_bo_handle, frame);
69                 return;
70         }
71
72         /* set frame info */
73         if (stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY)
74                 frame->format = MM_PIXEL_FORMAT_UYVY;
75         else
76                 frame->format = stream->format;
77
78         frame->width = stream->width;
79         frame->height = stream->height;
80         frame->timestamp = stream->timestamp;
81         frame->num_of_planes = stream->num_planes;
82
83         if (num_buffer_fd == 0) {
84 //LCOV_EXCL_START
85                 /* non-zero copy */
86                 if (!data_bo_handle || !data_bo_handle->ptr) {
87                         CAM_LOG_ERROR("NULL pointer");
88                         return;
89                 }
90
91                 buf_pos = data_bo_handle->ptr;
92
93                 if (stream->format == MM_PIXEL_FORMAT_ENCODED_H264) {
94                         frame->data.encoded_plane.data = buf_pos;
95                         frame->data.encoded_plane.size = stream->data.encoded.length_data;
96                         frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
97                         total_size = stream->data.encoded.length_data;
98                 } else if (stream->format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
99                         frame->data.encoded_plane.data = buf_pos;
100                         frame->data.encoded_plane.size = stream->data.encoded.length_data;
101                         total_size = stream->data.encoded.length_data;
102                 } else if (stream->format == MM_PIXEL_FORMAT_INVZ) {
103                         frame->data.depth_plane.data = buf_pos;
104                         frame->data.depth_plane.size = stream->data.depth.length_data;
105                         total_size = stream->data.depth.length_data;
106                 } else if (stream->format == MM_PIXEL_FORMAT_RGBA ||
107                         stream->format == MM_PIXEL_FORMAT_ARGB) {
108                         frame->data.rgb_plane.data = buf_pos;
109                         frame->data.rgb_plane.size = stream->data.rgb.length_data;
110                         total_size = stream->data.rgb.length_data;
111                 } else {
112                         switch (stream->num_planes) {
113                         case 1:
114                                 frame->data.single_plane.yuv = buf_pos;
115                                 frame->data.single_plane.size = stream->data.yuv420.length_yuv;
116                                 total_size = stream->data.yuv420.length_yuv;
117                                 break;
118                         case 2:
119                                 frame->data.double_plane.y = buf_pos;
120                                 frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
121                                 buf_pos += stream->data.yuv420sp.length_y;
122                                 frame->data.double_plane.uv = buf_pos;
123                                 frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
124                                 total_size = stream->data.yuv420sp.length_y + \
125                                         stream->data.yuv420sp.length_uv;
126                                 break;
127                         case 3:
128                                 frame->data.triple_plane.y = buf_pos;
129                                 frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
130                                 buf_pos += stream->data.yuv420p.length_y;
131                                 frame->data.triple_plane.u = buf_pos;
132                                 frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
133                                 buf_pos += stream->data.yuv420p.length_u;
134                                 frame->data.triple_plane.v = buf_pos;
135                                 frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
136                                 total_size = stream->data.yuv420p.length_y + \
137                                         stream->data.yuv420p.length_u + \
138                                         stream->data.yuv420p.length_v;
139                                 break;
140                         default:
141                                 break;
142                         }
143                 }
144 //LCOV_EXCL_STOP
145         } else {
146                 /* zero copy */
147                 switch (stream->num_planes) {
148 //LCOV_EXCL_START
149                 case 1:
150                         frame->data.single_plane.yuv = buffer_bo_handle[0].ptr;
151                         frame->data.single_plane.size = stream->data.yuv420.length_yuv;
152                         total_size = stream->data.yuv420.length_yuv;
153                         break;
154 //LCOV_EXCL_STOP
155                 case 2:
156                         frame->data.double_plane.y = buffer_bo_handle[0].ptr;
157                         if (stream->num_planes == (unsigned int)num_buffer_fd)
158                                 frame->data.double_plane.uv = buffer_bo_handle[1].ptr;
159                         else
160                                 frame->data.double_plane.uv = buffer_bo_handle[0].ptr + stream->data.yuv420sp.length_y;
161                         frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
162                         frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
163                         total_size = stream->data.yuv420sp.length_y + \
164                                 stream->data.yuv420sp.length_uv;
165                         break;
166                 case 3:
167 //LCOV_EXCL_START
168                         frame->data.triple_plane.y = buffer_bo_handle[0].ptr;
169                         if (stream->num_planes == (unsigned int)num_buffer_fd) {
170                                 frame->data.triple_plane.u = buffer_bo_handle[1].ptr;
171                                 frame->data.triple_plane.v = buffer_bo_handle[2].ptr;
172                         } else {
173                                 frame->data.triple_plane.u = buffer_bo_handle[0].ptr + stream->data.yuv420p.length_y;
174                                 frame->data.triple_plane.v = buffer_bo_handle[1].ptr + stream->data.yuv420p.length_u;
175                         }
176                         frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
177                         frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
178                         frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
179                         total_size = stream->data.yuv420p.length_y + \
180                                 stream->data.yuv420p.length_u + \
181                                 stream->data.yuv420p.length_v;
182                         break;
183 //LCOV_EXCL_STOP
184                 default:
185                         break;
186                 }
187         }
188
189         CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
190                 frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
191 }
192
193 //LCOV_EXCL_START
194 int camera_create_network(camera_device_e device, camera_h *camera)
195 {
196         return _camera_create_private(device, true, camera);
197 }
198
199
200 int camera_device_manager_initialize(camera_device_manager_h *manager)
201 {
202         unsigned int i = 0;
203         int ret = CAMERA_ERROR_NONE;
204         void *dl_handle = NULL;
205         camera_device_manager *new_manager = g_new0(camera_device_manager, 1);
206         cdm_symbol_table sym_table[] = {
207                 {(void **)&new_manager->initialize, "cdm_initialize"},
208                 {(void **)&new_manager->deinitialize, "cdm_deinitialize"},
209                 {(void **)&new_manager->get_device_list, "cdm_get_device_list"},
210                 {(void **)&new_manager->add_device_list_changed_cb, "cdm_add_device_list_changed_cb"},
211                 {(void **)&new_manager->remove_device_list_changed_cb, "cdm_remove_device_list_changed_cb"},
212         };
213
214         if (!manager) {
215                 CAM_LOG_ERROR("NULL manager");
216                 ret = CAMERA_ERROR_INVALID_PARAMETER;
217                 goto _INITIALIZE_FAILED;
218         }
219
220         dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW);
221         if (!dl_handle) {
222                 CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror());
223                 ret = CAMERA_ERROR_NOT_SUPPORTED;
224                 goto _INITIALIZE_FAILED;
225         }
226
227         /* get symbols */
228         for (i = 0 ; i < G_N_ELEMENTS(sym_table) ; i++) {
229                 *sym_table[i].func_ptr = dlsym(dl_handle, sym_table[i].func_name);
230                 if (*sym_table[i].func_ptr == NULL) {
231                         CAM_LOG_ERROR("symbol failed[%s]", sym_table[i].func_name);
232                         ret = CAMERA_ERROR_INVALID_OPERATION;
233                         goto _INITIALIZE_FAILED;
234                 }
235         }
236
237         ret = new_manager->initialize();
238         if (ret != CAMERA_ERROR_NONE) {
239                 CAM_LOG_ERROR("failed[0x%x]", ret);
240                 goto _INITIALIZE_FAILED;
241         }
242
243         new_manager->dl_handle = dl_handle;
244         *manager = (camera_device_manager_h)new_manager;
245
246         CAM_LOG_INFO("camera device manager[%p]", new_manager);
247
248         return CAMERA_ERROR_NONE;
249
250 _INITIALIZE_FAILED:
251         if (dl_handle)
252                 dlclose(dl_handle);
253         g_free(new_manager);
254         return ret;
255 }
256
257
258 int camera_device_manager_deinitialize(camera_device_manager_h manager)
259 {
260         int ret = CAMERA_ERROR_NONE;
261         camera_device_manager *m = (camera_device_manager *)manager;
262
263         if (!m) {
264                 CAM_LOG_ERROR("NULL manager");
265                 return CAMERA_ERROR_INVALID_PARAMETER;
266         }
267
268         ret = m->deinitialize();
269         if (ret != CAMERA_ERROR_NONE) {
270                 CAM_LOG_ERROR("failed[0x%x]", ret);
271                 return ret;
272         }
273
274         dlclose(m->dl_handle);
275         memset(m, 0x0, sizeof(camera_device_manager));
276         g_free(m);
277
278         CAM_LOG_INFO("finalized");
279
280         return ret;
281 }
282
283
284 int camera_device_manager_get_device_list(camera_device_manager_h manager, camera_device_list_s *list)
285 {
286         int ret = CAMERA_ERROR_NONE;
287         unsigned int i = 0;
288         camera_device_manager *m = (camera_device_manager *)manager;
289
290         if (!m || !list) {
291                 CAM_LOG_ERROR("NULL parameter[%p,%p]", m, list);
292                 return CAMERA_ERROR_INVALID_PARAMETER;
293         }
294
295         CAM_LOG_INFO("enter");
296
297         ret = m->get_device_list(list);
298         if (ret != CAMERA_ERROR_NONE) {
299                 CAM_LOG_ERROR("failed[0x%x]", ret);
300                 return ret;
301         }
302
303         CAM_LOG_INFO("device count[%d]", list->count);
304
305         for (i = 0 ; i < list->count ; i++) {
306                 CAM_LOG_INFO("    [%d] : type[%d], device index[%d], name[%s], id[%s]",
307                         i, list->device[i].type, list->device[i].index,
308                         list->device[i].name, list->device[i].id);
309         }
310
311         return ret;
312 }
313
314
315 int camera_device_manager_add_device_list_changed_cb(camera_device_manager_h manager,
316         camera_device_list_changed_cb callback, void *user_data, int *cb_id)
317 {
318         int ret = CAMERA_ERROR_NONE;
319         camera_device_manager *m = (camera_device_manager *)manager;
320
321         if (!m || !callback || !cb_id) {
322                 CAM_LOG_ERROR("NULL parameter[%p,%p,%p]", m, callback, cb_id);
323                 return CAMERA_ERROR_INVALID_PARAMETER;
324         }
325
326         CAM_LOG_INFO("enter");
327
328         ret = m->add_device_list_changed_cb(callback, user_data, cb_id);
329         if (ret != CAMERA_ERROR_NONE) {
330                 CAM_LOG_ERROR("failed[0x%x]", ret);
331                 return ret;
332         }
333
334         CAM_LOG_INFO("cb_id[%d] added", *cb_id);
335
336         return ret;
337 }
338
339
340 int camera_device_manager_remove_device_list_changed_cb(camera_device_manager_h manager, int cb_id)
341 {
342         int ret = CAMERA_ERROR_NONE;
343         camera_device_manager *m = (camera_device_manager *)manager;
344
345         if (!m) {
346                 CAM_LOG_ERROR("NULL manager");
347                 return CAMERA_ERROR_INVALID_PARAMETER;
348         }
349
350         CAM_LOG_INFO("enter - cb_id[%d]", cb_id);
351
352         ret = m->remove_device_list_changed_cb(cb_id);
353         if (ret != CAMERA_ERROR_NONE) {
354                 CAM_LOG_ERROR("failed[0x%x]", ret);
355                 return ret;
356         }
357
358         CAM_LOG_INFO("cb_id[%d] removed", cb_id);
359
360         return ret;
361 }
362
363
364 int camera_attr_set_flash_brightness(camera_h camera, int level)
365 {
366         int ret = CAMERA_ERROR_NONE;
367         camera_cli_s *pc = (camera_cli_s *)camera;
368         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_BRIGHTNESS;
369         camera_msg_param param;
370
371         if (!pc || !pc->cb_info) {
372                 CAM_LOG_ERROR("NULL handle");
373                 return CAMERA_ERROR_INVALID_PARAMETER;
374         }
375
376         CAM_LOG_INFO("Enter");
377
378         CAMERA_MSG_PARAM_SET(param, INT, level);
379
380         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
381
382         CAM_LOG_INFO("ret : 0x%x", ret);
383
384         return ret;
385 }
386
387
388 int camera_attr_get_flash_brightness(camera_h camera, int *level)
389 {
390         int ret = CAMERA_ERROR_NONE;
391         camera_cli_s *pc = (camera_cli_s *)camera;
392         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS;
393
394         if (!pc || !pc->cb_info || !level) {
395                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
396                 return CAMERA_ERROR_INVALID_PARAMETER;
397         }
398
399         CAM_LOG_INFO("Enter");
400
401         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
402
403         if (ret == CAMERA_ERROR_NONE)
404                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_BRIGHTNESS];
405
406         CAM_LOG_INFO("ret : 0x%x", ret);
407
408         return ret;
409 }
410
411
412 int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max)
413 {
414         int ret = CAMERA_ERROR_NONE;
415         camera_cli_s *pc = (camera_cli_s *)camera;
416         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS_RANGE;
417
418         if (!pc || !pc->cb_info || !min || !max) {
419                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
420                 return CAMERA_ERROR_INVALID_PARAMETER;
421         }
422
423         CAM_LOG_INFO("Enter");
424
425         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
426
427         if (ret == CAMERA_ERROR_NONE) {
428                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][0];
429                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][1];
430         }
431
432         CAM_LOG_INFO("ret : 0x%x", ret);
433
434         return ret;
435 }
436
437
438 int camera_attr_set_focus_level(camera_h camera, int level)
439 {
440         int ret = CAMERA_ERROR_NONE;
441         camera_cli_s *pc = (camera_cli_s *)camera;
442         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FOCUS_LEVEL;
443         camera_msg_param param;
444
445         if (!pc || !pc->cb_info) {
446                 CAM_LOG_ERROR("NULL handle");
447                 return CAMERA_ERROR_INVALID_PARAMETER;
448         }
449
450         CAM_LOG_INFO("Enter");
451
452         CAMERA_MSG_PARAM_SET(param, INT, level);
453
454         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
455
456         CAM_LOG_INFO("ret : 0x%x", ret);
457
458         return ret;
459 }
460
461
462 int camera_attr_get_focus_level(camera_h camera, int *level)
463 {
464         int ret = CAMERA_ERROR_NONE;
465         camera_cli_s *pc = (camera_cli_s *)camera;
466         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL;
467
468         if (!pc || !pc->cb_info || !level) {
469                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
470                 return CAMERA_ERROR_INVALID_PARAMETER;
471         }
472
473         CAM_LOG_INFO("Enter");
474
475         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
476
477         if (ret == CAMERA_ERROR_NONE)
478                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FOCUS_LEVEL];
479
480         CAM_LOG_INFO("ret : 0x%x", ret);
481
482         return ret;
483 }
484
485
486 int camera_attr_get_focus_level_range(camera_h camera, int *min, int *max)
487 {
488         int ret = CAMERA_ERROR_NONE;
489         camera_cli_s *pc = (camera_cli_s *)camera;
490         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL_RANGE;
491
492         if (!pc || !pc->cb_info || !min || !max) {
493                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
494                 return CAMERA_ERROR_INVALID_PARAMETER;
495         }
496
497         CAM_LOG_INFO("Enter");
498
499         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
500
501         if (ret == CAMERA_ERROR_NONE) {
502                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][0];
503                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][1];
504         }
505
506         CAM_LOG_INFO("ret : 0x%x", ret);
507
508         return ret;
509 }
510
511
512 int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callback, void *user_data)
513 {
514         int ret = CAMERA_ERROR_NONE;
515         camera_cli_s *pc = (camera_cli_s *)camera;
516         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_CB;
517
518         if (!pc || !pc->cb_info || !callback) {
519                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
520                 return CAMERA_ERROR_INVALID_PARAMETER;
521         }
522
523         CAM_LOG_INFO("Enter");
524
525         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
526
527         if (ret == CAMERA_ERROR_NONE) {
528                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
529
530                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = callback;
531                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = user_data;
532
533                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
534         }
535
536         CAM_LOG_INFO("ret : 0x%x", ret);
537
538         return ret;
539 }
540
541
542 int camera_unset_extra_preview_cb(camera_h camera)
543 {
544         int ret = CAMERA_ERROR_NONE;
545         camera_cli_s *pc = (camera_cli_s *)camera;
546         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_EXTRA_PREVIEW_CB;
547
548         if (!pc || !pc->cb_info) {
549                 CAM_LOG_ERROR("NULL handle");
550                 return CAMERA_ERROR_INVALID_PARAMETER;
551         }
552
553         CAM_LOG_INFO("Enter");
554
555         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
556
557         if (ret == CAMERA_ERROR_NONE) {
558                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
559
560                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
561                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
562
563                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
564         }
565
566         CAM_LOG_INFO("ret : 0x%x", ret);
567
568         return ret;
569 }
570
571
572 int camera_set_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e pixel_format, int width, int height, int fps)
573 {
574         int ret = CAMERA_ERROR_NONE;
575         int send_ret = 0;
576         int stream_format[4] = {pixel_format, width, height, fps};
577         char *msg = NULL;
578         camera_cli_s *pc = (camera_cli_s *)camera;
579         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_STREAM_FORMAT;
580
581         if (!pc || !pc->cb_info) {
582                 CAM_LOG_ERROR("NULL handle");
583                 return CAMERA_ERROR_INVALID_PARAMETER;
584         }
585
586         CAM_LOG_INFO("Enter - stream_id[%d],[%d,%dx%d,%d]",
587                 stream_id, pixel_format, width, height, fps);
588
589         msg = muse_core_msg_new(api,
590                 MUSE_TYPE_INT, "stream_id", stream_id,
591                 MUSE_TYPE_ARRAY, "stream_format", 4, stream_format,
592                 NULL);
593         if (!msg) {
594                 CAM_LOG_ERROR("msg creation failed: api %d", api);
595                 return CAMERA_ERROR_OUT_OF_MEMORY;
596         }
597
598         if (pc->cb_info->is_server_connected) {
599                 _camera_update_api_waiting(pc->cb_info, api, 1);
600
601                 g_mutex_lock(&pc->cb_info->fd_lock);
602                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
603                 g_mutex_unlock(&pc->cb_info->fd_lock);
604         }
605
606         if (send_ret < 0) {
607                 CAM_LOG_ERROR("message send failed");
608                 ret = CAMERA_ERROR_INVALID_OPERATION;
609         } else {
610                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
611         }
612
613         _camera_update_api_waiting(pc->cb_info, api, -1);
614
615         muse_core_msg_free(msg);
616
617         CAM_LOG_INFO("ret : 0x%x", ret);
618
619         return ret;
620 }
621
622
623 int camera_get_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e *pixel_format, int *width, int *height, int *fps)
624 {
625         int ret = CAMERA_ERROR_NONE;
626         camera_cli_s *pc = (camera_cli_s *)camera;
627         camera_msg_param param;
628         muse_camera_api_e api = MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT;
629
630         if (!pc || !pc->cb_info || !pixel_format || !width || !height || !fps) {
631                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, pixel_format, width, height, fps);
632                 return CAMERA_ERROR_INVALID_PARAMETER;
633         }
634
635         CAM_LOG_INFO("Enter - stream_id[%d]", stream_id);
636
637         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
638
639         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
640
641         if (ret == CAMERA_ERROR_NONE) {
642                 *pixel_format = (camera_pixel_format_e)pc->cb_info->get_extra_preview_stream_format[0];
643                 *width = pc->cb_info->get_extra_preview_stream_format[1];
644                 *height = pc->cb_info->get_extra_preview_stream_format[2];
645                 *fps = pc->cb_info->get_extra_preview_stream_format[3];
646         }
647
648         CAM_LOG_INFO("ret : 0x%x", ret);
649
650         return ret;
651 }
652 //LCOV_EXCL_STOP