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