Add preview callback information for debug
[platform/core/api/camera.git] / src / camera.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 <unistd.h>
22 #include <mm.h>
23 #include <mm_types.h>
24 #include <mm_camcorder.h>
25 #include <muse_camera_msg.h>
26 #include <camera_private.h>
27 #include <muse_client.h>
28 #include <dlog.h>
29 #include <gio/gio.h>
30 #include <dlfcn.h>
31
32 #ifdef LOG_TAG
33 #undef LOG_TAG
34 #endif
35 #define LOG_TAG         "TIZEN_N_CAMERA"
36 #define MODULE_NAME     "camera"
37 #define LIB_CAMERA_DEVICE_MANAGER PATH_LIBDIR"/libcamera_device_manager.so"
38 #define CAMERA_CHECK_DEVICE_MANAGER \
39         do {\
40                 if (access(LIB_CAMERA_DEVICE_MANAGER, F_OK) != 0) {\
41                         CAM_LOG_ERROR("no camera device maanger[errno:%d]", errno);\
42                         return CAMERA_ERROR_NOT_SUPPORTED;\
43                 }\
44         } while (0)
45
46
47 /* for camera device manager */
48 typedef struct _cdm_symbol_table {
49         void **func_ptr;
50         const char *func_name;
51 } cdm_symbol_table;
52
53 /* for device changed callback */
54 static GMutex g_cam_dev_state_changed_cb_lock;
55 static GList *g_cam_dev_state_changed_cb_list;
56 static int g_cam_dev_state_changed_cb_id;
57 static GDBusConnection *g_cam_dev_state_changed_cb_conn;
58 static guint g_cam_dev_state_changed_cb_subscribe_id;
59 static GMutex g_cam_idle_event_lock;
60
61 /* log level */
62 static int g_camera_log_level = CAMERA_LOG_LEVEL_INFO;
63
64 static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle);
65 static void __camera_release_imported_bo(tbm_bo *bo);
66
67 static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
68         camera_media_packet_data *mp_data, media_packet_h *packet);
69 static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
70         tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data);
71 static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info);
72
73 static gboolean __camera_allocate_preview_buffer(camera_h camera);
74 static void __camera_release_preview_buffer(camera_h camera);
75 static void __camera_release_tfd(int tfd[MUSE_NUM_FD]);
76
77 static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
78         int type, const char *thread_name, camera_cb_info_s *cb_info);
79 static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info);
80
81
82 //LCOV_EXCL_START
83 static gboolean __camera_allocate_preview_buffer(camera_h camera)
84 {
85         int i = 0;
86         int ret = CAMERA_ERROR_NONE;
87         int format = CAMERA_PIXEL_FORMAT_INVALID;
88         int width = 0;
89         int height = 0;
90         int buffer_size = 0;
91         camera_cli_s *pc = (camera_cli_s *)camera;
92         camera_cb_info_s *cb_info = NULL;
93
94         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, FALSE);
95
96         cb_info = pc->cb_info;
97
98         CAM_LOG_INFO("Enter");
99
100         /* get preview info and calculate size */
101         ret = camera_get_preview_format(camera, &format);
102         if (ret != CAMERA_ERROR_NONE) {
103                 CAM_LOG_ERROR("get preview format failed 0x%x", ret);
104                 return FALSE;
105         }
106
107         ret = camera_get_preview_resolution(camera, &width, &height);
108         if (ret != CAMERA_ERROR_NONE) {
109                 CAM_LOG_ERROR("get preview resolution failed 0x%x", ret);
110                 return FALSE;
111         }
112
113         CAM_LOG_INFO("preview %dx%d, format %d", width, height, format);
114
115         switch (format) {
116         case CAMERA_PIXEL_FORMAT_INVZ:
117                 buffer_size = width * height;
118                 break;
119         case CAMERA_PIXEL_FORMAT_NV12:
120         case CAMERA_PIXEL_FORMAT_I420:
121                 buffer_size = (width * height * 3) >> 1;
122                 break;
123         case CAMERA_PIXEL_FORMAT_YUYV:
124         case CAMERA_PIXEL_FORMAT_UYVY:
125                 buffer_size = width * height * 2;
126                 break;
127         default:
128                 CAM_LOG_ERROR("unhandled format %d", format);
129                 goto _ALLOCATE_PREVIEW_BUFFER_FAILED;
130         }
131
132         CAM_LOG_INFO("buffer size %d, num %d", buffer_size, MUSE_NUM_FD);
133
134         for (i = 0 ; i < MUSE_NUM_FD ; i++) {
135                 cb_info->bos[i] = tbm_bo_alloc(cb_info->bufmgr, buffer_size, TBM_BO_DEFAULT);
136                 if (!cb_info->bos[i]) {
137                         CAM_LOG_ERROR("bo alloc failed [%d,i:%d]", buffer_size, i);
138                         goto _ALLOCATE_PREVIEW_BUFFER_FAILED;
139                 }
140
141                 cb_info->fds[i] = tbm_bo_export_fd(cb_info->bos[i]);
142                 if (cb_info->fds[i] < 0) {
143                         CAM_LOG_ERROR("export fd failed [%d,i:%d] errno %d", buffer_size, i, errno);
144                         goto _ALLOCATE_PREVIEW_BUFFER_FAILED;
145                 }
146
147                 CAM_LOG_INFO("bo %p, fd %d", cb_info->bos[i], cb_info->fds[i]);
148         }
149
150         CAM_LOG_INFO("Done");
151
152         return TRUE;
153
154 _ALLOCATE_PREVIEW_BUFFER_FAILED:
155         __camera_release_preview_buffer(camera);
156         return FALSE;
157 }
158
159
160 static void __camera_release_preview_buffer(camera_h camera)
161 {
162         int i = 0;
163         camera_cli_s *pc = (camera_cli_s *)camera;
164         camera_cb_info_s *cb_info = NULL;
165
166         CAMERA_CHECK_HANDLE_RETURN(pc);
167
168         CAM_LOG_INFO("Enter");
169
170         cb_info = pc->cb_info;
171
172         /* close exported fd and bos */
173         for (i = 0 ; i < MUSE_NUM_FD ; i++) {
174                 CAM_LOG_INFO("unref bo %p, close fd %d", cb_info->bos[i], cb_info->fds[i]);
175
176                 if (cb_info->bos[i]) {
177                         tbm_bo_unref(cb_info->bos[i]);
178                         cb_info->bos[i] = NULL;
179                 } else {
180                         break;
181                 }
182
183                 if (CAMERA_IS_FD_VALID(cb_info->fds[i])) {
184                         close(cb_info->fds[i]);
185                         cb_info->fds[i] = CAMERA_FD_INIT;
186                 }
187         }
188
189         CAM_LOG_INFO("Done");
190 }
191 //LCOV_EXCL_STOP
192
193 static void __camera_release_tfd(int tfd[MUSE_NUM_FD])
194 {
195         int i;
196
197         if (!tfd) {
198                 CAM_LOG_WARNING("NULL tfd");
199                 return;
200         }
201
202         for (i = 0 ; i < MUSE_NUM_FD ; i++) {
203                 if (!CAMERA_IS_FD_VALID(tfd[i]))
204                         break;
205
206                 close(tfd[i]);
207                 tfd[i] = CAMERA_FD_INIT;
208         }
209 }
210
211
212 void _camera_update_api_waiting(camera_cb_info_s *cb_info, int api, int value)
213 {
214         if (!cb_info ||
215                 api < 0 || api >= MUSE_CAMERA_API_MAX) {
216                 CAM_LOG_ERROR("invalid param %p %d", cb_info, api);
217                 return;
218         }
219
220         g_mutex_lock(&(cb_info->api_mutex[api]));
221         cb_info->api_waiting[api] += value;
222         g_mutex_unlock(&(cb_info->api_mutex[api]));
223
224         CAM_LOG_DEBUG("api[%d], value[%d], waiting[%d]",
225                 api, value, cb_info->api_waiting[api]);
226 }
227
228
229 static void __camera_device_state_changed_cb(GDBusConnection *connection,
230         const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
231         const gchar *signal_name, GVariant *param, gpointer user_data)
232 {
233         int value = 0;
234         camera_device_e device = CAMERA_DEVICE_CAMERA0;
235         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
236         GList *tmp_list = NULL;
237         camera_cb_info *info = NULL;
238
239         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
240
241         if (!g_cam_dev_state_changed_cb_list || !param) {
242                 CAM_LOG_WARNING("no callback or NULL param %p", param);
243                 goto _DONE;
244         }
245
246         /* get device and state */
247         g_variant_get(param, "(i)", &value);
248
249         device = value >> 16;
250         state = 0x0000ffff & value;
251
252         CAM_LOG_INFO("device %d, state %d", device, state);
253
254         tmp_list = g_cam_dev_state_changed_cb_list;
255
256         do {
257                 info = (camera_cb_info *)tmp_list->data;
258
259                 if (info) {
260                         if (info->callback) {
261                                 CAM_LOG_INFO("start id[%d] callback", info->id);
262                                 ((camera_device_state_changed_cb)info->callback)(device, state, info->user_data);
263                                 CAM_LOG_INFO("returned id[%d] callback", info->id);
264                         } else {
265                                 CAM_LOG_WARNING("NULL callback for id %d", info->id);
266                         }
267                 }
268
269                 tmp_list = tmp_list->next;
270         } while (tmp_list);
271
272 _DONE:
273         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
274 }
275
276
277 static void __camera_preview_cb_monitoring_info_sub_reset(monitoring_info_sub_s *info_sub)
278 {
279         if (!info_sub) {
280                 CAM_LOG_ERROR("NULL info_sub");
281                 return;
282         }
283
284         info_sub->frame_count = 0;
285         info_sub->elapsed_sec_accum = 0.0;
286         info_sub->elapsed_sec_peak = 0.0;
287 }
288
289
290 static void __camera_preview_cb_monitoring_info_reset(camera_preview_cb_monitoring_info_s *info)
291 {
292         if (!info) {
293                 CAM_LOG_ERROR("NULL info");
294                 return;
295         }
296
297         __camera_preview_cb_monitoring_info_sub_reset(info->total);
298         __camera_preview_cb_monitoring_info_sub_reset(info->interval);
299 }
300
301
302 static void __camera_preview_cb_monitoring_info_start(camera_preview_cb_monitoring_info_s *info)
303 {
304         if (!info) {
305                 CAM_LOG_ERROR("NULL info");
306                 return;
307         }
308
309         g_timer_start(info->timer_calling);
310
311         if (info->interval->frame_count == 0)
312                 g_timer_start(info->timer_interval);
313 }
314
315
316 static void __camera_preview_cb_monitoring_info_sub_update(monitoring_info_sub_s *info_sub, gdouble elapsed_sec)
317 {
318         if (!info_sub) {
319                 CAM_LOG_ERROR("NULL info_sub");
320                 return;
321         }
322
323         info_sub->frame_count++;
324         info_sub->elapsed_sec_accum += elapsed_sec;
325
326         if (info_sub->elapsed_sec_peak < elapsed_sec)
327                 info_sub->elapsed_sec_peak = elapsed_sec;
328 }
329
330
331 static void __camera_preview_cb_monitoring_info_end(camera_preview_cb_monitoring_info_s *info)
332 {
333         gdouble elapsed_sec = 0.0;
334         gdouble elapsed_sec_interval = 0.0;
335
336         if (!info) {
337                 CAM_LOG_ERROR("NULL info");
338                 return;
339         }
340
341         elapsed_sec = g_timer_elapsed(info->timer_calling, NULL);
342         elapsed_sec_interval = g_timer_elapsed(info->timer_interval, NULL);
343
344         __camera_preview_cb_monitoring_info_sub_update(info->total, elapsed_sec);
345         __camera_preview_cb_monitoring_info_sub_update(info->interval, elapsed_sec);
346
347         if (elapsed_sec_interval >= 1.0) {
348                 CAM_LOG_INFO("id[%d], frame count[t:%llu,i:%llu], elapsed - avg[t:%dms,i:%dms], peak[t:%dms,i:%dms]",
349                         info->stream_id, info->total->frame_count, info->interval->frame_count,
350                         (int)((info->total->elapsed_sec_accum / (gdouble)info->total->frame_count) * 1000),
351                         (int)((info->interval->elapsed_sec_accum / (gdouble)info->interval->frame_count) * 1000),
352                         (int)(info->total->elapsed_sec_peak * 1000), (int)(info->interval->elapsed_sec_peak * 1000));
353
354                 __camera_preview_cb_monitoring_info_sub_reset(info->interval);
355         }
356 }
357
358
359 static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
360 {
361         int i = 0;
362         int ret = 0;
363         int ret_fd = CAMERA_FD_INIT;
364         int preview_fd = CAMERA_FD_INIT;
365         int num_buffer_fd = 0;
366         unsigned char *buf_pos = NULL;
367
368         tbm_bo bo = NULL;
369         tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM] = {NULL, };
370         tbm_bo_handle bo_handle = {.ptr = NULL};
371         tbm_bo_handle buffer_bo_handle[BUFFER_MAX_PLANE_NUM] = {{.ptr = NULL}, };
372         tbm_bo data_bo = NULL;
373         tbm_bo_handle data_bo_handle = {.ptr = NULL};
374
375         camera_msg_param param;
376         camera_preview_data_s frame;
377         MMCamcorderVideoStreamDataType *stream = NULL;
378         camera_media_packet_data *mp_data = NULL;
379         media_packet_h pkt = NULL;
380         camera_preview_cb_monitoring_info_s *monitoring_info = NULL;
381
382         /* tfd[0]: MMCamcorderVideoStreamDataType
383            tfd[1]: data_bo or zero copy bo[0]
384            tfd[2]: zero copy bo[1]
385            tfd[3]: zero copy bo[2] */
386
387         if (!cb_info || !recv_msg || !tfd) {
388                 CAM_LOG_ERROR("invalid param %p %p %p", cb_info, recv_msg, tfd);
389                 return;
390         }
391
392         muse_camera_msg_get(preview_fd, recv_msg);
393         muse_camera_msg_get(num_buffer_fd, recv_msg);
394
395         CAM_LOG_DEBUG("preview_fd %d, num_buffer_fd %d", preview_fd, num_buffer_fd);
396
397         memset(&frame, 0x0, sizeof(camera_preview_data_s));
398
399         if (tfd[0] < 0) {
400                 CAM_LOG_ERROR("invalid fd %d", tfd[0]);
401                 return;
402         }
403
404         ret_fd = preview_fd;
405         CAMERA_MSG_PARAM_SET(param, INT, ret_fd);
406
407         if (cb_info->invoke_preview_cb == FALSE) {
408                 CAM_LOG_WARNING("Skip preview callback for fd[%d] due to preview stop.", ret_fd);
409                 goto _PREVIEW_CB_HANDLER_DONE;
410         }
411
412         if (num_buffer_fd < 0 || num_buffer_fd > BUFFER_MAX_PLANE_NUM) {
413                 CAM_LOG_ERROR("invalid num buffer fd %d", num_buffer_fd);
414                 goto _PREVIEW_CB_HANDLER_DONE;
415         }
416
417         /* import tbm bo and get virtual address */
418         if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
419                 CAM_LOG_ERROR("failed to import fd %d", tfd[0]);
420                 goto _PREVIEW_CB_HANDLER_DONE;
421         }
422
423         buf_pos = (unsigned char *)bo_handle.ptr;
424
425         /* get stream info */
426         stream = (MMCamcorderVideoStreamDataType *)buf_pos;
427
428         if (num_buffer_fd == 0 && CAMERA_IS_FD_VALID(tfd[1])) {
429                 /* import tbm data_bo and get virtual address */
430                 if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
431                         CAM_LOG_ERROR("failed to import data fd %d", tfd[1]);
432                         goto _PREVIEW_CB_HANDLER_DONE;
433                 }
434
435                 if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
436                         stream->data.encoded.data = data_bo_handle.ptr;
437         } else {
438                 for (i = 0 ; i < num_buffer_fd ; i++) {
439                         /* import buffer bo and get virtual address */
440                         if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[i + 1], &buffer_bo[i], &buffer_bo_handle[i])) {
441                                 CAM_LOG_ERROR("failed to import buffer fd %d", tfd[i + 1]);
442                                 goto _PREVIEW_CB_HANDLER_DONE;
443                         }
444                 }
445
446                 if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
447                         stream->data.encoded.data = buffer_bo_handle[0].ptr;
448         }
449
450         /* preview callback */
451         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] ||
452                 cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]) {
453                 camera_create_preview_frame(stream, num_buffer_fd, buffer_bo_handle, &data_bo_handle, &frame);
454
455                 /* set stream data for camera_get_preview_frame_rotation() */
456                 cb_info->stream_data = stream;
457
458                 if (stream->extra_stream_id < 0) {
459                         monitoring_info = cb_info->monitoring_info_preview;
460                         __camera_preview_cb_monitoring_info_start(monitoring_info);
461
462                         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])
463                                 ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
464                                         cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
465                 } else {
466                         monitoring_info = cb_info->monitoring_info_preview_ex[stream->extra_stream_id];
467                         __camera_preview_cb_monitoring_info_start(monitoring_info);
468
469                         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])
470                                 ((camera_extra_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])(&frame,
471                                         stream->extra_stream_id, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
472                 }
473
474                 __camera_preview_cb_monitoring_info_end(monitoring_info);
475
476                 cb_info->stream_data = NULL;
477         }
478
479         if (stream->extra_stream_id >= 0)
480                 goto _PREVIEW_CB_HANDLER_DONE;
481
482         /* make media packet with below cases.
483          * 1. media_packet_preview_cb is set
484          * 2. EVAS display rendering
485          * 3. media bridge is set
486          */
487         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] ||
488                 cb_info->is_evas_render ||
489                 cb_info->bridge) {
490                 ret = __camera_create_media_packet_data(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
491                 if (ret != CAMERA_ERROR_NONE) {
492                         CAM_LOG_ERROR("__camera_create_media_packet_data failed[0x%x]", ret);
493                         goto _PREVIEW_CB_HANDLER_DONE;
494                 }
495
496                 ret = __camera_create_media_packet(cb_info, stream, mp_data, &pkt);
497                 if (ret != CAMERA_ERROR_NONE) {
498                         CAM_LOG_ERROR("__camera_create_media_packet failed[0x%x]", ret);
499                         __camera_release_media_packet_data(mp_data, cb_info);
500                         mp_data = NULL;
501                         goto _PREVIEW_CB_HANDLER_DONE;
502                 }
503         }
504
505         /* 1. media packet preview callback */
506         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]) {
507                 media_packet_ref(pkt);
508
509                 monitoring_info = cb_info->monitoring_info_preview_mp;
510                 __camera_preview_cb_monitoring_info_start(monitoring_info);
511
512                 ((camera_media_packet_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW])(pkt,
513                         cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
514
515                 __camera_preview_cb_monitoring_info_end(monitoring_info);
516         }
517
518         /* 2. call evas renderer */
519         if (cb_info->is_evas_render) {
520                 if (cb_info->run_evas_render) {
521                         media_packet_ref(pkt);
522                         ret = mm_display_interface_evas_render(cb_info->dp_interface, pkt);
523                         if (ret != MM_ERROR_NONE) {
524                                 CAM_LOG_ERROR("mm_display_interface_evas_render failed[0x%x]", ret);
525                                 media_packet_unref(pkt);
526                         }
527                 } else {
528                         CAM_LOG_WARNING("evas renderer is stopped, skip this buffer...");
529                 }
530         }
531
532 //LCOV_EXCL_START
533         /* 3. media bridge */
534         g_mutex_lock(&cb_info->bridge_lock);
535
536         if (cb_info->bridge) {
537                 media_packet_ref(pkt);
538                 ret = media_bridge_push_packet(cb_info->bridge, pkt);
539                 if (ret != MEDIA_BRIDGE_ERROR_NONE) {
540                         CAM_LOG_ERROR("push packet to bridge failed[0x%x]", ret);
541                         media_packet_unref(pkt);
542                 }
543         }
544 //LCOV_EXCL_STOP
545
546         g_mutex_unlock(&cb_info->bridge_lock);
547
548 _PREVIEW_CB_HANDLER_DONE:
549         /* send PREVIEW_CB_RETURN message if zero copy buffer is used(num_buffer_fd is bigger than 0)
550            and preview callback(normal or media packet) is set. */
551         if (num_buffer_fd > 0 &&
552                 (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] ||
553                  cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]))
554                 _camera_msg_send(MUSE_CAMERA_API_PREVIEW_CB_RETURN, NULL, cb_info, NULL, 0);
555
556         if (pkt) {
557                 media_packet_unref(pkt);
558                 return;
559         }
560
561         /* return buffer */
562         _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
563
564         CAM_LOG_DEBUG("return buffer Done[tfd:%d, ret fd:%d]", tfd[0], ret_fd);
565
566         /* release imported bo and fd */
567         __camera_release_imported_bo(&data_bo);
568         __camera_release_imported_bo(&bo);
569
570         for (i = 0 ; i < num_buffer_fd && i < BUFFER_MAX_PLANE_NUM ; i++)
571                 __camera_release_imported_bo(&buffer_bo[i]);
572
573         __camera_release_tfd(tfd);
574 }
575
576
577 static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
578 {
579         int tfd_index = 0;
580         int capture_fd_main = 0;
581         int capture_fd_post = 0;
582         int capture_fd_thumb = 0;
583         unsigned char *buf_pos = NULL;
584
585         camera_image_data_s *rImage = NULL;
586         camera_image_data_s *rPostview = NULL;
587         camera_image_data_s *rThumbnail = NULL;
588
589         tbm_bo bo_main = NULL;
590         tbm_bo bo_post = NULL;
591         tbm_bo bo_thumb = NULL;
592         tbm_bo_handle bo_main_handle = {.ptr = NULL};
593         tbm_bo_handle bo_post_handle = {.ptr = NULL};
594         tbm_bo_handle bo_thumb_handle = {.ptr = NULL};
595
596         if (!cb_info || !recv_msg || !tfd) {
597                 CAM_LOG_ERROR("invalid param %p %p %p", cb_info, recv_msg, tfd);
598                 return;
599         }
600
601         muse_camera_msg_get(capture_fd_main, recv_msg);
602         muse_camera_msg_get(capture_fd_post, recv_msg);
603         muse_camera_msg_get(capture_fd_thumb, recv_msg);
604
605         CAM_LOG_INFO("capture fd %d %d %d, received fd %d %d %d",
606                 capture_fd_main, capture_fd_post, capture_fd_thumb,
607                 tfd[0], tfd[1], tfd[2]);
608
609         if (capture_fd_main < 0 || tfd[tfd_index] < 0) {
610                 CAM_LOG_ERROR("invalid main fd %d %d", capture_fd_main, tfd[tfd_index]);
611                 goto _CAPTURE_CB_HANDLER_DONE;
612         }
613
614         if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] == NULL) {
615                 CAM_LOG_WARNING("NULL callback");
616                 goto _CAPTURE_CB_HANDLER_DONE;
617         }
618
619         /* import tbm bo and get virtual address */
620         if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_main, &bo_main_handle)) {
621                 CAM_LOG_ERROR("failed to import fd [%d] for main", tfd[tfd_index]);
622                 goto _CAPTURE_CB_HANDLER_DONE;
623         }
624
625         buf_pos = (unsigned char *)bo_main_handle.ptr;
626         rImage = (camera_image_data_s *)buf_pos;
627         rImage->data = buf_pos + sizeof(camera_image_data_s);
628         if (rImage->exif && rImage->exif_size > 0) {
629                 rImage->exif = rImage->data + rImage->size;
630         } else {
631                 rImage->exif = NULL;
632                 rImage->exif_size = 0;
633         }
634
635         CAM_LOG_INFO("image info %dx%d, size %d, EXIF info %p, size %d",
636                 rImage->width, rImage->height, rImage->size, rImage->exif, rImage->exif_size);
637
638 //LCOV_EXCL_START
639         if (CAMERA_IS_FD_VALID(capture_fd_post)) {
640                 /* import tbm bo and get virtual address */
641                 tfd_index++;
642                 if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_post, &bo_post_handle)) {
643                         buf_pos = (unsigned char *)bo_post_handle.ptr;
644                         rPostview = (camera_image_data_s *)buf_pos;
645                         CAM_LOG_INFO("rPostview->size : %d", rPostview->size);
646                         rPostview->data = buf_pos + sizeof(camera_image_data_s);
647                 } else {
648                         CAM_LOG_ERROR("failed to import fd [i:%d][%d] for postview", tfd_index, tfd[tfd_index]);
649                 }
650         }
651
652         if (CAMERA_IS_FD_VALID(capture_fd_thumb)) {
653                 /* import tbm bo and get virtual address */
654                 tfd_index++;
655                 if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_thumb, &bo_thumb_handle)) {
656                         buf_pos = (unsigned char *)bo_thumb_handle.ptr;
657                         rThumbnail = (camera_image_data_s *)buf_pos;
658                         CAM_LOG_INFO("rThumbnail->size : %d", rThumbnail->size);
659                         rThumbnail->data = buf_pos + sizeof(camera_image_data_s);
660                 } else {
661                         CAM_LOG_ERROR("failed to import fd [%d] for thumbnail", tfd[tfd_index]);
662                 }
663         }
664 //LCOV_EXCL_STOP
665
666         ((camera_capturing_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE])(rImage,
667                 rPostview, rThumbnail, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE]);
668
669 _CAPTURE_CB_HANDLER_DONE:
670         /* return buffer */
671         if (CAMERA_IS_FD_VALID(capture_fd_main)) {
672                 __camera_release_imported_bo(&bo_main);
673                 _camera_msg_return_buffer(capture_fd_main, cb_info);
674         }
675
676         if (CAMERA_IS_FD_VALID(capture_fd_post)) {
677                 __camera_release_imported_bo(&bo_post);
678                 _camera_msg_return_buffer(capture_fd_post, cb_info);
679         }
680
681         if (CAMERA_IS_FD_VALID(capture_fd_thumb)) {
682                 __camera_release_imported_bo(&bo_thumb);
683                 _camera_msg_return_buffer(capture_fd_thumb, cb_info);
684         }
685
686         __camera_release_tfd(tfd);
687
688         CAM_LOG_INFO("return buffer done");
689 }
690
691
692 //LCOV_EXCL_START
693 static void __camera_event_handler_face_detection(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
694 {
695         int count = 0;
696         int face_fd = CAMERA_FD_INIT;
697         camera_detected_face_s *faces = NULL;
698
699         tbm_bo bo = NULL;
700         tbm_bo_handle bo_handle = {.ptr = NULL};
701
702         if (!cb_info || !recv_msg || !tfd) {
703                 CAM_LOG_ERROR("invalid param %p %p %p", cb_info, recv_msg, tfd);
704                 return;
705         }
706
707         muse_camera_msg_get(count, recv_msg);
708         muse_camera_msg_get(face_fd, recv_msg);
709
710         if (count >= 0 && cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]) {
711                 CAM_LOG_INFO("FACE_DETECTION - count %d, fd %d", count, tfd[0]);
712
713                 if (CAMERA_IS_FD_VALID(tfd[0])) {
714                         if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
715                                 /* set face info */
716                                 faces = bo_handle.ptr;
717                         }
718
719                         close(tfd[0]);
720                         tfd[0] = CAMERA_FD_INIT;
721                 }
722
723                 ((camera_face_detected_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION])(faces,
724                         count, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
725
726                 /* release bo */
727                 __camera_release_imported_bo(&bo);
728         } else {
729                 CAM_LOG_WARNING("skip face detection message [count %d, fd %d, cb %p]",
730                         count, tfd[0], cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
731         }
732
733         /* return buffer */
734         _camera_msg_return_buffer(face_fd, cb_info);
735 }
736 //LCOV_EXCL_STOP
737
738
739 static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
740 {
741         tbm_bo tmp_bo = NULL;
742         tbm_bo_handle tmp_bo_handle = {NULL, };
743
744         if (!bufmgr || !bo || !bo_handle || fd < 0) {
745                 CAM_LOG_ERROR("invalid parameter - %p %p %p, fd %d",
746                      bufmgr, bo, bo_handle, fd);
747                 return false;
748         }
749
750         tmp_bo = tbm_bo_import_fd(bufmgr, (tbm_fd)fd);
751         if (tmp_bo == NULL) {
752                 CAM_LOG_ERROR("import failed - fd %d", fd);
753                 return false;
754         }
755
756         tmp_bo_handle = tbm_bo_get_handle(tmp_bo, TBM_DEVICE_CPU);
757         if (tmp_bo_handle.ptr == NULL) {
758                 CAM_LOG_ERROR("tbm_bo_get_handle() failed %p", tmp_bo);
759                 tbm_bo_unref(tmp_bo);
760                 tmp_bo = NULL;
761                 return false;
762         }
763
764         /* set bo and bo_handle */
765         *bo = tmp_bo;
766         *bo_handle = tmp_bo_handle;
767
768         CAM_LOG_VERBOSE("fd[%d] -> bo[%p]", fd, tmp_bo);
769
770         return true;
771 }
772
773 static void __camera_release_imported_bo(tbm_bo *bo)
774 {
775         if (!bo || !(*bo)) {
776                 CAM_LOG_DEBUG("NULL bo");
777                 return;
778         }
779
780         tbm_bo_unref(*bo);
781         *bo = NULL;
782 }
783
784
785 static bool __is_supported(camera_h camera, muse_camera_api_e api)
786 {
787         int ret = CAMERA_ERROR_NONE;
788         camera_cli_s *pc = (camera_cli_s *)camera;
789
790         if (!pc || !pc->cb_info) {
791                 CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
792                 set_last_result(CAMERA_ERROR_INVALID_PARAMETER);
793                 return false;
794         }
795
796         CAM_LOG_INFO("Enter - api[%d]", api);
797
798         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
799
800         CAM_LOG_INFO("Leave - api[%d], ret[%d]", api, ret);
801
802         return !!ret;
803 }
804
805
806 static int __set_mode(camera_h camera, muse_camera_api_e api, int set_mode)
807 {
808         int ret = CAMERA_ERROR_NONE;
809         camera_cli_s *pc = (camera_cli_s *)camera;
810         camera_msg_param param;
811
812         if (!pc || !pc->cb_info) {
813                 CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
814                 return CAMERA_ERROR_INVALID_PARAMETER;
815         }
816
817         CAM_LOG_INFO("Enter - api[%d], mode[%d]", api, set_mode);
818
819         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
820
821         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
822
823         CAM_LOG_INFO("Leave - api[%d], ret[0x%x]", api, ret);
824
825         return ret;
826 }
827
828
829 static int __set_enable(camera_h camera, muse_camera_api_e api, int set_enable)
830 {
831         int ret = CAMERA_ERROR_NONE;
832         camera_cli_s *pc = (camera_cli_s *)camera;
833         camera_msg_param param;
834
835         if (!pc || !pc->cb_info) {
836                 CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
837                 return CAMERA_ERROR_INVALID_PARAMETER;
838         }
839
840         CAM_LOG_INFO("Enter - api[%d], enable[%d]", api, set_enable);
841
842         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
843
844         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
845
846         CAM_LOG_INFO("Leave - api[%d], ret[0x%x]", api, ret);
847
848         return ret;
849 }
850
851
852 void _camera_send_message_get_return(camera_cb_info_s *cb_info, muse_camera_api_e api, char *msg, int time_out, int *ret)
853 {
854         int send_ret = 0;
855
856         if (!msg) {
857                 CAM_LOG_ERROR("api[%d] message failed", api);
858                 if (ret)
859                         *ret = CAMERA_ERROR_OUT_OF_MEMORY;
860
861                 return;
862         }
863
864         if (api != MUSE_CAMERA_API_RETURN_BUFFER && api != MUSE_CAMERA_API_PREVIEW_CB_RETURN)
865                 CAM_LOG_INFO("api[%d], message[%s]", api, msg);
866         else
867                 CAM_LOG_DEBUG("api[%d], message[%s]", api, msg);
868
869         if (cb_info->is_server_connected) {
870                 _camera_update_api_waiting(cb_info, api, 1);
871
872                 g_mutex_lock(&cb_info->fd_lock);
873                 send_ret = muse_core_msg_send(cb_info->fd, msg);
874                 g_mutex_unlock(&cb_info->fd_lock);
875         }
876
877         if (send_ret < 0) {
878                 CAM_LOG_ERROR("message send failed");
879                 if (ret)
880                         *ret = CAMERA_ERROR_INVALID_OPERATION;
881         } else {
882                 if (ret)
883                         *ret = _camera_client_wait_for_cb_return(api, cb_info, time_out);
884         }
885
886         _camera_update_api_waiting(cb_info, api, -1);
887
888         muse_core_msg_free(msg);
889
890         if (api != MUSE_CAMERA_API_RETURN_BUFFER && api != MUSE_CAMERA_API_PREVIEW_CB_RETURN)
891                 CAM_LOG_INFO("api[%d] ret[0x%x]", api, ret ? *ret : 0x0);
892         else
893                 CAM_LOG_DEBUG("api[%d] ret[0x%x]", api, ret ? *ret : 0x0);
894 }
895
896
897 int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_info_s *cb_info, int time_out)
898 {
899         int ret = CAMERA_ERROR_NONE;
900         gint64 end_time;
901
902         if (!cb_info->is_server_connected) {
903                 CAM_LOG_ERROR("server is disconnected");
904                 return CAMERA_ERROR_SERVICE_DISCONNECTED;
905         }
906
907         g_mutex_lock(&(cb_info->api_mutex[api]));
908
909         CAM_LOG_INFO("api [%d], timeout [%d sec]", api, time_out);
910
911         end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
912
913         while (!cb_info->api_activating[api]) {
914                 if (time_out == CAMERA_CB_NO_TIMEOUT) {
915                         g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
916                         CAM_LOG_WARNING("api %d returned 0x%x", api, cb_info->api_ret[api]);
917                 } else if (!g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
918                         CAM_LOG_ERROR("api %d TIMED OUT!", api);
919                         ret = CAMERA_ERROR_INVALID_OPERATION;
920                         goto _CB_RETURN_END;
921                 }
922
923                 if (!cb_info->is_server_connected) {
924                         ret = CAMERA_ERROR_SERVICE_DISCONNECTED;
925                         goto _CB_RETURN_END;
926                 }
927
928                 if (!cb_info->api_activating[api])
929                         CAM_LOG_WARNING("invalid signal received, wait again...");
930         }
931
932         ret = cb_info->api_ret[api];
933         cb_info->api_activating[api] = FALSE;
934
935 _CB_RETURN_END:
936         g_mutex_unlock(&(cb_info->api_mutex[api]));
937
938         if (ret != CAMERA_ERROR_NONE)
939                 CAM_LOG_ERROR("api %d : error 0x%x", api, ret);
940
941         return ret;
942 }
943
944
945 void _camera_msg_send(int api, int *fds, camera_cb_info_s *cb_info,
946         int *ret, int timeout)
947 {
948         char *msg = NULL;
949
950         if (!cb_info) {
951                 CAM_LOG_ERROR("NULL info - api %d", api);
952
953                 if (ret)
954                         *ret = CAMERA_ERROR_INVALID_PARAMETER;
955
956                 return;
957         }
958
959         msg = muse_core_msg_new(api, NULL);
960
961         _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
962 }
963
964
965 void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
966         int *ret, camera_msg_param *param, int timeout)
967 {
968         int array_length;
969         char *msg = NULL;
970
971         if (!cb_info || !param) {
972                 CAM_LOG_ERROR("invalid pointer : api %d - %p %p", api, cb_info, param);
973
974                 if (ret)
975                         *ret = CAMERA_ERROR_INVALID_PARAMETER;
976
977                 return;
978         }
979
980         CAM_LOG_DEBUG("type[%d], name[%s]", param->type, param->name);
981
982         switch (param->type) {
983         case MUSE_TYPE_INT:
984                 msg = muse_core_msg_new(api,
985                         param->type, param->name, param->value.value_INT,
986                         NULL);
987                 break;
988         case MUSE_TYPE_STRING:
989                 msg = muse_core_msg_new(api,
990                         param->type, param->name, param->value.value_STRING,
991                         NULL);
992                 break;
993         case MUSE_TYPE_ARRAY:
994                 array_length = param->value_size / sizeof(int) + \
995                         (param->value_size % sizeof(int) ? 1 : 0);
996
997                 msg = muse_core_msg_new(api,
998                         param->type, param->name, array_length, param->value.value_ARRAY,
999                         NULL);
1000                 break;
1001         default:
1002                 CAM_LOG_ERROR("unknown type %d", param->type);
1003                 break;
1004         }
1005
1006         _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
1007 }
1008
1009
1010 void _camera_msg_send_param2_int(int api, camera_cb_info_s *cb_info,
1011         int *ret, camera_msg_param *param0, camera_msg_param *param1, int timeout)
1012 {
1013         char *msg = NULL;
1014
1015         if (!cb_info || !param0 || !param1) {
1016                 CAM_LOG_ERROR("invalid ptr %p %p %p : api %d",
1017                         cb_info, param0, param1, api);
1018
1019                 if (ret)
1020                         *ret = CAMERA_ERROR_INVALID_PARAMETER;
1021
1022                 return;
1023         }
1024
1025         CAM_LOG_DEBUG("api[%d], param0[%s:%d], param1[%s:%d]",
1026                 api,
1027                 param0->name, param0->value.value_INT,
1028                 param1->name, param1->value.value_INT);
1029
1030         msg = muse_core_msg_new(api,
1031                 param0->type, param0->name, param0->value.value_INT,
1032                 param1->type, param1->name, param1->value.value_INT,
1033                 NULL);
1034
1035         _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
1036 }
1037
1038
1039 void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info)
1040 {
1041         camera_msg_param param;
1042
1043         if (ret_fd < 0) {
1044                 CAM_LOG_WARNING("invalid fd %d", ret_fd);
1045                 return;
1046         }
1047
1048         CAMERA_MSG_PARAM_SET(param, INT, ret_fd);
1049
1050         _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
1051 }
1052
1053
1054 int _camera_get_tbm_format(int in_format, uint32_t *out_format)
1055 {
1056         if (in_format <= MM_PIXEL_FORMAT_INVALID ||
1057             in_format >= MM_PIXEL_FORMAT_NUM ||
1058             out_format == NULL) {
1059                 CAM_LOG_ERROR("INVALID_PARAMETER : in_format %d, out_format ptr %p", in_format, out_format);
1060                 return CAMERA_ERROR_INVALID_PARAMETER;
1061         }
1062
1063         switch (in_format) {
1064         case MM_PIXEL_FORMAT_NV12:
1065         case MM_PIXEL_FORMAT_NV12T:
1066                 *out_format = TBM_FORMAT_NV12;
1067                 break;
1068 //LCOV_EXCL_START
1069         case MM_PIXEL_FORMAT_NV16:
1070                 *out_format = TBM_FORMAT_NV16;
1071                 break;
1072         case MM_PIXEL_FORMAT_NV21:
1073                 *out_format = TBM_FORMAT_NV21;
1074                 break;
1075         case MM_PIXEL_FORMAT_YUYV:
1076                 *out_format = TBM_FORMAT_YUYV;
1077                 break;
1078         case MM_PIXEL_FORMAT_UYVY:
1079         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1080                 *out_format = TBM_FORMAT_UYVY;
1081                 break;
1082         case MM_PIXEL_FORMAT_422P:
1083                 *out_format = TBM_FORMAT_YUV422;
1084                 break;
1085         case MM_PIXEL_FORMAT_I420:
1086                 *out_format = TBM_FORMAT_YUV420;
1087                 break;
1088         case MM_PIXEL_FORMAT_YV12:
1089                 *out_format = TBM_FORMAT_YVU420;
1090                 break;
1091         case MM_PIXEL_FORMAT_RGB565:
1092                 *out_format = TBM_FORMAT_RGB565;
1093                 break;
1094         case MM_PIXEL_FORMAT_RGB888:
1095                 *out_format = TBM_FORMAT_RGB888;
1096                 break;
1097         case MM_PIXEL_FORMAT_RGBA:
1098                 *out_format = TBM_FORMAT_RGBA8888;
1099                 break;
1100         case MM_PIXEL_FORMAT_ARGB:
1101                 *out_format = TBM_FORMAT_ARGB8888;
1102                 break;
1103         default:
1104                 CAM_LOG_ERROR("invalid in_format %d", in_format);
1105                 return CAMERA_ERROR_INVALID_PARAMETER;
1106 //LCOV_EXCL_STOP
1107         }
1108
1109         return CAMERA_ERROR_NONE;
1110 }
1111
1112
1113 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype)
1114 {
1115         if (in_format <= MM_PIXEL_FORMAT_INVALID ||
1116             in_format >= MM_PIXEL_FORMAT_NUM ||
1117             mimetype == NULL) {
1118                 CAM_LOG_ERROR("INVALID_PARAMETER : in_format %d, mimetype ptr %p", in_format, mimetype);
1119                 return CAMERA_ERROR_INVALID_PARAMETER;
1120         }
1121
1122         switch (in_format) {
1123         case MM_PIXEL_FORMAT_NV12:
1124         case MM_PIXEL_FORMAT_NV12T:
1125                 *mimetype = MEDIA_FORMAT_NV12;
1126                 break;
1127 //LCOV_EXCL_START
1128         case MM_PIXEL_FORMAT_NV16:
1129                 *mimetype = MEDIA_FORMAT_NV16;
1130                 break;
1131         case MM_PIXEL_FORMAT_NV21:
1132                 *mimetype = MEDIA_FORMAT_NV21;
1133                 break;
1134         case MM_PIXEL_FORMAT_YUYV:
1135                 *mimetype = MEDIA_FORMAT_YUYV;
1136                 break;
1137         case MM_PIXEL_FORMAT_UYVY:
1138         case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
1139                 *mimetype = MEDIA_FORMAT_UYVY;
1140                 break;
1141         case MM_PIXEL_FORMAT_422P:
1142                 *mimetype = MEDIA_FORMAT_422P;
1143                 break;
1144         case MM_PIXEL_FORMAT_I420:
1145                 *mimetype = MEDIA_FORMAT_I420;
1146                 break;
1147         case MM_PIXEL_FORMAT_YV12:
1148                 *mimetype = MEDIA_FORMAT_YV12;
1149                 break;
1150         case MM_PIXEL_FORMAT_RGB565:
1151                 *mimetype = MEDIA_FORMAT_RGB565;
1152                 break;
1153         case MM_PIXEL_FORMAT_RGB888:
1154                 *mimetype = MEDIA_FORMAT_RGB888;
1155                 break;
1156         case MM_PIXEL_FORMAT_RGBA:
1157                 *mimetype = MEDIA_FORMAT_RGBA;
1158                 break;
1159         case MM_PIXEL_FORMAT_ARGB:
1160                 *mimetype = MEDIA_FORMAT_ARGB;
1161                 break;
1162         case MM_PIXEL_FORMAT_ENCODED_H264:
1163                 /* TODO: How can we determine the profile for H.264 format? */
1164                 *mimetype = MEDIA_FORMAT_H264_SP;
1165                 break;
1166         case MM_PIXEL_FORMAT_ENCODED_MJPEG:
1167                 *mimetype = MEDIA_FORMAT_MJPEG;
1168                 break;
1169         case MM_PIXEL_FORMAT_ENCODED_VP8:
1170                 *mimetype = MEDIA_FORMAT_VP8;
1171                 break;
1172         case MM_PIXEL_FORMAT_ENCODED_VP9:
1173                 *mimetype = MEDIA_FORMAT_VP9;
1174                 break;
1175         default:
1176                 CAM_LOG_ERROR("unsupported format[%d]", in_format);
1177                 return CAMERA_ERROR_NOT_SUPPORTED;
1178 //LCOV_EXCL_STOP
1179         }
1180
1181         return CAMERA_ERROR_NONE;
1182 }
1183
1184
1185 static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
1186         tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data)
1187 {
1188         int i = 0;
1189         int ret = CAMERA_ERROR_NONE;
1190         camera_media_packet_data *new_mp_data = NULL;
1191
1192         if (!tfd || !mp_data) {
1193                 CAM_LOG_ERROR("NULL param[%p,%p]", tfd, mp_data);
1194                 return CAMERA_ERROR_INVALID_PARAMETER;
1195         }
1196
1197         new_mp_data = g_new0(camera_media_packet_data, 1);
1198
1199         new_mp_data->ret_fd = ret_fd;
1200         new_mp_data->fd = tfd[0];
1201         new_mp_data->num_buffer_fd = num_buffer_fd;
1202         new_mp_data->bo = bo;
1203
1204         CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", new_mp_data->fd, new_mp_data->ret_fd);
1205
1206         if (data_bo) {
1207                 /* non-zero copy */
1208                 new_mp_data->data_bo = data_bo;
1209                 new_mp_data->data_fd = tfd[1];
1210
1211                 CAM_LOG_VERBOSE("bo[%p], fd[%d]",
1212                         new_mp_data->data_bo, new_mp_data->data_fd);
1213         } else {
1214                 /* zero copy */
1215                 for (i = 0 ; i < num_buffer_fd ; i++) {
1216                         new_mp_data->buffer_bo[i] = buffer_bo[i];
1217                         new_mp_data->buffer_fd[i] = (tbm_fd)tfd[i + 1];
1218
1219                         CAM_LOG_VERBOSE("    [%d] bo[%p], fd[%d]",
1220                                 i, new_mp_data->buffer_bo[i], new_mp_data->buffer_fd[i]);
1221                 }
1222
1223                 for (i = num_buffer_fd ; i < MUSE_NUM_FD ; i++)
1224                         new_mp_data->buffer_fd[i] = CAMERA_FD_INIT;
1225
1226                 new_mp_data->data_fd = CAMERA_FD_INIT;
1227         }
1228
1229         *mp_data = new_mp_data;
1230
1231         CAM_LOG_DEBUG("mp_data %p", new_mp_data);
1232
1233         return ret;
1234 }
1235
1236 static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
1237 {
1238         int i = 0;
1239
1240         if (!mp_data || !cb_info) {
1241                 CAM_LOG_ERROR("NULL pointer %p %p", mp_data, cb_info);
1242                 return;
1243         }
1244
1245         CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", mp_data->fd, mp_data->ret_fd);
1246
1247         /* release imported bo and close fd */
1248         for (i = 0 ; i < mp_data->num_buffer_fd ; i++) {
1249                 CAM_LOG_VERBOSE("    release buffer[%d] fd[%d],bo[%p]",
1250                         i, mp_data->buffer_fd[i], mp_data->buffer_bo[i]);
1251
1252                 tbm_bo_unref(mp_data->buffer_bo[i]);
1253
1254                 if (CAMERA_IS_FD_VALID(mp_data->buffer_fd[i]))
1255                         close(mp_data->buffer_fd[i]);
1256                 else
1257                         CAM_LOG_WARNING("invalid fd[%d] for buffer[%d]", mp_data->buffer_fd[i], i);
1258         }
1259
1260         if (mp_data->data_bo) {
1261                 CAM_LOG_VERBOSE("release data_fd[%d],data_bo[%p]",
1262                         mp_data->data_fd, mp_data->data_bo);
1263
1264                 tbm_bo_unref(mp_data->data_bo);
1265
1266                 if (CAMERA_IS_FD_VALID(mp_data->data_fd))
1267                         close(mp_data->data_fd);
1268                 else
1269                         CAM_LOG_WARNING("invalid data_fd[%d]", mp_data->data_fd);
1270         }
1271
1272         CAM_LOG_VERBOSE("release fd[%d],bo[%p]", mp_data->fd, mp_data->bo);
1273
1274         tbm_bo_unref(mp_data->bo);
1275
1276         if (CAMERA_IS_FD_VALID(mp_data->fd))
1277                 close(mp_data->fd);
1278         else
1279                 CAM_LOG_WARNING("invalid fd[%d]", mp_data->fd);
1280
1281         /* return buffer */
1282         _camera_msg_return_buffer(mp_data->ret_fd, cb_info);
1283
1284         g_free(mp_data);
1285 }
1286
1287
1288 static tbm_surface_h __camera_get_tbm_surface(MMCamcorderVideoStreamDataType *stream, camera_media_packet_data *mp_data)
1289 {
1290         int i = 0;
1291         int ret = CAMERA_ERROR_NONE;
1292         uint32_t tbm_format = 0;
1293         tbm_bo bos[BUFFER_MAX_PLANE_NUM] = {NULL, };
1294         tbm_surface_info_s tsurf_info;
1295
1296         if (!stream || !mp_data) {
1297                 CAM_LOG_ERROR("NULL param [%p,%p]", stream, mp_data);
1298                 return NULL;
1299         }
1300
1301         if (mp_data->num_buffer_fd < 1 && !mp_data->data_bo) {
1302                 CAM_LOG_ERROR("No valid data");
1303                 return NULL;
1304         }
1305
1306         ret = _camera_get_tbm_format(stream->format, &tbm_format);
1307         if (ret != CAMERA_ERROR_NONE)
1308                 return NULL;
1309
1310         memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
1311
1312         if (mp_data->num_buffer_fd > 0) {
1313                 for (i = 0 ; i < mp_data->num_buffer_fd ; i++)
1314                         bos[i] = mp_data->buffer_bo[i];
1315         } else {
1316                 bos[0] = mp_data->data_bo;
1317         }
1318
1319         tsurf_info.width = stream->width;
1320         tsurf_info.height = stream->height;
1321         tsurf_info.format = tbm_format;
1322         tsurf_info.bpp = tbm_surface_internal_get_bpp(tbm_format);
1323         tsurf_info.num_planes = tbm_surface_internal_get_num_planes(tbm_format);
1324
1325         switch (tbm_format) {
1326         case TBM_FORMAT_NV12:   /* fall through */
1327         case TBM_FORMAT_NV21:   /* fall through */
1328         case TBM_FORMAT_YUV420: /* fall through */
1329         case TBM_FORMAT_YVU420: /* fall through */
1330         case TBM_FORMAT_UYVY:   /* fall through */
1331         case TBM_FORMAT_YUYV:
1332                 for (i = 0 ; i < (int)tsurf_info.num_planes ; i++) {
1333                         tsurf_info.planes[i].stride = stream->stride[i];
1334                         tsurf_info.planes[i].size = stream->stride[i] * stream->elevation[i];
1335                         if (i != 0 && mp_data->num_buffer_fd <= 1)
1336                                 tsurf_info.planes[i].offset = tsurf_info.planes[i - 1].offset + tsurf_info.planes[i - 1].size;
1337                         tsurf_info.size += tsurf_info.planes[i].size;
1338
1339                         CAM_LOG_VERBOSE("[plane:%d] st[%d], el[%d], size[%d]",
1340                                 i, stream->stride[i], stream->elevation[i], tsurf_info.planes[i].size);
1341                 }
1342                 break;
1343 //LCOV_EXCL_START
1344         case TBM_FORMAT_RGB565:     /* fall through */
1345         case TBM_FORMAT_RGB888:     /* fall through */
1346         case TBM_FORMAT_RGBA8888:   /* fall through */
1347         case TBM_FORMAT_ARGB8888:
1348                 tsurf_info.planes[0].size = stream->data.rgb.length_data;
1349                 tsurf_info.planes[0].offset = 0;
1350                 tsurf_info.size = stream->data.rgb.length_data;
1351                 break;
1352         default:
1353                 CAM_LOG_ERROR("Not supported format[%d]", stream->format);
1354                 return NULL;
1355 //LCOV_EXCL_STOP
1356         }
1357
1358         return tbm_surface_internal_create_with_bos(&tsurf_info, bos,
1359                 mp_data->num_buffer_fd > 0 ? mp_data->num_buffer_fd : 1);
1360 }
1361
1362
1363 static int __camera_update_media_packet_format(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream)
1364 {
1365         int ret = CAMERA_ERROR_NONE;
1366         int pkt_fmt_width = 0;
1367         int pkt_fmt_height = 0;
1368         bool make_pkt_fmt = false;
1369         media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
1370         media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
1371
1372         if (!cb_info || !stream) {
1373                 CAM_LOG_ERROR("invalid parameter - %p, %p", cb_info, stream);
1374                 return CAMERA_ERROR_INVALID_PARAMETER;
1375         }
1376
1377         ret = _camera_get_media_packet_mimetype(stream->format, &mimetype);
1378         if (ret != CAMERA_ERROR_NONE)
1379                 return ret;
1380
1381         /* check media packet format */
1382         if (cb_info->pkt_fmt) {
1383                 media_format_get_video_info(cb_info->pkt_fmt,
1384                         &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
1385
1386                 CAM_LOG_DEBUG("pkt_fmt %dx%d - stream %dx%d",
1387                         pkt_fmt_width, pkt_fmt_height, stream->width, stream->height);
1388
1389                 if (pkt_fmt_mimetype != mimetype ||
1390                         pkt_fmt_width != stream->width ||
1391                         pkt_fmt_height != stream->height) {
1392                         CAM_LOG_WARNING("change fmt[previous:0x%x,%dx%d]",
1393                                         pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height);
1394
1395                         media_format_unref(cb_info->pkt_fmt);
1396                         cb_info->pkt_fmt = NULL;
1397                         make_pkt_fmt = true;
1398                 }
1399         } else {
1400                 make_pkt_fmt = true;
1401         }
1402
1403         /* create packet format */
1404         if (make_pkt_fmt) {
1405                 CAM_LOG_WARNING("make new fmt - 0x%x, %dx%d",
1406                         mimetype, stream->width, stream->height);
1407
1408                 ret = media_format_create(&cb_info->pkt_fmt);
1409                 if (ret != MEDIA_FORMAT_ERROR_NONE) {
1410                         CAM_LOG_ERROR("media_format_create failed 0x%x", ret);
1411                         return CAMERA_ERROR_INVALID_OPERATION;
1412                 }
1413
1414                 ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
1415                 ret |= media_format_set_video_width(cb_info->pkt_fmt, stream->width);
1416                 ret |= media_format_set_video_height(cb_info->pkt_fmt, stream->height);
1417                 if (ret != MEDIA_FORMAT_ERROR_NONE) {
1418                         CAM_LOG_ERROR("media format set failed 0x%x", ret);
1419                         return CAMERA_ERROR_INVALID_OPERATION;
1420                 }
1421         }
1422
1423         return CAMERA_ERROR_NONE;
1424 }
1425
1426
1427 static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
1428         camera_media_packet_data *mp_data, media_packet_h *packet)
1429 {
1430         media_packet_h pkt = NULL;
1431         tbm_surface_h tsurf = NULL;
1432         int ret = CAMERA_ERROR_NONE;
1433
1434         if (!cb_info || !stream || !mp_data || !packet) {
1435                 CAM_LOG_ERROR("invalid parameter - %p, %p, %p, %p",
1436                         cb_info, stream, mp_data, packet);
1437                 return CAMERA_ERROR_INVALID_PARAMETER;
1438         }
1439
1440         ret = __camera_update_media_packet_format(cb_info, stream);
1441         if (ret != CAMERA_ERROR_NONE)
1442                 return ret;
1443
1444         if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED) {
1445                 ret = media_packet_new_from_external_memory(cb_info->pkt_fmt,
1446                         stream->data.encoded.data, stream->data.encoded.length_data,
1447                         (media_packet_dispose_cb)_camera_media_packet_dispose, (void *)cb_info,
1448                         &pkt);
1449
1450                 if (pkt) {
1451                         if (!stream->data.encoded.is_delta_frame)
1452                                 media_packet_set_flags(pkt, MEDIA_PACKET_SYNC_FRAME);
1453
1454                         if (stream->data.encoded.is_header_included) {
1455                                 media_packet_set_flags(pkt, MEDIA_PACKET_CODEC_CONFIG);
1456                                 CAM_LOG_INFO("Codec config in buffer");
1457                         }
1458                 }
1459         } else {
1460                 tsurf = __camera_get_tbm_surface(stream, mp_data);
1461                 if (!tsurf) {
1462                         CAM_LOG_ERROR("get tbm surface failed");
1463                         ret = CAMERA_ERROR_INVALID_OPERATION;
1464                         goto _PACKET_CREATE_FAILED;
1465                 }
1466
1467                 ret = media_packet_new_from_tbm_surface(cb_info->pkt_fmt,
1468                         tsurf, (media_packet_dispose_cb)_camera_media_packet_dispose,
1469                         (void *)cb_info, &pkt);
1470         }
1471
1472         if (ret != MEDIA_PACKET_ERROR_NONE) {
1473                 CAM_LOG_ERROR("media_packet_new[t:%d] failed 0x%x", stream->data_type, ret);
1474                 goto _PACKET_CREATE_FAILED;
1475         }
1476
1477         ret = media_packet_set_extra(pkt, (void *)mp_data);
1478         if (ret != MEDIA_PACKET_ERROR_NONE) {
1479                 CAM_LOG_ERROR("media_packet_set_extra failed");
1480                 goto _PACKET_CREATE_FAILED;
1481         }
1482
1483         if (media_packet_set_pts(pkt, stream->timestamp_nsec) != MEDIA_PACKET_ERROR_NONE)
1484                 CAM_LOG_WARNING("media_packet_set_pts failed");
1485
1486         if (media_packet_set_rotate_method(pkt, (media_packet_rotate_method_e)stream->rotation) != MEDIA_PACKET_ERROR_NONE)
1487                 CAM_LOG_WARNING("media_packet_set_rotate_method failed");
1488
1489         CAM_LOG_VERBOSE("new media packet[%p], tbm surface[%p]", pkt, tsurf);
1490
1491         *packet = pkt;
1492
1493         return CAMERA_ERROR_NONE;
1494
1495 _PACKET_CREATE_FAILED:
1496         if (tsurf)
1497                 tbm_surface_destroy(tsurf);
1498         if (pkt)
1499                 media_packet_unref(pkt);
1500
1501         return CAMERA_ERROR_INVALID_OPERATION;
1502 }
1503
1504 void _camera_media_packet_dispose(media_packet_h pkt, void *user_data)
1505 {
1506         int ret = 0;
1507         camera_cb_info_s *cb_info = (camera_cb_info_s *)user_data;
1508         camera_media_packet_data *mp_data = NULL;
1509         tbm_surface_h tsurf = NULL;
1510
1511         if (!pkt || !cb_info) {
1512                 CAM_LOG_ERROR("NULL pointer %p %p", pkt, cb_info);
1513                 return;
1514         }
1515
1516         ret = media_packet_get_extra(pkt, (void **)&mp_data);
1517         if (ret != MEDIA_PACKET_ERROR_NONE || !mp_data) {
1518                 CAM_LOG_ERROR("media_packet_get_extra failed 0x%x", ret);
1519                 return;
1520         }
1521
1522         ret = media_packet_get_tbm_surface(pkt, &tsurf);
1523
1524         CAM_LOG_VERBOSE("media packet[%p] - mp_data[%p],tsurf[%p]",
1525                 pkt, mp_data, tsurf);
1526
1527         if (tsurf)
1528                 tbm_surface_destroy(tsurf);
1529
1530         g_mutex_lock(&cb_info->mp_data_mutex);
1531         __camera_release_media_packet_data(mp_data, cb_info);
1532         g_mutex_unlock(&cb_info->mp_data_mutex);
1533 }
1534
1535 static void __camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_msg, muse_camera_event_e event, int *tfd)
1536 {
1537         int param1 = 0;
1538         int param2 = 0;
1539
1540         if (!recv_msg || event >= MUSE_CAMERA_EVENT_TYPE_NUM) {
1541                 CAM_LOG_ERROR("invalid parameter - camera msg %p, event %d", recv_msg, event);
1542                 return;
1543         }
1544
1545         CAM_LOG_DEBUG("get camera msg[%s], event[%d]", recv_msg, event);
1546
1547         g_mutex_lock(&cb_info->user_cb_mutex[event]);
1548
1549         if (cb_info->user_cb[event] == NULL) {
1550                 if (event != MUSE_CAMERA_EVENT_TYPE_PREVIEW &&
1551                         event != MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW &&
1552                         event != MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION &&
1553                         event != MUSE_CAMERA_EVENT_TYPE_CAPTURE) {
1554                         g_mutex_unlock(&cb_info->user_cb_mutex[event]);
1555                         CAM_LOG_WARNING("NULL callback for event %d, return here", event);
1556                         return;
1557                 }
1558
1559                 /* return buffer message should be sent for some events.
1560                  - MUSE_CAMERA_EVENT_TYPE_PREVIEW
1561                  - MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW
1562                  - MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION
1563                  - MUSE_CAMERA_EVENT_TYPE_CAPTURE
1564                 */
1565         }
1566
1567         switch (event) {
1568         case MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE:
1569                 {
1570                         int previous = 0;
1571                         int current = 0;
1572                         int by_policy = 0;
1573
1574                         muse_camera_msg_get(previous, recv_msg);
1575                         muse_camera_msg_get(current, recv_msg);
1576                         muse_camera_msg_get(by_policy, recv_msg);
1577
1578                         CAM_LOG_INFO("STATE CHANGE - previous %d, current %d, by_policy %d",
1579                                 previous, current, by_policy);
1580
1581                         ((camera_state_changed_cb)cb_info->user_cb[event])((camera_state_e)previous,
1582                                 (camera_state_e)current, (bool)by_policy, cb_info->user_data[event]);
1583                 }
1584                 break;
1585         case MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE:
1586                 {
1587                         int state = 0;
1588
1589                         muse_camera_msg_get(state, recv_msg);
1590
1591                         CAM_LOG_INFO("FOCUS state - %d", state);
1592
1593                         ((camera_focus_changed_cb)cb_info->user_cb[event])((camera_focus_state_e)state, cb_info->user_data[event]);
1594                 }
1595                 break;
1596         case MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE:
1597                 CAM_LOG_INFO("CAPTURE_COMPLETED");
1598                 ((camera_capture_completed_cb)cb_info->user_cb[event])(cb_info->user_data[event]);
1599                 break;
1600         case MUSE_CAMERA_EVENT_TYPE_PREVIEW:
1601         case MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW:
1602                 __camera_event_handler_preview(cb_info, recv_msg, tfd);
1603                 break;
1604 //LCOV_EXCL_START
1605         case MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS:
1606                 {
1607                         int percent = 0;
1608
1609                         muse_camera_msg_get(percent, recv_msg);
1610
1611                         CAM_LOG_INFO("HDR progress - %d %%", percent);
1612
1613                         ((camera_attr_hdr_progress_cb)cb_info->user_cb[event])(percent, cb_info->user_data[event]);
1614                 }
1615                 break;
1616         case MUSE_CAMERA_EVENT_TYPE_INTERRUPTED:
1617                 {
1618                         int policy = 0;
1619                         int previous = 0;
1620                         int current = 0;
1621
1622                         muse_camera_msg_get(policy, recv_msg);
1623                         muse_camera_msg_get(previous, recv_msg);
1624                         muse_camera_msg_get(current, recv_msg);
1625
1626                         CAM_LOG_WARNING("INTERRUPTED - policy %d, state %d -> %d", policy, previous, current);
1627
1628                         ((camera_interrupted_cb)cb_info->user_cb[event])((camera_policy_e)policy,
1629                                 (camera_state_e)previous, (camera_state_e)current, cb_info->user_data[event]);
1630                 }
1631                 break;
1632         case MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED:
1633                 {
1634                         int policy = 0;
1635                         int state = 0;
1636
1637                         muse_camera_msg_get(policy, recv_msg);
1638                         muse_camera_msg_get(state, recv_msg);
1639
1640                         CAM_LOG_WARNING("INTERRUPT_STARTED - policy %d, state %d", policy, state);
1641
1642                         ((camera_interrupt_started_cb)cb_info->user_cb[event])((camera_policy_e)policy,
1643                                 (camera_state_e)state, cb_info->user_data[event]);
1644                 }
1645                 break;
1646         case MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION:
1647                 __camera_event_handler_face_detection(cb_info, recv_msg, tfd);
1648                 break;
1649         case MUSE_CAMERA_EVENT_TYPE_ERROR:
1650                 {
1651                         int error = 0;
1652                         int current_state = 0;
1653
1654                         muse_camera_msg_get(error, recv_msg);
1655                         muse_camera_msg_get(current_state, recv_msg);
1656
1657                         CAM_LOG_ERROR("ERROR - error 0x%x, current_state %d", error, current_state);
1658
1659                         ((camera_error_cb)cb_info->user_cb[event])((camera_error_e)error,
1660                                 (camera_state_e)current_state, cb_info->user_data[event]);
1661                 }
1662                 break;
1663 //LCOV_EXCL_STOP
1664         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION:
1665                 /* fall through */
1666         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION:
1667                 muse_camera_msg_get(param1, recv_msg);
1668                 muse_camera_msg_get(param2, recv_msg);
1669
1670                 CAM_LOG_DEBUG("event[%d] SUPPORTED[%d],[%d]", event, param1, param2);
1671
1672                 if (((camera_supported_cb_param2)cb_info->user_cb[event])(param1, param2, cb_info->user_data[event]) == false) {
1673                         cb_info->user_cb[event] = NULL;
1674                         cb_info->user_data[event] = NULL;
1675                         CAM_LOG_WARNING("stop foreach callback for event %d", event);
1676                 }
1677                 break;
1678         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT:
1679                 /* fall through */
1680         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT:
1681                 /* fall through */
1682         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE:
1683                 /* fall through */
1684         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE:
1685                 /* fall through */
1686         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO:
1687                 /* fall through */
1688         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE:
1689                 /* fall through */
1690         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT:
1691                 /* fall through */
1692         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE:
1693                 /* fall through */
1694         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE:
1695                 /* fall through */
1696         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS:
1697                 /* fall through */
1698         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION:
1699                 /* fall through */
1700         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP:
1701                 /* fall through */
1702         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION:
1703                 /* fall through */
1704 //LCOV_EXCL_START
1705         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE:
1706                 /* fall through */
1707         case MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE:
1708                 muse_camera_msg_get(param1, recv_msg);
1709
1710                 CAM_LOG_DEBUG("event[%d], SUPPORTED[%d] ", event, param1);
1711
1712                 if (((camera_supported_cb_param1)cb_info->user_cb[event])(param1, cb_info->user_data[event]) == false) {
1713                         cb_info->user_cb[event] = NULL;
1714                         cb_info->user_data[event] = NULL;
1715                         CAM_LOG_WARNING("stop foreach callback for event %d", event);
1716                 }
1717                 break;
1718 //LCOV_EXCL_STOP
1719         case MUSE_CAMERA_EVENT_TYPE_CAPTURE:
1720                 __camera_event_handler_capture(cb_info, recv_msg, tfd);
1721                 break;
1722         default:
1723                 CAM_LOG_WARNING("unhandled event %d", event);
1724                 break;
1725         }
1726
1727         g_mutex_unlock(&cb_info->user_cb_mutex[event]);
1728 }
1729
1730 static gboolean __camera_idle_event_callback(gpointer data)
1731 {
1732         camera_cb_info_s *cb_info = NULL;
1733         camera_idle_event_s *cam_idle_event = (camera_idle_event_s *)data;
1734
1735         if (cam_idle_event == NULL) {
1736                 CAM_LOG_ERROR("cam_idle_event is NULL");
1737                 return FALSE;
1738         }
1739
1740         /* lock event */
1741         g_mutex_lock(&g_cam_idle_event_lock);
1742
1743         cb_info = cam_idle_event->cb_info;
1744         if (cb_info == NULL) {
1745                 CAM_LOG_WARNING("camera cb_info is NULL. event %p %d", cam_idle_event, cam_idle_event->event);
1746                 g_mutex_unlock(&g_cam_idle_event_lock);
1747                 goto IDLE_EVENT_CALLBACK_DONE;
1748         }
1749
1750         /* remove event from list */
1751         if (cb_info->idle_event_list)
1752                 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
1753
1754         g_mutex_unlock(&g_cam_idle_event_lock);
1755
1756         /* user callback */
1757         __camera_client_user_callback(cb_info, cam_idle_event->recv_msg, cam_idle_event->event, cam_idle_event->tfd);
1758
1759 IDLE_EVENT_CALLBACK_DONE:
1760         /* release event */
1761         g_free(cam_idle_event);
1762         cam_idle_event = NULL;
1763
1764         return FALSE;
1765 }
1766
1767 static gpointer __camera_msg_handler_func(gpointer data)
1768 {
1769         int api = 0;
1770         int type = 0;
1771         camera_message_s *cam_msg = NULL;
1772         camera_idle_event_s *cam_idle_event = NULL;
1773         camera_msg_handler_info_s *handler_info = (camera_msg_handler_info_s *)data;
1774         camera_cb_info_s *cb_info = NULL;
1775         GThread *thread = NULL;
1776
1777         if (!handler_info || !handler_info->cb_info) {
1778                 CAM_LOG_ERROR("NULL handler %p", handler_info);
1779                 return NULL;
1780         }
1781
1782         cb_info = (camera_cb_info_s *)handler_info->cb_info;
1783         type = handler_info->type;
1784         thread = handler_info->thread;
1785
1786         CAM_LOG_INFO("t:%d start[thread:%p]", type, thread);
1787
1788         g_mutex_lock(&handler_info->mutex);
1789
1790         while (g_atomic_int_get(&handler_info->running)) {
1791                 if (g_queue_is_empty(handler_info->queue)) {
1792                         CAM_LOG_VERBOSE("t[%d] signal wait...", type);
1793                         g_cond_wait(&handler_info->cond, &handler_info->mutex);
1794                         CAM_LOG_VERBOSE("t[%d] signal received", type);
1795
1796                         if (g_atomic_int_get(&handler_info->running) == 0) {
1797                                 CAM_LOG_INFO("t:%d stop event thread", type);
1798                                 break;
1799                         }
1800                 }
1801
1802                 cam_msg = (camera_message_s *)g_queue_pop_head(handler_info->queue);
1803
1804                 g_mutex_unlock(&handler_info->mutex);
1805
1806                 if (cam_msg == NULL) {
1807                         CAM_LOG_ERROR("t:%d NULL message", type);
1808                         g_mutex_lock(&handler_info->mutex);
1809                         continue;
1810                 }
1811
1812                 api = cam_msg->api;
1813
1814                 if (api < MUSE_CAMERA_API_MAX) {
1815                         int ret = 0;
1816
1817                         g_mutex_lock(&cb_info->api_mutex[api]);
1818
1819                         if (muse_camera_msg_get(ret, cam_msg->recv_msg)) {
1820                                 if (cb_info->api_waiting[api] > 0) {
1821                                         cb_info->api_ret[api] = ret;
1822                                         cb_info->api_activating[api] = TRUE;
1823
1824                                         CAM_LOG_DEBUG("t[%d] camera api[%d] - return[0x%x]", type, api, ret);
1825
1826                                         g_cond_broadcast(&cb_info->api_cond[api]);
1827                                 } else {
1828                                         CAM_LOG_WARNING("no waiting for this api [%d]", api);
1829                                 }
1830                         } else {
1831                                 CAM_LOG_ERROR("t:%d failed to get camera ret for api %d, msg %s", type, api, cam_msg->recv_msg);
1832                         }
1833
1834                         g_mutex_unlock(&cb_info->api_mutex[api]);
1835                 } else if (api == MUSE_CAMERA_CB_EVENT) {
1836                         if (cam_msg->event == MUSE_CAMERA_EVENT_TYPE_INTERRUPTED) {
1837                                 CAM_LOG_WARNING("INTERRUPTED, release thread for preview cb");
1838                                 __destroy_msg_handler_thread(&cb_info->preview_cb_info);
1839                         }
1840
1841                         switch (cam_msg->event_class) {
1842                         case MUSE_CAMERA_EVENT_CLASS_THREAD_SUB:
1843                                 __camera_client_user_callback(cb_info, cam_msg->recv_msg, cam_msg->event, cam_msg->tfd);
1844                                 break;
1845                         case MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN:
1846                                 cam_idle_event = g_new0(camera_idle_event_s, 1);
1847                                 if (cam_idle_event == NULL) {
1848                                         CAM_LOG_ERROR("t:%d cam_idle_event alloc failed", type);
1849                                         break;
1850                                 }
1851
1852                                 cam_idle_event->event = cam_msg->event;
1853                                 cam_idle_event->cb_info = cb_info;
1854
1855                                 strncpy(cam_idle_event->recv_msg, cam_msg->recv_msg, sizeof(cam_idle_event->recv_msg));
1856                                 memcpy(cam_idle_event->tfd, cam_msg->tfd, sizeof(cam_idle_event->tfd));
1857
1858                                 CAM_LOG_DEBUG("t[%d] add camera event[%d, %p] to IDLE",
1859                                         type, cam_msg->event, cam_idle_event);
1860
1861                                 g_mutex_lock(&g_cam_idle_event_lock);
1862                                 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)cam_idle_event);
1863                                 g_mutex_unlock(&g_cam_idle_event_lock);
1864
1865                                 g_idle_add_full(G_PRIORITY_DEFAULT,
1866                                         (GSourceFunc)__camera_idle_event_callback,
1867                                         (gpointer)cam_idle_event,
1868                                         NULL);
1869                                 break;
1870                         default:
1871                                 CAM_LOG_ERROR("t:%d not handled event class %d", type, cam_msg->event_class);
1872                                 break;
1873                         }
1874                 } else {
1875                         CAM_LOG_ERROR("t:%d unknown camera api[%d] message[%s]", type, api, cam_msg->recv_msg);
1876                 }
1877
1878                 g_free(cam_msg);
1879                 cam_msg = NULL;
1880
1881                 g_mutex_lock(&handler_info->mutex);
1882         }
1883
1884         /* remove remained event */
1885         while (!g_queue_is_empty(handler_info->queue)) {
1886                 cam_msg = (camera_message_s *)g_queue_pop_head(handler_info->queue);
1887                 if (cam_msg) {
1888                         CAM_LOG_INFO("t:%d remove message %p", type, cam_msg);
1889                         __camera_release_tfd(cam_msg->tfd);
1890                         g_free(cam_msg);
1891                 } else {
1892                         CAM_LOG_WARNING("t:%d NULL message", type);
1893                 }
1894         }
1895
1896         g_mutex_unlock(&handler_info->mutex);
1897
1898         CAM_LOG_INFO("t:%d return[thread:%p]", type, thread);
1899
1900         return NULL;
1901 }
1902
1903
1904 static void __camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
1905 {
1906         camera_idle_event_s *cam_idle_event = NULL;
1907         GList *list = NULL;
1908
1909         if (cb_info == NULL) {
1910                 CAM_LOG_ERROR("cb_info is NULL");
1911                 return;
1912         }
1913
1914         g_mutex_lock(&g_cam_idle_event_lock);
1915
1916         if (cb_info->idle_event_list == NULL) {
1917                 CAM_LOG_INFO("No remained idle event");
1918                 g_mutex_unlock(&g_cam_idle_event_lock);
1919                 return;
1920         }
1921
1922         list = cb_info->idle_event_list;
1923
1924         while (list) {
1925                 cam_idle_event = list->data;
1926                 list = g_list_next(list);
1927
1928                 if (!cam_idle_event) {
1929                         CAM_LOG_WARNING("Fail to remove idle event. The event is NULL");
1930                         continue;
1931                 }
1932
1933                 if (g_idle_remove_by_data(cam_idle_event)) {
1934                         CAM_LOG_WARNING("remove idle event %p done", cam_idle_event);
1935
1936                         cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
1937
1938                         g_free(cam_idle_event);
1939                         cam_idle_event = NULL;
1940
1941                         continue;
1942                 }
1943
1944                 CAM_LOG_WARNING("set NULL cb_info for event %p %d, it will be freed on idle callback",
1945                         cam_idle_event, cam_idle_event->event);
1946
1947                 cam_idle_event->cb_info = NULL;
1948
1949                 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
1950         }
1951
1952         g_list_free(cb_info->idle_event_list);
1953         cb_info->idle_event_list = NULL;
1954
1955         g_mutex_unlock(&g_cam_idle_event_lock);
1956 }
1957
1958
1959 static void __camera_add_msg_to_queue(camera_cb_info_s *cb_info, int api, int event, int event_class, char *msg, int *tfd)
1960 {
1961         camera_message_s *cam_msg = NULL;
1962
1963         if (!cb_info || !msg) {
1964                 CAM_LOG_ERROR("NULL pointer %p %p", cb_info, msg);
1965                 return;
1966         }
1967
1968         cam_msg = g_new0(camera_message_s, 1);
1969         if (!cam_msg) {
1970                 CAM_LOG_ERROR("failed to alloc cam_msg for [%s]", msg);
1971                 return;
1972         }
1973
1974         cam_msg->api = api;
1975         cam_msg->event = event;
1976         cam_msg->event_class = event_class;
1977
1978         if (tfd)
1979                 memcpy(cam_msg->tfd, tfd, sizeof(cam_msg->tfd));
1980
1981         strncpy(cam_msg->recv_msg, msg, sizeof(cam_msg->recv_msg) - 1);
1982
1983         CAM_LOG_DEBUG("add message to queue : api[%d], event[%d], event_class[%d]",
1984                 api, event, event_class);
1985
1986         if (event == MUSE_CAMERA_EVENT_TYPE_PREVIEW) {
1987                 if (!cb_info->preview_cb_info.thread) {
1988                         LOGI("The thread for preview cb is not created yet, create it now");
1989                         if (!__create_msg_handler_thread(&cb_info->preview_cb_info,
1990                                         CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "cam:preview_cb", cb_info)) {
1991                                 CAM_LOG_ERROR("failed to create thread for preview cb");
1992                                 g_free(cam_msg);
1993                                 return;
1994                         }
1995                 }
1996
1997                 g_mutex_lock(&cb_info->preview_cb_info.mutex);
1998                 g_queue_push_tail(cb_info->preview_cb_info.queue, (gpointer)cam_msg);
1999                 g_cond_signal(&cb_info->preview_cb_info.cond);
2000                 g_mutex_unlock(&cb_info->preview_cb_info.mutex);
2001         } else if (event == MUSE_CAMERA_EVENT_TYPE_CAPTURE) {
2002                 g_mutex_lock(&cb_info->capture_cb_info.mutex);
2003                 g_queue_push_tail(cb_info->capture_cb_info.queue, (gpointer)cam_msg);
2004                 g_cond_signal(&cb_info->capture_cb_info.cond);
2005                 g_mutex_unlock(&cb_info->capture_cb_info.mutex);
2006         } else {
2007                 g_mutex_lock(&cb_info->msg_handler_info.mutex);
2008                 g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)cam_msg);
2009                 g_cond_signal(&cb_info->msg_handler_info.cond);
2010                 g_mutex_unlock(&cb_info->msg_handler_info.mutex);
2011         }
2012
2013         cam_msg = NULL;
2014 }
2015
2016
2017 static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd)
2018 {
2019         int ret = CAMERA_ERROR_NONE;
2020         int api = -1;
2021         int api_class = -1;
2022         int event = -1;
2023         int event_class = -1;
2024         int get_type = -1;
2025         int get_index = -1;
2026
2027         if (!cb_info || !msg) {
2028                 CAM_LOG_ERROR("invalid ptr %p %p", cb_info, msg);
2029                 return;
2030         }
2031
2032         CAM_LOG_DEBUG("msg[%s]", msg);
2033
2034         if (!muse_camera_msg_get(api, msg)) {
2035                 CAM_LOG_ERROR("failed to get camera api");
2036                 return;
2037         }
2038
2039         if (api == MUSE_CAMERA_CB_EVENT) {
2040                 if (!muse_camera_msg_get(event, msg) ||
2041                         !muse_camera_msg_get(event_class, msg)) {
2042                         CAM_LOG_ERROR("failed to get camera event or event_class [%s]", msg);
2043                         return;
2044                 }
2045         } else {
2046                 if (!muse_camera_msg_get(api_class, msg)) {
2047                         CAM_LOG_ERROR("failed to get camera api_class [%s]", msg);
2048                         return;
2049                 }
2050         }
2051
2052         if (api_class == MUSE_CAMERA_API_CLASS_IMMEDIATE) {
2053                 if (api >= MUSE_CAMERA_API_MAX) {
2054                         CAM_LOG_ERROR("invalid api %d", api);
2055                         return;
2056                 }
2057
2058                 if (!muse_camera_msg_get(ret, msg)) {
2059                         CAM_LOG_ERROR("failed to get camera ret");
2060                         return;
2061                 }
2062
2063                 g_mutex_lock(&cb_info->api_mutex[api]);
2064
2065                 switch (api) {
2066                 case MUSE_CAMERA_API_CREATE:
2067                         if (ret != CAMERA_ERROR_NONE) {
2068                                 g_atomic_int_set(&cb_info->msg_recv_running, 0);
2069                                 CAM_LOG_ERROR("camera create error 0x%x. close client cb handler", ret);
2070                         }
2071                         break;
2072                 case MUSE_CAMERA_API_DESTROY:
2073                         if (ret == CAMERA_ERROR_NONE) {
2074                                 g_atomic_int_set(&cb_info->msg_recv_running, 0);
2075                                 CAM_LOG_INFO("camera destroy done. close client cb handler");
2076                         }
2077                         break;
2078                 default:
2079                         muse_camera_msg_get(get_type, msg);
2080                         if (get_type != MUSE_CAMERA_GET_TYPE_NONE) {
2081                                 if (get_type != MUSE_CAMERA_GET_TYPE_ARRAY)
2082                                         muse_camera_msg_get(get_index, msg);
2083
2084                                 switch (get_type) {
2085                                 case MUSE_CAMERA_GET_TYPE_INT:
2086                                         muse_core_msg_deserialize("get_value", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int[get_index]);
2087                                         break;
2088                                 case MUSE_CAMERA_GET_TYPE_INT_PAIR:
2089                                         muse_core_msg_deserialize("get_value0", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int_pair[get_index][0]);
2090                                         muse_core_msg_deserialize("get_value1", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int_pair[get_index][1]);
2091                                         break;
2092                                 case MUSE_CAMERA_GET_TYPE_ARRAY:
2093                                         switch (api) {
2094                                         case MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA:
2095                                                 muse_core_msg_deserialize("get_value",
2096                                                         msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_display_roi_area);
2097                                                 CAM_LOG_INFO("get display roi %d,%d,%dx%d",
2098                                                         cb_info->get_display_roi_area[0],
2099                                                         cb_info->get_display_roi_area[1],
2100                                                         cb_info->get_display_roi_area[2],
2101                                                         cb_info->get_display_roi_area[3]);
2102                                                 break;
2103                                         case MUSE_CAMERA_API_ATTR_GET_GEOTAG:
2104                                                 muse_core_msg_deserialize("get_value",
2105                                                         msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_geotag);
2106                                                 CAM_LOG_INFO("get geotag %lf, %lf, %lf",
2107                                                         cb_info->get_geotag[0], cb_info->get_geotag[1], cb_info->get_geotag[2]);
2108                                                 break;
2109                                         case MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT:
2110                                                 muse_core_msg_deserialize("get_value",
2111                                                         msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_extra_preview_stream_format);
2112                                                 CAM_LOG_INFO("get extra preview stream format %d,%dx%d,%d",
2113                                                         cb_info->get_extra_preview_stream_format[0],
2114                                                         cb_info->get_extra_preview_stream_format[1],
2115                                                         cb_info->get_extra_preview_stream_format[2],
2116                                                         cb_info->get_extra_preview_stream_format[3]);
2117                                                 break;
2118                                         default:
2119                                                 CAM_LOG_WARNING("unknown api[%d]", api);
2120                                                 break;
2121                                         }
2122                                         break;
2123                                 case MUSE_CAMERA_GET_TYPE_STRING:
2124                                         muse_core_msg_deserialize("get_value", msg, NULL, NULL, MUSE_TYPE_STRING, cb_info->get_string[get_index]);
2125                                         break;
2126                                 default:
2127                                         CAM_LOG_WARNING("unknown type %d", get_type);
2128                                         break;
2129                                 }
2130                         }
2131                         break;
2132                 }
2133
2134                 if (cb_info->api_waiting[api] > 0) {
2135                         cb_info->api_ret[api] = ret;
2136                         cb_info->api_activating[api] = TRUE;
2137
2138                         g_cond_broadcast(&cb_info->api_cond[api]);
2139                 } else {
2140                         CAM_LOG_WARNING("no waiting for this api [%d]", api);
2141                 }
2142
2143                 g_mutex_unlock(&cb_info->api_mutex[api]);
2144         } else if (api_class == MUSE_CAMERA_API_CLASS_THREAD_SUB || api == MUSE_CAMERA_CB_EVENT) {
2145                 __camera_add_msg_to_queue(cb_info, api, event, event_class, msg, tfd);
2146         } else {
2147                 CAM_LOG_WARNING("unknown camera api %d, class %d", api, api_class);
2148         }
2149 }
2150
2151
2152 static gpointer __camera_msg_recv_func(gpointer data)
2153 {
2154         int i = 0;
2155         int recv_length = 0;
2156         int tfd[MUSE_NUM_FD] = {CAMERA_FD_INIT, CAMERA_FD_INIT, CAMERA_FD_INIT, CAMERA_FD_INIT};
2157         char *recv_msg = NULL;
2158         camera_cb_info_s *cb_info = (camera_cb_info_s *)data;
2159
2160         if (!cb_info) {
2161                 CAM_LOG_ERROR("cb_info NULL");
2162                 return NULL;
2163         }
2164
2165         CAM_LOG_INFO("start - fd : %d", cb_info->fd);
2166
2167         recv_msg = cb_info->recv_msg;
2168
2169         while (g_atomic_int_get(&cb_info->msg_recv_running)) {
2170                 for (i = 0 ; i < MUSE_NUM_FD ; i++)
2171                         tfd[i] = CAMERA_FD_INIT;
2172
2173                 recv_length = muse_core_msg_recv_fd(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH, tfd);
2174                 if (recv_length <= 0) {
2175                         cb_info->is_server_connected = FALSE;
2176                         CAM_LOG_ERROR("receive msg failed - server disconnected");
2177                         break;
2178                 }
2179
2180                 if (CAMERA_IS_FD_VALID(tfd[0]))
2181                         CAM_LOG_DEBUG("tfd[%d/%d/%d/%d]", tfd[0], tfd[1], tfd[2], tfd[3]);
2182
2183                 recv_msg[recv_length] = '\0';
2184
2185                 CAM_LOG_VERBOSE("recv msg[%s], length[%d]", recv_msg, recv_length);
2186
2187                 __camera_process_msg(cb_info, recv_msg, tfd);
2188         }
2189
2190         CAM_LOG_INFO("client cb exit - server connected %d", cb_info->is_server_connected);
2191
2192 //LCOV_EXCL_START
2193         if (!cb_info->is_server_connected) {
2194                 char *error_msg = NULL;
2195
2196                 if (cb_info->bufmgr == NULL) {
2197                         CAM_LOG_ERROR("No need to send error(handle is not created)");
2198                         return NULL;
2199                 }
2200
2201                 if (cb_info->fd < 0) {
2202                         CAM_LOG_ERROR("fd is closed in client side");
2203                         return NULL;
2204                 }
2205
2206                 /* send error msg for server disconnection */
2207                 error_msg = muse_core_msg_new(MUSE_CAMERA_CB_EVENT,
2208                         MUSE_TYPE_INT, "error", CAMERA_ERROR_SERVICE_DISCONNECTED,
2209                         MUSE_TYPE_INT, "current_state", CAMERA_STATE_NONE,
2210                         NULL);
2211
2212                 if (!error_msg) {
2213                         CAM_LOG_ERROR("error_msg failed");
2214                         return NULL;
2215                 }
2216
2217                 __camera_add_msg_to_queue(cb_info,
2218                         MUSE_CAMERA_CB_EVENT,
2219                         MUSE_CAMERA_EVENT_TYPE_ERROR,
2220                         MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
2221                         error_msg,
2222                         NULL);
2223
2224                 muse_core_msg_free(error_msg);
2225                 error_msg = NULL;
2226
2227                 for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2228                         if (cb_info->api_waiting[i])
2229                                 g_cond_broadcast(&cb_info->api_cond[i]);
2230                 }
2231
2232                 CAM_LOG_ERROR("add error msg for service disconnection done");
2233         }
2234 //LCOV_EXCL_STOP
2235
2236         return NULL;
2237 }
2238
2239
2240 static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
2241         int type, const char *thread_name, camera_cb_info_s *cb_info)
2242 {
2243         if (!handler_info || !thread_name || !cb_info) {
2244                 CAM_LOG_ERROR("t:%d NULL %p %p %p",
2245                         type, handler_info, thread_name, cb_info);
2246                 return false;
2247         }
2248
2249         g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&handler_info->mutex);
2250
2251         if (handler_info->thread) {
2252                 CAM_LOG_WARNING("t:%d thread[%p] is already created", type, handler_info->thread);
2253                 return true;
2254         }
2255
2256         CAM_LOG_INFO("t:%d [%s]", type, thread_name);
2257
2258         handler_info->type = type;
2259         handler_info->queue = g_queue_new();
2260         if (handler_info->queue == NULL) {
2261                 CAM_LOG_ERROR("t:%d queue failed", type);
2262                 return false;
2263         }
2264
2265         handler_info->cb_info = (void *)cb_info;
2266         g_atomic_int_set(&handler_info->running, 1);
2267
2268         handler_info->thread = g_thread_try_new(thread_name,
2269                 __camera_msg_handler_func, (gpointer)handler_info, NULL);
2270         if (handler_info->thread == NULL) {
2271                 CAM_LOG_ERROR("t:%d thread failed", type);
2272
2273                 g_queue_free(handler_info->queue);
2274                 handler_info->queue = NULL;
2275
2276                 return false;
2277         }
2278
2279         CAM_LOG_INFO("t:%d done[thread:%p]", type, handler_info->thread);
2280
2281         return true;
2282 }
2283
2284
2285 static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info)
2286 {
2287         GThread *thread = NULL;
2288
2289         if (!handler_info) {
2290                 CAM_LOG_ERROR("NULL handler");
2291                 return;
2292         }
2293
2294         g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&handler_info->mutex);
2295
2296         if (!handler_info->thread) {
2297                 CAM_LOG_WARNING("thread[t:%d] is not created", handler_info->type);
2298                 return;
2299         }
2300
2301         thread = handler_info->thread;
2302         handler_info->thread = NULL;
2303
2304         CAM_LOG_INFO("t:%d thread[%p]", handler_info->type, thread);
2305
2306         g_atomic_int_set(&handler_info->running, 0);
2307         g_cond_signal(&handler_info->cond);
2308
2309         g_clear_pointer(&locker, g_mutex_locker_free);
2310
2311         g_thread_join(thread);
2312
2313         g_queue_free(handler_info->queue);
2314         handler_info->queue = NULL;
2315
2316         CAM_LOG_INFO("t:%d done", handler_info->type);
2317 }
2318
2319
2320 static void __camera_mutex_cond_init(camera_cb_info_s *cb_info)
2321 {
2322         int i = 0;
2323
2324         if (!cb_info) {
2325                 CAM_LOG_ERROR("NULL cb_info");
2326                 return;
2327         }
2328
2329         for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2330                 g_mutex_init(&cb_info->api_mutex[i]);
2331                 g_cond_init(&cb_info->api_cond[i]);
2332         }
2333
2334         for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2335                 g_mutex_init(&cb_info->user_cb_mutex[i]);
2336
2337         g_mutex_init(&cb_info->fd_lock);
2338         g_mutex_init(&cb_info->mp_data_mutex);
2339         g_mutex_init(&cb_info->bridge_lock);
2340
2341         g_mutex_init(&cb_info->msg_handler_info.mutex);
2342         g_mutex_init(&cb_info->preview_cb_info.mutex);
2343         g_mutex_init(&cb_info->capture_cb_info.mutex);
2344         g_cond_init(&cb_info->msg_handler_info.cond);
2345         g_cond_init(&cb_info->preview_cb_info.cond);
2346         g_cond_init(&cb_info->capture_cb_info.cond);
2347
2348         CAM_LOG_INFO("done");
2349 }
2350
2351
2352 static void __camera_mutex_cond_clear(camera_cb_info_s *cb_info)
2353 {
2354         int i = 0;
2355
2356         if (!cb_info) {
2357                 CAM_LOG_ERROR("NULL cb_info");
2358                 return;
2359         }
2360
2361         g_mutex_clear(&cb_info->msg_handler_info.mutex);
2362         g_mutex_clear(&cb_info->preview_cb_info.mutex);
2363         g_mutex_clear(&cb_info->capture_cb_info.mutex);
2364         g_cond_clear(&cb_info->msg_handler_info.cond);
2365         g_cond_clear(&cb_info->preview_cb_info.cond);
2366         g_cond_clear(&cb_info->capture_cb_info.cond);
2367
2368         g_mutex_clear(&cb_info->fd_lock);
2369         g_mutex_clear(&cb_info->mp_data_mutex);
2370         g_mutex_clear(&cb_info->bridge_lock);
2371
2372         for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2373                 g_mutex_clear(&cb_info->user_cb_mutex[i]);
2374
2375         for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2376                 g_mutex_clear(&cb_info->api_mutex[i]);
2377                 g_cond_clear(&cb_info->api_cond[i]);
2378         }
2379
2380         CAM_LOG_INFO("done");
2381 }
2382
2383
2384 static camera_preview_cb_monitoring_info_s *__camera_preview_cb_monitoring_info_create(int stream_id)
2385 {
2386         camera_preview_cb_monitoring_info_s *new_info = g_new0(camera_preview_cb_monitoring_info_s, 1);
2387
2388         new_info->stream_id = stream_id;
2389         new_info->total = g_new0(monitoring_info_sub_s, 1);
2390         new_info->interval = g_new0(monitoring_info_sub_s, 1);
2391         new_info->timer_calling = g_timer_new();
2392         new_info->timer_interval = g_timer_new();
2393
2394         CAM_LOG_INFO("create preview cb monitoring info[%p]", new_info);
2395
2396         return new_info;
2397 }
2398
2399
2400 static void __camera_preview_cb_monitoring_info_destroy(camera_preview_cb_monitoring_info_s *info)
2401 {
2402         if (!info)
2403                 return;
2404
2405         g_timer_destroy(info->timer_calling);
2406         g_timer_destroy(info->timer_interval);
2407         g_free(info->total);
2408         g_free(info->interval);
2409
2410         CAM_LOG_INFO("destroy preview cb monitoring info[%p]", info);
2411
2412         g_free(info);
2413 }
2414
2415
2416 static camera_cb_info_s *__camera_client_callback_new(gint sockfd)
2417 {
2418         int i = 0;
2419         camera_cb_info_s *cb_info = NULL;
2420
2421         g_return_val_if_fail(sockfd > 0, NULL);
2422
2423         cb_info = g_new0(camera_cb_info_s, 1);
2424         if (!cb_info) {
2425                 CAM_LOG_ERROR("cb_info failed");
2426                 goto ErrorExit;
2427         }
2428
2429         cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 1;
2430
2431         __camera_mutex_cond_init(cb_info);
2432
2433         /* message handler thread */
2434         if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
2435                         CAMERA_MESSAGE_HANDLER_TYPE_GENERAL, "cam:msg_handler", cb_info)) {
2436                 CAM_LOG_ERROR("msg_handler_info failed");
2437                 goto ErrorExit;
2438         }
2439
2440         /* message handler thread for capture callback */
2441         if (!__create_msg_handler_thread(&cb_info->capture_cb_info,
2442                         CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB, "cam:capture_cb", cb_info)) {
2443                 CAM_LOG_ERROR("capture_cb_info failed");
2444                 goto ErrorExit;
2445         }
2446
2447         cb_info->fd = sockfd;
2448
2449         /* message receive thread */
2450         g_atomic_int_set(&cb_info->msg_recv_running, 1);
2451         cb_info->msg_recv_thread = g_thread_try_new("cam:msg_recv",
2452                 __camera_msg_recv_func, (gpointer)cb_info, NULL);
2453         if (cb_info->msg_recv_thread == NULL) {
2454                 CAM_LOG_ERROR("message receive thread creation failed");
2455                 goto ErrorExit;
2456         }
2457
2458         /* initialize fd */
2459         for (i = 0 ; i < MUSE_NUM_FD ; i++)
2460                 cb_info->fds[i] = CAMERA_FD_INIT;
2461
2462         cb_info->is_server_connected = TRUE;
2463
2464         cb_info->monitoring_info_preview = __camera_preview_cb_monitoring_info_create(CAMERA_MONITORING_INFO_STREAM_ID_PREVIEW);
2465         cb_info->monitoring_info_preview_mp = __camera_preview_cb_monitoring_info_create(CAMERA_MONITORING_INFO_STREAM_ID_PREVIEW_MP);
2466         for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_MAX ; i++)
2467                 cb_info->monitoring_info_preview_ex[i] = __camera_preview_cb_monitoring_info_create(i);
2468
2469         return cb_info;
2470 //LCOV_EXCL_START
2471 ErrorExit:
2472         if (cb_info) {
2473                 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
2474                 __destroy_msg_handler_thread(&cb_info->capture_cb_info);
2475
2476                 __camera_mutex_cond_clear(cb_info);
2477
2478                 g_free(cb_info);
2479                 cb_info = NULL;
2480         }
2481
2482         return NULL;
2483 //LCOV_EXCL_STOP
2484 }
2485
2486
2487 static void __camera_client_callback_destroy(camera_cb_info_s *cb_info)
2488 {
2489         int i = 0;
2490
2491         if (!cb_info) {
2492                 CAM_LOG_ERROR("NULL cb_info");
2493                 return;
2494         }
2495
2496         CAM_LOG_INFO("msg_recv thread[%p] destroy", cb_info->msg_recv_thread);
2497
2498         g_thread_join(cb_info->msg_recv_thread);
2499         cb_info->msg_recv_thread = NULL;
2500
2501         CAM_LOG_INFO("msg_recv thread removed");
2502
2503         /* destroy msg handler threads */
2504         __destroy_msg_handler_thread(&cb_info->preview_cb_info);
2505         __destroy_msg_handler_thread(&cb_info->msg_handler_info);
2506         __destroy_msg_handler_thread(&cb_info->capture_cb_info);
2507
2508         __camera_mutex_cond_clear(cb_info);
2509
2510         if (CAMERA_IS_FD_VALID(cb_info->fd)) {
2511                 muse_client_close(cb_info->fd);
2512                 cb_info->fd = CAMERA_FD_INIT;
2513         }
2514
2515         if (cb_info->bufmgr) {
2516                 tbm_bufmgr_deinit(cb_info->bufmgr);
2517                 cb_info->bufmgr = NULL;
2518         }
2519         if (cb_info->pkt_fmt) {
2520                 media_format_unref(cb_info->pkt_fmt);
2521                 cb_info->pkt_fmt = NULL;
2522         }
2523
2524         if (cb_info->dp_interface) {
2525                 mm_display_interface_deinit(cb_info->dp_interface);
2526                 cb_info->dp_interface = NULL;
2527         }
2528
2529         __camera_preview_cb_monitoring_info_destroy(cb_info->monitoring_info_preview);
2530         __camera_preview_cb_monitoring_info_destroy(cb_info->monitoring_info_preview_mp);
2531         for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_MAX ; i++)
2532                 __camera_preview_cb_monitoring_info_destroy(cb_info->monitoring_info_preview_ex[i]);
2533
2534         g_free(cb_info);
2535 }
2536
2537 //LCOV_EXCL_START
2538 int _camera_start_evas_rendering(camera_h camera)
2539 {
2540         camera_cli_s *pc = (camera_cli_s *)camera;
2541
2542         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2543
2544         CAM_LOG_INFO("start");
2545
2546         if (!pc->cb_info->is_evas_render) {
2547                 CAM_LOG_ERROR("EVAS surface is not set");
2548                 return CAMERA_ERROR_NONE;
2549         }
2550
2551         /* set evas render flag as RUN */
2552         pc->cb_info->run_evas_render = true;
2553
2554         return CAMERA_ERROR_NONE;
2555 }
2556
2557
2558 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen)
2559 {
2560         int ret = CAMERA_ERROR_NONE;
2561         camera_cli_s *pc = (camera_cli_s *)camera;
2562
2563         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2564
2565         CAM_LOG_INFO("stop - keep screen %d", keep_screen);
2566
2567         if (!pc->cb_info->is_evas_render) {
2568                 CAM_LOG_ERROR("EVAS surface is not set");
2569                 return CAMERA_ERROR_NONE;
2570         }
2571
2572         /* set evas render flag as STOP and release buffers */
2573         pc->cb_info->run_evas_render = false;
2574
2575         ret = mm_display_interface_evas_flush(pc->cb_info->dp_interface, keep_screen);
2576         if (ret == MM_ERROR_NONE) {
2577                 ret = CAMERA_ERROR_NONE;
2578         } else {
2579                 CAM_LOG_ERROR("mm_evas_renderer_retrieve_all_packets failed 0x%x", ret);
2580                 ret = CAMERA_ERROR_INVALID_OPERATION;
2581         }
2582
2583         return ret;
2584 }
2585 //LCOV_EXCL_STOP
2586
2587 int _camera_independent_request(int api, int device_type, const char *key, int *value)
2588 {
2589         int ret = CAMERA_ERROR_NONE;
2590         int sock_fd = CAMERA_FD_INIT;
2591         int module_index = -1;
2592         char *msg = NULL;
2593         char recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH] = {'\0',};
2594
2595         /* create muse connection */
2596         if (!key || !value) {
2597                 CAM_LOG_ERROR("NULL pointer");
2598                 return CAMERA_ERROR_INVALID_PARAMETER;
2599         }
2600
2601         sock_fd = muse_client_new();
2602         if (sock_fd < 0) {
2603                 CAM_LOG_ERROR("muse_client_new failed");
2604                 return CAMERA_ERROR_INVALID_OPERATION;
2605         }
2606
2607         if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2608                 CAM_LOG_ERROR("muse client get module index failed");
2609                 ret = CAMERA_ERROR_INVALID_OPERATION;
2610                 goto _REQUEST_EXIT;
2611         }
2612
2613         msg = muse_core_msg_new(api,
2614                 MUSE_TYPE_INT, "module", module_index,
2615                 MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
2616                 0);
2617         if (!msg) {
2618                 CAM_LOG_ERROR("msg failed");
2619                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2620                 goto _REQUEST_EXIT;
2621         }
2622
2623         ret = muse_core_msg_send(sock_fd, msg);
2624
2625         muse_core_msg_free(msg);
2626         msg = NULL;
2627
2628         if (ret < 0) {
2629                 CAM_LOG_ERROR("send msg failed");
2630                 ret = CAMERA_ERROR_INVALID_OPERATION;
2631                 goto _REQUEST_EXIT;
2632         }
2633
2634         ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_CAMERA_MSG_MAX_LENGTH);
2635         if (ret <= 0) {
2636                 CAM_LOG_ERROR("recv msg failed %d", errno);
2637                 ret = CAMERA_ERROR_INVALID_OPERATION;
2638                 goto _REQUEST_EXIT;
2639         }
2640
2641         if (!muse_camera_msg_get(ret, recv_msg)) {
2642                 CAM_LOG_ERROR("failed to get return value from msg [%s]", recv_msg);
2643                 ret = CAMERA_ERROR_INVALID_OPERATION;
2644                 goto _REQUEST_EXIT;
2645         }
2646
2647         if (ret == CAMERA_ERROR_NONE)
2648                 muse_core_msg_deserialize(key, recv_msg, NULL, NULL, MUSE_TYPE_ANY, value);
2649
2650         CAM_LOG_INFO("api %d - value %d", api, *value);
2651
2652 _REQUEST_EXIT:
2653         if (CAMERA_IS_FD_VALID(sock_fd)) {
2654                 muse_client_close(sock_fd);
2655                 sock_fd = CAMERA_FD_INIT;
2656         }
2657
2658         return ret;
2659 }
2660
2661
2662 int _camera_create_private(camera_device_e device, bool is_network, camera_h *camera)
2663 {
2664         int sock_fd = CAMERA_FD_INIT;
2665         char *send_msg = NULL;
2666         int send_ret = 0;
2667         int ret = CAMERA_ERROR_NONE;
2668         camera_cli_s *pc = NULL;
2669         tbm_bufmgr bufmgr = NULL;
2670
2671         muse_camera_api_e api = MUSE_CAMERA_API_CREATE;
2672         int module_index = -1;
2673         int device_type = (int)device;
2674
2675         CAM_LOG_INFO("device %d, is_network %d", device, is_network);
2676
2677         sock_fd = muse_client_new();
2678         if (sock_fd < 0) {
2679                 CAM_LOG_ERROR("muse_client_new failed - returned fd %d", sock_fd);
2680                 ret = CAMERA_ERROR_INVALID_OPERATION;
2681                 goto ErrorExit;
2682         }
2683
2684         if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2685                 CAM_LOG_ERROR("muse client get module index failed");
2686                 ret = CAMERA_ERROR_INVALID_OPERATION;
2687                 goto ErrorExit;
2688         }
2689
2690         send_msg = muse_core_msg_new(api,
2691                 MUSE_TYPE_INT, "module", module_index,
2692                 MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
2693                 MUSE_TYPE_INT, "is_network", (int)is_network,
2694                 0);
2695
2696         if (!send_msg) {
2697                 CAM_LOG_ERROR("NULL msg");
2698                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2699                 goto ErrorExit;
2700         }
2701
2702         send_ret = muse_core_msg_send(sock_fd, send_msg);
2703
2704         muse_core_msg_free(send_msg);
2705         send_msg = NULL;
2706
2707         if (send_ret < 0) {
2708                 CAM_LOG_ERROR("send msg failed %d", errno);
2709                 ret = CAMERA_ERROR_INVALID_OPERATION;
2710                 goto ErrorExit;
2711         }
2712
2713         pc = g_new0(camera_cli_s, 1);
2714         if (pc == NULL) {
2715                 CAM_LOG_ERROR("camera_cli_s alloc failed");
2716                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2717                 goto ErrorExit;
2718         }
2719
2720         bufmgr = tbm_bufmgr_init(-1);
2721         if (bufmgr == NULL) {
2722                 CAM_LOG_ERROR("get tbm bufmgr failed");
2723                 ret = CAMERA_ERROR_INVALID_OPERATION;
2724                 goto ErrorExit;
2725         }
2726
2727         pc->cb_info = __camera_client_callback_new(sock_fd);
2728         if (pc->cb_info == NULL) {
2729                 CAM_LOG_ERROR("cb_info alloc failed");
2730                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2731                 goto ErrorExit;
2732         }
2733
2734         sock_fd = CAMERA_FD_INIT;
2735
2736         CAM_LOG_INFO("cb info : %d", pc->cb_info->fd);
2737
2738         ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
2739
2740         pc->cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 0;
2741
2742         if (ret == CAMERA_ERROR_NONE) {
2743                 int preview_format = CAMERA_PIXEL_FORMAT_INVALID;
2744                 int user_buffer_supported = 0;
2745                 int log_level = CAMERA_LOG_LEVEL_INFO;
2746                 intptr_t handle = 0;
2747
2748                 muse_camera_msg_get_pointer(handle, pc->cb_info->recv_msg);
2749                 if (handle == 0) {
2750                         CAM_LOG_ERROR("Receiving Handle Failed!!");
2751                         ret = CAMERA_ERROR_INVALID_OPERATION;
2752                         goto ErrorExit;
2753                 }
2754
2755                 muse_camera_msg_get(preview_format, pc->cb_info->recv_msg);
2756                 muse_camera_msg_get(user_buffer_supported, pc->cb_info->recv_msg);
2757                 muse_camera_msg_get(log_level, pc->cb_info->recv_msg);
2758
2759                 pc->remote_handle = handle;
2760                 pc->cb_info->bufmgr = bufmgr;
2761                 pc->cb_info->preview_format = preview_format;
2762                 pc->cb_info->dp_info.type = CAMERA_DISPLAY_TYPE_NONE;
2763                 pc->cb_info->user_buffer_supported = (gboolean)user_buffer_supported;
2764                 pc->cb_info->is_network = is_network;
2765                 g_camera_log_level = log_level;
2766
2767                 CAM_LOG_INFO("default preview format %d, user buffer %d, log level %d",
2768                         preview_format, user_buffer_supported, g_camera_log_level);
2769
2770                 if (!camera) {
2771                         CAM_LOG_ERROR("NULL out handle");
2772                         ret= CAMERA_ERROR_INVALID_PARAMETER;
2773                         goto ErrorExit;
2774                 }
2775
2776                 *camera = (camera_h)pc;
2777
2778                 /* get display interface handle */
2779                 if (mm_display_interface_init(&pc->cb_info->dp_interface) != MM_ERROR_NONE)
2780                         CAM_LOG_WARNING("display interface init failed");
2781         } else {
2782                 goto ErrorExit;
2783         }
2784
2785         return ret;
2786 //LCOV_EXCL_START
2787 ErrorExit:
2788         if (bufmgr) {
2789                 tbm_bufmgr_deinit(bufmgr);
2790                 bufmgr = NULL;
2791         }
2792
2793         if (CAMERA_IS_FD_VALID(sock_fd)) {
2794                 muse_client_close(sock_fd);
2795                 sock_fd = CAMERA_FD_INIT;
2796         }
2797
2798         if (pc) {
2799                 if (pc->cb_info) {
2800                         int temp_fd = pc->cb_info->fd;
2801
2802                         /* pc->cb_info->fd should be closed,
2803                            because g_thread_join for msg_recv_thread is not returned
2804                            in __camera_client_callback_destroy. */
2805                         if (CAMERA_IS_FD_VALID(temp_fd)) {
2806                                 pc->cb_info->fd = CAMERA_FD_INIT;
2807                                 muse_client_close(temp_fd);
2808                         }
2809
2810                         __camera_client_callback_destroy(pc->cb_info);
2811                         pc->cb_info = NULL;
2812                 }
2813                 g_free(pc);
2814                 pc = NULL;
2815         }
2816
2817         CAM_LOG_ERROR("camera create error : 0x%x", ret);
2818
2819         return ret;
2820 //LCOV_EXCL_STOP
2821 }
2822
2823
2824 int camera_create(camera_device_e device, camera_h *camera)
2825 {
2826         return _camera_create_private(device, false, camera);
2827 }
2828
2829
2830 int camera_change_device(camera_h camera, camera_device_e device)
2831 {
2832         int i = 0;
2833         int ret = CAMERA_ERROR_NONE;
2834         muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
2835         camera_cli_s *pc = (camera_cli_s *)camera;
2836         camera_msg_param param;
2837
2838         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2839
2840         CAMERA_MSG_PARAM_SET(param, INT, device);
2841
2842         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2843
2844         if (ret == CAMERA_ERROR_NONE) {
2845                 /* reset callback and user data */
2846                 for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) {
2847                         pc->cb_info->user_cb[i] = NULL;
2848                         pc->cb_info->user_data[i] = NULL;
2849                 }
2850         }
2851
2852         return ret;
2853 }
2854
2855
2856 int camera_destroy(camera_h camera)
2857 {
2858         int ret = CAMERA_ERROR_NONE;
2859         muse_camera_api_e api = MUSE_CAMERA_API_DESTROY;
2860         camera_cli_s *pc = (camera_cli_s *)camera;
2861
2862         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2863
2864         CAM_LOG_INFO("Enter");
2865
2866         if (pc->cb_info->is_server_connected)
2867                 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2868         else
2869                 CAM_LOG_WARNING("server disconnected. release resource without send message.");
2870
2871         if (ret == CAMERA_ERROR_NONE) {
2872                 __camera_deactivate_idle_event_all(pc->cb_info);
2873                 __camera_client_callback_destroy(pc->cb_info);
2874                 pc->cb_info = NULL;
2875
2876                 g_free(pc);
2877                 pc = NULL;
2878         }
2879
2880         CAM_LOG_INFO("ret : 0x%x", ret);
2881
2882         return ret;
2883 }
2884
2885 int camera_start_preview(camera_h camera)
2886 {
2887         int i = 0;
2888         int ret = CAMERA_ERROR_NONE;
2889         int *fds = NULL;
2890         muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
2891         camera_cli_s *pc = (camera_cli_s *)camera;
2892         camera_state_e current_state = CAMERA_STATE_NONE;
2893
2894         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2895
2896         CAM_LOG_INFO("Enter : preview format %d, display type %d",
2897                 pc->cb_info->preview_format, pc->cb_info->dp_info.type);
2898
2899         if (pc->cb_info->preview_format == CAMERA_PIXEL_FORMAT_INVZ &&
2900                 pc->cb_info->dp_info.type != CAMERA_DISPLAY_TYPE_NONE) {
2901                 CAM_LOG_ERROR("CAMERA_DISPLAY_TYPE_NONE[current %d] should be set with INVZ format",
2902                         pc->cb_info->dp_info.type);
2903                 return CAMERA_ERROR_INVALID_OPERATION;
2904         }
2905
2906         ret = camera_get_state(camera, &current_state);
2907         if (ret != CAMERA_ERROR_NONE) {
2908                 CAM_LOG_ERROR("failed to get current state 0x%x", ret);
2909                 return ret;
2910         }
2911
2912         if (current_state == CAMERA_STATE_CREATED) {
2913                 __camera_preview_cb_monitoring_info_reset(pc->cb_info->monitoring_info_preview);
2914                 __camera_preview_cb_monitoring_info_reset(pc->cb_info->monitoring_info_preview_mp);
2915                 for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_MAX ; i++)
2916                         __camera_preview_cb_monitoring_info_reset(pc->cb_info->monitoring_info_preview_ex[i]);
2917
2918                 if (!__create_msg_handler_thread(&pc->cb_info->preview_cb_info,
2919                                 CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "cam:preview_cb", pc->cb_info)) {
2920                         CAM_LOG_ERROR("preview_cb_info failed");
2921                         return CAMERA_ERROR_INVALID_OPERATION;
2922                 }
2923
2924                 if (pc->cb_info->user_buffer_supported) {
2925                         if (!__camera_allocate_preview_buffer(camera)) {
2926                                 ret = CAMERA_ERROR_INVALID_OPERATION;
2927                                 goto _START_FAILED;
2928                         }
2929
2930                         fds = pc->cb_info->fds;
2931                 }
2932         }
2933
2934         pc->cb_info->invoke_preview_cb = TRUE;
2935
2936         _camera_msg_send(api, fds, pc->cb_info, &ret,
2937 #ifdef TIZEN_FEATURE_NO_TIMEOUT_FOR_PREVIEW
2938                 CAMERA_CB_NO_TIMEOUT);
2939 #else
2940                 CAMERA_CB_TIMEOUT_FOR_PREVIEW);
2941 #endif
2942         if (ret != CAMERA_ERROR_NONE)
2943                 goto _START_FAILED;
2944
2945         if (pc->cb_info->is_evas_render) {
2946                 ret = _camera_start_evas_rendering(camera);
2947                 if (ret != CAMERA_ERROR_NONE) {
2948                         CAM_LOG_ERROR("stop preview because of error");
2949                         _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
2950                         goto _START_FAILED;
2951                 }
2952         }
2953
2954         CAM_LOG_INFO("done");
2955
2956         return CAMERA_ERROR_NONE;
2957
2958 _START_FAILED:
2959         if (current_state == CAMERA_STATE_CREATED) {
2960                 if (pc->cb_info->user_buffer_supported)
2961                         __camera_release_preview_buffer(camera);
2962
2963                 __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
2964         }
2965
2966         CAM_LOG_ERROR("failed : 0x%x", ret);
2967
2968         return ret;
2969 }
2970
2971
2972 int camera_stop_preview(camera_h camera)
2973 {
2974         int ret = CAMERA_ERROR_NONE;
2975         camera_cli_s *pc = (camera_cli_s *)camera;
2976         muse_camera_api_e api = MUSE_CAMERA_API_STOP_PREVIEW;
2977         camera_state_e current_state = CAMERA_STATE_NONE;
2978
2979         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
2980
2981         CAM_LOG_INFO("Enter");
2982
2983 //LCOV_EXCL_START
2984         if (pc->cb_info->is_evas_render) {
2985                 ret = camera_get_state(camera, &current_state);
2986                 if (ret != CAMERA_ERROR_NONE) {
2987                         CAM_LOG_ERROR("failed to get current state 0x%x", ret);
2988                         return ret;
2989                 }
2990
2991                 if (current_state == CAMERA_STATE_PREVIEW) {
2992                         ret = _camera_stop_evas_rendering(camera, false);
2993                         if (ret != CAMERA_ERROR_NONE)
2994                                 return ret;
2995                 }
2996         }
2997 //LCOV_EXCL_STOP
2998
2999         pc->cb_info->invoke_preview_cb = FALSE;
3000
3001         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3002
3003         if (ret == CAMERA_ERROR_NONE) {
3004                 if (pc->cb_info->user_buffer_supported)
3005                         __camera_release_preview_buffer(camera);
3006
3007                 /* release remained message for preview callback */
3008                 __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
3009         } else if (current_state == CAMERA_STATE_PREVIEW) {
3010                 CAM_LOG_WARNING("restart evas rendering");
3011                 _camera_start_evas_rendering(camera);
3012         }
3013
3014         CAM_LOG_INFO("ret : 0x%x", ret);
3015
3016         return ret;
3017 }
3018
3019
3020 int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data)
3021 {
3022         int ret = CAMERA_ERROR_NONE;
3023         camera_cli_s *pc = (camera_cli_s *)camera;
3024         muse_camera_api_e api = MUSE_CAMERA_API_START_CAPTURE;
3025
3026         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3027
3028         CAM_LOG_INFO("Enter");
3029
3030         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
3031         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
3032
3033         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
3034         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
3035
3036         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3037
3038         CAM_LOG_INFO("ret : 0x%x", ret);
3039
3040         return ret;
3041 }
3042
3043
3044 bool camera_is_supported_continuous_capture(camera_h camera)
3045 {
3046         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE);
3047 }
3048
3049
3050 int camera_start_continuous_capture(camera_h camera, int count, int interval, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data)
3051 {
3052         int ret = CAMERA_ERROR_NONE;
3053         camera_cli_s *pc = (camera_cli_s *)camera;
3054         muse_camera_api_e api = MUSE_CAMERA_API_START_CONTINUOUS_CAPTURE;
3055         camera_msg_param param;
3056         int value = 0;
3057
3058         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3059
3060         CAM_LOG_INFO("Enter");
3061
3062         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
3063         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
3064
3065         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
3066         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
3067
3068         value = (count << 16) | interval;
3069         CAMERA_MSG_PARAM_SET(param, INT, value);
3070
3071         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3072
3073         CAM_LOG_INFO("ret : 0x%x", ret);
3074
3075         return ret;
3076 }
3077
3078
3079 int camera_stop_continuous_capture(camera_h camera)
3080 {
3081         int ret = CAMERA_ERROR_NONE;
3082         camera_cli_s *pc = (camera_cli_s *)camera;
3083         muse_camera_api_e api = MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE;
3084
3085         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3086
3087         CAM_LOG_INFO("Enter");
3088
3089         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3090
3091         CAM_LOG_INFO("ret : 0x%x", ret);
3092
3093         return ret;
3094 }
3095
3096
3097 bool camera_is_supported_face_detection(camera_h camera)
3098 {
3099         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_FACE_DETECTION);
3100 }
3101
3102
3103 bool camera_is_supported_zero_shutter_lag(camera_h camera)
3104 {
3105         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG);
3106 }
3107
3108
3109 bool camera_is_supported_media_packet_preview_cb(camera_h camera)
3110 {
3111         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB);
3112 }
3113
3114
3115 bool camera_is_supported_extra_preview(camera_h camera)
3116 {
3117         return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_EXTRA_PREVIEW);
3118 }
3119
3120
3121 int camera_get_device_count(camera_h camera, int *device_count)
3122 {
3123         int ret = CAMERA_ERROR_NONE;
3124         camera_cli_s *pc = (camera_cli_s *)camera;
3125         muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
3126
3127         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3128
3129         CAM_LOG_INFO("Enter");
3130
3131         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3132
3133         if (ret == CAMERA_ERROR_NONE)
3134                 *device_count = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DEVICE_COUNT];
3135
3136         CAM_LOG_INFO("ret : 0x%x", ret);
3137
3138         return ret;
3139 }
3140
3141 int camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void *user_data)
3142 {
3143         int ret = CAMERA_ERROR_NONE;
3144         camera_cli_s *pc = (camera_cli_s *)camera;
3145         muse_camera_api_e api = MUSE_CAMERA_API_START_FACE_DETECTION;
3146
3147         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3148
3149         CAM_LOG_INFO("Enter");
3150
3151         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3152
3153         if (ret == CAMERA_ERROR_NONE) {
3154                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3155
3156                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = callback;
3157                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = user_data;
3158
3159                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3160         }
3161
3162         CAM_LOG_INFO("ret : 0x%x", ret);
3163
3164         return ret;
3165 }
3166
3167 int camera_stop_face_detection(camera_h camera)
3168 {
3169         int ret = CAMERA_ERROR_NONE;
3170         camera_cli_s *pc = (camera_cli_s *)camera;
3171         muse_camera_api_e api = MUSE_CAMERA_API_STOP_FACE_DETECTION;
3172
3173         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3174
3175         CAM_LOG_INFO("Enter");
3176
3177         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3178
3179         if (ret == CAMERA_ERROR_NONE) {
3180                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3181
3182                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
3183                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
3184
3185                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3186         }
3187
3188         CAM_LOG_INFO("ret : 0x%x", ret);
3189
3190         return ret;
3191 }
3192
3193 int camera_get_state(camera_h camera, camera_state_e *state)
3194 {
3195         int ret = CAMERA_ERROR_NONE;
3196         camera_cli_s *pc = (camera_cli_s *)camera;
3197         muse_camera_api_e api = MUSE_CAMERA_API_GET_STATE;
3198
3199         if (!pc || !pc->cb_info || !state) {
3200                 CAM_LOG_ERROR("NULL pointer %p %p", pc, state);
3201                 return CAMERA_ERROR_INVALID_PARAMETER;
3202         }
3203
3204         CAM_LOG_INFO("Enter");
3205
3206         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3207
3208         if (ret == CAMERA_ERROR_NONE)
3209                 *state = (camera_state_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STATE];
3210
3211         CAM_LOG_INFO("ret : 0x%x", ret);
3212
3213         return ret;
3214 }
3215
3216 int camera_start_focusing(camera_h camera, bool continuous)
3217 {
3218         int ret = CAMERA_ERROR_NONE;
3219         camera_cli_s *pc = (camera_cli_s *)camera;
3220         muse_camera_api_e api = MUSE_CAMERA_API_START_FOCUSING;
3221         camera_msg_param param;
3222         int is_continuous = (int)continuous;
3223
3224         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3225
3226         CAM_LOG_INFO("Enter");
3227
3228         CAMERA_MSG_PARAM_SET(param, INT, is_continuous);
3229
3230         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3231
3232         CAM_LOG_INFO("ret : 0x%x", ret);
3233
3234         return ret;
3235 }
3236
3237 int camera_cancel_focusing(camera_h camera)
3238 {
3239         int ret = CAMERA_ERROR_NONE;
3240         camera_cli_s *pc = (camera_cli_s *)camera;
3241         muse_camera_api_e api = MUSE_CAMERA_API_CANCEL_FOCUSING;
3242
3243         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3244
3245         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
3246
3247         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3248
3249         CAM_LOG_INFO("ret : 0x%x", ret);
3250
3251         return ret;
3252 }
3253
3254
3255 int _camera_set_display(camera_h camera, mm_display_type_e type, void *display)
3256 {
3257         int mm_ret = MM_ERROR_NONE;
3258         int ret = CAMERA_ERROR_NONE;
3259         camera_cli_s *pc = (camera_cli_s *)camera;
3260         camera_cb_info_s *cb_info = NULL;
3261         camera_state_e current_state = CAMERA_STATE_NONE;
3262         camera_msg_param param;
3263         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY;
3264         muse_camera_display_info_s *dp_info = NULL;
3265
3266         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3267
3268         if (type > MM_DISPLAY_TYPE_OVERLAY_EXT) {
3269                 CAM_LOG_ERROR("invalid type %d", type);
3270                 return CAMERA_ERROR_INVALID_PARAMETER;
3271         }
3272
3273         if (type != MM_DISPLAY_TYPE_NONE && display == NULL) {
3274                 CAM_LOG_ERROR("display type[%d] is not NONE, but display handle is NULL", type);
3275                 return CAMERA_ERROR_INVALID_PARAMETER;
3276         }
3277
3278         cb_info = (camera_cb_info_s *)pc->cb_info;
3279         dp_info = &cb_info->dp_info;
3280
3281         ret = camera_get_state(camera, &current_state);
3282         if (ret != CAMERA_ERROR_NONE) {
3283                 CAM_LOG_ERROR("failed to get current state 0x%x", ret);
3284                 return ret;
3285         }
3286
3287         if (current_state != CAMERA_STATE_CREATED) {
3288                 CAM_LOG_ERROR("INVALID_STATE : current %d", current_state);
3289                 return CAMERA_ERROR_INVALID_STATE;
3290         }
3291
3292         CAM_LOG_INFO("Enter - type : %d, display : %p", type, display);
3293
3294         if (type != MM_DISPLAY_TYPE_NONE) {
3295                 /* check display interface handle */
3296                 if (!cb_info->dp_interface) {
3297                         CAM_LOG_ERROR("display interface not supported");
3298                         return CAMERA_ERROR_NOT_SUPPORTED;
3299                 }
3300
3301                 mm_ret = mm_display_interface_set_display(cb_info->dp_interface, type, display, &dp_info->parent_id);
3302                 if (mm_ret == (int)MM_ERROR_NOT_SUPPORT_API) {
3303                         CAM_LOG_ERROR("[NOT_SUPPORTED] type %d", type);
3304                         return CAMERA_ERROR_NOT_SUPPORTED;
3305                 } else if (mm_ret != MM_ERROR_NONE) {
3306                         CAM_LOG_ERROR("[INVALID_OPERATION] set display failed[0x%x]", mm_ret);
3307                         return CAMERA_ERROR_INVALID_OPERATION;
3308                 }
3309
3310                 if (type == MM_DISPLAY_TYPE_OVERLAY || type == MM_DISPLAY_TYPE_OVERLAY_EXT) {
3311                         mm_ret = mm_display_interface_get_window_rect(cb_info->dp_interface, &dp_info->window_rect);
3312
3313                         CAM_LOG_INFO("ret 0x%x, parent_id %d, window rect %d,%d,%dx%d",
3314                                 ret, dp_info->parent_id, dp_info->window_rect.x, dp_info->window_rect.y,
3315                                 dp_info->window_rect.width, dp_info->window_rect.height);
3316                 } else if (type == MM_DISPLAY_TYPE_EVAS) {
3317 //LCOV_EXCL_START
3318                         camera_flip_e flip = CAMERA_FLIP_NONE;
3319                         camera_display_mode_e mode = CAMERA_DISPLAY_MODE_LETTER_BOX;
3320                         camera_rotation_e rotation = CAMERA_ROTATION_NONE;
3321                         bool visible = 0;
3322                         int x = 0;
3323                         int y = 0;
3324                         int width = 0;
3325                         int height = 0;
3326
3327                         camera_get_display_flip(camera, &flip);
3328                         camera_get_display_mode(camera, &mode);
3329                         camera_get_display_rotation(camera, &rotation);
3330                         camera_is_display_visible(camera, &visible);
3331
3332                         CAM_LOG_INFO("current setting : flip %d, mode %d, rotation %d, visible %d",
3333                                 flip, mode, rotation, visible);
3334
3335                         mm_ret = mm_display_interface_evas_set_flip(cb_info->dp_interface, flip);
3336                         mm_ret |= mm_display_interface_evas_set_mode(cb_info->dp_interface, mode);
3337                         mm_ret |= mm_display_interface_evas_set_rotation(cb_info->dp_interface, rotation);
3338                         mm_ret |= mm_display_interface_evas_set_visible(cb_info->dp_interface, visible);
3339
3340                         if (mode == CAMERA_DISPLAY_MODE_CUSTOM_ROI) {
3341                                 camera_attr_get_display_roi_area(camera, &x, &y, &width, &height);
3342                                 CAM_LOG_INFO("current setting : roi %d,%d,%dx%d", x, y, width, height);
3343                                 mm_ret |= mm_display_interface_evas_set_roi_area(cb_info->dp_interface, x, y, width, height);
3344                         }
3345 //LCOV_EXCL_STOP
3346                 }
3347         }
3348
3349         if (mm_ret != MM_ERROR_NONE) {
3350                 CAM_LOG_ERROR("mm_ret 0x%x failed", mm_ret);
3351                 return CAMERA_ERROR_INVALID_OPERATION;
3352         }
3353
3354         dp_info->type = type;
3355
3356         CAMERA_MSG_PARAM_SET_ARRAY(param, ARRAY, dp_info, sizeof(muse_camera_display_info_s));
3357
3358         _camera_msg_send_param1(api, cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3359
3360         if (ret == CAMERA_ERROR_NONE)
3361                 cb_info->is_evas_render = (type == MM_DISPLAY_TYPE_EVAS) ? TRUE : FALSE;
3362
3363         return ret;
3364 }
3365
3366
3367 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display)
3368 {
3369         CAM_LOG_INFO("type %d, display %p", type, display);
3370         return _camera_set_display(camera, (mm_display_type_e)type, display);
3371 }
3372
3373
3374 int camera_set_preview_resolution(camera_h camera, int width, int height)
3375 {
3376         int ret = CAMERA_ERROR_NONE;
3377         camera_state_e current_state = CAMERA_STATE_NONE;
3378         camera_cli_s *pc = (camera_cli_s *)camera;
3379         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
3380         camera_msg_param param;
3381         int value = 0;
3382
3383         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3384
3385         if (pc->cb_info->is_evas_render) {
3386                 ret = camera_get_state(camera, &current_state);
3387                 if (ret != CAMERA_ERROR_NONE) {
3388                         CAM_LOG_ERROR("failed to get current state 0x%x", ret);
3389                         return ret;
3390                 }
3391
3392                 if (current_state == CAMERA_STATE_PREVIEW) {
3393                         ret = _camera_stop_evas_rendering(camera, true);
3394                         if (ret != CAMERA_ERROR_NONE)
3395                                 return ret;
3396                 }
3397         }
3398
3399         value = (width << 16) | height;
3400         CAMERA_MSG_PARAM_SET(param, INT, value);
3401
3402         CAM_LOG_INFO("%dx%d -> 0x%x", width, height, value);
3403
3404         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3405
3406         CAM_LOG_INFO("ret : 0x%x", ret);
3407
3408         if (current_state == CAMERA_STATE_PREVIEW) {
3409                 CAM_LOG_WARNING("restart evas rendering");
3410                 _camera_start_evas_rendering(camera);
3411         }
3412
3413         return ret;
3414 }
3415
3416
3417 int camera_set_capture_resolution(camera_h camera, int width, int height)
3418 {
3419         int ret = CAMERA_ERROR_NONE;
3420         camera_cli_s *pc = (camera_cli_s *)camera;
3421         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION;
3422         camera_msg_param param;
3423         int value = 0;
3424
3425         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3426
3427         CAM_LOG_INFO("Enter");
3428
3429         value = (width << 16) | height;
3430         CAMERA_MSG_PARAM_SET(param, INT, value);
3431
3432         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3433
3434         CAM_LOG_INFO("ret : 0x%x", ret);
3435
3436         return ret;
3437 }
3438
3439
3440 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
3441 {
3442         int ret = CAMERA_ERROR_NONE;
3443         int set_format = (int)format;
3444         camera_cli_s *pc = (camera_cli_s *)camera;
3445         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
3446         camera_msg_param param;
3447
3448         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3449
3450         CAM_LOG_INFO("Enter - format %d", set_format);
3451
3452         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3453
3454         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3455
3456         CAM_LOG_INFO("ret : 0x%x", ret);
3457
3458         return ret;
3459 }
3460
3461
3462 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
3463 {
3464         int ret = CAMERA_ERROR_NONE;
3465         int set_format = (int)format;
3466         camera_msg_param param;
3467         camera_cli_s *pc = (camera_cli_s *)camera;
3468         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
3469
3470         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3471
3472         CAM_LOG_INFO("Enter - format %d", set_format);
3473
3474         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3475
3476         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3477
3478         if (ret == CAMERA_ERROR_NONE)
3479                 pc->cb_info->preview_format = set_format;
3480
3481         CAM_LOG_INFO("ret : 0x%x", ret);
3482
3483         return ret;
3484 }
3485
3486
3487 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
3488 {
3489         int ret = CAMERA_ERROR_NONE;
3490         camera_cli_s *pc = (camera_cli_s *)camera;
3491         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
3492
3493         if (!pc || !pc->cb_info || !width || !height) {
3494                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
3495                 return CAMERA_ERROR_INVALID_PARAMETER;
3496         }
3497
3498         CAM_LOG_INFO("Enter");
3499
3500         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3501
3502         if (ret == CAMERA_ERROR_NONE) {
3503                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION] >> 16;
3504                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION];
3505         }
3506
3507         CAM_LOG_INFO("ret : 0x%x", ret);
3508
3509         return ret;
3510 }
3511
3512
3513 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
3514 {
3515         int ret = CAMERA_ERROR_NONE;
3516         int set_rotation = (int)rotation;
3517         camera_cli_s *pc = (camera_cli_s *)camera;
3518         camera_msg_param param;
3519
3520         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3521
3522         if (pc->cb_info->is_evas_render) {
3523                 ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
3524                 if (ret != MM_ERROR_NONE) {
3525                         CAM_LOG_ERROR("failed to set rotation for evas surface 0x%x", ret);
3526                         return CAMERA_ERROR_INVALID_OPERATION;
3527                 }
3528         }
3529
3530         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
3531
3532         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_ROTATION, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3533
3534         return ret;
3535 }
3536
3537
3538 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
3539 {
3540         int ret = CAMERA_ERROR_NONE;
3541         camera_cli_s *pc = (camera_cli_s *)camera;
3542
3543         if (!pc || !pc->cb_info || !rotation) {
3544                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
3545                 return CAMERA_ERROR_INVALID_PARAMETER;
3546         }
3547
3548         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_ROTATION, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3549
3550         if (ret == CAMERA_ERROR_NONE)
3551                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_ROTATION];
3552
3553         return ret;
3554 }
3555
3556
3557 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
3558 {
3559         int ret = CAMERA_ERROR_NONE;
3560         int set_flip = (int)flip;
3561         camera_cli_s *pc = (camera_cli_s *)camera;
3562         camera_msg_param param;
3563
3564         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3565
3566         if (pc->cb_info->is_evas_render) {
3567                 ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
3568                 if (ret != MM_ERROR_NONE) {
3569                         CAM_LOG_ERROR("failed to set flip for evas surface 0x%x", ret);
3570                         return CAMERA_ERROR_INVALID_OPERATION;
3571                 }
3572         }
3573
3574         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
3575
3576         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_FLIP, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3577
3578         return ret;
3579 }
3580
3581
3582 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
3583 {
3584         int ret = CAMERA_ERROR_NONE;
3585         camera_cli_s *pc = (camera_cli_s *)camera;
3586
3587         if (!pc || !pc->cb_info || !flip) {
3588                 CAM_LOG_ERROR("NULL pointer %p %p", pc, flip);
3589                 return CAMERA_ERROR_INVALID_PARAMETER;
3590         }
3591
3592         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_FLIP, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3593
3594         if (ret == CAMERA_ERROR_NONE)
3595                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_FLIP];
3596
3597         return ret;
3598 }
3599
3600
3601 int camera_set_display_visible(camera_h camera, bool visible)
3602 {
3603         int ret = CAMERA_ERROR_NONE;
3604         int set_visible = (int)visible;
3605         camera_cli_s *pc = (camera_cli_s *)camera;
3606         camera_msg_param param;
3607
3608         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3609
3610         if (pc->cb_info->is_evas_render) {
3611                 ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
3612                 if (ret != MM_ERROR_NONE) {
3613                         CAM_LOG_ERROR("failed to set visible for evas surface 0x%x", ret);
3614                         return CAMERA_ERROR_INVALID_OPERATION;
3615                 }
3616         }
3617
3618         CAMERA_MSG_PARAM_SET(param, INT, set_visible);
3619
3620         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3621
3622         return ret;
3623 }
3624
3625
3626 int camera_is_display_visible(camera_h camera, bool *visible)
3627 {
3628         int ret = CAMERA_ERROR_NONE;
3629         camera_cli_s *pc = (camera_cli_s *)camera;
3630
3631         if (!pc || !pc->cb_info || !visible) {
3632                 CAM_LOG_ERROR("NULL pointer %p %p", pc, visible);
3633                 return CAMERA_ERROR_INVALID_PARAMETER;
3634         }
3635
3636         _camera_msg_send(MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3637
3638         if (ret == CAMERA_ERROR_NONE)
3639                 *visible = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE];
3640
3641         return ret;
3642 }
3643
3644
3645 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
3646 {
3647         int ret = CAMERA_ERROR_NONE;
3648         int set_mode = (int)mode;
3649         camera_cli_s *pc = (camera_cli_s *)camera;
3650         camera_msg_param param;
3651
3652         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3653
3654         if (pc->cb_info->is_evas_render) {
3655                 ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
3656                 if (ret != MM_ERROR_NONE) {
3657                         CAM_LOG_ERROR("failed to set geometry for evas surface 0x%x", ret);
3658                         return CAMERA_ERROR_INVALID_OPERATION;
3659                 }
3660         }
3661
3662         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
3663
3664         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_MODE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3665
3666         return ret;
3667 }
3668
3669
3670 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
3671 {
3672         int ret = CAMERA_ERROR_NONE;
3673         camera_cli_s *pc = (camera_cli_s *)camera;
3674
3675         if (!pc || !pc->cb_info || !mode) {
3676                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
3677                 return CAMERA_ERROR_INVALID_PARAMETER;
3678         }
3679
3680         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_MODE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3681
3682         if (ret == CAMERA_ERROR_NONE)
3683                 *mode = (camera_display_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_MODE];
3684
3685         return ret;
3686 }
3687
3688
3689 int camera_set_display_reuse_hint(camera_h camera, bool hint)
3690 {
3691         int ret = CAMERA_ERROR_NONE;
3692         int set_hint = (int)hint;
3693         camera_cli_s *pc = (camera_cli_s *)camera;
3694         camera_msg_param param;
3695
3696         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3697
3698         CAM_LOG_INFO("Enter - hint %d", set_hint);
3699
3700         CAMERA_MSG_PARAM_SET(param, INT, set_hint);
3701
3702         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3703
3704         return ret;
3705 }
3706
3707
3708 int camera_get_display_reuse_hint(camera_h camera, bool *hint)
3709 {
3710         int ret = CAMERA_ERROR_NONE;
3711         camera_cli_s *pc = (camera_cli_s *)camera;
3712         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
3713
3714         if (!pc || !pc->cb_info || !hint) {
3715                 CAM_LOG_ERROR("NULL pointer %p %p", pc, hint);
3716                 return CAMERA_ERROR_INVALID_PARAMETER;
3717         }
3718
3719         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3720
3721         if (ret == CAMERA_ERROR_NONE) {
3722                 *hint = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT];
3723                 CAM_LOG_INFO("display reuse hint %d", *hint);
3724         }
3725
3726         return ret;
3727 }
3728
3729
3730 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
3731 {
3732         int ret = CAMERA_ERROR_NONE;
3733         camera_cli_s *pc = (camera_cli_s *)camera;
3734         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
3735
3736         if (!pc || !pc->cb_info || !width || !height) {
3737                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
3738                 return CAMERA_ERROR_INVALID_PARAMETER;
3739         }
3740
3741         CAM_LOG_INFO("Enter");
3742
3743         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3744
3745         if (ret == CAMERA_ERROR_NONE) {
3746                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION] >> 16;
3747                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION];
3748         }
3749
3750         CAM_LOG_INFO("ret : 0x%x", ret);
3751
3752         return ret;
3753 }
3754
3755
3756 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
3757 {
3758         int ret = CAMERA_ERROR_NONE;
3759         camera_cli_s *pc = (camera_cli_s *)camera;
3760         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
3761
3762         if (!pc || !pc->cb_info || !format) {
3763                 CAM_LOG_ERROR("NULL pointer %p %p", pc, format);
3764                 return CAMERA_ERROR_INVALID_PARAMETER;
3765         }
3766
3767         CAM_LOG_INFO("Enter");
3768
3769         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3770
3771         if (ret == CAMERA_ERROR_NONE)
3772                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_FORMAT];
3773
3774         CAM_LOG_INFO("ret : 0x%x", ret);
3775
3776         return ret;
3777 }
3778
3779
3780 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
3781 {
3782         int ret = CAMERA_ERROR_NONE;
3783         camera_cli_s *pc = (camera_cli_s *)camera;
3784         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
3785
3786         if (!pc || !pc->cb_info || !format) {
3787                 CAM_LOG_ERROR("NULL pointer %p %p", pc, format);
3788                 return CAMERA_ERROR_INVALID_PARAMETER;
3789         }
3790
3791         CAM_LOG_INFO("Enter");
3792
3793         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3794
3795         if (ret == CAMERA_ERROR_NONE)
3796                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FORMAT];
3797
3798         CAM_LOG_INFO("ret : 0x%x", ret);
3799
3800         return ret;
3801 }
3802
3803
3804 int camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction)
3805 {
3806         int ret = CAMERA_ERROR_NONE;
3807         camera_cli_s *pc = (camera_cli_s *)camera;
3808         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
3809
3810         if (!pc || !pc->cb_info || !facing_direction) {
3811                 CAM_LOG_ERROR("NULL pointer %p %p", pc, facing_direction);
3812                 return CAMERA_ERROR_INVALID_PARAMETER;
3813         }
3814
3815         CAM_LOG_INFO("Enter");
3816
3817         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3818
3819         if (ret == CAMERA_ERROR_NONE)
3820                 *facing_direction = (camera_facing_direction_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FACING_DIRECTION];
3821
3822         CAM_LOG_INFO("ret : 0x%x", ret);
3823
3824         return ret;
3825 }
3826
3827
3828 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
3829 {
3830         int ret = CAMERA_ERROR_NONE;
3831         camera_cli_s *pc = (camera_cli_s *)camera;
3832         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
3833
3834         if (!pc || !pc->cb_info || !callback) {
3835                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3836                 return CAMERA_ERROR_INVALID_PARAMETER;
3837         }
3838
3839         CAM_LOG_INFO("Enter");
3840
3841         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3842
3843         if (ret == CAMERA_ERROR_NONE) {
3844                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3845
3846                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
3847                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
3848
3849                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3850         }
3851
3852         CAM_LOG_INFO("ret : 0x%x", ret);
3853
3854         return ret;
3855 }
3856
3857
3858 int camera_unset_preview_cb(camera_h camera)
3859 {
3860         int ret = CAMERA_ERROR_NONE;
3861         camera_cli_s *pc = (camera_cli_s *)camera;
3862         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
3863
3864         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3865
3866         CAM_LOG_INFO("Enter");
3867
3868         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3869
3870         if (ret == CAMERA_ERROR_NONE) {
3871                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3872
3873                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3874                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3875
3876                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3877         }
3878
3879         CAM_LOG_INFO("ret : 0x%x", ret);
3880
3881         return ret;
3882 }
3883
3884
3885 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
3886 {
3887         int ret = CAMERA_ERROR_NONE;
3888         camera_cli_s *pc = (camera_cli_s *)camera;
3889         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
3890
3891         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3892
3893         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3894                 CAM_LOG_ERROR("NOT SUPPORTED");
3895                 return CAMERA_ERROR_NOT_SUPPORTED;
3896         }
3897
3898         if (callback == NULL) {
3899                 CAM_LOG_ERROR("NULL callback");
3900                 return CAMERA_ERROR_INVALID_PARAMETER;
3901         }
3902
3903         CAM_LOG_INFO("Enter");
3904
3905         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3906
3907         if (ret == CAMERA_ERROR_NONE) {
3908                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3909
3910                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
3911                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
3912
3913                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3914         }
3915
3916         CAM_LOG_INFO("ret : 0x%x", ret);
3917
3918         return ret;
3919 }
3920
3921
3922 int camera_unset_media_packet_preview_cb(camera_h camera)
3923 {
3924         int ret = CAMERA_ERROR_NONE;
3925         camera_cli_s *pc = (camera_cli_s *)camera;
3926         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
3927
3928         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3929
3930         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3931                 CAM_LOG_ERROR("NOT SUPPORTED");
3932                 return CAMERA_ERROR_NOT_SUPPORTED;
3933         }
3934
3935         CAM_LOG_INFO("Enter");
3936
3937         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3938
3939         if (ret == CAMERA_ERROR_NONE) {
3940                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3941
3942                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3943                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3944
3945                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3946         }
3947
3948         CAM_LOG_INFO("ret : 0x%x", ret);
3949
3950         return ret;
3951 }
3952
3953
3954 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
3955 {
3956         int ret = CAMERA_ERROR_NONE;
3957         camera_cli_s *pc = (camera_cli_s *)camera;
3958         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
3959
3960         if (!pc || !pc->cb_info || !callback) {
3961                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3962                 return CAMERA_ERROR_INVALID_PARAMETER;
3963         }
3964
3965         CAM_LOG_INFO("Enter");
3966
3967         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3968
3969         if (ret == CAMERA_ERROR_NONE) {
3970                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3971
3972                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
3973                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
3974
3975                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3976         }
3977
3978         CAM_LOG_INFO("ret : 0x%x", ret);
3979
3980         return ret;
3981 }
3982
3983
3984 int camera_unset_state_changed_cb(camera_h camera)
3985 {
3986         int ret = CAMERA_ERROR_NONE;
3987         camera_cli_s *pc = (camera_cli_s *)camera;
3988         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
3989
3990         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
3991
3992         CAM_LOG_INFO("Enter");
3993
3994         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3995
3996         if (ret == CAMERA_ERROR_NONE) {
3997                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3998
3999                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
4000                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
4001
4002                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
4003         }
4004
4005         CAM_LOG_INFO("ret : 0x%x", ret);
4006
4007         return ret;
4008 }
4009
4010
4011 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
4012 {
4013         int ret = CAMERA_ERROR_NONE;
4014         camera_cli_s *pc = (camera_cli_s *)camera;
4015         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
4016
4017         if (!pc || !pc->cb_info || !callback) {
4018                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
4019                 return CAMERA_ERROR_INVALID_PARAMETER;
4020         }
4021
4022         CAM_LOG_INFO("Enter");
4023
4024         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4025
4026         if (ret == CAMERA_ERROR_NONE) {
4027                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
4028
4029                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
4030                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
4031
4032                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
4033         }
4034
4035         CAM_LOG_INFO("ret : 0x%x", ret);
4036
4037         return ret;
4038 }
4039
4040
4041 int camera_unset_interrupted_cb(camera_h camera)
4042 {
4043         int ret = CAMERA_ERROR_NONE;
4044         camera_cli_s *pc = (camera_cli_s *)camera;
4045         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
4046
4047         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4048
4049         CAM_LOG_INFO("Enter");
4050
4051         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4052
4053         if (ret == CAMERA_ERROR_NONE) {
4054                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
4055
4056                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
4057                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
4058
4059                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
4060         }
4061
4062         CAM_LOG_INFO("ret : 0x%x", ret);
4063
4064         return ret;
4065 }
4066
4067
4068 int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
4069 {
4070         int ret = CAMERA_ERROR_NONE;
4071         camera_cli_s *pc = (camera_cli_s *)camera;
4072         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
4073
4074         if (!pc || !pc->cb_info || !callback) {
4075                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
4076                 return CAMERA_ERROR_INVALID_PARAMETER;
4077         }
4078
4079         CAM_LOG_INFO("Enter");
4080
4081         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4082
4083         if (ret == CAMERA_ERROR_NONE) {
4084                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4085
4086                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
4087                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
4088
4089                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4090         }
4091
4092         CAM_LOG_INFO("ret : 0x%x", ret);
4093
4094         return ret;
4095 }
4096
4097
4098 int camera_unset_interrupt_started_cb(camera_h camera)
4099 {
4100         int ret = CAMERA_ERROR_NONE;
4101         camera_cli_s *pc = (camera_cli_s *)camera;
4102         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
4103
4104         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4105
4106         CAM_LOG_INFO("Enter");
4107
4108         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4109
4110         if (ret == CAMERA_ERROR_NONE) {
4111                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4112
4113                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
4114                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
4115
4116                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4117         }
4118
4119         CAM_LOG_INFO("ret : 0x%x", ret);
4120
4121         return ret;
4122 }
4123
4124
4125 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
4126 {
4127         int ret = CAMERA_ERROR_NONE;
4128         camera_cli_s *pc = (camera_cli_s *)camera;
4129         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
4130
4131         if (!pc || !pc->cb_info || !callback) {
4132                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
4133                 return CAMERA_ERROR_INVALID_PARAMETER;
4134         }
4135
4136         CAM_LOG_INFO("Enter");
4137
4138         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4139
4140         if (ret == CAMERA_ERROR_NONE) {
4141                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4142
4143                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
4144                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
4145
4146                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4147         }
4148
4149         CAM_LOG_INFO("ret : 0x%x", ret);
4150
4151         return ret;
4152 }
4153
4154
4155 int camera_unset_focus_changed_cb(camera_h camera)
4156 {
4157         int ret = CAMERA_ERROR_NONE;
4158         camera_cli_s *pc = (camera_cli_s *)camera;
4159         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
4160
4161         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4162
4163         CAM_LOG_INFO("Enter");
4164
4165         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4166
4167         if (ret == CAMERA_ERROR_NONE) {
4168                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4169
4170                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4171                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4172
4173                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4174         }
4175
4176         CAM_LOG_INFO("ret : 0x%x", ret);
4177
4178         return ret;
4179 }
4180
4181
4182 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
4183 {
4184         int ret = CAMERA_ERROR_NONE;
4185         camera_cli_s *pc = (camera_cli_s *)camera;
4186         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
4187
4188         if (!pc || !pc->cb_info || !callback) {
4189                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
4190                 return CAMERA_ERROR_INVALID_PARAMETER;
4191         }
4192
4193         CAM_LOG_INFO("Enter");
4194
4195         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4196
4197         if (ret == CAMERA_ERROR_NONE) {
4198                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4199
4200                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
4201                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
4202
4203                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4204         }
4205
4206         CAM_LOG_INFO("ret : 0x%x", ret);
4207
4208         return ret;
4209 }
4210
4211
4212 int camera_unset_error_cb(camera_h camera)
4213 {
4214         int ret = CAMERA_ERROR_NONE;
4215         camera_cli_s *pc = (camera_cli_s *)camera;
4216         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
4217
4218         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4219
4220         CAM_LOG_INFO("Enter");
4221
4222         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4223
4224         if (ret == CAMERA_ERROR_NONE) {
4225                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4226
4227                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4228                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4229
4230                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4231         }
4232
4233         CAM_LOG_INFO("ret : 0x%x", ret);
4234
4235         return ret;
4236 }
4237
4238
4239 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
4240 {
4241         int ret = CAMERA_ERROR_NONE;
4242         camera_cli_s *pc = (camera_cli_s *)camera;
4243         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
4244
4245         if (!pc || !pc->cb_info || !foreach_cb) {
4246                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4247                 return CAMERA_ERROR_INVALID_PARAMETER;
4248         }
4249
4250         CAM_LOG_INFO("Enter");
4251
4252         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = foreach_cb;
4253         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = user_data;
4254
4255         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4256
4257         CAM_LOG_INFO("ret : 0x%x", ret);
4258
4259         return ret;
4260 }
4261
4262
4263 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
4264 {
4265         int ret = CAMERA_ERROR_NONE;
4266         camera_cli_s *pc = (camera_cli_s *)camera;
4267         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
4268
4269         if (!pc || !pc->cb_info || !foreach_cb) {
4270                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4271                 return CAMERA_ERROR_INVALID_PARAMETER;
4272         }
4273
4274         CAM_LOG_INFO("Enter");
4275
4276         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = foreach_cb;
4277         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = user_data;
4278
4279         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4280
4281         CAM_LOG_INFO("ret : 0x%x", ret);
4282
4283         return ret;
4284 }
4285
4286
4287 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
4288 {
4289         int ret = CAMERA_ERROR_NONE;
4290         camera_cli_s *pc = (camera_cli_s *)camera;
4291         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
4292
4293         if (!pc || !pc->cb_info || !foreach_cb) {
4294                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4295                 return CAMERA_ERROR_INVALID_PARAMETER;
4296         }
4297
4298         CAM_LOG_INFO("Enter");
4299
4300         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = foreach_cb;
4301         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = user_data;
4302
4303         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4304
4305         CAM_LOG_INFO("ret : 0x%x", ret);
4306
4307         return ret;
4308 }
4309
4310
4311 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
4312 {
4313         int ret = CAMERA_ERROR_NONE;
4314         camera_cli_s *pc = (camera_cli_s *)camera;
4315         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
4316
4317         if (!pc || !pc->cb_info || !foreach_cb) {
4318                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4319                 return CAMERA_ERROR_INVALID_PARAMETER;
4320         }
4321
4322         CAM_LOG_INFO("Enter");
4323
4324         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = foreach_cb;
4325         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = user_data;
4326
4327         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4328
4329         CAM_LOG_INFO("ret : 0x%x", ret);
4330
4331         return ret;
4332 }
4333
4334
4335 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
4336 {
4337         int ret = CAMERA_ERROR_NONE;
4338         camera_cli_s *pc = (camera_cli_s *)camera;
4339         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
4340
4341         if (!pc || !pc->cb_info || !width || !height) {
4342                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
4343                 return CAMERA_ERROR_INVALID_PARAMETER;
4344         }
4345
4346         CAM_LOG_INFO("Enter");
4347         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4348
4349         if (ret == CAMERA_ERROR_NONE) {
4350                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION] >> 16;
4351                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION];
4352         }
4353
4354         CAM_LOG_INFO("ret : 0x%x", ret);
4355
4356         return ret;
4357 }
4358
4359
4360 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
4361 {
4362         int ret = CAMERA_ERROR_NONE;
4363         camera_cli_s *pc = (camera_cli_s *)camera;
4364         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
4365
4366         if (!pc || !pc->cb_info || !angle) {
4367                 CAM_LOG_ERROR("NULL pointer %p %p", pc, angle);
4368                 return CAMERA_ERROR_INVALID_PARAMETER;
4369         }
4370
4371         CAM_LOG_INFO("Enter");
4372
4373         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4374
4375         if (ret == CAMERA_ERROR_NONE)
4376                 *angle = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_LENS_ORIENTATION];
4377
4378         CAM_LOG_INFO("ret : 0x%x", ret);
4379
4380         return ret;
4381 }
4382
4383
4384 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
4385 {
4386         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_THEATER_MODE, (int)mode);
4387 }
4388
4389
4390 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
4391 {
4392         int ret = CAMERA_ERROR_NONE;
4393         camera_cli_s *pc = (camera_cli_s *)camera;
4394         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
4395
4396         if (!pc || !pc->cb_info || !mode) {
4397                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
4398                 return CAMERA_ERROR_INVALID_PARAMETER;
4399         }
4400
4401         CAM_LOG_INFO("Enter");
4402
4403         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4404
4405         if (ret == CAMERA_ERROR_NONE)
4406                 *mode = (camera_attr_theater_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_THEATER_MODE];
4407
4408         CAM_LOG_INFO("ret : 0x%x", ret);
4409
4410         return ret;
4411 }
4412
4413
4414 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
4415 {
4416         int ret = CAMERA_ERROR_NONE;
4417         camera_cli_s *pc = (camera_cli_s *)camera;
4418         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
4419
4420         if (!pc || !pc->cb_info || !foreach_cb) {
4421                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4422                 return CAMERA_ERROR_INVALID_PARAMETER;
4423         }
4424
4425         CAM_LOG_INFO("Enter");
4426
4427         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = foreach_cb;
4428         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = user_data;
4429
4430         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4431
4432         CAM_LOG_INFO("Finish, return :%x", ret);
4433
4434         return ret;
4435 }
4436
4437
4438 int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
4439 {
4440         int ret = CAMERA_ERROR_NONE;
4441         camera_cli_s *pc = (camera_cli_s *)camera;
4442         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
4443         camera_msg_param param;
4444         int set_fps = (int)fps;
4445
4446         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4447
4448         CAM_LOG_INFO("Enter");
4449
4450         CAMERA_MSG_PARAM_SET(param, INT, set_fps);
4451
4452         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4453
4454         CAM_LOG_INFO("ret : 0x%x", ret);
4455
4456         return ret;
4457 }
4458
4459
4460 int camera_attr_set_image_quality(camera_h camera, int quality)
4461 {
4462         int ret = CAMERA_ERROR_NONE;
4463         camera_cli_s *pc = (camera_cli_s *)camera;
4464         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
4465         camera_msg_param param;
4466
4467         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4468
4469         CAM_LOG_INFO("Enter");
4470
4471         CAMERA_MSG_PARAM_SET(param, INT, quality);
4472
4473         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4474
4475         CAM_LOG_INFO("ret : 0x%x", ret);
4476
4477         return ret;
4478 }
4479
4480
4481 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
4482 {
4483         int ret = CAMERA_ERROR_NONE;
4484         camera_cli_s *pc = (camera_cli_s *)camera;
4485         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
4486
4487         if (!pc || !pc->cb_info || !fps) {
4488                 CAM_LOG_ERROR("NULL pointer %p %p", pc, fps);
4489                 return CAMERA_ERROR_INVALID_PARAMETER;
4490         }
4491
4492         CAM_LOG_INFO("Enter");
4493
4494         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4495
4496         if (ret == CAMERA_ERROR_NONE)
4497                 *fps = (camera_attr_fps_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FPS];
4498
4499         CAM_LOG_INFO("ret : 0x%x", ret);
4500
4501         return ret;
4502 }
4503
4504
4505 int camera_attr_get_image_quality(camera_h camera, int *quality)
4506 {
4507         int ret = CAMERA_ERROR_NONE;
4508         camera_cli_s *pc = (camera_cli_s *)camera;
4509         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
4510
4511         if (!pc || !pc->cb_info || !quality) {
4512                 CAM_LOG_ERROR("NULL pointer %p %p", pc, quality);
4513                 return CAMERA_ERROR_INVALID_PARAMETER;
4514         }
4515
4516         CAM_LOG_INFO("Enter");
4517
4518         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4519
4520         if (ret == CAMERA_ERROR_NONE)
4521                 *quality = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_IMAGE_QUALITY];
4522
4523         CAM_LOG_INFO("ret : 0x%x", ret);
4524
4525         return ret;
4526 }
4527
4528
4529 int camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate)
4530 {
4531         int ret = CAMERA_ERROR_NONE;
4532         camera_cli_s *pc = (camera_cli_s *)camera;
4533         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4534
4535         if (!pc || !pc->cb_info || !bitrate) {
4536                 CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
4537                 return CAMERA_ERROR_INVALID_PARAMETER;
4538         }
4539
4540         CAM_LOG_INFO("Enter");
4541
4542         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4543
4544         if (ret == CAMERA_ERROR_NONE)
4545                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE];
4546
4547         CAM_LOG_INFO("ret : 0x%x", ret);
4548
4549         return ret;
4550 }
4551
4552
4553 int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
4554 {
4555         int ret = CAMERA_ERROR_NONE;
4556         camera_cli_s *pc = (camera_cli_s *)camera;
4557         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4558         camera_msg_param param;
4559         int set_bitrate = bitrate;
4560
4561         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4562
4563         CAM_LOG_INFO("Enter");
4564
4565         CAMERA_MSG_PARAM_SET(param, INT, set_bitrate);
4566
4567         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4568
4569         CAM_LOG_INFO("ret : 0x%x", ret);
4570
4571         return ret;
4572 }
4573
4574
4575 int camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval)
4576 {
4577         int ret = CAMERA_ERROR_NONE;
4578         camera_cli_s *pc = (camera_cli_s *)camera;
4579         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4580
4581         if (!pc || !pc->cb_info || !interval) {
4582                 CAM_LOG_ERROR("NULL pointer %p %p", pc, interval);
4583                 return CAMERA_ERROR_INVALID_PARAMETER;
4584         }
4585
4586         CAM_LOG_INFO("Enter");
4587
4588         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4589
4590         if (ret == CAMERA_ERROR_NONE)
4591                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL];
4592
4593         CAM_LOG_INFO("ret : 0x%x", ret);
4594
4595         return ret;
4596 }
4597
4598
4599 int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
4600 {
4601         int ret = CAMERA_ERROR_NONE;
4602         camera_cli_s *pc = (camera_cli_s *)camera;
4603         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4604         camera_msg_param param;
4605         int set_gop_interval = interval;
4606
4607         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4608
4609         CAM_LOG_INFO("Enter");
4610
4611         CAMERA_MSG_PARAM_SET(param, INT, set_gop_interval);
4612
4613         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4614
4615         CAM_LOG_INFO("ret : 0x%x", ret);
4616
4617         return ret;
4618 }
4619
4620
4621 int camera_attr_set_zoom(camera_h camera, int zoom)
4622 {
4623         int ret = CAMERA_ERROR_NONE;
4624         camera_cli_s *pc = (camera_cli_s *)camera;
4625         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
4626         camera_msg_param param;
4627
4628         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4629
4630         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4631
4632         CAMERA_MSG_PARAM_SET(param, INT, zoom);
4633
4634         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4635
4636         CAM_LOG_INFO("ret : 0x%x", ret);
4637
4638         return ret;
4639 }
4640
4641
4642 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
4643 {
4644         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_AF_MODE, (int)mode);
4645 }
4646
4647
4648 int camera_attr_set_af_area(camera_h camera, int x, int y)
4649 {
4650         int ret = CAMERA_ERROR_NONE;
4651         camera_cli_s *pc = (camera_cli_s *)camera;
4652         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
4653         camera_msg_param param;
4654         int value = 0;
4655
4656         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4657
4658         CAM_LOG_INFO("Enter - %d,%d", x, y);
4659
4660         value = (x << 16) | y;
4661         CAMERA_MSG_PARAM_SET(param, INT, value);
4662
4663         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4664
4665         CAM_LOG_INFO("ret : 0x%x", ret);
4666
4667         return ret;
4668 }
4669
4670
4671 int camera_attr_clear_af_area(camera_h camera)
4672 {
4673         int ret = CAMERA_ERROR_NONE;
4674         camera_cli_s *pc = (camera_cli_s *)camera;
4675         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
4676
4677         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4678
4679         CAM_LOG_INFO("Enter");
4680
4681         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4682
4683         CAM_LOG_INFO("ret : 0x%x", ret);
4684
4685         return ret;
4686 }
4687
4688
4689 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
4690 {
4691         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE, (int)mode);
4692 }
4693
4694
4695 int camera_attr_set_exposure(camera_h camera, int value)
4696 {
4697         int ret = CAMERA_ERROR_NONE;
4698         camera_cli_s *pc = (camera_cli_s *)camera;
4699         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
4700         camera_msg_param param;
4701
4702         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4703
4704         CAM_LOG_INFO("Enter");
4705
4706         CAMERA_MSG_PARAM_SET(param, INT, value);
4707
4708         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4709
4710         CAM_LOG_INFO("ret : 0x%x", ret);
4711
4712         return ret;
4713 }
4714
4715
4716 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
4717 {
4718         int ret = CAMERA_ERROR_NONE;
4719         camera_cli_s *pc = (camera_cli_s *)camera;
4720         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
4721         camera_msg_param param;
4722         int set_iso = (int)iso;
4723
4724         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4725
4726         CAM_LOG_INFO("Enter");
4727
4728         CAMERA_MSG_PARAM_SET(param, INT, set_iso);
4729
4730         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4731
4732         CAM_LOG_INFO("ret : 0x%x", ret);
4733
4734         return ret;
4735 }
4736
4737
4738 int camera_attr_set_brightness(camera_h camera, int level)
4739 {
4740         int ret = CAMERA_ERROR_NONE;
4741         camera_cli_s *pc = (camera_cli_s *)camera;
4742         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
4743         camera_msg_param param;
4744
4745         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4746
4747         CAM_LOG_INFO("Enter");
4748
4749         CAMERA_MSG_PARAM_SET(param, INT, level);
4750
4751         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4752
4753         CAM_LOG_INFO("ret : 0x%x", ret);
4754
4755         return ret;
4756 }
4757
4758
4759 int camera_attr_set_contrast(camera_h camera, int level)
4760 {
4761         int ret = CAMERA_ERROR_NONE;
4762         camera_cli_s *pc = (camera_cli_s *)camera;
4763         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
4764         camera_msg_param param;
4765
4766         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4767
4768         CAM_LOG_INFO("Enter");
4769
4770         CAMERA_MSG_PARAM_SET(param, INT, level);
4771
4772         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4773
4774         CAM_LOG_INFO("ret : 0x%x", ret);
4775
4776         return ret;
4777 }
4778
4779
4780 int camera_attr_set_hue(camera_h camera, int level)
4781 {
4782         int ret = CAMERA_ERROR_NONE;
4783         camera_cli_s *pc = (camera_cli_s *)camera;
4784         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
4785         camera_msg_param param;
4786
4787         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4788
4789         CAM_LOG_INFO("Enter");
4790
4791         CAMERA_MSG_PARAM_SET(param, INT, level);
4792
4793         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4794
4795         CAM_LOG_INFO("ret : 0x%x", ret);
4796
4797         return ret;
4798 }
4799
4800
4801 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
4802 {
4803         int ret = CAMERA_ERROR_NONE;
4804         camera_cli_s *pc = (camera_cli_s *)camera;
4805         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
4806         camera_msg_param param;
4807         int set_whitebalance = (int)wb;
4808
4809         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4810
4811         CAM_LOG_INFO("Enter");
4812
4813         CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
4814
4815         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4816
4817         CAM_LOG_INFO("ret : 0x%x", ret);
4818
4819         return ret;
4820 }
4821
4822
4823 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
4824 {
4825         int ret = CAMERA_ERROR_NONE;
4826         camera_cli_s *pc = (camera_cli_s *)camera;
4827         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
4828         camera_msg_param param;
4829         int set_effect = (int)effect;
4830
4831         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4832
4833         CAM_LOG_INFO("Enter");
4834
4835         CAMERA_MSG_PARAM_SET(param, INT, set_effect);
4836
4837         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4838
4839         CAM_LOG_INFO("ret : 0x%x", ret);
4840
4841         return ret;
4842 }
4843
4844
4845 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
4846 {
4847         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_SCENE_MODE, (int)mode);
4848 }
4849
4850
4851 int camera_attr_enable_tag(camera_h camera, bool enable)
4852 {
4853         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_TAG, (int)enable);
4854 }
4855
4856
4857 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
4858 {
4859         int ret = CAMERA_ERROR_NONE;
4860         camera_cli_s *pc = (camera_cli_s *)camera;
4861         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
4862         camera_msg_param param;
4863
4864         if (!pc || !pc->cb_info || !description) {
4865                 CAM_LOG_ERROR("NULL pointer %p %p", pc, description);
4866                 return CAMERA_ERROR_INVALID_PARAMETER;
4867         }
4868
4869         CAM_LOG_INFO("Enter");
4870
4871         CAMERA_MSG_PARAM_SET(param, STRING, description);
4872
4873         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4874
4875         CAM_LOG_INFO("ret : 0x%x", ret);
4876
4877         return ret;
4878 }
4879
4880
4881 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
4882 {
4883         int ret = CAMERA_ERROR_NONE;
4884         camera_cli_s *pc = (camera_cli_s *)camera;
4885         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
4886         camera_msg_param param;
4887         int set_orientation = (int)orientation;
4888
4889         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4890
4891         CAM_LOG_INFO("Enter");
4892
4893         CAMERA_MSG_PARAM_SET(param, INT, set_orientation);
4894
4895         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4896
4897         CAM_LOG_INFO("ret : 0x%x", ret);
4898
4899         return ret;
4900 }
4901
4902
4903 int camera_attr_set_tag_software(camera_h camera, const char *software)
4904 {
4905         int ret = CAMERA_ERROR_NONE;
4906         camera_cli_s *pc = (camera_cli_s *)camera;
4907         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
4908         camera_msg_param param;
4909
4910         if (!pc || !pc->cb_info || !software) {
4911                 CAM_LOG_ERROR("NULL pointer %p %p", pc, software);
4912                 return CAMERA_ERROR_INVALID_PARAMETER;
4913         }
4914
4915         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4916
4917         CAMERA_MSG_PARAM_SET(param, STRING, software);
4918
4919         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4920
4921         CAM_LOG_INFO("ret : 0x%x", ret);
4922
4923         return ret;
4924 }
4925
4926
4927 int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, double altitude)
4928 {
4929         int ret = CAMERA_ERROR_NONE;
4930         camera_cli_s *pc = (camera_cli_s *)camera;
4931         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
4932         double set_geotag[3] = {latitude, longitude, altitude};
4933         char *msg = NULL;
4934         int length = 0;
4935
4936         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4937
4938         CAM_LOG_INFO("Enter");
4939
4940         length = sizeof(set_geotag) / sizeof(int) + \
4941                 (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
4942
4943         msg = muse_core_msg_new(api,
4944                 MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
4945                 NULL);
4946
4947         _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
4948
4949         return ret;
4950 }
4951
4952
4953 int camera_attr_remove_geotag(camera_h camera)
4954 {
4955         int ret = CAMERA_ERROR_NONE;
4956         camera_cli_s *pc = (camera_cli_s *)camera;
4957         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
4958
4959         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
4960
4961         CAM_LOG_INFO("Enter");
4962
4963         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4964
4965         CAM_LOG_INFO("ret : 0x%x", ret);
4966
4967         return ret;
4968 }
4969
4970
4971 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
4972 {
4973         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_MODE, (int)mode);
4974 }
4975
4976
4977 int camera_attr_get_zoom(camera_h camera, int *zoom)
4978 {
4979         int ret = CAMERA_ERROR_NONE;
4980         camera_cli_s *pc = (camera_cli_s *)camera;
4981         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
4982
4983         if (!pc || !pc->cb_info || !zoom) {
4984                 CAM_LOG_ERROR("NULL pointer %p %p", pc, zoom);
4985                 return CAMERA_ERROR_INVALID_PARAMETER;
4986         }
4987
4988         CAM_LOG_INFO("Enter");
4989
4990         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4991
4992         if (ret == CAMERA_ERROR_NONE)
4993                 *zoom = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ZOOM];
4994
4995         CAM_LOG_INFO("ret : 0x%x", ret);
4996
4997         return ret;
4998 }
4999
5000
5001 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
5002 {
5003         int ret = CAMERA_ERROR_NONE;
5004         camera_cli_s *pc = (camera_cli_s *)camera;
5005         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
5006
5007         if (!pc || !pc->cb_info || !min || !max) {
5008                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5009                 return CAMERA_ERROR_INVALID_PARAMETER;
5010         }
5011
5012         CAM_LOG_INFO("Enter");
5013
5014         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5015
5016         if (ret == CAMERA_ERROR_NONE) {
5017                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
5018                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
5019         }
5020
5021         CAM_LOG_INFO("ret : 0x%x", ret);
5022
5023         return ret;
5024 }
5025
5026
5027 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
5028 {
5029         int ret = CAMERA_ERROR_NONE;
5030         camera_cli_s *pc = (camera_cli_s *)camera;
5031         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
5032
5033         if (!pc || !pc->cb_info || !mode) {
5034                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5035                 return CAMERA_ERROR_INVALID_PARAMETER;
5036         }
5037
5038         CAM_LOG_INFO("Enter");
5039
5040         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5041
5042         if (ret == CAMERA_ERROR_NONE)
5043                 *mode = (camera_attr_af_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_AF_MODE];
5044
5045         CAM_LOG_INFO("ret : 0x%x", ret);
5046
5047         return ret;
5048 }
5049
5050
5051 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
5052 {
5053         int ret = CAMERA_ERROR_NONE;
5054         camera_cli_s *pc = (camera_cli_s *)camera;
5055         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
5056
5057         if (!pc || !pc->cb_info || !mode) {
5058                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5059                 return CAMERA_ERROR_INVALID_PARAMETER;
5060         }
5061
5062         CAM_LOG_INFO("Enter");
5063
5064         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5065
5066         if (ret == CAMERA_ERROR_NONE)
5067                 *mode = (camera_attr_exposure_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE_MODE];
5068
5069         CAM_LOG_INFO("ret : 0x%x", ret);
5070
5071         return ret;
5072 }
5073
5074
5075 int camera_attr_get_exposure(camera_h camera, int *value)
5076 {
5077         int ret = CAMERA_ERROR_NONE;
5078         camera_cli_s *pc = (camera_cli_s *)camera;
5079         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
5080
5081         if (!pc || !pc->cb_info || !value) {
5082                 CAM_LOG_ERROR("NULL pointer %p %p", pc, value);
5083                 return CAMERA_ERROR_INVALID_PARAMETER;
5084         }
5085
5086         CAM_LOG_INFO("Enter");
5087
5088         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5089
5090         if (ret == CAMERA_ERROR_NONE)
5091                 *value = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE];
5092
5093         CAM_LOG_INFO("ret : 0x%x", ret);
5094
5095         return ret;
5096 }
5097
5098
5099 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
5100 {
5101         int ret = CAMERA_ERROR_NONE;
5102         camera_cli_s *pc = (camera_cli_s *)camera;
5103         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
5104
5105         if (!pc || !pc->cb_info || !min || !max) {
5106                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5107                 return CAMERA_ERROR_INVALID_PARAMETER;
5108         }
5109
5110         CAM_LOG_INFO("Enter");
5111
5112         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5113
5114         if (ret == CAMERA_ERROR_NONE) {
5115                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
5116                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
5117         }
5118
5119         CAM_LOG_INFO("ret : 0x%x", ret);
5120
5121         return ret;
5122 }
5123
5124
5125 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
5126 {
5127         int ret = CAMERA_ERROR_NONE;
5128         camera_cli_s *pc = (camera_cli_s *)camera;
5129         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
5130
5131         if (!pc || !pc->cb_info || !iso) {
5132                 CAM_LOG_ERROR("NULL pointer %p %p", pc, iso);
5133                 return CAMERA_ERROR_INVALID_PARAMETER;
5134         }
5135
5136         CAM_LOG_INFO("Enter");
5137
5138         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5139
5140         if (ret == CAMERA_ERROR_NONE)
5141                 *iso = (camera_attr_iso_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ISO];
5142
5143         CAM_LOG_INFO("ret : 0x%x", ret);
5144
5145         return ret;
5146 }
5147
5148
5149 int camera_attr_get_brightness(camera_h camera, int *level)
5150 {
5151         int ret = CAMERA_ERROR_NONE;
5152         camera_cli_s *pc = (camera_cli_s *)camera;
5153         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
5154
5155         if (!pc || !pc->cb_info || !level) {
5156                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5157                 return CAMERA_ERROR_INVALID_PARAMETER;
5158         }
5159
5160         CAM_LOG_INFO("Enter");
5161
5162         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5163
5164         if (ret == CAMERA_ERROR_NONE)
5165                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
5166
5167         CAM_LOG_INFO("ret : 0x%x", ret);
5168
5169         return ret;
5170 }
5171
5172
5173 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
5174 {
5175         int ret = CAMERA_ERROR_NONE;
5176         camera_cli_s *pc = (camera_cli_s *)camera;
5177         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
5178
5179         if (!pc || !pc->cb_info || !min || !max) {
5180                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5181                 return CAMERA_ERROR_INVALID_PARAMETER;
5182         }
5183
5184         CAM_LOG_INFO("Enter");
5185
5186         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5187
5188         if (ret == CAMERA_ERROR_NONE) {
5189                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
5190                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
5191         }
5192
5193         CAM_LOG_INFO("ret : 0x%x", ret);
5194
5195         return ret;
5196 }
5197
5198
5199 int camera_attr_get_contrast(camera_h camera, int *level)
5200 {
5201         int ret = CAMERA_ERROR_NONE;
5202         camera_cli_s *pc = (camera_cli_s *)camera;
5203         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
5204
5205         if (!pc || !pc->cb_info || !level) {
5206                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5207                 return CAMERA_ERROR_INVALID_PARAMETER;
5208         }
5209
5210         CAM_LOG_INFO("Enter");
5211
5212         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5213
5214         if (ret == CAMERA_ERROR_NONE)
5215                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
5216
5217         CAM_LOG_INFO("ret : 0x%x", ret);
5218
5219         return ret;
5220 }
5221
5222
5223 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
5224 {
5225         int ret = CAMERA_ERROR_NONE;
5226         camera_cli_s *pc = (camera_cli_s *)camera;
5227         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
5228
5229         if (!pc || !pc->cb_info || !min || !max) {
5230                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5231                 return CAMERA_ERROR_INVALID_PARAMETER;
5232         }
5233
5234         CAM_LOG_INFO("Enter");
5235
5236         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5237
5238         if (ret == CAMERA_ERROR_NONE) {
5239                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
5240                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
5241                 CAM_LOG_INFO("min %d, max %d", *min, *max);
5242         }
5243
5244         CAM_LOG_INFO("ret : 0x%x", ret);
5245
5246         return ret;
5247 }
5248
5249
5250 int camera_attr_get_hue(camera_h camera, int *level)
5251 {
5252         int ret = CAMERA_ERROR_NONE;
5253         camera_cli_s *pc = (camera_cli_s *)camera;
5254         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
5255
5256         if (!pc || !pc->cb_info || !level) {
5257                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5258                 return CAMERA_ERROR_INVALID_PARAMETER;
5259         }
5260
5261         CAM_LOG_INFO("Enter");
5262
5263         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5264
5265         if (ret == CAMERA_ERROR_NONE)
5266                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
5267
5268         CAM_LOG_INFO("ret : 0x%x", ret);
5269
5270         return ret;
5271 }
5272
5273
5274 int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
5275 {
5276         int ret = CAMERA_ERROR_NONE;
5277         camera_cli_s *pc = (camera_cli_s *)camera;
5278         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
5279
5280         if (!pc || !pc->cb_info || !min || !max) {
5281                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5282                 return CAMERA_ERROR_INVALID_PARAMETER;
5283         }
5284
5285         CAM_LOG_INFO("Enter");
5286
5287         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5288
5289         if (ret == CAMERA_ERROR_NONE) {
5290                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
5291                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
5292                 CAM_LOG_INFO("min %d, max %d", *min, *max);
5293         }
5294
5295         CAM_LOG_INFO("ret : 0x%x", ret);
5296
5297         return ret;
5298 }
5299
5300
5301 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
5302 {
5303         int ret = CAMERA_ERROR_NONE;
5304         camera_cli_s *pc = (camera_cli_s *)camera;
5305         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
5306
5307         if (!pc || !pc->cb_info || !wb) {
5308                 CAM_LOG_ERROR("NULL pointer %p %p", pc, wb);
5309                 return CAMERA_ERROR_INVALID_PARAMETER;
5310         }
5311
5312         CAM_LOG_INFO("Enter");
5313
5314         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5315
5316         if (ret == CAMERA_ERROR_NONE)
5317                 *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
5318
5319         CAM_LOG_INFO("ret : 0x%x", ret);
5320
5321         return ret;
5322 }
5323
5324
5325 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
5326 {
5327         int ret = CAMERA_ERROR_NONE;
5328         camera_cli_s *pc = (camera_cli_s *)camera;
5329         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
5330
5331         if (!pc || !pc->cb_info || !effect) {
5332                 CAM_LOG_ERROR("NULL pointer %p %p", pc, effect);
5333                 return CAMERA_ERROR_INVALID_PARAMETER;
5334         }
5335
5336         CAM_LOG_INFO("Enter");
5337
5338         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5339
5340         if (ret == CAMERA_ERROR_NONE)
5341                 *effect = (camera_attr_effect_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EFFECT];
5342
5343         CAM_LOG_INFO("ret : 0x%x", ret);
5344
5345         return ret;
5346 }
5347
5348
5349 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
5350 {
5351         int ret = CAMERA_ERROR_NONE;
5352         camera_cli_s *pc = (camera_cli_s *)camera;
5353         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
5354
5355         if (!pc || !pc->cb_info || !mode) {
5356                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5357                 return CAMERA_ERROR_INVALID_PARAMETER;
5358         }
5359
5360         CAM_LOG_INFO("Enter");
5361
5362         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5363
5364         if (ret == CAMERA_ERROR_NONE)
5365                 *mode = (camera_attr_scene_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_SCENE_MODE];
5366
5367         CAM_LOG_INFO("ret : 0x%x", ret);
5368
5369         return ret;
5370 }
5371
5372
5373 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
5374 {
5375         int ret = CAMERA_ERROR_NONE;
5376         camera_cli_s *pc = (camera_cli_s *)camera;
5377         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
5378
5379         if (!pc || !pc->cb_info || !enable) {
5380                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enable);
5381                 return CAMERA_ERROR_INVALID_PARAMETER;
5382         }
5383
5384         CAM_LOG_INFO("Enter");
5385
5386         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5387
5388         if (ret == CAMERA_ERROR_NONE)
5389                 *enable = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_TAG];
5390
5391         CAM_LOG_INFO("ret : 0x%x", ret);
5392
5393         return ret;
5394 }
5395
5396
5397 int camera_attr_get_tag_image_description(camera_h camera, char **description)
5398 {
5399         int ret = CAMERA_ERROR_NONE;
5400         camera_cli_s *pc = (camera_cli_s *)camera;
5401         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
5402
5403         if (!pc || !pc->cb_info || !description) {
5404                 CAM_LOG_ERROR("NULL pointer %p %p", pc, description);
5405                 return CAMERA_ERROR_INVALID_PARAMETER;
5406         }
5407
5408         CAM_LOG_INFO("Enter");
5409
5410         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5411
5412         if (ret == CAMERA_ERROR_NONE)
5413                 *description = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION]);
5414
5415         CAM_LOG_INFO("ret : 0x%x", ret);
5416
5417         return ret;
5418 }
5419
5420
5421 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
5422 {
5423         int ret = CAMERA_ERROR_NONE;
5424         camera_cli_s *pc = (camera_cli_s *)camera;
5425         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
5426
5427         if (!pc || !pc->cb_info || !orientation) {
5428                 CAM_LOG_ERROR("NULL pointer %p %p", pc, orientation);
5429                 return CAMERA_ERROR_INVALID_PARAMETER;
5430         }
5431
5432         CAM_LOG_INFO("Enter");
5433
5434         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5435
5436         if (ret == CAMERA_ERROR_NONE)
5437                 *orientation = (camera_attr_tag_orientation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TAG_ORIENTATION];
5438
5439         CAM_LOG_INFO("ret : 0x%x", ret);
5440
5441         return ret;
5442 }
5443
5444
5445 int camera_attr_get_tag_software(camera_h camera, char **software)
5446 {
5447         int ret = CAMERA_ERROR_NONE;
5448         camera_cli_s *pc = (camera_cli_s *)camera;
5449         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
5450
5451         if (!pc || !pc->cb_info || !software) {
5452                 CAM_LOG_ERROR("NULL pointer %p %p", pc, software);
5453                 return CAMERA_ERROR_INVALID_PARAMETER;
5454         }
5455
5456         CAM_LOG_INFO("Enter");
5457
5458         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5459
5460         if (ret == CAMERA_ERROR_NONE)
5461                 *software = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_SOFTWARE]);
5462
5463         CAM_LOG_INFO("ret : 0x%x", ret);
5464
5465         return ret;
5466 }
5467
5468
5469 int camera_attr_get_geotag(camera_h camera, double *latitude, double *longitude, double *altitude)
5470 {
5471         int ret = CAMERA_ERROR_NONE;
5472         camera_cli_s *pc = (camera_cli_s *)camera;
5473         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
5474
5475         if (!pc || !pc->cb_info || !latitude || !longitude || !altitude) {
5476                 CAM_LOG_ERROR("NULL pointer %p %p %p %p", pc, latitude, longitude, altitude);
5477                 return CAMERA_ERROR_INVALID_PARAMETER;
5478         }
5479
5480         CAM_LOG_INFO("Enter");
5481
5482         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5483
5484         if (ret == CAMERA_ERROR_NONE) {
5485                 *latitude = pc->cb_info->get_geotag[0];
5486                 *longitude = pc->cb_info->get_geotag[1];
5487                 *altitude = pc->cb_info->get_geotag[2];
5488         }
5489
5490         CAM_LOG_INFO("ret : 0x%x", ret);
5491
5492         return ret;
5493 }
5494
5495
5496 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
5497 {
5498         int ret = CAMERA_ERROR_NONE;
5499         camera_cli_s *pc = (camera_cli_s *)camera;
5500         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
5501
5502         if (!pc || !pc->cb_info || !mode) {
5503                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5504                 return CAMERA_ERROR_INVALID_PARAMETER;
5505         }
5506
5507         CAM_LOG_INFO("Enter");
5508
5509         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5510
5511         if (ret == CAMERA_ERROR_NONE)
5512                 *mode = (camera_attr_flash_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_MODE];
5513
5514         CAM_LOG_INFO("ret : 0x%x", ret);
5515
5516         return ret;
5517 }
5518
5519
5520 int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state)
5521 {
5522         int ret = CAMERA_ERROR_NONE;
5523         int get_flash_state = 0;
5524
5525         if (!state) {
5526                 CAM_LOG_ERROR("NULL pointer");
5527                 return CAMERA_ERROR_INVALID_PARAMETER;
5528         }
5529
5530         ret = _camera_independent_request(MUSE_CAMERA_API_GET_FLASH_STATE,
5531                 (int)device, "get_flash_state", &get_flash_state);
5532
5533         if (ret == CAMERA_ERROR_NONE) {
5534                 *state = (camera_flash_state_e)get_flash_state;
5535                 CAM_LOG_INFO("flash state %d", *state);
5536         } else {
5537                 CAM_LOG_ERROR("failed 0x%x", ret);
5538         }
5539
5540         return ret;
5541 }
5542
5543
5544 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
5545 {
5546         int ret = CAMERA_ERROR_NONE;
5547         camera_cli_s *pc = (camera_cli_s *)camera;
5548         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
5549
5550         if (!pc || !pc->cb_info || !foreach_cb) {
5551                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5552                 return CAMERA_ERROR_INVALID_PARAMETER;
5553         }
5554
5555         CAM_LOG_INFO("Enter");
5556
5557         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = foreach_cb;
5558         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = user_data;
5559
5560         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5561
5562         CAM_LOG_INFO("ret : 0x%x", ret);
5563
5564         return ret;
5565 }
5566
5567
5568 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
5569 {
5570         int ret = CAMERA_ERROR_NONE;
5571         camera_cli_s *pc = (camera_cli_s *)camera;
5572         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
5573
5574         if (!pc || !pc->cb_info || !foreach_cb) {
5575                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5576                 return CAMERA_ERROR_INVALID_PARAMETER;
5577         }
5578
5579         CAM_LOG_INFO("Enter");
5580
5581         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = foreach_cb;
5582         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = user_data;
5583
5584         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5585
5586         CAM_LOG_INFO("ret : 0x%x", ret);
5587
5588         return ret;
5589 }
5590
5591
5592 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
5593 {
5594         int ret = CAMERA_ERROR_NONE;
5595         camera_cli_s *pc = (camera_cli_s *)camera;
5596         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
5597
5598         if (!pc || !pc->cb_info || !foreach_cb) {
5599                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5600                 return CAMERA_ERROR_INVALID_PARAMETER;
5601         }
5602
5603         CAM_LOG_INFO("Enter");
5604
5605         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = foreach_cb;
5606         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = user_data;
5607
5608         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5609
5610         CAM_LOG_INFO("ret : 0x%x", ret);
5611
5612         return ret;
5613 }
5614
5615
5616 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
5617 {
5618         int ret = CAMERA_ERROR_NONE;
5619         camera_cli_s *pc = (camera_cli_s *)camera;
5620         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
5621
5622         if (!pc || !pc->cb_info || !foreach_cb) {
5623                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5624                 return CAMERA_ERROR_INVALID_PARAMETER;
5625         }
5626
5627         CAM_LOG_INFO("Enter");
5628
5629         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = foreach_cb;
5630         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = user_data;
5631
5632         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5633
5634         CAM_LOG_INFO("ret : 0x%x", ret);
5635
5636         return ret;
5637 }
5638
5639
5640 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
5641 {
5642         int ret = CAMERA_ERROR_NONE;
5643         camera_cli_s *pc = (camera_cli_s *)camera;
5644         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
5645
5646         if (!pc || !pc->cb_info || !foreach_cb) {
5647                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5648                 return CAMERA_ERROR_INVALID_PARAMETER;
5649         }
5650
5651         CAM_LOG_INFO("Enter");
5652
5653         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = foreach_cb;
5654         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = user_data;
5655
5656         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5657
5658         CAM_LOG_INFO("ret : 0x%x", ret);
5659
5660         return ret;
5661 }
5662
5663
5664 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
5665 {
5666         int ret = CAMERA_ERROR_NONE;
5667         camera_cli_s *pc = (camera_cli_s *)camera;
5668         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
5669
5670         if (!pc || !pc->cb_info || !foreach_cb) {
5671                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5672                 return CAMERA_ERROR_INVALID_PARAMETER;
5673         }
5674
5675         CAM_LOG_INFO("Enter");
5676
5677         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = foreach_cb;
5678         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = user_data;
5679
5680         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5681
5682         CAM_LOG_INFO("ret : 0x%x", ret);
5683
5684         return ret;
5685 }
5686
5687
5688 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
5689 {
5690         int ret = CAMERA_ERROR_NONE;
5691         camera_cli_s *pc = (camera_cli_s *)camera;
5692         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
5693
5694         if (!pc || !pc->cb_info || !foreach_cb) {
5695                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5696                 return CAMERA_ERROR_INVALID_PARAMETER;
5697         }
5698
5699         CAM_LOG_INFO("Enter");
5700
5701         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = foreach_cb;
5702         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = user_data;
5703
5704         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5705
5706         CAM_LOG_INFO("ret : 0x%x", ret);
5707
5708         return ret;
5709 }
5710
5711
5712 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5713 {
5714         int ret = CAMERA_ERROR_NONE;
5715         camera_cli_s *pc = (camera_cli_s *)camera;
5716         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
5717
5718         if (!pc || !pc->cb_info || !foreach_cb) {
5719                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5720                 return CAMERA_ERROR_INVALID_PARAMETER;
5721         }
5722
5723         CAM_LOG_INFO("Enter");
5724
5725         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = foreach_cb;
5726         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = user_data;
5727
5728         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5729
5730         CAM_LOG_INFO("Enter, handle :%td", pc->remote_handle);
5731
5732         return ret;
5733 }
5734
5735
5736 int camera_attr_foreach_supported_fps_by_resolution(camera_h camera, int width, int height, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5737 {
5738         int ret = CAMERA_ERROR_NONE;
5739         camera_cli_s *pc = (camera_cli_s *)camera;
5740         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
5741         camera_msg_param param;
5742         int value = 0;
5743
5744         if (!pc || !pc->cb_info || !foreach_cb) {
5745                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5746                 return CAMERA_ERROR_INVALID_PARAMETER;
5747         }
5748
5749         CAM_LOG_INFO("Enter");
5750
5751         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = foreach_cb;
5752         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = user_data;
5753
5754         value = (width << 16) | height;
5755         CAMERA_MSG_PARAM_SET(param, INT, value);
5756
5757         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5758
5759         CAM_LOG_INFO("ret : 0x%x", ret);
5760
5761         return ret;
5762 }
5763
5764
5765 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
5766 {
5767         int ret = CAMERA_ERROR_NONE;
5768         camera_cli_s *pc = (camera_cli_s *)camera;
5769         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
5770
5771         if (!pc || !pc->cb_info || !foreach_cb) {
5772                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5773                 return CAMERA_ERROR_INVALID_PARAMETER;
5774         }
5775
5776         CAM_LOG_INFO("Enter");
5777
5778         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = foreach_cb;
5779         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = user_data;
5780
5781         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5782
5783         CAM_LOG_INFO("ret : 0x%x", ret);
5784
5785         return ret;
5786 }
5787
5788
5789 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
5790 {
5791         int ret = CAMERA_ERROR_NONE;
5792         camera_cli_s *pc = (camera_cli_s *)camera;
5793         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
5794
5795         if (!pc || !pc->cb_info || !foreach_cb) {
5796                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5797                 return CAMERA_ERROR_INVALID_PARAMETER;
5798         }
5799
5800         CAM_LOG_INFO("Enter");
5801
5802         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = foreach_cb;
5803         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = user_data;
5804
5805         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5806
5807         CAM_LOG_INFO("ret : 0x%x", ret);
5808
5809         return ret;
5810 }
5811
5812
5813 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
5814 {
5815         int ret = CAMERA_ERROR_NONE;
5816         camera_cli_s *pc = (camera_cli_s *)camera;
5817         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
5818         camera_msg_param param;
5819         int set_rotation = (int)rotation;
5820
5821         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5822
5823         CAM_LOG_INFO("Enter");
5824
5825         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
5826
5827         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5828
5829         CAM_LOG_INFO("ret : 0x%x", ret);
5830
5831         return ret;
5832 }
5833
5834
5835 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
5836 {
5837         int ret = CAMERA_ERROR_NONE;
5838         camera_cli_s *pc = (camera_cli_s *)camera;
5839         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
5840
5841         if (!pc || !pc->cb_info || !rotation) {
5842                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
5843                 return CAMERA_ERROR_INVALID_PARAMETER;
5844         }
5845
5846         CAM_LOG_INFO("Enter");
5847
5848         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5849
5850         if (ret == CAMERA_ERROR_NONE)
5851                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_ROTATION];
5852
5853         CAM_LOG_INFO("ret : 0x%x", ret);
5854
5855         return ret;
5856 }
5857
5858
5859 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
5860 {
5861         int ret = CAMERA_ERROR_NONE;
5862         camera_cli_s *pc = (camera_cli_s *)camera;
5863         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
5864         camera_msg_param param;
5865         int set_flip = (int)flip;
5866
5867         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5868
5869         CAM_LOG_INFO("Enter");
5870
5871         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
5872
5873         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5874
5875         CAM_LOG_INFO("ret : 0x%x", ret);
5876
5877         return ret;
5878 }
5879
5880
5881 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
5882 {
5883         int ret = CAMERA_ERROR_NONE;
5884         camera_cli_s *pc = (camera_cli_s *)camera;
5885         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
5886
5887         if (!pc || !pc->cb_info || !flip) {
5888                 CAM_LOG_ERROR("NULL pointer %p %p", pc, flip);
5889                 return CAMERA_ERROR_INVALID_PARAMETER;
5890         }
5891
5892         CAM_LOG_INFO("Enter");
5893
5894         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5895
5896         if (ret == CAMERA_ERROR_NONE)
5897                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_FLIP];
5898
5899         CAM_LOG_INFO("ret : 0x%x", ret);
5900
5901         return ret;
5902 }
5903
5904 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
5905 {
5906         return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_HDR_MODE, (int)mode);
5907 }
5908
5909
5910 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
5911 {
5912         int ret = CAMERA_ERROR_NONE;
5913         camera_cli_s *pc = (camera_cli_s *)camera;
5914         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
5915
5916         if (!pc || !pc->cb_info || !mode) {
5917                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5918                 return CAMERA_ERROR_INVALID_PARAMETER;
5919         }
5920
5921         CAM_LOG_INFO("Enter");
5922
5923         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5924
5925         if (ret == CAMERA_ERROR_NONE)
5926                 *mode = (camera_attr_hdr_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HDR_MODE];
5927
5928         CAM_LOG_INFO("ret : 0x%x", ret);
5929
5930         return ret;
5931 }
5932
5933
5934 bool camera_attr_is_supported_hdr_capture(camera_h camera)
5935 {
5936         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE);
5937 }
5938
5939
5940 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
5941 {
5942         int ret = CAMERA_ERROR_NONE;
5943         camera_cli_s *pc = (camera_cli_s *)camera;
5944         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
5945
5946         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5947
5948         CAM_LOG_INFO("Enter");
5949
5950         if (!camera_attr_is_supported_hdr_capture(camera)) {
5951                 CAM_LOG_ERROR("HDR not supported");
5952                 return CAMERA_ERROR_NOT_SUPPORTED;
5953         }
5954
5955         if (!callback) {
5956                 CAM_LOG_ERROR("NULL callback");
5957                 return CAMERA_ERROR_INVALID_PARAMETER;
5958         }
5959
5960         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5961
5962         if (ret == CAMERA_ERROR_NONE) {
5963                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5964
5965                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
5966                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
5967
5968                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5969         }
5970
5971         CAM_LOG_INFO("ret : 0x%x", ret);
5972
5973         return ret;
5974 }
5975
5976
5977 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
5978 {
5979         int ret = CAMERA_ERROR_NONE;
5980         camera_cli_s *pc = (camera_cli_s *)camera;
5981         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
5982
5983         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
5984
5985         CAM_LOG_INFO("Enter");
5986
5987         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5988
5989         if (ret == CAMERA_ERROR_NONE) {
5990                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5991
5992                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
5993                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
5994
5995                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5996         }
5997
5998         CAM_LOG_INFO("ret : 0x%x", ret);
5999
6000         return ret;
6001 }
6002
6003
6004 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
6005 {
6006         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE, (int)enable);
6007 }
6008
6009
6010 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
6011 {
6012         int ret = CAMERA_ERROR_NONE;
6013         camera_cli_s *pc = (camera_cli_s *)camera;
6014         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
6015
6016         if (!pc || !pc->cb_info || !enabled) {
6017                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
6018                 return CAMERA_ERROR_INVALID_PARAMETER;
6019         }
6020
6021         CAM_LOG_INFO("Enter");
6022
6023         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6024
6025         if (ret == CAMERA_ERROR_NONE)
6026                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE];
6027
6028         CAM_LOG_INFO("ret : 0x%x", ret);
6029
6030         return ret;
6031 }
6032
6033
6034 bool camera_attr_is_supported_anti_shake(camera_h camera)
6035 {
6036         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE);
6037 }
6038
6039
6040 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
6041 {
6042         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION, (int)enable);
6043 }
6044
6045
6046 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
6047 {
6048         int ret = CAMERA_ERROR_NONE;
6049         camera_cli_s *pc = (camera_cli_s *)camera;
6050         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
6051
6052         if (!pc || !pc->cb_info || !enabled) {
6053                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
6054                 return CAMERA_ERROR_INVALID_PARAMETER;
6055         }
6056
6057         CAM_LOG_INFO("Enter");
6058
6059         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6060
6061         if (ret == CAMERA_ERROR_NONE)
6062                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION];
6063
6064         CAM_LOG_INFO("ret : 0x%x", ret);
6065
6066         return ret;
6067 }
6068
6069
6070 bool camera_attr_is_supported_video_stabilization(camera_h camera)
6071 {
6072         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION);
6073 }
6074
6075
6076 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
6077 {
6078         return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST, (int)enable);
6079 }
6080
6081
6082 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
6083 {
6084         int ret = CAMERA_ERROR_NONE;
6085         camera_cli_s *pc = (camera_cli_s *)camera;
6086         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
6087
6088         if (!pc || !pc->cb_info || !enabled) {
6089                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
6090                 return CAMERA_ERROR_INVALID_PARAMETER;
6091         }
6092
6093         CAM_LOG_INFO("Enter");
6094
6095         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6096
6097         if (ret == CAMERA_ERROR_NONE)
6098                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST];
6099
6100         CAM_LOG_INFO("ret : 0x%x", ret);
6101
6102         return ret;
6103 }
6104
6105
6106 bool camera_attr_is_supported_auto_contrast(camera_h camera)
6107 {
6108         return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST);
6109 }
6110
6111
6112 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
6113 {
6114         int ret = CAMERA_ERROR_NONE;
6115         camera_cli_s *pc = (camera_cli_s *)camera;
6116         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
6117         camera_msg_param param;
6118         int set_disable = (int)disable;
6119
6120         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6121
6122         CAM_LOG_INFO("Enter");
6123
6124         CAMERA_MSG_PARAM_SET(param, INT, set_disable);
6125
6126         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6127
6128         CAM_LOG_INFO("ret : 0x%x", ret);
6129
6130         return ret;
6131 }
6132
6133
6134 int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type, int pan_step)
6135 {
6136         int ret = CAMERA_ERROR_NONE;
6137         camera_cli_s *pc = (camera_cli_s *)camera;
6138         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
6139         camera_msg_param param0;
6140         camera_msg_param param1;
6141
6142         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6143
6144         CAM_LOG_INFO("Enter");
6145
6146         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6147         CAMERA_MSG_PARAM_SET(param1, INT, pan_step);
6148
6149         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6150                 &param0, &param1, CAMERA_CB_TIMEOUT);
6151
6152         CAM_LOG_INFO("ret : 0x%x", ret);
6153
6154         return ret;
6155 }
6156
6157
6158 int camera_attr_get_pan(camera_h camera, int *pan_step)
6159 {
6160         int ret = CAMERA_ERROR_NONE;
6161         camera_cli_s *pc = (camera_cli_s *)camera;
6162         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
6163
6164         if (!pc || !pc->cb_info || !pan_step) {
6165                 CAM_LOG_ERROR("NULL pointer %p %p", pc, pan_step);
6166                 return CAMERA_ERROR_INVALID_PARAMETER;
6167         }
6168
6169         CAM_LOG_INFO("Enter");
6170
6171         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6172
6173         if (ret == CAMERA_ERROR_NONE)
6174                 *pan_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PAN];
6175
6176         CAM_LOG_INFO("ret : 0x%x", ret);
6177
6178         return ret;
6179 }
6180
6181
6182 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
6183 {
6184         int ret = CAMERA_ERROR_NONE;
6185         camera_cli_s *pc = (camera_cli_s *)camera;
6186         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
6187
6188         if (!pc || !pc->cb_info || !min || !max) {
6189                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
6190                 return CAMERA_ERROR_INVALID_PARAMETER;
6191         }
6192
6193         CAM_LOG_INFO("Enter");
6194
6195         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6196
6197         if (ret == CAMERA_ERROR_NONE) {
6198                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
6199                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
6200         }
6201
6202         CAM_LOG_INFO("ret : 0x%x", ret);
6203
6204         return ret;
6205 }
6206
6207
6208 int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type, int tilt_step)
6209 {
6210         int ret = CAMERA_ERROR_NONE;
6211         camera_cli_s *pc = (camera_cli_s *)camera;
6212         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
6213         camera_msg_param param0;
6214         camera_msg_param param1;
6215
6216         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6217
6218         CAM_LOG_INFO("Enter");
6219
6220         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6221         CAMERA_MSG_PARAM_SET(param1, INT, tilt_step);
6222
6223         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6224                 &param0, &param1, CAMERA_CB_TIMEOUT);
6225
6226         CAM_LOG_INFO("ret : 0x%x", ret);
6227
6228         return ret;
6229 }
6230
6231
6232 int camera_attr_get_tilt(camera_h camera, int *tilt_step)
6233 {
6234         int ret = CAMERA_ERROR_NONE;
6235         camera_cli_s *pc = (camera_cli_s *)camera;
6236         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
6237
6238         if (!pc || !pc->cb_info || !tilt_step) {
6239                 CAM_LOG_ERROR("NULL pointer %p %p", pc, tilt_step);
6240                 return CAMERA_ERROR_INVALID_PARAMETER;
6241         }
6242
6243         CAM_LOG_INFO("Enter");
6244
6245         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6246
6247         if (ret == CAMERA_ERROR_NONE)
6248                 *tilt_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TILT];
6249
6250         CAM_LOG_INFO("ret : 0x%x", ret);
6251
6252         return ret;
6253 }
6254
6255
6256 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
6257 {
6258         int ret = CAMERA_ERROR_NONE;
6259         camera_cli_s *pc = (camera_cli_s *)camera;
6260         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
6261
6262         if (!pc || !pc->cb_info || !min || !max) {
6263                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
6264                 return CAMERA_ERROR_INVALID_PARAMETER;
6265         }
6266
6267         CAM_LOG_INFO("Enter");
6268
6269         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6270
6271         if (ret == CAMERA_ERROR_NONE) {
6272                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
6273                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
6274         }
6275
6276         CAM_LOG_INFO("ret : 0x%x", ret);
6277
6278         return ret;
6279 }
6280
6281
6282 int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
6283 {
6284         int ret = CAMERA_ERROR_NONE;
6285         camera_cli_s *pc = (camera_cli_s *)camera;
6286         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
6287         camera_msg_param param;
6288         int set_ptz_type = (int)ptz_type;
6289
6290         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6291
6292         CAM_LOG_INFO("Enter");
6293
6294         CAMERA_MSG_PARAM_SET(param, INT, set_ptz_type);
6295
6296         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6297
6298         CAM_LOG_INFO("ret : 0x%x", ret);
6299
6300         return ret;
6301 }
6302
6303
6304 int camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data)
6305 {
6306         int ret = CAMERA_ERROR_NONE;
6307         camera_cli_s *pc = (camera_cli_s *)camera;
6308         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
6309
6310         if (!pc || !pc->cb_info || !foreach_cb) {
6311                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
6312                 return CAMERA_ERROR_INVALID_PARAMETER;
6313         }
6314
6315         CAM_LOG_INFO("Enter");
6316
6317         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = foreach_cb;
6318         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = user_data;
6319
6320         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6321
6322         CAM_LOG_INFO("ret : 0x%x", ret);
6323
6324         return ret;
6325 }
6326
6327
6328 int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, int height)
6329 {
6330         int ret = CAMERA_ERROR_NONE;
6331         camera_cli_s *pc = (camera_cli_s *)camera;
6332         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
6333         int set_display_roi_area[4] = {x, y, width, height};
6334         char *msg = NULL;
6335         int length = 0;
6336
6337         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6338
6339         CAM_LOG_INFO("Enter");
6340
6341         if (pc->cb_info->is_evas_render) {
6342                 ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
6343                 if (ret != MM_ERROR_NONE) {
6344                         CAM_LOG_ERROR("mm_evas_renderer_set_roi_area error 0x%x", ret);
6345                         return CAMERA_ERROR_INVALID_OPERATION;
6346                 }
6347         }
6348
6349         length = sizeof(set_display_roi_area) / sizeof(int) + \
6350                 (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
6351
6352         msg = muse_core_msg_new(api,
6353                 MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
6354                 NULL);
6355
6356         _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
6357
6358         return ret;
6359 }
6360
6361
6362 int camera_attr_get_display_roi_area(camera_h camera, int *x, int *y, int *width, int *height)
6363 {
6364         camera_cli_s *pc = (camera_cli_s *)camera;
6365         int ret = CAMERA_ERROR_NONE;
6366         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
6367
6368         if (!pc || !pc->cb_info || !x || !y || !width || !height) {
6369                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, x, y, width, height);
6370                 return CAMERA_ERROR_INVALID_PARAMETER;
6371         }
6372
6373         CAM_LOG_INFO("Enter");
6374
6375         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6376
6377         if (ret == CAMERA_ERROR_NONE) {
6378                 *x = pc->cb_info->get_display_roi_area[0];
6379                 *y = pc->cb_info->get_display_roi_area[1];
6380                 *width = pc->cb_info->get_display_roi_area[2];
6381                 *height = pc->cb_info->get_display_roi_area[3];
6382         }
6383
6384         CAM_LOG_INFO("ret : 0x%x", ret);
6385
6386         return ret;
6387 }
6388
6389
6390 int camera_get_device_state(camera_device_e device, camera_device_state_e *state)
6391 {
6392         int ret = CAMERA_ERROR_NONE;
6393         int get_device_state = 0;
6394
6395         if (!state) {
6396                 CAM_LOG_ERROR("NULL pointer");
6397                 return CAMERA_ERROR_INVALID_PARAMETER;
6398         }
6399
6400         ret = _camera_independent_request(MUSE_CAMERA_API_GET_DEVICE_STATE,
6401                 (int)device, "get_device_state", &get_device_state);
6402
6403         if (ret == CAMERA_ERROR_NONE) {
6404                 *state = (camera_device_state_e)get_device_state;
6405                 CAM_LOG_INFO("device state %d", *state);
6406         } else {
6407                 CAM_LOG_ERROR("failed 0x%x", ret);
6408         }
6409
6410         return ret;
6411 }
6412
6413
6414 int camera_add_device_state_changed_cb(camera_device_state_changed_cb callback, void *user_data, int *cb_id)
6415 {
6416         int ret = CAMERA_ERROR_NONE;
6417         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6418         camera_cb_info *info = NULL;
6419
6420         if (!callback || !cb_id) {
6421                 CAM_LOG_ERROR("invalid pointer %p %p", callback, cb_id);
6422                 return CAMERA_ERROR_INVALID_PARAMETER;
6423         }
6424
6425         /* check camera support */
6426         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6427         if (ret != CAMERA_ERROR_NONE) {
6428                 CAM_LOG_ERROR("get device state failed");
6429                 return ret;
6430         }
6431
6432         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6433
6434         info = g_new0(camera_cb_info, 1);
6435         if (!info) {
6436                 CAM_LOG_ERROR("info failed");
6437                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
6438                 goto _DONE;
6439         }
6440
6441         info->id = ++g_cam_dev_state_changed_cb_id;
6442         info->callback = (void *)callback;
6443         info->user_data = user_data;
6444
6445         *cb_id = info->id;
6446
6447         /* subscribe dbus signal for camera state change */
6448         if (!g_cam_dev_state_changed_cb_conn) {
6449                 g_cam_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
6450                 if (!g_cam_dev_state_changed_cb_conn) {
6451                         CAM_LOG_ERROR("failed to get gdbus connection");
6452                         ret = CAMERA_ERROR_INVALID_OPERATION;
6453                         goto _DONE;
6454                 }
6455
6456                 CAM_LOG_INFO("subscribe signal %s - %s - %s",
6457                         MM_CAMCORDER_DBUS_OBJECT,
6458                         MM_CAMCORDER_DBUS_INTERFACE_CAMERA,
6459                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
6460
6461                 g_cam_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_cam_dev_state_changed_cb_conn,
6462                         NULL, MM_CAMCORDER_DBUS_INTERFACE_CAMERA, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
6463                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__camera_device_state_changed_cb, NULL, NULL);
6464                 if (!g_cam_dev_state_changed_cb_subscribe_id) {
6465                         CAM_LOG_ERROR("failed to get gdbus connection");
6466                         ret = CAMERA_ERROR_INVALID_OPERATION;
6467                         goto _DONE;
6468                 }
6469
6470                 CAM_LOG_INFO("signal subscribe id %u", g_cam_dev_state_changed_cb_subscribe_id);
6471         }
6472
6473         g_cam_dev_state_changed_cb_list = g_list_prepend(g_cam_dev_state_changed_cb_list, (gpointer)info);
6474
6475         CAM_LOG_INFO("callback id %d", info->id);
6476
6477 _DONE:
6478         if (ret != CAMERA_ERROR_NONE) {
6479                 if (info) {
6480                         g_free(info);
6481                         info = NULL;
6482                 }
6483
6484                 if (g_cam_dev_state_changed_cb_conn) {
6485                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6486                         g_cam_dev_state_changed_cb_conn = NULL;
6487                 }
6488         }
6489
6490         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6491
6492         return ret;
6493 }
6494
6495
6496 int camera_remove_device_state_changed_cb(int cb_id)
6497 {
6498         int ret = CAMERA_ERROR_NONE;
6499         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6500         GList *tmp_list = NULL;
6501         camera_cb_info *info = NULL;
6502
6503         /* check camera support */
6504         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6505         if (ret != CAMERA_ERROR_NONE) {
6506                 CAM_LOG_ERROR("get device state failed");
6507                 return ret;
6508         }
6509
6510         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6511
6512         if (!g_cam_dev_state_changed_cb_list) {
6513                 CAM_LOG_ERROR("there is no callback info");
6514                 ret = CAMERA_ERROR_INVALID_OPERATION;
6515                 goto _DONE;
6516         }
6517
6518         tmp_list = g_cam_dev_state_changed_cb_list;
6519
6520         do {
6521                 info = tmp_list->data;
6522                 tmp_list = tmp_list->next;
6523
6524                 if (!info) {
6525                         CAM_LOG_WARNING("NULL info");
6526                         continue;
6527                 }
6528
6529                 if (info->id == cb_id) {
6530                         g_cam_dev_state_changed_cb_list = g_list_remove(g_cam_dev_state_changed_cb_list, info);
6531
6532                         g_free(info);
6533                         info = NULL;
6534
6535                         if (!g_cam_dev_state_changed_cb_list) {
6536                                 /* no remained callback */
6537                                 if (g_cam_dev_state_changed_cb_conn) {
6538                                         /* unsubscribe signal */
6539                                         g_dbus_connection_signal_unsubscribe(g_cam_dev_state_changed_cb_conn, g_cam_dev_state_changed_cb_subscribe_id);
6540                                         g_cam_dev_state_changed_cb_subscribe_id = 0;
6541
6542                                         /* unref connection */
6543                                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6544                                         g_cam_dev_state_changed_cb_conn = NULL;
6545                                 }
6546                         }
6547
6548                         CAM_LOG_INFO("id %d callback removed", cb_id);
6549                         ret = CAMERA_ERROR_NONE;
6550
6551                         goto _DONE;
6552                 }
6553         } while (tmp_list);
6554
6555         CAM_LOG_ERROR("id %d callback not found", cb_id);
6556         ret = CAMERA_ERROR_INVALID_PARAMETER;
6557
6558 _DONE:
6559         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6560
6561         return ret;
6562 }
6563
6564
6565 //LCOV_EXCL_START
6566 int camera_media_bridge_set_bridge(camera_h camera, media_bridge_h bridge)
6567 {
6568         int ret = CAMERA_ERROR_NONE;
6569         camera_cli_s *pc = (camera_cli_s *)camera;
6570         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_BRIDGE;
6571
6572         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6573
6574         g_mutex_lock(&pc->cb_info->bridge_lock);
6575
6576         if (pc->cb_info->bridge) {
6577                 CAM_LOG_ERROR("media bridge[%p] is already set", pc->cb_info->bridge);
6578                 ret = CAMERA_ERROR_INVALID_OPERATION;
6579                 goto _SET_MEDIA_BRIDGE_DONE;
6580         }
6581
6582         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6583         if (ret != CAMERA_ERROR_NONE) {
6584                 CAM_LOG_ERROR("set media bridge failed[0x%x]", ret);
6585                 goto _SET_MEDIA_BRIDGE_DONE;
6586         }
6587
6588         pc->cb_info->bridge = bridge;
6589
6590         CAM_LOG_INFO("[%p] set media bridge[%p]", camera, bridge);
6591
6592 _SET_MEDIA_BRIDGE_DONE:
6593         g_mutex_unlock(&pc->cb_info->bridge_lock);
6594
6595         return ret;
6596 }
6597
6598
6599 int camera_media_bridge_unset_bridge(camera_h camera)
6600 {
6601         int ret = CAMERA_ERROR_NONE;
6602         camera_cli_s *pc = (camera_cli_s *)camera;
6603         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_BRIDGE;
6604
6605         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6606
6607         g_mutex_lock(&pc->cb_info->bridge_lock);
6608
6609         if (!pc->cb_info->bridge) {
6610                 CAM_LOG_ERROR("no media bridge");
6611                 ret = CAMERA_ERROR_INVALID_OPERATION;
6612                 goto _UNSET_MEDIA_BRIDGE_DONE;
6613         }
6614
6615         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6616         if (ret != CAMERA_ERROR_NONE) {
6617                 CAM_LOG_ERROR("unset media bridge failed[0x%x]", ret);
6618                 goto _UNSET_MEDIA_BRIDGE_DONE;
6619         }
6620
6621         CAM_LOG_INFO("[%p] unset media bridge[%p]", camera, pc->cb_info->bridge);
6622
6623         pc->cb_info->bridge = NULL;
6624
6625 _UNSET_MEDIA_BRIDGE_DONE:
6626         g_mutex_unlock(&pc->cb_info->bridge_lock);
6627
6628         return ret;
6629 }
6630 //LCOV_EXCL_STOP
6631
6632
6633 int camera_create_network(camera_device_e device, camera_h *camera)
6634 {
6635         return _camera_create_private(device, true, camera);
6636 }
6637
6638
6639 int camera_device_manager_initialize(camera_device_manager_h *manager)
6640 {
6641         unsigned int i = 0;
6642         int ret = CAMERA_ERROR_NONE;
6643         void *dl_handle = NULL;
6644         g_autofree camera_device_manager *new_manager = g_new0(camera_device_manager, 1);
6645         cdm_symbol_table sym_table[] = {
6646                 {(void **)&new_manager->initialize, "cdm_initialize"},
6647                 {(void **)&new_manager->deinitialize, "cdm_deinitialize"},
6648                 {(void **)&new_manager->get_device_list, "cdm_get_device_list"},
6649                 {(void **)&new_manager->add_device_connection_changed_cb, "cdm_add_device_connection_changed_cb"},
6650                 {(void **)&new_manager->remove_device_connection_changed_cb, "cdm_remove_device_connection_changed_cb"},
6651         };
6652
6653         CAMERA_CHECK_DEVICE_MANAGER;
6654
6655         if (!manager) {
6656                 CAM_LOG_ERROR("NULL manager");
6657                 ret = CAMERA_ERROR_INVALID_PARAMETER;
6658                 goto _INITIALIZE_FAILED;
6659         }
6660
6661         dl_handle = dlopen(LIB_CAMERA_DEVICE_MANAGER, RTLD_NOW);
6662         if (!dl_handle) {
6663                 CAM_LOG_ERROR("dlopen[%s] failed[%s]", LIB_CAMERA_DEVICE_MANAGER, dlerror());
6664                 ret = CAMERA_ERROR_INVALID_OPERATION;
6665                 goto _INITIALIZE_FAILED;
6666         }
6667
6668         /* get symbols */
6669         for (i = 0 ; i < G_N_ELEMENTS(sym_table) ; i++) {
6670                 *sym_table[i].func_ptr = dlsym(dl_handle, sym_table[i].func_name);
6671                 if (*sym_table[i].func_ptr == NULL) {
6672                         CAM_LOG_ERROR("symbol failed[%s]", sym_table[i].func_name);
6673                         ret = CAMERA_ERROR_INVALID_OPERATION;
6674                         goto _INITIALIZE_FAILED;
6675                 }
6676         }
6677
6678         ret = new_manager->initialize();
6679         if (ret != CAMERA_ERROR_NONE) {
6680                 CAM_LOG_ERROR("failed[0x%x]", ret);
6681                 goto _INITIALIZE_FAILED;
6682         }
6683
6684         new_manager->dl_handle = dl_handle;
6685         *manager = (camera_device_manager_h)g_steal_pointer(&new_manager);
6686
6687         CAM_LOG_INFO("camera device manager[%p](dl handle[%p]) initialized",
6688                 *manager, dl_handle);
6689
6690         return CAMERA_ERROR_NONE;
6691
6692 _INITIALIZE_FAILED:
6693         if (dl_handle)
6694                 dlclose(dl_handle);
6695
6696         return ret;
6697 }
6698
6699
6700 //LCOV_EXCL_START
6701 int camera_device_manager_deinitialize(camera_device_manager_h manager)
6702 {
6703         int ret = CAMERA_ERROR_NONE;
6704         camera_device_manager *m = (camera_device_manager *)manager;
6705
6706         CAMERA_CHECK_DEVICE_MANAGER;
6707
6708         if (!m) {
6709                 CAM_LOG_ERROR("NULL manager");
6710                 return CAMERA_ERROR_INVALID_PARAMETER;
6711         }
6712
6713         CAM_LOG_INFO("deinitialize camera device manager[%p]", m);
6714
6715         ret = m->deinitialize();
6716         if (ret != CAMERA_ERROR_NONE) {
6717                 CAM_LOG_ERROR("failed[0x%x]", ret);
6718                 return ret;
6719         }
6720
6721         CAM_LOG_INFO("close dl handle[%p]", m->dl_handle);
6722
6723         dlclose(m->dl_handle);
6724
6725         memset(m, 0x0, sizeof(camera_device_manager));
6726         g_free(m);
6727
6728         return CAMERA_ERROR_NONE;
6729 }
6730
6731
6732 int camera_device_manager_foreach_supported_device(camera_device_manager_h manager, camera_supported_device_cb callback, void *user_data)
6733 {
6734         int ret = CAMERA_ERROR_NONE;
6735         unsigned int i = 0;
6736         camera_device_list_s device_list;
6737         camera_device_s *device = NULL;
6738         camera_device_manager *m = (camera_device_manager *)manager;
6739
6740         CAMERA_CHECK_DEVICE_MANAGER;
6741
6742         if (!m || !callback) {
6743                 CAM_LOG_ERROR("NULL parameter[%p,%p]", m, callback);
6744                 return CAMERA_ERROR_INVALID_PARAMETER;
6745         }
6746
6747         CAM_LOG_INFO("enter");
6748
6749         memset(&device_list, 0x0, sizeof(camera_device_list_s));
6750
6751         ret = m->get_device_list(&device_list);
6752         if (ret != CAMERA_ERROR_NONE) {
6753                 CAM_LOG_ERROR("failed[0x%x]", ret);
6754                 return ret;
6755         }
6756
6757         CAM_LOG_INFO("device count[%d]", device_list.count);
6758
6759         for (i = 0 ; i < device_list.count ; i++) {
6760                 device = &device_list.device[i];
6761
6762                 CAM_LOG_INFO("    [%d] : type[%d], index[%d], name[%s], id[%s], ex-stream[%d]",
6763                         i, device->type, device->index,
6764                         device->name, device->id, device->extra_stream_num);
6765
6766                 if (!callback(device, user_data)) {
6767                         CAM_LOG_WARNING("callback is stopped[called:%u,total:%u]",
6768                                 i + 1, device_list.count);
6769                         break;
6770                 }
6771         }
6772
6773         return CAMERA_ERROR_NONE;
6774 }
6775
6776
6777 int camera_device_manager_add_device_connection_changed_cb(camera_device_manager_h manager,
6778         camera_device_connection_changed_cb callback, void *user_data, int *cb_id)
6779 {
6780         int ret = CAMERA_ERROR_NONE;
6781         camera_device_manager *m = (camera_device_manager *)manager;
6782
6783         CAMERA_CHECK_DEVICE_MANAGER;
6784
6785         if (!m || !callback || !cb_id) {
6786                 CAM_LOG_ERROR("NULL parameter[%p,%p,%p]", m, callback, cb_id);
6787                 return CAMERA_ERROR_INVALID_PARAMETER;
6788         }
6789
6790         CAM_LOG_INFO("enter");
6791
6792         ret = m->add_device_connection_changed_cb(callback, user_data, cb_id);
6793         if (ret != CAMERA_ERROR_NONE) {
6794                 CAM_LOG_ERROR("failed[0x%x]", ret);
6795                 return ret;
6796         }
6797
6798         CAM_LOG_INFO("cb_id[%d] added", *cb_id);
6799
6800         return CAMERA_ERROR_NONE;
6801 }
6802
6803
6804 int camera_device_manager_remove_device_connection_changed_cb(camera_device_manager_h manager, int cb_id)
6805 {
6806         int ret = CAMERA_ERROR_NONE;
6807         camera_device_manager *m = (camera_device_manager *)manager;
6808
6809         CAMERA_CHECK_DEVICE_MANAGER;
6810
6811         if (!m) {
6812                 CAM_LOG_ERROR("NULL manager");
6813                 return CAMERA_ERROR_INVALID_PARAMETER;
6814         }
6815
6816         CAM_LOG_INFO("enter - cb_id[%d]", cb_id);
6817
6818         ret = m->remove_device_connection_changed_cb(cb_id);
6819         if (ret != CAMERA_ERROR_NONE) {
6820                 CAM_LOG_ERROR("failed[0x%x]", ret);
6821                 return ret;
6822         }
6823
6824         CAM_LOG_INFO("cb_id[%d] removed", cb_id);
6825
6826         return CAMERA_ERROR_NONE;
6827 }
6828 //LCOV_EXCL_STOP
6829
6830
6831 int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callback, void *user_data)
6832 {
6833         int ret = CAMERA_ERROR_NONE;
6834         camera_cli_s *pc = (camera_cli_s *)camera;
6835         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_CB;
6836
6837         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6838
6839         if (!camera_is_supported_extra_preview(camera)) {
6840                 CAM_LOG_ERROR("extra preview is not supported");
6841                 return CAMERA_ERROR_NOT_SUPPORTED;
6842         }
6843
6844         if (!callback) {
6845                 CAM_LOG_ERROR("NULL callback");
6846                 return CAMERA_ERROR_INVALID_PARAMETER;
6847         }
6848
6849         CAM_LOG_INFO("Enter");
6850
6851         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6852
6853         if (ret == CAMERA_ERROR_NONE) {
6854                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6855
6856                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = callback;
6857                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = user_data;
6858
6859                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6860         }
6861
6862         CAM_LOG_INFO("ret : 0x%x", ret);
6863
6864         return ret;
6865 }
6866
6867
6868 int camera_unset_extra_preview_cb(camera_h camera)
6869 {
6870         int ret = CAMERA_ERROR_NONE;
6871         camera_cli_s *pc = (camera_cli_s *)camera;
6872         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_EXTRA_PREVIEW_CB;
6873
6874         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6875
6876         if (!camera_is_supported_extra_preview(camera)) {
6877                 CAM_LOG_ERROR("extra preview is not supported");
6878                 return CAMERA_ERROR_NOT_SUPPORTED;
6879         }
6880
6881         CAM_LOG_INFO("Enter");
6882
6883         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6884
6885         if (ret == CAMERA_ERROR_NONE) {
6886                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6887
6888                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
6889                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
6890
6891                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
6892         }
6893
6894         CAM_LOG_INFO("ret : 0x%x", ret);
6895
6896         return ret;
6897 }
6898
6899
6900 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)
6901 {
6902         int ret = CAMERA_ERROR_NONE;
6903         int stream_format[4] = {pixel_format, width, height, fps};
6904         char *msg = NULL;
6905         camera_cli_s *pc = (camera_cli_s *)camera;
6906         muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_STREAM_FORMAT;
6907
6908         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6909
6910         CAM_LOG_INFO("Enter - stream[%d],[%d,%dx%d,%d]",
6911                 stream_id, pixel_format, width, height, fps);
6912
6913         msg = muse_core_msg_new(api,
6914                 MUSE_TYPE_INT, "stream_id", stream_id,
6915                 MUSE_TYPE_ARRAY, "stream_format", 4, stream_format,
6916                 NULL);
6917
6918         _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
6919
6920         return ret;
6921 }
6922
6923
6924 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)
6925 {
6926         int ret = CAMERA_ERROR_NONE;
6927         camera_cli_s *pc = (camera_cli_s *)camera;
6928         camera_msg_param param;
6929         muse_camera_api_e api = MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT;
6930
6931         if (!pc || !pc->cb_info || !pixel_format || !width || !height || !fps) {
6932                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, pixel_format, width, height, fps);
6933                 return CAMERA_ERROR_INVALID_PARAMETER;
6934         }
6935
6936         CAM_LOG_INFO("Enter - stream[%d]", stream_id);
6937
6938         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
6939
6940         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6941
6942         if (ret == CAMERA_ERROR_NONE) {
6943                 *pixel_format = (camera_pixel_format_e)pc->cb_info->get_extra_preview_stream_format[0];
6944                 *width = pc->cb_info->get_extra_preview_stream_format[1];
6945                 *height = pc->cb_info->get_extra_preview_stream_format[2];
6946                 *fps = pc->cb_info->get_extra_preview_stream_format[3];
6947         }
6948
6949         CAM_LOG_INFO("ret : 0x%x", ret);
6950
6951         return ret;
6952 }
6953
6954
6955 int camera_attr_set_extra_preview_bitrate(camera_h camera, int stream_id, int bitrate)
6956 {
6957         int ret = CAMERA_ERROR_NONE;
6958         camera_cli_s *pc = (camera_cli_s *)camera;
6959         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_BITRATE;
6960         camera_msg_param param0;
6961         camera_msg_param param1;
6962
6963         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
6964
6965         CAM_LOG_INFO("Enter - stream[%d], bitrate[%d]", stream_id, bitrate);
6966
6967         CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
6968         CAMERA_MSG_PARAM_SET(param1, INT, bitrate);
6969
6970         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6971                 &param0, &param1, CAMERA_CB_TIMEOUT);
6972
6973         CAM_LOG_INFO("ret : 0x%x", ret);
6974
6975         return ret;
6976 }
6977
6978
6979 int camera_attr_get_extra_preview_bitrate(camera_h camera, int stream_id, int *bitrate)
6980 {
6981         int ret = CAMERA_ERROR_NONE;
6982         camera_cli_s *pc = (camera_cli_s *)camera;
6983         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_BITRATE;
6984         camera_msg_param param;
6985
6986         if (!pc || !pc->cb_info || !bitrate) {
6987                 CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
6988                 return CAMERA_ERROR_INVALID_PARAMETER;
6989         }
6990
6991         CAM_LOG_INFO("Enter - stream[%d]", stream_id);
6992
6993         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
6994
6995         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6996
6997         if (ret == CAMERA_ERROR_NONE) {
6998                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_BITRATE];
6999                 CAM_LOG_INFO("get bitrate[%d] for stream[%d]", *bitrate, stream_id);
7000         } else {
7001                 CAM_LOG_ERROR("get bitrate failed for stream[%d] : 0x%x", stream_id, ret);
7002         }
7003
7004         return ret;
7005 }
7006
7007
7008 int camera_attr_set_extra_preview_gop_interval(camera_h camera, int stream_id, int interval)
7009 {
7010         int ret = CAMERA_ERROR_NONE;
7011         camera_cli_s *pc = (camera_cli_s *)camera;
7012         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_GOP_INTERVAL;
7013         camera_msg_param param0;
7014         camera_msg_param param1;
7015
7016         CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
7017
7018         CAM_LOG_INFO("Enter - stream[%d], GOP interval[%d]", stream_id, interval);
7019
7020         CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
7021         CAMERA_MSG_PARAM_SET(param1, INT, interval);
7022
7023         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
7024                 &param0, &param1, CAMERA_CB_TIMEOUT);
7025
7026         CAM_LOG_INFO("ret : 0x%x", ret);
7027
7028         return ret;
7029 }
7030
7031
7032 int camera_attr_get_extra_preview_gop_interval(camera_h camera, int stream_id, int *interval)
7033 {
7034         int ret = CAMERA_ERROR_NONE;
7035         camera_cli_s *pc = (camera_cli_s *)camera;
7036         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_GOP_INTERVAL;
7037         camera_msg_param param;
7038
7039         if (!pc || !pc->cb_info || !interval) {
7040                 CAM_LOG_ERROR("NULL pointer %p %p", pc, interval);
7041                 return CAMERA_ERROR_INVALID_PARAMETER;
7042         }
7043
7044         CAM_LOG_INFO("Enter - stream[%d]", stream_id);
7045
7046         CAMERA_MSG_PARAM_SET(param, INT, stream_id);
7047
7048         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
7049
7050         if (ret == CAMERA_ERROR_NONE) {
7051                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_GOP_INTERVAL];
7052                 CAM_LOG_INFO("get GOP interval[%d] for stream[%d]", *interval, stream_id);
7053         } else {
7054                 CAM_LOG_ERROR("get GOP interval failed for stream[%d] : 0x%x", stream_id, ret);
7055         }
7056
7057         return ret;
7058 }
7059
7060
7061 int camera_attr_get_preview_frame_rotation(camera_h camera, camera_rotation_e *rotation)
7062 {
7063         camera_cli_s *pc = (camera_cli_s *)camera;
7064
7065         if (!pc || !pc->cb_info || !rotation) {
7066                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
7067                 return CAMERA_ERROR_INVALID_PARAMETER;
7068         }
7069
7070         if (!pc->cb_info->stream_data) {
7071                 CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
7072                 return CAMERA_ERROR_INVALID_OPERATION;
7073         }
7074
7075         *rotation = pc->cb_info->stream_data->rotation;
7076
7077         CAM_LOG_DEBUG("frame rotation[%d]", *rotation);
7078
7079         return CAMERA_ERROR_NONE;
7080 }
7081
7082
7083 int _camera_get_log_level(void)
7084 {
7085         return g_camera_log_level;
7086 }
7087