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