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