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