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