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