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