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