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