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