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