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