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