Add new internal APIs for extra preview bitrate
[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                 switch (stream->format) {
94                 case MM_PIXEL_FORMAT_ENCODED_H264:
95                         /* fall through */
96                 case MM_PIXEL_FORMAT_ENCODED_MJPEG:
97                         /* fall through */
98                 case MM_PIXEL_FORMAT_ENCODED_VP8:
99                         /* fall through */
100                 case MM_PIXEL_FORMAT_ENCODED_VP9:
101                         frame->data.encoded_plane.data = buf_pos;
102                         frame->data.encoded_plane.size = stream->data.encoded.length_data;
103                         frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
104                         total_size = stream->data.encoded.length_data;
105                         break;
106
107                 case MM_PIXEL_FORMAT_INVZ:
108                         frame->data.depth_plane.data = buf_pos;
109                         frame->data.depth_plane.size = stream->data.depth.length_data;
110                         total_size = stream->data.depth.length_data;
111                         break;
112
113                 case MM_PIXEL_FORMAT_RGBA:
114                         /* fall through */
115                 case MM_PIXEL_FORMAT_ARGB:
116                         frame->data.rgb_plane.data = buf_pos;
117                         frame->data.rgb_plane.size = stream->data.rgb.length_data;
118                         total_size = stream->data.rgb.length_data;
119                         break;
120
121                 default:
122                         switch (stream->num_planes) {
123                         case 1:
124                                 frame->data.single_plane.yuv = buf_pos;
125                                 frame->data.single_plane.size = stream->data.yuv420.length_yuv;
126                                 total_size = stream->data.yuv420.length_yuv;
127                                 break;
128                         case 2:
129                                 frame->data.double_plane.y = buf_pos;
130                                 frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
131                                 buf_pos += stream->data.yuv420sp.length_y;
132                                 frame->data.double_plane.uv = buf_pos;
133                                 frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
134                                 total_size = stream->data.yuv420sp.length_y + \
135                                         stream->data.yuv420sp.length_uv;
136                                 break;
137                         case 3:
138                                 frame->data.triple_plane.y = buf_pos;
139                                 frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
140                                 buf_pos += stream->data.yuv420p.length_y;
141                                 frame->data.triple_plane.u = buf_pos;
142                                 frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
143                                 buf_pos += stream->data.yuv420p.length_u;
144                                 frame->data.triple_plane.v = buf_pos;
145                                 frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
146                                 total_size = stream->data.yuv420p.length_y + \
147                                         stream->data.yuv420p.length_u + \
148                                         stream->data.yuv420p.length_v;
149                                 break;
150                         default:
151                                 break;
152                         }
153                         break;
154                 }
155 //LCOV_EXCL_STOP
156         } else {
157                 /* zero copy */
158                 switch (stream->num_planes) {
159 //LCOV_EXCL_START
160                 case 1:
161                         frame->data.single_plane.yuv = buffer_bo_handle[0].ptr;
162                         frame->data.single_plane.size = stream->data.yuv420.length_yuv;
163                         total_size = stream->data.yuv420.length_yuv;
164                         break;
165 //LCOV_EXCL_STOP
166                 case 2:
167                         frame->data.double_plane.y = buffer_bo_handle[0].ptr;
168                         if (stream->num_planes == (unsigned int)num_buffer_fd)
169                                 frame->data.double_plane.uv = buffer_bo_handle[1].ptr;
170                         else
171                                 frame->data.double_plane.uv = buffer_bo_handle[0].ptr + stream->data.yuv420sp.length_y;
172                         frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
173                         frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
174                         total_size = stream->data.yuv420sp.length_y + \
175                                 stream->data.yuv420sp.length_uv;
176                         break;
177                 case 3:
178 //LCOV_EXCL_START
179                         frame->data.triple_plane.y = buffer_bo_handle[0].ptr;
180                         if (stream->num_planes == (unsigned int)num_buffer_fd) {
181                                 frame->data.triple_plane.u = buffer_bo_handle[1].ptr;
182                                 frame->data.triple_plane.v = buffer_bo_handle[2].ptr;
183                         } else {
184                                 frame->data.triple_plane.u = buffer_bo_handle[0].ptr + stream->data.yuv420p.length_y;
185                                 frame->data.triple_plane.v = buffer_bo_handle[1].ptr + stream->data.yuv420p.length_u;
186                         }
187                         frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
188                         frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
189                         frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
190                         total_size = stream->data.yuv420p.length_y + \
191                                 stream->data.yuv420p.length_u + \
192                                 stream->data.yuv420p.length_v;
193                         break;
194 //LCOV_EXCL_STOP
195                 default:
196                         break;
197                 }
198         }
199
200         CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
201                 frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
202 }
203
204 //LCOV_EXCL_START
205 int camera_create_network(camera_device_e device, camera_h *camera)
206 {
207         return _camera_create_private(device, true, camera);
208 }
209
210
211 int camera_device_manager_initialize(camera_device_manager_h *manager)
212 {
213         unsigned int i = 0;
214         int ret = CAMERA_ERROR_NONE;
215         void *dl_handle = NULL;
216         camera_device_manager *new_manager = g_new0(camera_device_manager, 1);
217         cdm_symbol_table sym_table[] = {
218                 {(void **)&new_manager->initialize, "cdm_initialize"},
219                 {(void **)&new_manager->deinitialize, "cdm_deinitialize"},
220                 {(void **)&new_manager->get_device_list, "cdm_get_device_list"},
221                 {(void **)&new_manager->add_device_connection_changed_cb, "cdm_add_device_connection_changed_cb"},
222                 {(void **)&new_manager->remove_device_connection_changed_cb, "cdm_remove_device_connection_changed_cb"},
223         };
224
225         if (!manager) {
226                 CAM_LOG_ERROR("NULL manager");
227                 ret = CAMERA_ERROR_INVALID_PARAMETER;
228                 goto _INITIALIZE_FAILED;
229         }
230
231         dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW);
232         if (!dl_handle) {
233                 CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror());
234                 ret = CAMERA_ERROR_NOT_SUPPORTED;
235                 goto _INITIALIZE_FAILED;
236         }
237
238         /* get symbols */
239         for (i = 0 ; i < G_N_ELEMENTS(sym_table) ; i++) {
240                 *sym_table[i].func_ptr = dlsym(dl_handle, sym_table[i].func_name);
241                 if (*sym_table[i].func_ptr == NULL) {
242                         CAM_LOG_ERROR("symbol failed[%s]", sym_table[i].func_name);
243                         ret = CAMERA_ERROR_INVALID_OPERATION;
244                         goto _INITIALIZE_FAILED;
245                 }
246         }
247
248         ret = new_manager->initialize();
249         if (ret != CAMERA_ERROR_NONE) {
250                 CAM_LOG_ERROR("failed[0x%x]", ret);
251                 goto _INITIALIZE_FAILED;
252         }
253
254         new_manager->dl_handle = dl_handle;
255         *manager = (camera_device_manager_h)new_manager;
256
257         CAM_LOG_INFO("camera device manager[%p]", new_manager);
258
259         return CAMERA_ERROR_NONE;
260
261 _INITIALIZE_FAILED:
262         if (dl_handle)
263                 dlclose(dl_handle);
264         g_free(new_manager);
265         return ret;
266 }
267
268
269 int camera_device_manager_deinitialize(camera_device_manager_h manager)
270 {
271         int ret = CAMERA_ERROR_NONE;
272         camera_device_manager *m = (camera_device_manager *)manager;
273
274         if (!m) {
275                 CAM_LOG_ERROR("NULL manager");
276                 return CAMERA_ERROR_INVALID_PARAMETER;
277         }
278
279         ret = m->deinitialize();
280         if (ret != CAMERA_ERROR_NONE) {
281                 CAM_LOG_ERROR("failed[0x%x]", ret);
282                 return ret;
283         }
284
285         dlclose(m->dl_handle);
286         memset(m, 0x0, sizeof(camera_device_manager));
287         g_free(m);
288
289         CAM_LOG_INFO("finalized");
290
291         return CAMERA_ERROR_NONE;
292 }
293
294
295 int camera_device_manager_get_device_list(camera_device_manager_h manager, camera_device_list_s *list)
296 {
297         int ret = CAMERA_ERROR_NONE;
298         unsigned int i = 0;
299         camera_device_manager *m = (camera_device_manager *)manager;
300
301         if (!m || !list) {
302                 CAM_LOG_ERROR("NULL parameter[%p,%p]", m, list);
303                 return CAMERA_ERROR_INVALID_PARAMETER;
304         }
305
306         CAM_LOG_INFO("enter");
307
308         ret = m->get_device_list(list);
309         if (ret != CAMERA_ERROR_NONE) {
310                 CAM_LOG_ERROR("failed[0x%x]", ret);
311                 return ret;
312         }
313
314         CAM_LOG_INFO("device count[%d]", list->count);
315
316         for (i = 0 ; i < list->count ; i++) {
317                 CAM_LOG_INFO("    [%d] : type[%d], device index[%d], name[%s], id[%s]",
318                         i, list->device[i].type, list->device[i].index,
319                         list->device[i].name, list->device[i].id);
320         }
321
322         return CAMERA_ERROR_NONE;
323 }
324
325
326 int camera_device_manager_add_device_connection_changed_cb(camera_device_manager_h manager,
327         camera_device_connection_changed_cb callback, void *user_data, int *cb_id)
328 {
329         int ret = CAMERA_ERROR_NONE;
330         camera_device_manager *m = (camera_device_manager *)manager;
331
332         if (!m || !callback || !cb_id) {
333                 CAM_LOG_ERROR("NULL parameter[%p,%p,%p]", m, callback, cb_id);
334                 return CAMERA_ERROR_INVALID_PARAMETER;
335         }
336
337         CAM_LOG_INFO("enter");
338
339         ret = m->add_device_connection_changed_cb(callback, user_data, cb_id);
340         if (ret != CAMERA_ERROR_NONE) {
341                 CAM_LOG_ERROR("failed[0x%x]", ret);
342                 return ret;
343         }
344
345         CAM_LOG_INFO("cb_id[%d] added", *cb_id);
346
347         return CAMERA_ERROR_NONE;
348 }
349
350
351 int camera_device_manager_remove_device_connection_changed_cb(camera_device_manager_h manager, int cb_id)
352 {
353         int ret = CAMERA_ERROR_NONE;
354         camera_device_manager *m = (camera_device_manager *)manager;
355
356         if (!m) {
357                 CAM_LOG_ERROR("NULL manager");
358                 return CAMERA_ERROR_INVALID_PARAMETER;
359         }
360
361         CAM_LOG_INFO("enter - cb_id[%d]", cb_id);
362
363         ret = m->remove_device_connection_changed_cb(cb_id);
364         if (ret != CAMERA_ERROR_NONE) {
365                 CAM_LOG_ERROR("failed[0x%x]", ret);
366                 return ret;
367         }
368
369         CAM_LOG_INFO("cb_id[%d] removed", cb_id);
370
371         return CAMERA_ERROR_NONE;
372 }
373
374
375 int camera_attr_set_flash_brightness(camera_h camera, int level)
376 {
377         int ret = CAMERA_ERROR_NONE;
378         camera_cli_s *pc = (camera_cli_s *)camera;
379         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_BRIGHTNESS;
380         camera_msg_param param;
381
382         if (!pc || !pc->cb_info) {
383                 CAM_LOG_ERROR("NULL handle");
384                 return CAMERA_ERROR_INVALID_PARAMETER;
385         }
386
387         CAM_LOG_INFO("Enter");
388
389         CAMERA_MSG_PARAM_SET(param, INT, level);
390
391         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
392
393         CAM_LOG_INFO("ret : 0x%x", ret);
394
395         return ret;
396 }
397
398
399 int camera_attr_get_flash_brightness(camera_h camera, int *level)
400 {
401         int ret = CAMERA_ERROR_NONE;
402         camera_cli_s *pc = (camera_cli_s *)camera;
403         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS;
404
405         if (!pc || !pc->cb_info || !level) {
406                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
407                 return CAMERA_ERROR_INVALID_PARAMETER;
408         }
409
410         CAM_LOG_INFO("Enter");
411
412         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
413
414         if (ret == CAMERA_ERROR_NONE)
415                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_BRIGHTNESS];
416
417         CAM_LOG_INFO("ret : 0x%x", ret);
418
419         return ret;
420 }
421
422
423 int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max)
424 {
425         int ret = CAMERA_ERROR_NONE;
426         camera_cli_s *pc = (camera_cli_s *)camera;
427         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS_RANGE;
428
429         if (!pc || !pc->cb_info || !min || !max) {
430                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
431                 return CAMERA_ERROR_INVALID_PARAMETER;
432         }
433
434         CAM_LOG_INFO("Enter");
435
436         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
437
438         if (ret == CAMERA_ERROR_NONE) {
439                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][0];
440                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][1];
441         }
442
443         CAM_LOG_INFO("ret : 0x%x", ret);
444
445         return ret;
446 }
447
448
449 int camera_attr_set_focus_level(camera_h camera, int level)
450 {
451         int ret = CAMERA_ERROR_NONE;
452         camera_cli_s *pc = (camera_cli_s *)camera;
453         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FOCUS_LEVEL;
454         camera_msg_param param;
455
456         if (!pc || !pc->cb_info) {
457                 CAM_LOG_ERROR("NULL handle");
458                 return CAMERA_ERROR_INVALID_PARAMETER;
459         }
460
461         CAM_LOG_INFO("Enter");
462
463         CAMERA_MSG_PARAM_SET(param, INT, level);
464
465         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
466
467         CAM_LOG_INFO("ret : 0x%x", ret);
468
469         return ret;
470 }
471
472
473 int camera_attr_get_focus_level(camera_h camera, int *level)
474 {
475         int ret = CAMERA_ERROR_NONE;
476         camera_cli_s *pc = (camera_cli_s *)camera;
477         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL;
478
479         if (!pc || !pc->cb_info || !level) {
480                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
481                 return CAMERA_ERROR_INVALID_PARAMETER;
482         }
483
484         CAM_LOG_INFO("Enter");
485
486         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
487
488         if (ret == CAMERA_ERROR_NONE)
489                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FOCUS_LEVEL];
490
491         CAM_LOG_INFO("ret : 0x%x", ret);
492
493         return ret;
494 }
495
496
497 int camera_attr_get_focus_level_range(camera_h camera, int *min, int *max)
498 {
499         int ret = CAMERA_ERROR_NONE;
500         camera_cli_s *pc = (camera_cli_s *)camera;
501         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL_RANGE;
502
503         if (!pc || !pc->cb_info || !min || !max) {
504                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
505                 return CAMERA_ERROR_INVALID_PARAMETER;
506         }
507
508         CAM_LOG_INFO("Enter");
509
510         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
511
512         if (ret == CAMERA_ERROR_NONE) {
513                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][0];
514                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][1];
515         }
516
517         CAM_LOG_INFO("ret : 0x%x", ret);
518
519         return ret;
520 }
521
522
523 int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callback, void *user_data)
524 {
525         int ret = CAMERA_ERROR_NONE;
526         camera_cli_s *pc = (camera_cli_s *)camera;
527         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_CB;
528
529         if (!pc || !pc->cb_info || !callback) {
530                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
531                 return CAMERA_ERROR_INVALID_PARAMETER;
532         }
533
534         CAM_LOG_INFO("Enter");
535
536         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
537
538         if (ret == CAMERA_ERROR_NONE) {
539                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
540
541                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = callback;
542                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = user_data;
543
544                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
545         }
546
547         CAM_LOG_INFO("ret : 0x%x", ret);
548
549         return ret;
550 }
551
552
553 int camera_unset_extra_preview_cb(camera_h camera)
554 {
555         int ret = CAMERA_ERROR_NONE;
556         camera_cli_s *pc = (camera_cli_s *)camera;
557         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_EXTRA_PREVIEW_CB;
558
559         if (!pc || !pc->cb_info) {
560                 CAM_LOG_ERROR("NULL handle");
561                 return CAMERA_ERROR_INVALID_PARAMETER;
562         }
563
564         CAM_LOG_INFO("Enter");
565
566         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
567
568         if (ret == CAMERA_ERROR_NONE) {
569                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
570
571                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
572                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
573
574                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
575         }
576
577         CAM_LOG_INFO("ret : 0x%x", ret);
578
579         return ret;
580 }
581
582
583 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)
584 {
585         int ret = CAMERA_ERROR_NONE;
586         int send_ret = 0;
587         int stream_format[4] = {pixel_format, width, height, fps};
588         char *msg = NULL;
589         camera_cli_s *pc = (camera_cli_s *)camera;
590         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_STREAM_FORMAT;
591
592         if (!pc || !pc->cb_info) {
593                 CAM_LOG_ERROR("NULL handle");
594                 return CAMERA_ERROR_INVALID_PARAMETER;
595         }
596
597         CAM_LOG_INFO("Enter - stream_id[%d],[%d,%dx%d,%d]",
598                 stream_id, pixel_format, width, height, fps);
599
600         msg = muse_core_msg_new(api,
601                 MUSE_TYPE_INT, "stream_id", stream_id,
602                 MUSE_TYPE_ARRAY, "stream_format", 4, stream_format,
603                 NULL);
604         if (!msg) {
605                 CAM_LOG_ERROR("msg creation failed: api %d", api);
606                 return CAMERA_ERROR_OUT_OF_MEMORY;
607         }
608
609         if (pc->cb_info->is_server_connected) {
610                 _camera_update_api_waiting(pc->cb_info, api, 1);
611
612                 g_mutex_lock(&pc->cb_info->fd_lock);
613                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
614                 g_mutex_unlock(&pc->cb_info->fd_lock);
615         }
616
617         if (send_ret < 0) {
618                 CAM_LOG_ERROR("message send failed");
619                 ret = CAMERA_ERROR_INVALID_OPERATION;
620         } else {
621                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
622         }
623
624         _camera_update_api_waiting(pc->cb_info, api, -1);
625
626         muse_core_msg_free(msg);
627
628         CAM_LOG_INFO("ret : 0x%x", ret);
629
630         return ret;
631 }
632
633
634 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)
635 {
636         int ret = CAMERA_ERROR_NONE;
637         camera_cli_s *pc = (camera_cli_s *)camera;
638         camera_msg_param param;
639         muse_camera_api_e api = MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT;
640
641         if (!pc || !pc->cb_info || !pixel_format || !width || !height || !fps) {
642                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, pixel_format, width, height, fps);
643                 return CAMERA_ERROR_INVALID_PARAMETER;
644         }
645
646         CAM_LOG_INFO("Enter - stream_id[%d]", stream_id);
647
648         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
649
650         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
651
652         if (ret == CAMERA_ERROR_NONE) {
653                 *pixel_format = (camera_pixel_format_e)pc->cb_info->get_extra_preview_stream_format[0];
654                 *width = pc->cb_info->get_extra_preview_stream_format[1];
655                 *height = pc->cb_info->get_extra_preview_stream_format[2];
656                 *fps = pc->cb_info->get_extra_preview_stream_format[3];
657         }
658
659         CAM_LOG_INFO("ret : 0x%x", ret);
660
661         return ret;
662 }
663
664
665 int camera_attr_set_extra_preview_bitrate(camera_h camera, int stream_id, int bitrate)
666 {
667         int ret = CAMERA_ERROR_NONE;
668         camera_cli_s *pc = (camera_cli_s *)camera;
669         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_BITRATE;
670         camera_msg_param param0;
671         camera_msg_param param1;
672
673         if (!pc || !pc->cb_info) {
674                 CAM_LOG_ERROR("NULL handle");
675                 return CAMERA_ERROR_INVALID_PARAMETER;
676         }
677
678         CAM_LOG_INFO("Enter - stream_id[%d], bitrate[%d]", stream_id, bitrate);
679
680         CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
681         CAMERA_MSG_PARAM_SET(param1, INT, bitrate);
682
683         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
684                 &param0, &param1, CAMERA_CB_TIMEOUT);
685
686         CAM_LOG_INFO("ret : 0x%x", ret);
687
688         return ret;
689 }
690
691
692 int camera_attr_get_extra_preview_bitrate(camera_h camera, int stream_id, int *bitrate)
693 {
694         int ret = CAMERA_ERROR_NONE;
695         camera_cli_s *pc = (camera_cli_s *)camera;
696         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_BITRATE;
697         camera_msg_param param;
698
699         if (!pc || !pc->cb_info || !bitrate) {
700                 CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
701                 return CAMERA_ERROR_INVALID_PARAMETER;
702         }
703
704         CAM_LOG_INFO("Enter - stream_id[%d]", stream_id);
705
706         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
707
708         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
709
710         if (ret == CAMERA_ERROR_NONE) {
711                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_BITRATE];
712                 CAM_LOG_INFO("get bitrate[%d] for stream[%d]", *bitrate, stream_id);
713         } else {
714                 CAM_LOG_ERROR("get bitrate failed for stream[%d] : 0x%x", stream_id, ret);
715         }
716
717         return ret;
718 }
719
720 //LCOV_EXCL_STOP