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