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