Add new internal APIs
[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_private(camera_device_e device, bool is_network, 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, is_network %d", device, is_network);
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                 MUSE_TYPE_INT, "is_network", (int)is_network,
2395                 0);
2396
2397         if (!send_msg) {
2398                 CAM_LOG_ERROR("NULL msg");
2399                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2400                 goto ErrorExit;
2401         }
2402
2403         send_ret = muse_core_msg_send(sock_fd, send_msg);
2404
2405         muse_core_msg_free(send_msg);
2406         send_msg = NULL;
2407
2408         if (send_ret < 0) {
2409                 CAM_LOG_ERROR("send msg failed %d", errno);
2410                 ret = CAMERA_ERROR_INVALID_OPERATION;
2411                 goto ErrorExit;
2412         }
2413
2414         pc = g_new0(camera_cli_s, 1);
2415         if (pc == NULL) {
2416                 CAM_LOG_ERROR("camera_cli_s alloc failed");
2417                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2418                 goto ErrorExit;
2419         }
2420
2421         bufmgr = tbm_bufmgr_init(-1);
2422         if (bufmgr == NULL) {
2423                 CAM_LOG_ERROR("get tbm bufmgr failed");
2424                 ret = CAMERA_ERROR_INVALID_OPERATION;
2425                 goto ErrorExit;
2426         }
2427
2428         pc->cb_info = _camera_client_callback_new(sock_fd);
2429         if (pc->cb_info == NULL) {
2430                 CAM_LOG_ERROR("cb_info alloc failed");
2431                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2432                 goto ErrorExit;
2433         }
2434
2435         sock_fd = -1;
2436
2437         CAM_LOG_INFO("cb info : %d", pc->cb_info->fd);
2438
2439         ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
2440
2441         pc->cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 0;
2442
2443         if (ret == CAMERA_ERROR_NONE) {
2444                 int preview_format = CAMERA_PIXEL_FORMAT_INVALID;
2445                 int user_buffer_supported = 0;
2446                 int log_level = CAMERA_LOG_LEVEL_INFO;
2447                 intptr_t handle = 0;
2448
2449                 muse_camera_msg_get_pointer(handle, pc->cb_info->recv_msg);
2450                 if (handle == 0) {
2451                         CAM_LOG_ERROR("Receiving Handle Failed!!");
2452                         ret = CAMERA_ERROR_INVALID_OPERATION;
2453                         goto ErrorExit;
2454                 }
2455
2456                 muse_camera_msg_get(preview_format, pc->cb_info->recv_msg);
2457                 muse_camera_msg_get(user_buffer_supported, pc->cb_info->recv_msg);
2458                 muse_camera_msg_get(log_level, pc->cb_info->recv_msg);
2459
2460                 pc->remote_handle = handle;
2461                 pc->cb_info->bufmgr = bufmgr;
2462                 pc->cb_info->preview_format = preview_format;
2463                 pc->cb_info->dp_info.type = CAMERA_DISPLAY_TYPE_NONE;
2464                 pc->cb_info->user_buffer_supported = (gboolean)user_buffer_supported;
2465                 g_mmcam_log_level = log_level;
2466
2467                 CAM_LOG_INFO("default preview format %d, user buffer %d, log level %d",
2468                         preview_format, user_buffer_supported, g_mmcam_log_level);
2469
2470                 *camera = (camera_h)pc;
2471
2472                 /* get display interface handle */
2473                 if (mm_display_interface_init(&pc->cb_info->dp_interface) != MM_ERROR_NONE)
2474                         CAM_LOG_WARNING("display interface init failed");
2475         } else {
2476                 goto ErrorExit;
2477         }
2478
2479         return ret;
2480 //LCOV_EXCL_START
2481 ErrorExit:
2482         if (bufmgr) {
2483                 tbm_bufmgr_deinit(bufmgr);
2484                 bufmgr = NULL;
2485         }
2486
2487         if (sock_fd > -1) {
2488                 muse_client_close(sock_fd);
2489                 sock_fd = -1;
2490         }
2491
2492         if (pc) {
2493                 if (pc->cb_info) {
2494                         int temp_fd = pc->cb_info->fd;
2495
2496                         /* pc->cb_info->fd should be closed,
2497                            because g_thread_join for msg_recv_thread is not returned
2498                            in _camera_client_callback_destroy. */
2499                         if (temp_fd > -1) {
2500                                 pc->cb_info->fd = -1;
2501                                 muse_client_close(temp_fd);
2502                         }
2503
2504                         _camera_client_callback_destroy(pc->cb_info);
2505                         pc->cb_info = NULL;
2506                 }
2507                 g_free(pc);
2508                 pc = NULL;
2509         }
2510
2511         CAM_LOG_ERROR("camera create error : 0x%x", ret);
2512
2513         return ret;
2514 //LCOV_EXCL_STOP
2515 }
2516
2517
2518 int camera_create(camera_device_e device, camera_h *camera)
2519 {
2520         return _camera_create_private(device, false, camera);
2521 }
2522
2523
2524 int camera_change_device(camera_h camera, camera_device_e device)
2525 {
2526         int i = 0;
2527         int ret = CAMERA_ERROR_NONE;
2528         muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
2529         camera_cli_s *pc = (camera_cli_s *)camera;
2530         camera_msg_param param;
2531
2532         if (!pc || !pc->cb_info) {
2533                 CAM_LOG_ERROR("NULL handle");
2534                 return CAMERA_ERROR_INVALID_PARAMETER;
2535         }
2536
2537         CAMERA_MSG_PARAM_SET(param, INT, device);
2538
2539         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2540
2541         if (ret == CAMERA_ERROR_NONE) {
2542                 /* reset callback and user data */
2543                 for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) {
2544                         pc->cb_info->user_cb[i] = NULL;
2545                         pc->cb_info->user_data[i] = NULL;
2546                 }
2547                 UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
2548         }
2549
2550         return ret;
2551 }
2552
2553
2554 int camera_destroy(camera_h camera)
2555 {
2556         int ret = CAMERA_ERROR_NONE;
2557         muse_camera_api_e api = MUSE_CAMERA_API_DESTROY;
2558         camera_cli_s *pc = (camera_cli_s *)camera;
2559
2560         if (!pc || !pc->cb_info) {
2561                 CAM_LOG_ERROR("NULL handle");
2562                 return CAMERA_ERROR_INVALID_PARAMETER;
2563         }
2564
2565         CAM_LOG_INFO("Enter");
2566
2567         if (pc->cb_info->is_server_connected)
2568                 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2569         else
2570                 CAM_LOG_WARNING("server disconnected. release resource without send message.");
2571
2572         if (ret == CAMERA_ERROR_NONE) {
2573                 _camera_deactivate_idle_event_all(pc->cb_info);
2574                 _camera_client_callback_destroy(pc->cb_info);
2575                 pc->cb_info = NULL;
2576
2577                 g_free(pc);
2578                 pc = NULL;
2579         }
2580
2581         CAM_LOG_INFO("ret : 0x%x", ret);
2582
2583         return ret;
2584 }
2585
2586 int camera_start_preview(camera_h camera)
2587 {
2588         int ret = CAMERA_ERROR_NONE;
2589         muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
2590         camera_cli_s *pc = (camera_cli_s *)camera;
2591         camera_state_e current_state = CAMERA_STATE_NONE;
2592
2593         if (!pc || !pc->cb_info) {
2594                 CAM_LOG_ERROR("NULL handle");
2595                 return CAMERA_ERROR_INVALID_PARAMETER;
2596         }
2597
2598         CAM_LOG_INFO("Enter : preview format %d, display type %d",
2599                 pc->cb_info->preview_format, pc->cb_info->dp_info.type);
2600
2601         ret = camera_get_state(camera, &current_state);
2602         if (ret != CAMERA_ERROR_NONE) {
2603                 CAM_LOG_ERROR("failed to get current state 0x%x", ret);
2604                 return ret;
2605         }
2606
2607         if (pc->cb_info->preview_format == CAMERA_PIXEL_FORMAT_INVZ &&
2608                 pc->cb_info->dp_info.type != CAMERA_DISPLAY_TYPE_NONE) {
2609                 CAM_LOG_ERROR("CAMERA_DISPLAY_TYPE_NONE[current %d] should be set with INVZ format",
2610                         pc->cb_info->dp_info.type);
2611                 return CAMERA_ERROR_INVALID_OPERATION;
2612         }
2613
2614         if (current_state == CAMERA_STATE_CREATED && pc->cb_info->user_buffer_supported) {
2615                 if (!_camera_allocate_preview_buffer(camera))
2616                         return CAMERA_ERROR_INVALID_OPERATION;
2617
2618                 _camera_msg_send(api, pc->cb_info->fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
2619         } else {
2620                 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
2621         }
2622
2623         if (ret == CAMERA_ERROR_NONE && CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
2624                 ret = _camera_start_evas_rendering(camera);
2625                 if (ret != CAMERA_ERROR_NONE) {
2626                         CAM_LOG_ERROR("stop preview because of error");
2627                         _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
2628                 }
2629         }
2630
2631         CAM_LOG_INFO("ret : 0x%x", ret);
2632
2633         return ret;
2634 }
2635
2636
2637 int camera_stop_preview(camera_h camera)
2638 {
2639         int ret = CAMERA_ERROR_NONE;
2640         camera_cli_s *pc = (camera_cli_s *)camera;
2641         muse_camera_api_e api = MUSE_CAMERA_API_STOP_PREVIEW;
2642         camera_state_e current_state = CAMERA_STATE_NONE;
2643
2644         if (!pc || !pc->cb_info) {
2645                 CAM_LOG_ERROR("NULL handle");
2646                 return CAMERA_ERROR_INVALID_PARAMETER;
2647         }
2648
2649         CAM_LOG_INFO("Enter");
2650
2651 //LCOV_EXCL_START
2652         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
2653                 ret = camera_get_state(camera, &current_state);
2654                 if (ret != CAMERA_ERROR_NONE) {
2655                         CAM_LOG_ERROR("failed to get current state 0x%x", ret);
2656                         return ret;
2657                 }
2658
2659                 if (current_state == CAMERA_STATE_PREVIEW) {
2660                         ret = _camera_stop_evas_rendering(camera, false);
2661                         if (ret != CAMERA_ERROR_NONE)
2662                                 return ret;
2663                 }
2664         }
2665 //LCOV_EXCL_STOP
2666         /* send stop preview message */
2667         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2668
2669         if (ret == CAMERA_ERROR_NONE) {
2670                 if (pc->cb_info->user_buffer_supported)
2671                         _camera_release_preview_buffer(camera);
2672         } else if (current_state == CAMERA_STATE_PREVIEW) {
2673                 CAM_LOG_WARNING("restart evas rendering");
2674                 _camera_start_evas_rendering(camera);
2675         }
2676
2677         CAM_LOG_INFO("ret : 0x%x", ret);
2678
2679         return ret;
2680 }
2681
2682
2683 int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data)
2684 {
2685         int ret = CAMERA_ERROR_NONE;
2686         camera_cli_s *pc = (camera_cli_s *)camera;
2687         muse_camera_api_e api = MUSE_CAMERA_API_START_CAPTURE;
2688
2689         if (!pc || !pc->cb_info) {
2690                 CAM_LOG_ERROR("NULL handle");
2691                 return CAMERA_ERROR_INVALID_PARAMETER;
2692         }
2693
2694         CAM_LOG_INFO("Enter");
2695
2696         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
2697         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
2698
2699         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
2700         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
2701
2702         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2703
2704         CAM_LOG_INFO("ret : 0x%x", ret);
2705
2706         return ret;
2707 }
2708
2709
2710 bool camera_is_supported_continuous_capture(camera_h camera)
2711 {
2712         int ret = CAMERA_ERROR_NONE;
2713         camera_cli_s *pc = (camera_cli_s *)camera;
2714         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE;
2715
2716         if (!pc || !pc->cb_info) {
2717                 CAM_LOG_ERROR("NULL handle");
2718                 return CAMERA_ERROR_INVALID_PARAMETER;
2719         }
2720
2721         CAM_LOG_INFO("Enter");
2722
2723         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2724
2725         if (ret < 0) {
2726                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
2727                 ret = false;
2728         }
2729
2730         CAM_LOG_INFO("ret : %d", ret);
2731
2732         return (bool)ret;
2733 }
2734
2735
2736 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)
2737 {
2738         int ret = CAMERA_ERROR_NONE;
2739         camera_cli_s *pc = (camera_cli_s *)camera;
2740         muse_camera_api_e api = MUSE_CAMERA_API_START_CONTINUOUS_CAPTURE;
2741         camera_msg_param param;
2742         int value = 0;
2743
2744         if (!pc || !pc->cb_info) {
2745                 CAM_LOG_ERROR("NULL handle");
2746                 return CAMERA_ERROR_INVALID_PARAMETER;
2747         }
2748
2749         CAM_LOG_INFO("Enter");
2750
2751         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
2752         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
2753
2754         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
2755         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
2756
2757         value = (count << 16) | interval;
2758         CAMERA_MSG_PARAM_SET(param, INT, value);
2759
2760         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2761
2762         CAM_LOG_INFO("ret : 0x%x", ret);
2763
2764         return ret;
2765 }
2766
2767
2768 int camera_stop_continuous_capture(camera_h camera)
2769 {
2770         int ret = CAMERA_ERROR_NONE;
2771         camera_cli_s *pc = (camera_cli_s *)camera;
2772         muse_camera_api_e api = MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE;
2773
2774         if (!pc || !pc->cb_info) {
2775                 CAM_LOG_ERROR("NULL handle");
2776                 return CAMERA_ERROR_INVALID_PARAMETER;
2777         }
2778
2779         CAM_LOG_INFO("Enter");
2780
2781         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2782
2783         CAM_LOG_INFO("ret : 0x%x", ret);
2784
2785         return ret;
2786 }
2787
2788
2789 bool camera_is_supported_face_detection(camera_h camera)
2790 {
2791         int ret = CAMERA_ERROR_NONE;
2792         camera_cli_s *pc = (camera_cli_s *)camera;
2793         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_FACE_DETECTION;
2794
2795         if (!pc || !pc->cb_info) {
2796                 CAM_LOG_ERROR("NULL handle");
2797                 return CAMERA_ERROR_INVALID_PARAMETER;
2798         }
2799
2800         CAM_LOG_INFO("Enter");
2801
2802         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2803
2804         if (ret < 0) {
2805                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
2806                 ret = false;
2807         }
2808
2809         CAM_LOG_INFO("ret : %d", ret);
2810
2811         return (bool)ret;
2812 }
2813
2814
2815 bool camera_is_supported_zero_shutter_lag(camera_h camera)
2816 {
2817         int ret = CAMERA_ERROR_NONE;
2818         camera_cli_s *pc = (camera_cli_s *)camera;
2819         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG;
2820
2821         if (!pc || !pc->cb_info) {
2822                 CAM_LOG_ERROR("NULL handle");
2823                 return CAMERA_ERROR_INVALID_PARAMETER;
2824         }
2825
2826         CAM_LOG_INFO("Enter");
2827
2828         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2829
2830         if (ret < 0) {
2831                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
2832                 ret = false;
2833         }
2834
2835         CAM_LOG_INFO("ret : %d", ret);
2836
2837         return (bool)ret;
2838 }
2839
2840
2841 bool camera_is_supported_media_packet_preview_cb(camera_h camera)
2842 {
2843         int ret = CAMERA_ERROR_NONE;
2844         camera_cli_s *pc = (camera_cli_s *)camera;
2845         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB;
2846
2847         if (!pc || !pc->cb_info) {
2848                 CAM_LOG_ERROR("NULL handle");
2849                 return CAMERA_ERROR_INVALID_PARAMETER;
2850         }
2851
2852         CAM_LOG_INFO("Enter");
2853
2854         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2855
2856         if (ret < 0) {
2857                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
2858                 ret = false;
2859         }
2860
2861         CAM_LOG_INFO("ret : %d", ret);
2862
2863         return (bool)ret;
2864 }
2865
2866 int camera_get_device_count(camera_h camera, int *device_count)
2867 {
2868         int ret = CAMERA_ERROR_NONE;
2869         camera_cli_s *pc = (camera_cli_s *)camera;
2870         muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
2871
2872         if (!pc || !pc->cb_info) {
2873                 CAM_LOG_ERROR("NULL handle");
2874                 return CAMERA_ERROR_INVALID_PARAMETER;
2875         }
2876
2877         CAM_LOG_INFO("Enter");
2878
2879         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2880
2881         if (ret == CAMERA_ERROR_NONE)
2882                 *device_count = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DEVICE_COUNT];
2883
2884         CAM_LOG_INFO("ret : 0x%x", ret);
2885
2886         return ret;
2887 }
2888
2889 int camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void *user_data)
2890 {
2891         int ret = CAMERA_ERROR_NONE;
2892         camera_cli_s *pc = (camera_cli_s *)camera;
2893         muse_camera_api_e api = MUSE_CAMERA_API_START_FACE_DETECTION;
2894
2895         if (!pc || !pc->cb_info) {
2896                 CAM_LOG_ERROR("NULL handle");
2897                 return CAMERA_ERROR_INVALID_PARAMETER;
2898         }
2899
2900         CAM_LOG_INFO("Enter");
2901
2902         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2903
2904         if (ret == CAMERA_ERROR_NONE) {
2905                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2906
2907                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = callback;
2908                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = user_data;
2909
2910                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2911         }
2912
2913         CAM_LOG_INFO("ret : 0x%x", ret);
2914
2915         return ret;
2916 }
2917
2918 int camera_stop_face_detection(camera_h camera)
2919 {
2920         int ret = CAMERA_ERROR_NONE;
2921         camera_cli_s *pc = (camera_cli_s *)camera;
2922         muse_camera_api_e api = MUSE_CAMERA_API_STOP_FACE_DETECTION;
2923
2924         if (!pc || !pc->cb_info) {
2925                 CAM_LOG_ERROR("NULL handle");
2926                 return CAMERA_ERROR_INVALID_PARAMETER;
2927         }
2928
2929         CAM_LOG_INFO("Enter");
2930
2931         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2932
2933         if (ret == CAMERA_ERROR_NONE) {
2934                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2935
2936                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
2937                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
2938
2939                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2940         }
2941
2942         CAM_LOG_INFO("ret : 0x%x", ret);
2943
2944         return ret;
2945 }
2946
2947 int camera_get_state(camera_h camera, camera_state_e *state)
2948 {
2949         int ret = CAMERA_ERROR_NONE;
2950         camera_cli_s *pc = (camera_cli_s *)camera;
2951         muse_camera_api_e api = MUSE_CAMERA_API_GET_STATE;
2952
2953         if (!pc || !pc->cb_info || !state) {
2954                 CAM_LOG_ERROR("NULL pointer %p %p", pc, state);
2955                 return CAMERA_ERROR_INVALID_PARAMETER;
2956         }
2957
2958         CAM_LOG_INFO("Enter");
2959
2960         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2961
2962         if (ret == CAMERA_ERROR_NONE)
2963                 *state = (camera_state_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STATE];
2964
2965         CAM_LOG_INFO("ret : 0x%x", ret);
2966
2967         return ret;
2968 }
2969
2970 int camera_start_focusing(camera_h camera, bool continuous)
2971 {
2972         int ret = CAMERA_ERROR_NONE;
2973         camera_cli_s *pc = (camera_cli_s *)camera;
2974         muse_camera_api_e api = MUSE_CAMERA_API_START_FOCUSING;
2975         camera_msg_param param;
2976         int is_continuous = (int)continuous;
2977
2978         if (!pc || !pc->cb_info) {
2979                 CAM_LOG_ERROR("NULL handle");
2980                 return CAMERA_ERROR_INVALID_PARAMETER;
2981         }
2982
2983         CAM_LOG_INFO("Enter");
2984
2985         CAMERA_MSG_PARAM_SET(param, INT, is_continuous);
2986
2987         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2988
2989         CAM_LOG_INFO("ret : 0x%x", ret);
2990
2991         return ret;
2992 }
2993
2994 int camera_cancel_focusing(camera_h camera)
2995 {
2996         int ret = CAMERA_ERROR_NONE;
2997         camera_cli_s *pc = (camera_cli_s *)camera;
2998         muse_camera_api_e api = MUSE_CAMERA_API_CANCEL_FOCUSING;
2999
3000         if (!pc || !pc->cb_info) {
3001                 CAM_LOG_ERROR("NULL handle");
3002                 return CAMERA_ERROR_INVALID_PARAMETER;
3003         }
3004
3005         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
3006
3007         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3008
3009         CAM_LOG_INFO("ret : 0x%x", ret);
3010
3011         return ret;
3012 }
3013
3014
3015 int _camera_set_display(camera_h camera, mm_display_type_e type, void *display)
3016 {
3017         int mm_ret = MM_ERROR_NONE;
3018         int ret = CAMERA_ERROR_NONE;
3019         camera_cli_s *pc = (camera_cli_s *)camera;
3020         camera_cb_info_s *cb_info = NULL;
3021         camera_state_e current_state = CAMERA_STATE_NONE;
3022         camera_msg_param param;
3023         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY;
3024         muse_camera_display_info_s *dp_info = NULL;
3025
3026         if (!pc || !pc->cb_info) {
3027                 CAM_LOG_ERROR("NULL handle");
3028                 return CAMERA_ERROR_INVALID_PARAMETER;
3029         }
3030
3031         if (type > MM_DISPLAY_TYPE_OVERLAY_EXT) {
3032                 CAM_LOG_ERROR("invalid type %d", type);
3033                 return CAMERA_ERROR_INVALID_PARAMETER;
3034         }
3035
3036         if (type != MM_DISPLAY_TYPE_NONE && display == NULL) {
3037                 CAM_LOG_ERROR("display type[%d] is not NONE, but display handle is NULL", type);
3038                 return CAMERA_ERROR_INVALID_PARAMETER;
3039         }
3040
3041         cb_info = (camera_cb_info_s *)pc->cb_info;
3042         dp_info = &cb_info->dp_info;
3043
3044         ret = camera_get_state(camera, &current_state);
3045         if (ret != CAMERA_ERROR_NONE) {
3046                 CAM_LOG_ERROR("failed to get current state 0x%x", ret);
3047                 return ret;
3048         }
3049
3050         if (current_state != CAMERA_STATE_CREATED) {
3051                 CAM_LOG_ERROR("INVALID_STATE : current %d", current_state);
3052                 return CAMERA_ERROR_INVALID_STATE;
3053         }
3054
3055         CAM_LOG_INFO("Enter - type : %d, display : %p", type, display);
3056
3057         if (type != MM_DISPLAY_TYPE_NONE) {
3058                 /* check display interface handle */
3059                 if (!cb_info->dp_interface) {
3060                         CAM_LOG_ERROR("display interface not supported");
3061                         return CAMERA_ERROR_NOT_SUPPORTED;
3062                 }
3063
3064                 mm_ret = mm_display_interface_set_display(cb_info->dp_interface, type, display, &dp_info->parent_id);
3065                 if (mm_ret == (int)MM_ERROR_NOT_SUPPORT_API) {
3066                         CAM_LOG_ERROR("[NOT_SUPPORTED] type %d", type);
3067                         return CAMERA_ERROR_NOT_SUPPORTED;
3068                 } else if (mm_ret != MM_ERROR_NONE) {
3069                         CAM_LOG_ERROR("[INVALID_OPERATION] set display failed[0x%x]", mm_ret);
3070                         return CAMERA_ERROR_INVALID_OPERATION;
3071                 }
3072
3073                 if (type == MM_DISPLAY_TYPE_OVERLAY || type == MM_DISPLAY_TYPE_OVERLAY_EXT) {
3074                         mm_ret = mm_display_interface_get_window_rect(cb_info->dp_interface, &dp_info->window_rect);
3075
3076                         CAM_LOG_INFO("ret 0x%x, parent_id %d, window rect %d,%d,%dx%d",
3077                                 ret, dp_info->parent_id, dp_info->window_rect.x, dp_info->window_rect.y,
3078                                 dp_info->window_rect.width, dp_info->window_rect.height);
3079                 } else if (type == MM_DISPLAY_TYPE_EVAS) {
3080 //LCOV_EXCL_START
3081                         camera_flip_e flip = CAMERA_FLIP_NONE;
3082                         camera_display_mode_e mode = CAMERA_DISPLAY_MODE_LETTER_BOX;
3083                         camera_rotation_e rotation = CAMERA_ROTATION_NONE;
3084                         bool visible = 0;
3085                         int x = 0;
3086                         int y = 0;
3087                         int width = 0;
3088                         int height = 0;
3089
3090                         camera_get_display_flip(camera, &flip);
3091                         camera_get_display_mode(camera, &mode);
3092                         camera_get_display_rotation(camera, &rotation);
3093                         camera_is_display_visible(camera, &visible);
3094
3095                         CAM_LOG_INFO("current setting : flip %d, mode %d, rotation %d, visible %d",
3096                                 flip, mode, rotation, visible);
3097
3098                         mm_ret = mm_display_interface_evas_set_flip(cb_info->dp_interface, flip);
3099                         mm_ret |= mm_display_interface_evas_set_mode(cb_info->dp_interface, mode);
3100                         mm_ret |= mm_display_interface_evas_set_rotation(cb_info->dp_interface, rotation);
3101                         mm_ret |= mm_display_interface_evas_set_visible(cb_info->dp_interface, visible);
3102
3103                         if (mode == CAMERA_DISPLAY_MODE_CUSTOM_ROI) {
3104                                 camera_attr_get_display_roi_area(camera, &x, &y, &width, &height);
3105                                 CAM_LOG_INFO("current setting : roi %d,%d,%dx%d", x, y, width, height);
3106                                 mm_ret |= mm_display_interface_evas_set_roi_area(cb_info->dp_interface, x, y, width, height);
3107                         }
3108 //LCOV_EXCL_STOP
3109                 }
3110         }
3111
3112         if (mm_ret != MM_ERROR_NONE) {
3113                 CAM_LOG_ERROR("mm_ret 0x%x failed", mm_ret);
3114                 return CAMERA_ERROR_INVALID_OPERATION;
3115         }
3116
3117         dp_info->type = type;
3118
3119         CAMERA_MSG_PARAM_SET_ARRAY(param, ARRAY, dp_info, sizeof(muse_camera_display_info_s));
3120
3121         _camera_msg_send_param1(api, cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3122
3123         if (ret == CAMERA_ERROR_NONE) {
3124                 if (type == MM_DISPLAY_TYPE_EVAS)
3125                         SET_PREVIEW_CB_TYPE(cb_info, PREVIEW_CB_TYPE_EVAS);
3126         }
3127
3128         return ret;
3129 }
3130
3131
3132 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display)
3133 {
3134         CAM_LOG_INFO("type %d, display %p", type, display);
3135         return _camera_set_display(camera, (mm_display_type_e)type, display);
3136 }
3137
3138
3139 int camera_set_preview_resolution(camera_h camera, int width, int height)
3140 {
3141         int ret = CAMERA_ERROR_NONE;
3142         camera_state_e current_state = CAMERA_STATE_NONE;
3143         camera_cli_s *pc = (camera_cli_s *)camera;
3144         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
3145         camera_msg_param param;
3146         int value = 0;
3147
3148         if (!pc || !pc->cb_info) {
3149                 CAM_LOG_ERROR("NULL handle");
3150                 return CAMERA_ERROR_INVALID_PARAMETER;
3151         }
3152
3153         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3154                 ret = camera_get_state(camera, &current_state);
3155                 if (ret != CAMERA_ERROR_NONE) {
3156                         CAM_LOG_ERROR("failed to get current state 0x%x", ret);
3157                         return ret;
3158                 }
3159
3160                 if (current_state == CAMERA_STATE_PREVIEW) {
3161                         ret = _camera_stop_evas_rendering(camera, true);
3162                         if (ret != CAMERA_ERROR_NONE)
3163                                 return ret;
3164                 }
3165         }
3166
3167         value = (width << 16) | height;
3168         CAMERA_MSG_PARAM_SET(param, INT, value);
3169
3170         CAM_LOG_INFO("%dx%d -> 0x%x", width, height, value);
3171
3172         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3173
3174         CAM_LOG_INFO("ret : 0x%x", ret);
3175
3176         if (current_state == CAMERA_STATE_PREVIEW) {
3177                 CAM_LOG_WARNING("restart evas rendering");
3178                 _camera_start_evas_rendering(camera);
3179         }
3180
3181         return ret;
3182 }
3183
3184
3185 int camera_set_capture_resolution(camera_h camera, int width, int height)
3186 {
3187         int ret = CAMERA_ERROR_NONE;
3188         camera_cli_s *pc = (camera_cli_s *)camera;
3189         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION;
3190         camera_msg_param param;
3191         int value = 0;
3192
3193         if (!pc || !pc->cb_info) {
3194                 CAM_LOG_ERROR("NULL handle");
3195                 return CAMERA_ERROR_INVALID_PARAMETER;
3196         }
3197
3198         CAM_LOG_INFO("Enter");
3199
3200         value = (width << 16) | height;
3201         CAMERA_MSG_PARAM_SET(param, INT, value);
3202
3203         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3204
3205         CAM_LOG_INFO("ret : 0x%x", ret);
3206
3207         return ret;
3208 }
3209
3210
3211 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
3212 {
3213         int ret = CAMERA_ERROR_NONE;
3214         int set_format = (int)format;
3215         camera_cli_s *pc = (camera_cli_s *)camera;
3216         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
3217         camera_msg_param param;
3218
3219         if (!pc || !pc->cb_info) {
3220                 CAM_LOG_ERROR("NULL handle");
3221                 return CAMERA_ERROR_INVALID_PARAMETER;
3222         }
3223
3224         CAM_LOG_INFO("Enter - format %d", set_format);
3225
3226         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3227
3228         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3229
3230         CAM_LOG_INFO("ret : 0x%x", ret);
3231
3232         return ret;
3233 }
3234
3235
3236 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
3237 {
3238         int ret = CAMERA_ERROR_NONE;
3239         int set_format = (int)format;
3240         camera_msg_param param;
3241         camera_cli_s *pc = (camera_cli_s *)camera;
3242         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
3243
3244         if (!pc || !pc->cb_info) {
3245                 CAM_LOG_ERROR("NULL handle");
3246                 return CAMERA_ERROR_INVALID_PARAMETER;
3247         }
3248
3249         CAM_LOG_INFO("Enter - format %d", set_format);
3250
3251         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3252
3253         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3254
3255         if (ret == CAMERA_ERROR_NONE)
3256                 pc->cb_info->preview_format = set_format;
3257
3258         CAM_LOG_INFO("ret : 0x%x", ret);
3259
3260         return ret;
3261 }
3262
3263
3264 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
3265 {
3266         int ret = CAMERA_ERROR_NONE;
3267         camera_cli_s *pc = (camera_cli_s *)camera;
3268         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
3269
3270         if (!pc || !pc->cb_info || !width || !height) {
3271                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
3272                 return CAMERA_ERROR_INVALID_PARAMETER;
3273         }
3274
3275         CAM_LOG_INFO("Enter");
3276
3277         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3278
3279         if (ret == CAMERA_ERROR_NONE) {
3280                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION] >> 16;
3281                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION];
3282         }
3283
3284         CAM_LOG_INFO("ret : 0x%x", ret);
3285
3286         return ret;
3287 }
3288
3289
3290 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
3291 {
3292         int ret = CAMERA_ERROR_NONE;
3293         int set_rotation = (int)rotation;
3294         camera_cli_s *pc = (camera_cli_s *)camera;
3295         camera_msg_param param;
3296
3297         if (!pc || !pc->cb_info) {
3298                 CAM_LOG_ERROR("NULL handle");
3299                 return CAMERA_ERROR_INVALID_PARAMETER;
3300         }
3301
3302         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3303                 ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
3304                 if (ret != MM_ERROR_NONE) {
3305                         CAM_LOG_ERROR("failed to set rotation for evas surface 0x%x", ret);
3306                         return CAMERA_ERROR_INVALID_OPERATION;
3307                 }
3308         }
3309
3310         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
3311
3312         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_ROTATION, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3313
3314         return ret;
3315 }
3316
3317
3318 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
3319 {
3320         int ret = CAMERA_ERROR_NONE;
3321         camera_cli_s *pc = (camera_cli_s *)camera;
3322
3323         if (!pc || !pc->cb_info || !rotation) {
3324                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
3325                 return CAMERA_ERROR_INVALID_PARAMETER;
3326         }
3327
3328         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_ROTATION, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3329
3330         if (ret == CAMERA_ERROR_NONE)
3331                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_ROTATION];
3332
3333         return ret;
3334 }
3335
3336
3337 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
3338 {
3339         int ret = CAMERA_ERROR_NONE;
3340         int set_flip = (int)flip;
3341         camera_cli_s *pc = (camera_cli_s *)camera;
3342         camera_msg_param param;
3343
3344         if (!pc || !pc->cb_info) {
3345                 CAM_LOG_ERROR("NULL handle");
3346                 return CAMERA_ERROR_INVALID_PARAMETER;
3347         }
3348
3349         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3350                 ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
3351                 if (ret != MM_ERROR_NONE) {
3352                         CAM_LOG_ERROR("failed to set flip for evas surface 0x%x", ret);
3353                         return CAMERA_ERROR_INVALID_OPERATION;
3354                 }
3355         }
3356
3357         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
3358
3359         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_FLIP, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3360
3361         return ret;
3362 }
3363
3364
3365 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
3366 {
3367         int ret = CAMERA_ERROR_NONE;
3368         camera_cli_s *pc = (camera_cli_s *)camera;
3369
3370         if (!pc || !pc->cb_info || !flip) {
3371                 CAM_LOG_ERROR("NULL pointer %p %p", pc, flip);
3372                 return CAMERA_ERROR_INVALID_PARAMETER;
3373         }
3374
3375         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_FLIP, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3376
3377         if (ret == CAMERA_ERROR_NONE)
3378                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_FLIP];
3379
3380         return ret;
3381 }
3382
3383
3384 int camera_set_display_visible(camera_h camera, bool visible)
3385 {
3386         int ret = CAMERA_ERROR_NONE;
3387         int set_visible = (int)visible;
3388         camera_cli_s *pc = (camera_cli_s *)camera;
3389         camera_msg_param param;
3390
3391         if (!pc || !pc->cb_info) {
3392                 CAM_LOG_ERROR("NULL handle");
3393                 return CAMERA_ERROR_INVALID_PARAMETER;
3394         }
3395
3396         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3397                 ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
3398                 if (ret != MM_ERROR_NONE) {
3399                         CAM_LOG_ERROR("failed to set visible for evas surface 0x%x", ret);
3400                         return CAMERA_ERROR_INVALID_OPERATION;
3401                 }
3402         }
3403
3404         CAMERA_MSG_PARAM_SET(param, INT, set_visible);
3405
3406         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3407
3408         return ret;
3409 }
3410
3411
3412 int camera_is_display_visible(camera_h camera, bool *visible)
3413 {
3414         int ret = CAMERA_ERROR_NONE;
3415         camera_cli_s *pc = (camera_cli_s *)camera;
3416
3417         if (!pc || !pc->cb_info || !visible) {
3418                 CAM_LOG_ERROR("NULL pointer %p %p", pc, visible);
3419                 return CAMERA_ERROR_INVALID_PARAMETER;
3420         }
3421
3422         _camera_msg_send(MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3423
3424         if (ret == CAMERA_ERROR_NONE)
3425                 *visible = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE];
3426
3427         return ret;
3428 }
3429
3430
3431 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
3432 {
3433         int ret = CAMERA_ERROR_NONE;
3434         int set_mode = (int)mode;
3435         camera_cli_s *pc = (camera_cli_s *)camera;
3436         camera_msg_param param;
3437
3438         if (!pc || !pc->cb_info) {
3439                 CAM_LOG_ERROR("NULL handle");
3440                 return CAMERA_ERROR_INVALID_PARAMETER;
3441         }
3442
3443         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3444                 ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
3445                 if (ret != MM_ERROR_NONE) {
3446                         CAM_LOG_ERROR("failed to set geometry for evas surface 0x%x", ret);
3447                         return CAMERA_ERROR_INVALID_OPERATION;
3448                 }
3449         }
3450
3451         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
3452
3453         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_MODE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3454
3455         return ret;
3456 }
3457
3458
3459 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
3460 {
3461         int ret = CAMERA_ERROR_NONE;
3462         camera_cli_s *pc = (camera_cli_s *)camera;
3463
3464         if (!pc || !pc->cb_info || !mode) {
3465                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
3466                 return CAMERA_ERROR_INVALID_PARAMETER;
3467         }
3468
3469         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_MODE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3470
3471         if (ret == CAMERA_ERROR_NONE)
3472                 *mode = (camera_display_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_MODE];
3473
3474         return ret;
3475 }
3476
3477
3478 int camera_set_display_reuse_hint(camera_h camera, bool hint)
3479 {
3480         int ret = CAMERA_ERROR_NONE;
3481         int set_hint = (int)hint;
3482         camera_cli_s *pc = (camera_cli_s *)camera;
3483         camera_msg_param param;
3484
3485         if (!pc || !pc->cb_info) {
3486                 CAM_LOG_ERROR("NULL handle");
3487                 return CAMERA_ERROR_INVALID_PARAMETER;
3488         }
3489
3490         CAM_LOG_INFO("Enter - hint %d", set_hint);
3491
3492         CAMERA_MSG_PARAM_SET(param, INT, set_hint);
3493
3494         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3495
3496         return ret;
3497 }
3498
3499
3500 int camera_get_display_reuse_hint(camera_h camera, bool *hint)
3501 {
3502         int ret = CAMERA_ERROR_NONE;
3503         camera_cli_s *pc = (camera_cli_s *)camera;
3504         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
3505
3506         if (!pc || !pc->cb_info || !hint) {
3507                 CAM_LOG_ERROR("NULL pointer %p %p", pc, hint);
3508                 return CAMERA_ERROR_INVALID_PARAMETER;
3509         }
3510
3511         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3512
3513         if (ret == CAMERA_ERROR_NONE) {
3514                 *hint = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT];
3515                 CAM_LOG_INFO("display reuse hint %d", *hint);
3516         }
3517
3518         return ret;
3519 }
3520
3521
3522 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
3523 {
3524         int ret = CAMERA_ERROR_NONE;
3525         camera_cli_s *pc = (camera_cli_s *)camera;
3526         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
3527
3528         if (!pc || !pc->cb_info || !width || !height) {
3529                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
3530                 return CAMERA_ERROR_INVALID_PARAMETER;
3531         }
3532
3533         CAM_LOG_INFO("Enter");
3534
3535         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3536
3537         if (ret == CAMERA_ERROR_NONE) {
3538                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION] >> 16;
3539                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION];
3540         }
3541
3542         CAM_LOG_INFO("ret : 0x%x", ret);
3543
3544         return ret;
3545 }
3546
3547
3548 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
3549 {
3550         int ret = CAMERA_ERROR_NONE;
3551         camera_cli_s *pc = (camera_cli_s *)camera;
3552         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
3553
3554         if (!pc || !pc->cb_info || !format) {
3555                 CAM_LOG_ERROR("NULL pointer %p %p", pc, format);
3556                 return CAMERA_ERROR_INVALID_PARAMETER;
3557         }
3558
3559         CAM_LOG_INFO("Enter");
3560
3561         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3562
3563         if (ret == CAMERA_ERROR_NONE)
3564                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_FORMAT];
3565
3566         CAM_LOG_INFO("ret : 0x%x", ret);
3567
3568         return ret;
3569 }
3570
3571
3572 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
3573 {
3574         int ret = CAMERA_ERROR_NONE;
3575         camera_cli_s *pc = (camera_cli_s *)camera;
3576         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
3577
3578         if (!pc || !pc->cb_info || !format) {
3579                 CAM_LOG_ERROR("NULL pointer %p %p", pc, format);
3580                 return CAMERA_ERROR_INVALID_PARAMETER;
3581         }
3582
3583         CAM_LOG_INFO("Enter");
3584
3585         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3586
3587         if (ret == CAMERA_ERROR_NONE)
3588                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FORMAT];
3589
3590         CAM_LOG_INFO("ret : 0x%x", ret);
3591
3592         return ret;
3593 }
3594
3595
3596 int camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction)
3597 {
3598         int ret = CAMERA_ERROR_NONE;
3599         camera_cli_s *pc = (camera_cli_s *)camera;
3600         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
3601
3602         if (!pc || !pc->cb_info || !facing_direction) {
3603                 CAM_LOG_ERROR("NULL pointer %p %p", pc, facing_direction);
3604                 return CAMERA_ERROR_INVALID_PARAMETER;
3605         }
3606
3607         CAM_LOG_INFO("Enter");
3608
3609         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3610
3611         if (ret == CAMERA_ERROR_NONE)
3612                 *facing_direction = (camera_facing_direction_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FACING_DIRECTION];
3613
3614         CAM_LOG_INFO("ret : 0x%x", ret);
3615
3616         return ret;
3617 }
3618
3619
3620 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
3621 {
3622         int ret = CAMERA_ERROR_NONE;
3623         camera_cli_s *pc = (camera_cli_s *)camera;
3624         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
3625
3626         if (!pc || !pc->cb_info || !callback) {
3627                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3628                 return CAMERA_ERROR_INVALID_PARAMETER;
3629         }
3630
3631         CAM_LOG_INFO("Enter");
3632
3633         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3634
3635         if (ret == CAMERA_ERROR_NONE) {
3636                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3637
3638                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
3639                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
3640
3641                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3642
3643                 SET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3644         }
3645
3646         CAM_LOG_INFO("ret : 0x%x", ret);
3647
3648         return ret;
3649 }
3650
3651
3652 int camera_unset_preview_cb(camera_h camera)
3653 {
3654         int ret = CAMERA_ERROR_NONE;
3655         camera_cli_s *pc = (camera_cli_s *)camera;
3656         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
3657
3658         if (!pc || !pc->cb_info) {
3659                 CAM_LOG_ERROR("NULL handle");
3660                 return CAMERA_ERROR_INVALID_PARAMETER;
3661         }
3662
3663         CAM_LOG_INFO("Enter");
3664
3665         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3666
3667         if (ret == CAMERA_ERROR_NONE) {
3668                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3669
3670                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3671                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3672
3673                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3674
3675                 UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3676         }
3677
3678         CAM_LOG_INFO("ret : 0x%x", ret);
3679
3680         return ret;
3681 }
3682
3683
3684 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
3685 {
3686         int ret = CAMERA_ERROR_NONE;
3687         camera_cli_s *pc = (camera_cli_s *)camera;
3688         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
3689
3690         if (!pc || !pc->cb_info) {
3691                 CAM_LOG_ERROR("NULL handle");
3692                 return CAMERA_ERROR_INVALID_PARAMETER;
3693         }
3694
3695         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3696                 CAM_LOG_ERROR("NOT SUPPORTED");
3697                 return CAMERA_ERROR_NOT_SUPPORTED;
3698         }
3699
3700         if (callback == NULL) {
3701                 CAM_LOG_ERROR("NULL callback");
3702                 return CAMERA_ERROR_INVALID_PARAMETER;
3703         }
3704
3705         CAM_LOG_INFO("Enter");
3706
3707         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3708
3709         if (ret == CAMERA_ERROR_NONE) {
3710                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3711
3712                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
3713                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
3714
3715                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3716         }
3717
3718         CAM_LOG_INFO("ret : 0x%x", ret);
3719
3720         return ret;
3721 }
3722
3723
3724 int camera_unset_media_packet_preview_cb(camera_h camera)
3725 {
3726         int ret = CAMERA_ERROR_NONE;
3727         camera_cli_s *pc = (camera_cli_s *)camera;
3728         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
3729
3730         if (!pc || !pc->cb_info) {
3731                 CAM_LOG_ERROR("NULL handle");
3732                 return CAMERA_ERROR_INVALID_PARAMETER;
3733         }
3734
3735         CAM_LOG_INFO("Enter");
3736
3737         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3738
3739         if (ret == CAMERA_ERROR_NONE) {
3740                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3741
3742                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3743                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3744
3745                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3746         }
3747
3748         CAM_LOG_INFO("ret : 0x%x", ret);
3749
3750         return ret;
3751 }
3752
3753
3754 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
3755 {
3756         int ret = CAMERA_ERROR_NONE;
3757         camera_cli_s *pc = (camera_cli_s *)camera;
3758         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
3759
3760         if (!pc || !pc->cb_info || !callback) {
3761                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3762                 return CAMERA_ERROR_INVALID_PARAMETER;
3763         }
3764
3765         CAM_LOG_INFO("Enter");
3766
3767         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3768
3769         if (ret == CAMERA_ERROR_NONE) {
3770                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3771
3772                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
3773                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
3774
3775                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3776         }
3777
3778         CAM_LOG_INFO("ret : 0x%x", ret);
3779
3780         return ret;
3781 }
3782
3783
3784 int camera_unset_state_changed_cb(camera_h camera)
3785 {
3786         int ret = CAMERA_ERROR_NONE;
3787         camera_cli_s *pc = (camera_cli_s *)camera;
3788         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
3789
3790         if (!pc || !pc->cb_info) {
3791                 CAM_LOG_ERROR("NULL handle");
3792                 return CAMERA_ERROR_INVALID_PARAMETER;
3793         }
3794
3795         CAM_LOG_INFO("Enter");
3796
3797         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3798
3799         if (ret == CAMERA_ERROR_NONE) {
3800                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3801
3802                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3803                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3804
3805                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3806         }
3807
3808         CAM_LOG_INFO("ret : 0x%x", ret);
3809
3810         return ret;
3811 }
3812
3813
3814 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
3815 {
3816         int ret = CAMERA_ERROR_NONE;
3817         camera_cli_s *pc = (camera_cli_s *)camera;
3818         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
3819
3820         if (!pc || !pc->cb_info || !callback) {
3821                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3822                 return CAMERA_ERROR_INVALID_PARAMETER;
3823         }
3824
3825         CAM_LOG_INFO("Enter");
3826
3827         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3828
3829         if (ret == CAMERA_ERROR_NONE) {
3830                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3831
3832                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
3833                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
3834
3835                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3836         }
3837
3838         CAM_LOG_INFO("ret : 0x%x", ret);
3839
3840         return ret;
3841 }
3842
3843
3844 int camera_unset_interrupted_cb(camera_h camera)
3845 {
3846         int ret = CAMERA_ERROR_NONE;
3847         camera_cli_s *pc = (camera_cli_s *)camera;
3848         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
3849
3850         if (!pc || !pc->cb_info) {
3851                 CAM_LOG_ERROR("NULL handle");
3852                 return CAMERA_ERROR_INVALID_PARAMETER;
3853         }
3854
3855         CAM_LOG_INFO("Enter");
3856
3857         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3858
3859         if (ret == CAMERA_ERROR_NONE) {
3860                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3861
3862                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3863                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3864
3865                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3866         }
3867
3868         CAM_LOG_INFO("ret : 0x%x", ret);
3869
3870         return ret;
3871 }
3872
3873
3874 int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
3875 {
3876         int ret = CAMERA_ERROR_NONE;
3877         camera_cli_s *pc = (camera_cli_s *)camera;
3878         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
3879
3880         if (!pc || !pc->cb_info || !callback) {
3881                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3882                 return CAMERA_ERROR_INVALID_PARAMETER;
3883         }
3884
3885         CAM_LOG_INFO("Enter");
3886
3887         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3888
3889         if (ret == CAMERA_ERROR_NONE) {
3890                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3891
3892                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
3893                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
3894
3895                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3896         }
3897
3898         CAM_LOG_INFO("ret : 0x%x", ret);
3899
3900         return ret;
3901 }
3902
3903
3904 int camera_unset_interrupt_started_cb(camera_h camera)
3905 {
3906         int ret = CAMERA_ERROR_NONE;
3907         camera_cli_s *pc = (camera_cli_s *)camera;
3908         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
3909
3910         if (!pc || !pc->cb_info) {
3911                 CAM_LOG_ERROR("NULL handle");
3912                 return CAMERA_ERROR_INVALID_PARAMETER;
3913         }
3914
3915         CAM_LOG_INFO("Enter");
3916
3917         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3918
3919         if (ret == CAMERA_ERROR_NONE) {
3920                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3921
3922                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3923                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3924
3925                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3926         }
3927
3928         CAM_LOG_INFO("ret : 0x%x", ret);
3929
3930         return ret;
3931 }
3932
3933
3934 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
3935 {
3936         int ret = CAMERA_ERROR_NONE;
3937         camera_cli_s *pc = (camera_cli_s *)camera;
3938         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
3939
3940         if (!pc || !pc->cb_info || !callback) {
3941                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
3942                 return CAMERA_ERROR_INVALID_PARAMETER;
3943         }
3944
3945         CAM_LOG_INFO("Enter");
3946
3947         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3948
3949         if (ret == CAMERA_ERROR_NONE) {
3950                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3951
3952                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
3953                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
3954
3955                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3956         }
3957
3958         CAM_LOG_INFO("ret : 0x%x", ret);
3959
3960         return ret;
3961 }
3962
3963
3964 int camera_unset_focus_changed_cb(camera_h camera)
3965 {
3966         int ret = CAMERA_ERROR_NONE;
3967         camera_cli_s *pc = (camera_cli_s *)camera;
3968         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
3969
3970         if (!pc || !pc->cb_info) {
3971                 CAM_LOG_ERROR("NULL handle");
3972                 return CAMERA_ERROR_INVALID_PARAMETER;
3973         }
3974
3975         CAM_LOG_INFO("Enter");
3976
3977         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3978
3979         if (ret == CAMERA_ERROR_NONE) {
3980                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3981
3982                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
3983                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
3984
3985                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3986         }
3987
3988         CAM_LOG_INFO("ret : 0x%x", ret);
3989
3990         return ret;
3991 }
3992
3993
3994 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
3995 {
3996         int ret = CAMERA_ERROR_NONE;
3997         camera_cli_s *pc = (camera_cli_s *)camera;
3998         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
3999
4000         if (!pc || !pc->cb_info || !callback) {
4001                 CAM_LOG_ERROR("NULL pointer %p %p", pc, callback);
4002                 return CAMERA_ERROR_INVALID_PARAMETER;
4003         }
4004
4005         CAM_LOG_INFO("Enter");
4006
4007         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4008
4009         if (ret == CAMERA_ERROR_NONE) {
4010                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4011
4012                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
4013                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
4014
4015                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4016         }
4017
4018         CAM_LOG_INFO("ret : 0x%x", ret);
4019
4020         return ret;
4021 }
4022
4023
4024 int camera_unset_error_cb(camera_h camera)
4025 {
4026         int ret = CAMERA_ERROR_NONE;
4027         camera_cli_s *pc = (camera_cli_s *)camera;
4028         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
4029
4030         if (!pc || !pc->cb_info) {
4031                 CAM_LOG_ERROR("NULL handle");
4032                 return CAMERA_ERROR_INVALID_PARAMETER;
4033         }
4034
4035         CAM_LOG_INFO("Enter");
4036
4037         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4038
4039         if (ret == CAMERA_ERROR_NONE) {
4040                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4041
4042                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4043                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4044
4045                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4046         }
4047
4048         CAM_LOG_INFO("ret : 0x%x", ret);
4049
4050         return ret;
4051 }
4052
4053
4054 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
4055 {
4056         int ret = CAMERA_ERROR_NONE;
4057         camera_cli_s *pc = (camera_cli_s *)camera;
4058         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
4059
4060         if (!pc || !pc->cb_info || !foreach_cb) {
4061                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4062                 return CAMERA_ERROR_INVALID_PARAMETER;
4063         }
4064
4065         CAM_LOG_INFO("Enter");
4066
4067         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = foreach_cb;
4068         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = user_data;
4069
4070         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4071
4072         CAM_LOG_INFO("ret : 0x%x", ret);
4073
4074         return ret;
4075 }
4076
4077
4078 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
4079 {
4080         int ret = CAMERA_ERROR_NONE;
4081         camera_cli_s *pc = (camera_cli_s *)camera;
4082         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
4083
4084         if (!pc || !pc->cb_info || !foreach_cb) {
4085                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4086                 return CAMERA_ERROR_INVALID_PARAMETER;
4087         }
4088
4089         CAM_LOG_INFO("Enter");
4090
4091         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = foreach_cb;
4092         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = user_data;
4093
4094         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4095
4096         CAM_LOG_INFO("ret : 0x%x", ret);
4097
4098         return ret;
4099 }
4100
4101
4102 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
4103 {
4104         int ret = CAMERA_ERROR_NONE;
4105         camera_cli_s *pc = (camera_cli_s *)camera;
4106         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
4107
4108         if (!pc || !pc->cb_info || !foreach_cb) {
4109                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4110                 return CAMERA_ERROR_INVALID_PARAMETER;
4111         }
4112
4113         CAM_LOG_INFO("Enter");
4114
4115         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = foreach_cb;
4116         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = user_data;
4117
4118         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4119
4120         CAM_LOG_INFO("ret : 0x%x", ret);
4121
4122         return ret;
4123 }
4124
4125
4126 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
4127 {
4128         int ret = CAMERA_ERROR_NONE;
4129         camera_cli_s *pc = (camera_cli_s *)camera;
4130         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
4131
4132         if (!pc || !pc->cb_info || !foreach_cb) {
4133                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4134                 return CAMERA_ERROR_INVALID_PARAMETER;
4135         }
4136
4137         CAM_LOG_INFO("Enter");
4138
4139         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = foreach_cb;
4140         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = user_data;
4141
4142         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4143
4144         CAM_LOG_INFO("ret : 0x%x", ret);
4145
4146         return ret;
4147 }
4148
4149
4150 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
4151 {
4152         int ret = CAMERA_ERROR_NONE;
4153         camera_cli_s *pc = (camera_cli_s *)camera;
4154         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
4155
4156         if (!pc || !pc->cb_info || !width || !height) {
4157                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, width, height);
4158                 return CAMERA_ERROR_INVALID_PARAMETER;
4159         }
4160
4161         CAM_LOG_INFO("Enter");
4162         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4163
4164         if (ret == CAMERA_ERROR_NONE) {
4165                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION] >> 16;
4166                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION];
4167         }
4168
4169         CAM_LOG_INFO("ret : 0x%x", ret);
4170
4171         return ret;
4172 }
4173
4174
4175 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
4176 {
4177         int ret = CAMERA_ERROR_NONE;
4178         camera_cli_s *pc = (camera_cli_s *)camera;
4179         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
4180
4181         if (!pc || !pc->cb_info || !angle) {
4182                 CAM_LOG_ERROR("NULL pointer %p %p", pc, angle);
4183                 return CAMERA_ERROR_INVALID_PARAMETER;
4184         }
4185
4186         CAM_LOG_INFO("Enter");
4187
4188         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4189
4190         if (ret == CAMERA_ERROR_NONE)
4191                 *angle = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_LENS_ORIENTATION];
4192
4193         CAM_LOG_INFO("ret : 0x%x", ret);
4194
4195         return ret;
4196 }
4197
4198
4199 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
4200 {
4201         int ret = CAMERA_ERROR_NONE;
4202         camera_cli_s *pc = (camera_cli_s *)camera;
4203         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_THEATER_MODE;
4204         camera_msg_param param;
4205         int set_mode = (int)mode;
4206
4207         if (!pc || !pc->cb_info) {
4208                 CAM_LOG_ERROR("NULL handle");
4209                 return CAMERA_ERROR_INVALID_PARAMETER;
4210         }
4211
4212         CAM_LOG_INFO("Enter");
4213
4214         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4215
4216         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4217
4218         CAM_LOG_INFO("ret : 0x%x", ret);
4219
4220         return ret;
4221 }
4222
4223
4224 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
4225 {
4226         int ret = CAMERA_ERROR_NONE;
4227         camera_cli_s *pc = (camera_cli_s *)camera;
4228         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
4229
4230         if (!pc || !pc->cb_info || !mode) {
4231                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
4232                 return CAMERA_ERROR_INVALID_PARAMETER;
4233         }
4234
4235         CAM_LOG_INFO("Enter");
4236
4237         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4238
4239         if (ret == CAMERA_ERROR_NONE)
4240                 *mode = (camera_attr_theater_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_THEATER_MODE];
4241
4242         CAM_LOG_INFO("ret : 0x%x", ret);
4243
4244         return ret;
4245 }
4246
4247
4248 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
4249 {
4250         int ret = CAMERA_ERROR_NONE;
4251         camera_cli_s *pc = (camera_cli_s *)camera;
4252         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
4253
4254         if (!pc || !pc->cb_info || !foreach_cb) {
4255                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
4256                 return CAMERA_ERROR_INVALID_PARAMETER;
4257         }
4258
4259         CAM_LOG_INFO("Enter");
4260
4261         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = foreach_cb;
4262         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = user_data;
4263
4264         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4265
4266         CAM_LOG_INFO("Finish, return :%x", ret);
4267
4268         return ret;
4269 }
4270
4271
4272 int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
4273 {
4274         int ret = CAMERA_ERROR_NONE;
4275         camera_cli_s *pc = (camera_cli_s *)camera;
4276         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
4277         camera_msg_param param;
4278         int set_fps = (int)fps;
4279
4280         if (!pc || !pc->cb_info) {
4281                 CAM_LOG_ERROR("NULL handle");
4282                 return CAMERA_ERROR_INVALID_PARAMETER;
4283         }
4284
4285         CAM_LOG_INFO("Enter");
4286
4287         CAMERA_MSG_PARAM_SET(param, INT, set_fps);
4288
4289         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4290
4291         CAM_LOG_INFO("ret : 0x%x", ret);
4292
4293         return ret;
4294 }
4295
4296
4297 int camera_attr_set_image_quality(camera_h camera, int quality)
4298 {
4299         int ret = CAMERA_ERROR_NONE;
4300         camera_cli_s *pc = (camera_cli_s *)camera;
4301         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
4302         camera_msg_param param;
4303
4304         if (!pc || !pc->cb_info) {
4305                 CAM_LOG_ERROR("NULL handle");
4306                 return CAMERA_ERROR_INVALID_PARAMETER;
4307         }
4308
4309         CAM_LOG_INFO("Enter");
4310
4311         CAMERA_MSG_PARAM_SET(param, INT, quality);
4312
4313         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4314
4315         CAM_LOG_INFO("ret : 0x%x", ret);
4316
4317         return ret;
4318 }
4319
4320
4321 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
4322 {
4323         int ret = CAMERA_ERROR_NONE;
4324         camera_cli_s *pc = (camera_cli_s *)camera;
4325         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
4326
4327         if (!pc || !pc->cb_info || !fps) {
4328                 CAM_LOG_ERROR("NULL pointer %p %p", pc, fps);
4329                 return CAMERA_ERROR_INVALID_PARAMETER;
4330         }
4331
4332         CAM_LOG_INFO("Enter");
4333
4334         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4335
4336         if (ret == CAMERA_ERROR_NONE)
4337                 *fps = (camera_attr_fps_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FPS];
4338
4339         CAM_LOG_INFO("ret : 0x%x", ret);
4340
4341         return ret;
4342 }
4343
4344
4345 int camera_attr_get_image_quality(camera_h camera, int *quality)
4346 {
4347         int ret = CAMERA_ERROR_NONE;
4348         camera_cli_s *pc = (camera_cli_s *)camera;
4349         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
4350
4351         if (!pc || !pc->cb_info || !quality) {
4352                 CAM_LOG_ERROR("NULL pointer %p %p", pc, quality);
4353                 return CAMERA_ERROR_INVALID_PARAMETER;
4354         }
4355
4356         CAM_LOG_INFO("Enter");
4357
4358         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4359
4360         if (ret == CAMERA_ERROR_NONE)
4361                 *quality = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_IMAGE_QUALITY];
4362
4363         CAM_LOG_INFO("ret : 0x%x", ret);
4364
4365         return ret;
4366 }
4367
4368
4369 int camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate)
4370 {
4371         int ret = CAMERA_ERROR_NONE;
4372         camera_cli_s *pc = (camera_cli_s *)camera;
4373         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4374
4375         if (!pc || !pc->cb_info || !bitrate) {
4376                 CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
4377                 return CAMERA_ERROR_INVALID_PARAMETER;
4378         }
4379
4380         CAM_LOG_INFO("Enter");
4381
4382         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4383
4384         if (ret == CAMERA_ERROR_NONE)
4385                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE];
4386
4387         CAM_LOG_INFO("ret : 0x%x", ret);
4388
4389         return ret;
4390 }
4391
4392
4393 int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
4394 {
4395         int ret = CAMERA_ERROR_NONE;
4396         camera_cli_s *pc = (camera_cli_s *)camera;
4397         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4398         camera_msg_param param;
4399         int set_bitrate = bitrate;
4400
4401         if (!pc || !pc->cb_info) {
4402                 CAM_LOG_ERROR("NULL handle");
4403                 return CAMERA_ERROR_INVALID_PARAMETER;
4404         }
4405
4406         CAM_LOG_INFO("Enter");
4407
4408         CAMERA_MSG_PARAM_SET(param, INT, set_bitrate);
4409
4410         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4411
4412         CAM_LOG_INFO("ret : 0x%x", ret);
4413
4414         return ret;
4415 }
4416
4417
4418 int camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval)
4419 {
4420         int ret = CAMERA_ERROR_NONE;
4421         camera_cli_s *pc = (camera_cli_s *)camera;
4422         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4423
4424         if (!pc || !pc->cb_info || !interval) {
4425                 CAM_LOG_ERROR("NULL pointer %p %p", pc, interval);
4426                 return CAMERA_ERROR_INVALID_PARAMETER;
4427         }
4428
4429         CAM_LOG_INFO("Enter");
4430
4431         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4432
4433         if (ret == CAMERA_ERROR_NONE)
4434                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL];
4435
4436         CAM_LOG_INFO("ret : 0x%x", ret);
4437
4438         return ret;
4439 }
4440
4441
4442 int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
4443 {
4444         int ret = CAMERA_ERROR_NONE;
4445         camera_cli_s *pc = (camera_cli_s *)camera;
4446         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4447         camera_msg_param param;
4448         int set_gop_interval = interval;
4449
4450         if (!pc || !pc->cb_info) {
4451                 CAM_LOG_ERROR("NULL handle");
4452                 return CAMERA_ERROR_INVALID_PARAMETER;
4453         }
4454
4455         CAM_LOG_INFO("Enter");
4456
4457         CAMERA_MSG_PARAM_SET(param, INT, set_gop_interval);
4458
4459         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4460
4461         CAM_LOG_INFO("ret : 0x%x", ret);
4462
4463         return ret;
4464 }
4465
4466
4467 int camera_attr_set_zoom(camera_h camera, int zoom)
4468 {
4469         int ret = CAMERA_ERROR_NONE;
4470         camera_cli_s *pc = (camera_cli_s *)camera;
4471         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
4472         camera_msg_param param;
4473
4474         if (!pc || !pc->cb_info) {
4475                 CAM_LOG_ERROR("NULL handle");
4476                 return CAMERA_ERROR_INVALID_PARAMETER;
4477         }
4478
4479         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4480
4481         CAMERA_MSG_PARAM_SET(param, INT, zoom);
4482
4483         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4484
4485         CAM_LOG_INFO("ret : 0x%x", ret);
4486
4487         return ret;
4488 }
4489
4490
4491 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
4492 {
4493         int ret = CAMERA_ERROR_NONE;
4494         camera_cli_s *pc = (camera_cli_s *)camera;
4495         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_MODE;
4496         camera_msg_param param;
4497         int set_mode = (int)mode;
4498
4499         if (!pc || !pc->cb_info) {
4500                 CAM_LOG_ERROR("NULL handle");
4501                 return CAMERA_ERROR_INVALID_PARAMETER;
4502         }
4503
4504         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4505
4506         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4507
4508         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4509
4510         return ret;
4511 }
4512
4513
4514 int camera_attr_set_af_area(camera_h camera, int x, int y)
4515 {
4516         int ret = CAMERA_ERROR_NONE;
4517         camera_cli_s *pc = (camera_cli_s *)camera;
4518         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
4519         camera_msg_param param;
4520         int value = 0;
4521
4522         if (!pc || !pc->cb_info) {
4523                 CAM_LOG_ERROR("NULL handle");
4524                 return CAMERA_ERROR_INVALID_PARAMETER;
4525         }
4526
4527         CAM_LOG_INFO("Enter - %d,%d", x, y);
4528
4529         value = (x << 16) | y;
4530         CAMERA_MSG_PARAM_SET(param, INT, value);
4531
4532         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4533
4534         CAM_LOG_INFO("ret : 0x%x", ret);
4535
4536         return ret;
4537 }
4538
4539
4540 int camera_attr_clear_af_area(camera_h camera)
4541 {
4542         int ret = CAMERA_ERROR_NONE;
4543         camera_cli_s *pc = (camera_cli_s *)camera;
4544         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
4545
4546         if (!pc || !pc->cb_info) {
4547                 CAM_LOG_ERROR("NULL handle");
4548                 return CAMERA_ERROR_INVALID_PARAMETER;
4549         }
4550
4551         CAM_LOG_INFO("Enter");
4552
4553         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4554
4555         CAM_LOG_INFO("ret : 0x%x", ret);
4556
4557         return ret;
4558 }
4559
4560
4561 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
4562 {
4563         int ret = CAMERA_ERROR_NONE;
4564         camera_cli_s *pc = (camera_cli_s *)camera;
4565         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE;
4566         camera_msg_param param;
4567         int set_mode = (int)mode;
4568
4569         if (!pc || !pc->cb_info) {
4570                 CAM_LOG_ERROR("NULL handle");
4571                 return CAMERA_ERROR_INVALID_PARAMETER;
4572         }
4573
4574         CAM_LOG_INFO("Enter");
4575
4576         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4577
4578         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4579
4580         CAM_LOG_INFO("ret : 0x%x", ret);
4581
4582         return ret;
4583 }
4584
4585
4586 int camera_attr_set_exposure(camera_h camera, int value)
4587 {
4588         int ret = CAMERA_ERROR_NONE;
4589         camera_cli_s *pc = (camera_cli_s *)camera;
4590         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
4591         camera_msg_param param;
4592
4593         if (!pc || !pc->cb_info) {
4594                 CAM_LOG_ERROR("NULL handle");
4595                 return CAMERA_ERROR_INVALID_PARAMETER;
4596         }
4597
4598         CAM_LOG_INFO("Enter");
4599
4600         CAMERA_MSG_PARAM_SET(param, INT, value);
4601
4602         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4603
4604         CAM_LOG_INFO("ret : 0x%x", ret);
4605
4606         return ret;
4607 }
4608
4609
4610 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
4611 {
4612         int ret = CAMERA_ERROR_NONE;
4613         camera_cli_s *pc = (camera_cli_s *)camera;
4614         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
4615         camera_msg_param param;
4616         int set_iso = (int)iso;
4617
4618         if (!pc || !pc->cb_info) {
4619                 CAM_LOG_ERROR("NULL handle");
4620                 return CAMERA_ERROR_INVALID_PARAMETER;
4621         }
4622
4623         CAM_LOG_INFO("Enter");
4624
4625         CAMERA_MSG_PARAM_SET(param, INT, set_iso);
4626
4627         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4628
4629         CAM_LOG_INFO("ret : 0x%x", ret);
4630
4631         return ret;
4632 }
4633
4634
4635 int camera_attr_set_brightness(camera_h camera, int level)
4636 {
4637         int ret = CAMERA_ERROR_NONE;
4638         camera_cli_s *pc = (camera_cli_s *)camera;
4639         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
4640         camera_msg_param param;
4641
4642         if (!pc || !pc->cb_info) {
4643                 CAM_LOG_ERROR("NULL handle");
4644                 return CAMERA_ERROR_INVALID_PARAMETER;
4645         }
4646
4647         CAM_LOG_INFO("Enter");
4648
4649         CAMERA_MSG_PARAM_SET(param, INT, level);
4650
4651         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4652
4653         CAM_LOG_INFO("ret : 0x%x", ret);
4654
4655         return ret;
4656 }
4657
4658
4659 int camera_attr_set_contrast(camera_h camera, int level)
4660 {
4661         int ret = CAMERA_ERROR_NONE;
4662         camera_cli_s *pc = (camera_cli_s *)camera;
4663         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
4664         camera_msg_param param;
4665
4666         if (!pc || !pc->cb_info) {
4667                 CAM_LOG_ERROR("NULL handle");
4668                 return CAMERA_ERROR_INVALID_PARAMETER;
4669         }
4670
4671         CAM_LOG_INFO("Enter");
4672
4673         CAMERA_MSG_PARAM_SET(param, INT, level);
4674
4675         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4676
4677         CAM_LOG_INFO("ret : 0x%x", ret);
4678
4679         return ret;
4680 }
4681
4682
4683 int camera_attr_set_hue(camera_h camera, int level)
4684 {
4685         int ret = CAMERA_ERROR_NONE;
4686         camera_cli_s *pc = (camera_cli_s *)camera;
4687         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
4688         camera_msg_param param;
4689
4690         if (!pc || !pc->cb_info) {
4691                 CAM_LOG_ERROR("NULL handle");
4692                 return CAMERA_ERROR_INVALID_PARAMETER;
4693         }
4694
4695         CAM_LOG_INFO("Enter");
4696
4697         CAMERA_MSG_PARAM_SET(param, INT, level);
4698
4699         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4700
4701         CAM_LOG_INFO("ret : 0x%x", ret);
4702
4703         return ret;
4704 }
4705
4706
4707 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
4708 {
4709         int ret = CAMERA_ERROR_NONE;
4710         camera_cli_s *pc = (camera_cli_s *)camera;
4711         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
4712         camera_msg_param param;
4713         int set_whitebalance = (int)wb;
4714
4715         if (!pc || !pc->cb_info) {
4716                 CAM_LOG_ERROR("NULL handle");
4717                 return CAMERA_ERROR_INVALID_PARAMETER;
4718         }
4719
4720         CAM_LOG_INFO("Enter");
4721
4722         CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
4723
4724         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4725
4726         CAM_LOG_INFO("ret : 0x%x", ret);
4727
4728         return ret;
4729 }
4730
4731
4732 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
4733 {
4734         int ret = CAMERA_ERROR_NONE;
4735         camera_cli_s *pc = (camera_cli_s *)camera;
4736         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
4737         camera_msg_param param;
4738         int set_effect = (int)effect;
4739
4740         if (!pc || !pc->cb_info) {
4741                 CAM_LOG_ERROR("NULL handle");
4742                 return CAMERA_ERROR_INVALID_PARAMETER;
4743         }
4744
4745         CAM_LOG_INFO("Enter");
4746
4747         CAMERA_MSG_PARAM_SET(param, INT, set_effect);
4748
4749         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4750
4751         CAM_LOG_INFO("ret : 0x%x", ret);
4752
4753         return ret;
4754 }
4755
4756
4757 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
4758 {
4759         int ret = CAMERA_ERROR_NONE;
4760         camera_cli_s *pc = (camera_cli_s *)camera;
4761         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_SCENE_MODE;
4762         camera_msg_param param;
4763         int set_mode = (int)mode;
4764
4765         if (!pc || !pc->cb_info) {
4766                 CAM_LOG_ERROR("NULL handle");
4767                 return CAMERA_ERROR_INVALID_PARAMETER;
4768         }
4769
4770         CAM_LOG_INFO("Enter");
4771
4772         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4773
4774         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4775
4776         CAM_LOG_INFO("ret : 0x%x", ret);
4777
4778         return ret;
4779 }
4780
4781
4782 int camera_attr_enable_tag(camera_h camera, bool enable)
4783 {
4784         int ret = CAMERA_ERROR_NONE;
4785         camera_cli_s *pc = (camera_cli_s *)camera;
4786         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_TAG;
4787         camera_msg_param param;
4788         int set_enable = (int)enable;
4789
4790         if (!pc || !pc->cb_info) {
4791                 CAM_LOG_ERROR("NULL handle");
4792                 return CAMERA_ERROR_INVALID_PARAMETER;
4793         }
4794
4795         CAM_LOG_INFO("Enter");
4796
4797         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
4798
4799         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4800
4801         CAM_LOG_INFO("ret : 0x%x", ret);
4802
4803         return ret;
4804 }
4805
4806
4807 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
4808 {
4809         int ret = CAMERA_ERROR_NONE;
4810         camera_cli_s *pc = (camera_cli_s *)camera;
4811         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
4812         camera_msg_param param;
4813
4814         if (!pc || !pc->cb_info || !description) {
4815                 CAM_LOG_ERROR("NULL pointer %p %p", pc, description);
4816                 return CAMERA_ERROR_INVALID_PARAMETER;
4817         }
4818
4819         CAM_LOG_INFO("Enter");
4820
4821         CAMERA_MSG_PARAM_SET(param, STRING, description);
4822
4823         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4824
4825         CAM_LOG_INFO("ret : 0x%x", ret);
4826
4827         return ret;
4828 }
4829
4830
4831 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
4832 {
4833         int ret = CAMERA_ERROR_NONE;
4834         camera_cli_s *pc = (camera_cli_s *)camera;
4835         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
4836         camera_msg_param param;
4837         int set_orientation = (int)orientation;
4838
4839         if (!pc || !pc->cb_info) {
4840                 CAM_LOG_ERROR("NULL handle");
4841                 return CAMERA_ERROR_INVALID_PARAMETER;
4842         }
4843
4844         CAM_LOG_INFO("Enter");
4845
4846         CAMERA_MSG_PARAM_SET(param, INT, set_orientation);
4847
4848         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4849
4850         CAM_LOG_INFO("ret : 0x%x", ret);
4851
4852         return ret;
4853 }
4854
4855
4856 int camera_attr_set_tag_software(camera_h camera, const char *software)
4857 {
4858         int ret = CAMERA_ERROR_NONE;
4859         camera_cli_s *pc = (camera_cli_s *)camera;
4860         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
4861         camera_msg_param param;
4862
4863         if (!pc || !pc->cb_info || !software) {
4864                 CAM_LOG_ERROR("NULL pointer %p %p", pc, software);
4865                 return CAMERA_ERROR_INVALID_PARAMETER;
4866         }
4867
4868         CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
4869
4870         CAMERA_MSG_PARAM_SET(param, STRING, software);
4871
4872         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4873
4874         CAM_LOG_INFO("ret : 0x%x", ret);
4875
4876         return ret;
4877 }
4878
4879
4880 int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, double altitude)
4881 {
4882         int ret = CAMERA_ERROR_NONE;
4883         camera_cli_s *pc = (camera_cli_s *)camera;
4884         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
4885         double set_geotag[3] = {latitude, longitude, altitude};
4886         char *msg = NULL;
4887         int length = 0;
4888         int send_ret = 0;
4889
4890         if (!pc || !pc->cb_info) {
4891                 CAM_LOG_ERROR("NULL handle");
4892                 return CAMERA_ERROR_INVALID_PARAMETER;
4893         }
4894
4895         CAM_LOG_INFO("Enter");
4896
4897         length = sizeof(set_geotag) / sizeof(int) + \
4898                 (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
4899
4900         msg = muse_core_msg_new(api,
4901                 MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
4902                 NULL);
4903         if (!msg) {
4904                 CAM_LOG_ERROR("msg creation failed: api %d", api);
4905                 return CAMERA_ERROR_OUT_OF_MEMORY;
4906         }
4907
4908         if (pc->cb_info->is_server_connected) {
4909                 __camera_update_api_waiting(pc->cb_info, api, 1);
4910
4911                 g_mutex_lock(&pc->cb_info->fd_lock);
4912                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
4913                 g_mutex_unlock(&pc->cb_info->fd_lock);
4914         }
4915
4916         if (send_ret < 0) {
4917                 CAM_LOG_ERROR("message send failed");
4918                 ret = CAMERA_ERROR_INVALID_OPERATION;
4919         } else {
4920                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
4921         }
4922
4923         __camera_update_api_waiting(pc->cb_info, api, -1);
4924
4925         muse_core_msg_free(msg);
4926
4927         CAM_LOG_INFO("ret : 0x%x", ret);
4928
4929         return ret;
4930 }
4931
4932
4933 int camera_attr_remove_geotag(camera_h camera)
4934 {
4935         int ret = CAMERA_ERROR_NONE;
4936         camera_cli_s *pc = (camera_cli_s *)camera;
4937         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
4938
4939         if (!pc || !pc->cb_info) {
4940                 CAM_LOG_ERROR("NULL handle");
4941                 return CAMERA_ERROR_INVALID_PARAMETER;
4942         }
4943
4944         CAM_LOG_INFO("Enter");
4945
4946         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4947
4948         CAM_LOG_INFO("ret : 0x%x", ret);
4949
4950         return ret;
4951 }
4952
4953
4954 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
4955 {
4956         int ret = CAMERA_ERROR_NONE;
4957         camera_cli_s *pc = (camera_cli_s *)camera;
4958         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
4959         camera_msg_param param;
4960         int set_mode = (int)mode;
4961
4962         if (!pc || !pc->cb_info) {
4963                 CAM_LOG_ERROR("NULL handle");
4964                 return CAMERA_ERROR_INVALID_PARAMETER;
4965         }
4966
4967         CAM_LOG_INFO("Enter");
4968
4969         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4970
4971         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4972
4973         CAM_LOG_INFO("ret : 0x%x", ret);
4974
4975         return ret;
4976 }
4977
4978
4979 int camera_attr_get_zoom(camera_h camera, int *zoom)
4980 {
4981         int ret = CAMERA_ERROR_NONE;
4982         camera_cli_s *pc = (camera_cli_s *)camera;
4983         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
4984
4985         if (!pc || !pc->cb_info || !zoom) {
4986                 CAM_LOG_ERROR("NULL pointer %p %p", pc, zoom);
4987                 return CAMERA_ERROR_INVALID_PARAMETER;
4988         }
4989
4990         CAM_LOG_INFO("Enter");
4991
4992         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4993
4994         if (ret == CAMERA_ERROR_NONE)
4995                 *zoom = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ZOOM];
4996
4997         CAM_LOG_INFO("ret : 0x%x", ret);
4998
4999         return ret;
5000 }
5001
5002
5003 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
5004 {
5005         int ret = CAMERA_ERROR_NONE;
5006         camera_cli_s *pc = (camera_cli_s *)camera;
5007         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
5008
5009         if (!pc || !pc->cb_info || !min || !max) {
5010                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5011                 return CAMERA_ERROR_INVALID_PARAMETER;
5012         }
5013
5014         CAM_LOG_INFO("Enter");
5015
5016         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5017
5018         if (ret == CAMERA_ERROR_NONE) {
5019                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
5020                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
5021         }
5022
5023         CAM_LOG_INFO("ret : 0x%x", ret);
5024
5025         return ret;
5026 }
5027
5028
5029 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
5030 {
5031         int ret = CAMERA_ERROR_NONE;
5032         camera_cli_s *pc = (camera_cli_s *)camera;
5033         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
5034
5035         if (!pc || !pc->cb_info || !mode) {
5036                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5037                 return CAMERA_ERROR_INVALID_PARAMETER;
5038         }
5039
5040         CAM_LOG_INFO("Enter");
5041
5042         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5043
5044         if (ret == CAMERA_ERROR_NONE)
5045                 *mode = (camera_attr_af_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_AF_MODE];
5046
5047         CAM_LOG_INFO("ret : 0x%x", ret);
5048
5049         return ret;
5050 }
5051
5052
5053 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
5054 {
5055         int ret = CAMERA_ERROR_NONE;
5056         camera_cli_s *pc = (camera_cli_s *)camera;
5057         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
5058
5059         if (!pc || !pc->cb_info || !mode) {
5060                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5061                 return CAMERA_ERROR_INVALID_PARAMETER;
5062         }
5063
5064         CAM_LOG_INFO("Enter");
5065
5066         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5067
5068         if (ret == CAMERA_ERROR_NONE)
5069                 *mode = (camera_attr_exposure_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE_MODE];
5070
5071         CAM_LOG_INFO("ret : 0x%x", ret);
5072
5073         return ret;
5074 }
5075
5076
5077 int camera_attr_get_exposure(camera_h camera, int *value)
5078 {
5079         int ret = CAMERA_ERROR_NONE;
5080         camera_cli_s *pc = (camera_cli_s *)camera;
5081         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
5082
5083         if (!pc || !pc->cb_info || !value) {
5084                 CAM_LOG_ERROR("NULL pointer %p %p", pc, value);
5085                 return CAMERA_ERROR_INVALID_PARAMETER;
5086         }
5087
5088         CAM_LOG_INFO("Enter");
5089
5090         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5091
5092         if (ret == CAMERA_ERROR_NONE)
5093                 *value = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE];
5094
5095         CAM_LOG_INFO("ret : 0x%x", ret);
5096
5097         return ret;
5098 }
5099
5100
5101 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
5102 {
5103         int ret = CAMERA_ERROR_NONE;
5104         camera_cli_s *pc = (camera_cli_s *)camera;
5105         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
5106
5107         if (!pc || !pc->cb_info || !min || !max) {
5108                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5109                 return CAMERA_ERROR_INVALID_PARAMETER;
5110         }
5111
5112         CAM_LOG_INFO("Enter");
5113
5114         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5115
5116         if (ret == CAMERA_ERROR_NONE) {
5117                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
5118                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
5119         }
5120
5121         CAM_LOG_INFO("ret : 0x%x", ret);
5122
5123         return ret;
5124 }
5125
5126
5127 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
5128 {
5129         int ret = CAMERA_ERROR_NONE;
5130         camera_cli_s *pc = (camera_cli_s *)camera;
5131         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
5132
5133         if (!pc || !pc->cb_info || !iso) {
5134                 CAM_LOG_ERROR("NULL pointer %p %p", pc, iso);
5135                 return CAMERA_ERROR_INVALID_PARAMETER;
5136         }
5137
5138         CAM_LOG_INFO("Enter");
5139
5140         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5141
5142         if (ret == CAMERA_ERROR_NONE)
5143                 *iso = (camera_attr_iso_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ISO];
5144
5145         CAM_LOG_INFO("ret : 0x%x", ret);
5146
5147         return ret;
5148 }
5149
5150
5151 int camera_attr_get_brightness(camera_h camera, int *level)
5152 {
5153         int ret = CAMERA_ERROR_NONE;
5154         camera_cli_s *pc = (camera_cli_s *)camera;
5155         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
5156
5157         if (!pc || !pc->cb_info || !level) {
5158                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5159                 return CAMERA_ERROR_INVALID_PARAMETER;
5160         }
5161
5162         CAM_LOG_INFO("Enter");
5163
5164         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5165
5166         if (ret == CAMERA_ERROR_NONE)
5167                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
5168
5169         CAM_LOG_INFO("ret : 0x%x", ret);
5170
5171         return ret;
5172 }
5173
5174
5175 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
5176 {
5177         int ret = CAMERA_ERROR_NONE;
5178         camera_cli_s *pc = (camera_cli_s *)camera;
5179         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
5180
5181         if (!pc || !pc->cb_info || !min || !max) {
5182                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5183                 return CAMERA_ERROR_INVALID_PARAMETER;
5184         }
5185
5186         CAM_LOG_INFO("Enter");
5187
5188         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5189
5190         if (ret == CAMERA_ERROR_NONE) {
5191                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
5192                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
5193         }
5194
5195         CAM_LOG_INFO("ret : 0x%x", ret);
5196
5197         return ret;
5198 }
5199
5200
5201 int camera_attr_get_contrast(camera_h camera, int *level)
5202 {
5203         int ret = CAMERA_ERROR_NONE;
5204         camera_cli_s *pc = (camera_cli_s *)camera;
5205         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
5206
5207         if (!pc || !pc->cb_info || !level) {
5208                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5209                 return CAMERA_ERROR_INVALID_PARAMETER;
5210         }
5211
5212         CAM_LOG_INFO("Enter");
5213
5214         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5215
5216         if (ret == CAMERA_ERROR_NONE)
5217                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
5218
5219         CAM_LOG_INFO("ret : 0x%x", ret);
5220
5221         return ret;
5222 }
5223
5224
5225 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
5226 {
5227         int ret = CAMERA_ERROR_NONE;
5228         camera_cli_s *pc = (camera_cli_s *)camera;
5229         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
5230
5231         if (!pc || !pc->cb_info || !min || !max) {
5232                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5233                 return CAMERA_ERROR_INVALID_PARAMETER;
5234         }
5235
5236         CAM_LOG_INFO("Enter");
5237
5238         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5239
5240         if (ret == CAMERA_ERROR_NONE) {
5241                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
5242                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
5243                 CAM_LOG_INFO("min %d, max %d", *min, *max);
5244         }
5245
5246         CAM_LOG_INFO("ret : 0x%x", ret);
5247
5248         return ret;
5249 }
5250
5251
5252 int camera_attr_get_hue(camera_h camera, int *level)
5253 {
5254         int ret = CAMERA_ERROR_NONE;
5255         camera_cli_s *pc = (camera_cli_s *)camera;
5256         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
5257
5258         if (!pc || !pc->cb_info || !level) {
5259                 CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
5260                 return CAMERA_ERROR_INVALID_PARAMETER;
5261         }
5262
5263         CAM_LOG_INFO("Enter");
5264
5265         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5266
5267         if (ret == CAMERA_ERROR_NONE)
5268                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
5269
5270         CAM_LOG_INFO("ret : 0x%x", ret);
5271
5272         return ret;
5273 }
5274
5275
5276 int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
5277 {
5278         int ret = CAMERA_ERROR_NONE;
5279         camera_cli_s *pc = (camera_cli_s *)camera;
5280         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
5281
5282         if (!pc || !pc->cb_info || !min || !max) {
5283                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
5284                 return CAMERA_ERROR_INVALID_PARAMETER;
5285         }
5286
5287         CAM_LOG_INFO("Enter");
5288
5289         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5290
5291         if (ret == CAMERA_ERROR_NONE) {
5292                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
5293                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
5294                 CAM_LOG_INFO("min %d, max %d", *min, *max);
5295         }
5296
5297         CAM_LOG_INFO("ret : 0x%x", ret);
5298
5299         return ret;
5300 }
5301
5302
5303 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
5304 {
5305         int ret = CAMERA_ERROR_NONE;
5306         camera_cli_s *pc = (camera_cli_s *)camera;
5307         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
5308
5309         if (!pc || !pc->cb_info || !wb) {
5310                 CAM_LOG_ERROR("NULL pointer %p %p", pc, wb);
5311                 return CAMERA_ERROR_INVALID_PARAMETER;
5312         }
5313
5314         CAM_LOG_INFO("Enter");
5315
5316         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5317
5318         if (ret == CAMERA_ERROR_NONE)
5319                 *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
5320
5321         CAM_LOG_INFO("ret : 0x%x", ret);
5322
5323         return ret;
5324 }
5325
5326
5327 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
5328 {
5329         int ret = CAMERA_ERROR_NONE;
5330         camera_cli_s *pc = (camera_cli_s *)camera;
5331         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
5332
5333         if (!pc || !pc->cb_info || !effect) {
5334                 CAM_LOG_ERROR("NULL pointer %p %p", pc, effect);
5335                 return CAMERA_ERROR_INVALID_PARAMETER;
5336         }
5337
5338         CAM_LOG_INFO("Enter");
5339
5340         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5341
5342         if (ret == CAMERA_ERROR_NONE)
5343                 *effect = (camera_attr_effect_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EFFECT];
5344
5345         CAM_LOG_INFO("ret : 0x%x", ret);
5346
5347         return ret;
5348 }
5349
5350
5351 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
5352 {
5353         int ret = CAMERA_ERROR_NONE;
5354         camera_cli_s *pc = (camera_cli_s *)camera;
5355         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
5356
5357         if (!pc || !pc->cb_info || !mode) {
5358                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5359                 return CAMERA_ERROR_INVALID_PARAMETER;
5360         }
5361
5362         CAM_LOG_INFO("Enter");
5363
5364         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5365
5366         if (ret == CAMERA_ERROR_NONE)
5367                 *mode = (camera_attr_scene_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_SCENE_MODE];
5368
5369         CAM_LOG_INFO("ret : 0x%x", ret);
5370
5371         return ret;
5372 }
5373
5374
5375 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
5376 {
5377         int ret = CAMERA_ERROR_NONE;
5378         camera_cli_s *pc = (camera_cli_s *)camera;
5379         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
5380
5381         if (!pc || !pc->cb_info || !enable) {
5382                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enable);
5383                 return CAMERA_ERROR_INVALID_PARAMETER;
5384         }
5385
5386         CAM_LOG_INFO("Enter");
5387
5388         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5389
5390         if (ret == CAMERA_ERROR_NONE)
5391                 *enable = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_TAG];
5392
5393         CAM_LOG_INFO("ret : 0x%x", ret);
5394
5395         return ret;
5396 }
5397
5398
5399 int camera_attr_get_tag_image_description(camera_h camera, char **description)
5400 {
5401         int ret = CAMERA_ERROR_NONE;
5402         camera_cli_s *pc = (camera_cli_s *)camera;
5403         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
5404
5405         if (!pc || !pc->cb_info || !description) {
5406                 CAM_LOG_ERROR("NULL pointer %p %p", pc, description);
5407                 return CAMERA_ERROR_INVALID_PARAMETER;
5408         }
5409
5410         CAM_LOG_INFO("Enter");
5411
5412         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5413
5414         if (ret == CAMERA_ERROR_NONE)
5415                 *description = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION]);
5416
5417         CAM_LOG_INFO("ret : 0x%x", ret);
5418
5419         return ret;
5420 }
5421
5422
5423 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
5424 {
5425         int ret = CAMERA_ERROR_NONE;
5426         camera_cli_s *pc = (camera_cli_s *)camera;
5427         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
5428
5429         if (!pc || !pc->cb_info || !orientation) {
5430                 CAM_LOG_ERROR("NULL pointer %p %p", pc, orientation);
5431                 return CAMERA_ERROR_INVALID_PARAMETER;
5432         }
5433
5434         CAM_LOG_INFO("Enter");
5435
5436         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5437
5438         if (ret == CAMERA_ERROR_NONE)
5439                 *orientation = (camera_attr_tag_orientation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TAG_ORIENTATION];
5440
5441         CAM_LOG_INFO("ret : 0x%x", ret);
5442
5443         return ret;
5444 }
5445
5446
5447 int camera_attr_get_tag_software(camera_h camera, char **software)
5448 {
5449         int ret = CAMERA_ERROR_NONE;
5450         camera_cli_s *pc = (camera_cli_s *)camera;
5451         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
5452
5453         if (!pc || !pc->cb_info || !software) {
5454                 CAM_LOG_ERROR("NULL pointer %p %p", pc, software);
5455                 return CAMERA_ERROR_INVALID_PARAMETER;
5456         }
5457
5458         CAM_LOG_INFO("Enter");
5459
5460         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5461
5462         if (ret == CAMERA_ERROR_NONE)
5463                 *software = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_SOFTWARE]);
5464
5465         CAM_LOG_INFO("ret : 0x%x", ret);
5466
5467         return ret;
5468 }
5469
5470
5471 int camera_attr_get_geotag(camera_h camera, double *latitude, double *longitude, double *altitude)
5472 {
5473         int ret = CAMERA_ERROR_NONE;
5474         camera_cli_s *pc = (camera_cli_s *)camera;
5475         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
5476
5477         if (!pc || !pc->cb_info || !latitude || !longitude || !altitude) {
5478                 CAM_LOG_ERROR("NULL pointer %p %p %p %p", pc, latitude, longitude, altitude);
5479                 return CAMERA_ERROR_INVALID_PARAMETER;
5480         }
5481
5482         CAM_LOG_INFO("Enter");
5483
5484         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5485
5486         if (ret == CAMERA_ERROR_NONE) {
5487                 *latitude = pc->cb_info->get_geotag[0];
5488                 *longitude = pc->cb_info->get_geotag[1];
5489                 *altitude = pc->cb_info->get_geotag[2];
5490         }
5491
5492         CAM_LOG_INFO("ret : 0x%x", ret);
5493
5494         return ret;
5495 }
5496
5497
5498 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
5499 {
5500         int ret = CAMERA_ERROR_NONE;
5501         camera_cli_s *pc = (camera_cli_s *)camera;
5502         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
5503
5504         if (!pc || !pc->cb_info || !mode) {
5505                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5506                 return CAMERA_ERROR_INVALID_PARAMETER;
5507         }
5508
5509         CAM_LOG_INFO("Enter");
5510
5511         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5512
5513         if (ret == CAMERA_ERROR_NONE)
5514                 *mode = (camera_attr_flash_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_MODE];
5515
5516         CAM_LOG_INFO("ret : 0x%x", ret);
5517
5518         return ret;
5519 }
5520
5521
5522 int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state)
5523 {
5524         int ret = CAMERA_ERROR_NONE;
5525         int get_flash_state = 0;
5526
5527         if (!state) {
5528                 CAM_LOG_ERROR("NULL pointer");
5529                 return CAMERA_ERROR_INVALID_PARAMETER;
5530         }
5531
5532         ret = _camera_independent_request(MUSE_CAMERA_API_GET_FLASH_STATE,
5533                 (int)device, "get_flash_state", &get_flash_state);
5534
5535         if (ret == CAMERA_ERROR_NONE) {
5536                 *state = (camera_flash_state_e)get_flash_state;
5537                 CAM_LOG_INFO("flash state %d", *state);
5538         } else {
5539                 CAM_LOG_ERROR("failed 0x%x", ret);
5540         }
5541
5542         return ret;
5543 }
5544
5545
5546 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
5547 {
5548         int ret = CAMERA_ERROR_NONE;
5549         camera_cli_s *pc = (camera_cli_s *)camera;
5550         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
5551
5552         if (!pc || !pc->cb_info || !foreach_cb) {
5553                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5554                 return CAMERA_ERROR_INVALID_PARAMETER;
5555         }
5556
5557         CAM_LOG_INFO("Enter");
5558
5559         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = foreach_cb;
5560         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = user_data;
5561
5562         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5563
5564         CAM_LOG_INFO("ret : 0x%x", ret);
5565
5566         return ret;
5567 }
5568
5569
5570 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
5571 {
5572         int ret = CAMERA_ERROR_NONE;
5573         camera_cli_s *pc = (camera_cli_s *)camera;
5574         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
5575
5576         if (!pc || !pc->cb_info || !foreach_cb) {
5577                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5578                 return CAMERA_ERROR_INVALID_PARAMETER;
5579         }
5580
5581         CAM_LOG_INFO("Enter");
5582
5583         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = foreach_cb;
5584         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = user_data;
5585
5586         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5587
5588         CAM_LOG_INFO("ret : 0x%x", ret);
5589
5590         return ret;
5591 }
5592
5593
5594 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
5595 {
5596         int ret = CAMERA_ERROR_NONE;
5597         camera_cli_s *pc = (camera_cli_s *)camera;
5598         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
5599
5600         if (!pc || !pc->cb_info || !foreach_cb) {
5601                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5602                 return CAMERA_ERROR_INVALID_PARAMETER;
5603         }
5604
5605         CAM_LOG_INFO("Enter");
5606
5607         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = foreach_cb;
5608         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = user_data;
5609
5610         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5611
5612         CAM_LOG_INFO("ret : 0x%x", ret);
5613
5614         return ret;
5615 }
5616
5617
5618 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
5619 {
5620         int ret = CAMERA_ERROR_NONE;
5621         camera_cli_s *pc = (camera_cli_s *)camera;
5622         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
5623
5624         if (!pc || !pc->cb_info || !foreach_cb) {
5625                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5626                 return CAMERA_ERROR_INVALID_PARAMETER;
5627         }
5628
5629         CAM_LOG_INFO("Enter");
5630
5631         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = foreach_cb;
5632         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = user_data;
5633
5634         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5635
5636         CAM_LOG_INFO("ret : 0x%x", ret);
5637
5638         return ret;
5639 }
5640
5641
5642 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
5643 {
5644         int ret = CAMERA_ERROR_NONE;
5645         camera_cli_s *pc = (camera_cli_s *)camera;
5646         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
5647
5648         if (!pc || !pc->cb_info || !foreach_cb) {
5649                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5650                 return CAMERA_ERROR_INVALID_PARAMETER;
5651         }
5652
5653         CAM_LOG_INFO("Enter");
5654
5655         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = foreach_cb;
5656         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = user_data;
5657
5658         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5659
5660         CAM_LOG_INFO("ret : 0x%x", ret);
5661
5662         return ret;
5663 }
5664
5665
5666 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
5667 {
5668         int ret = CAMERA_ERROR_NONE;
5669         camera_cli_s *pc = (camera_cli_s *)camera;
5670         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
5671
5672         if (!pc || !pc->cb_info || !foreach_cb) {
5673                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5674                 return CAMERA_ERROR_INVALID_PARAMETER;
5675         }
5676
5677         CAM_LOG_INFO("Enter");
5678
5679         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = foreach_cb;
5680         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = user_data;
5681
5682         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5683
5684         CAM_LOG_INFO("ret : 0x%x", ret);
5685
5686         return ret;
5687 }
5688
5689
5690 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
5691 {
5692         int ret = CAMERA_ERROR_NONE;
5693         camera_cli_s *pc = (camera_cli_s *)camera;
5694         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
5695
5696         if (!pc || !pc->cb_info || !foreach_cb) {
5697                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5698                 return CAMERA_ERROR_INVALID_PARAMETER;
5699         }
5700
5701         CAM_LOG_INFO("Enter");
5702
5703         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = foreach_cb;
5704         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = user_data;
5705
5706         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5707
5708         CAM_LOG_INFO("ret : 0x%x", ret);
5709
5710         return ret;
5711 }
5712
5713
5714 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5715 {
5716         int ret = CAMERA_ERROR_NONE;
5717         camera_cli_s *pc = (camera_cli_s *)camera;
5718         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
5719
5720         if (!pc || !pc->cb_info || !foreach_cb) {
5721                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5722                 return CAMERA_ERROR_INVALID_PARAMETER;
5723         }
5724
5725         CAM_LOG_INFO("Enter");
5726
5727         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = foreach_cb;
5728         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = user_data;
5729
5730         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5731
5732         CAM_LOG_INFO("Enter, handle :%td", pc->remote_handle);
5733
5734         return ret;
5735 }
5736
5737
5738 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)
5739 {
5740         int ret = CAMERA_ERROR_NONE;
5741         camera_cli_s *pc = (camera_cli_s *)camera;
5742         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
5743         camera_msg_param param;
5744         int value = 0;
5745
5746         if (!pc || !pc->cb_info || !foreach_cb) {
5747                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5748                 return CAMERA_ERROR_INVALID_PARAMETER;
5749         }
5750
5751         CAM_LOG_INFO("Enter");
5752
5753         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = foreach_cb;
5754         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = user_data;
5755
5756         value = (width << 16) | height;
5757         CAMERA_MSG_PARAM_SET(param, INT, value);
5758
5759         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5760
5761         CAM_LOG_INFO("ret : 0x%x", ret);
5762
5763         return ret;
5764 }
5765
5766
5767 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
5768 {
5769         int ret = CAMERA_ERROR_NONE;
5770         camera_cli_s *pc = (camera_cli_s *)camera;
5771         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
5772
5773         if (!pc || !pc->cb_info || !foreach_cb) {
5774                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5775                 return CAMERA_ERROR_INVALID_PARAMETER;
5776         }
5777
5778         CAM_LOG_INFO("Enter");
5779
5780         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = foreach_cb;
5781         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = user_data;
5782
5783         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5784
5785         CAM_LOG_INFO("ret : 0x%x", ret);
5786
5787         return ret;
5788 }
5789
5790
5791 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
5792 {
5793         int ret = CAMERA_ERROR_NONE;
5794         camera_cli_s *pc = (camera_cli_s *)camera;
5795         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
5796
5797         if (!pc || !pc->cb_info || !foreach_cb) {
5798                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
5799                 return CAMERA_ERROR_INVALID_PARAMETER;
5800         }
5801
5802         CAM_LOG_INFO("Enter");
5803
5804         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = foreach_cb;
5805         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = user_data;
5806
5807         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5808
5809         CAM_LOG_INFO("ret : 0x%x", ret);
5810
5811         return ret;
5812 }
5813
5814
5815 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
5816 {
5817         int ret = CAMERA_ERROR_NONE;
5818         camera_cli_s *pc = (camera_cli_s *)camera;
5819         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
5820         camera_msg_param param;
5821         int set_rotation = (int)rotation;
5822
5823         if (!pc || !pc->cb_info) {
5824                 CAM_LOG_ERROR("NULL handle");
5825                 return CAMERA_ERROR_INVALID_PARAMETER;
5826         }
5827
5828         CAM_LOG_INFO("Enter");
5829
5830         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
5831
5832         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5833
5834         CAM_LOG_INFO("ret : 0x%x", ret);
5835
5836         return ret;
5837 }
5838
5839
5840 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
5841 {
5842         int ret = CAMERA_ERROR_NONE;
5843         camera_cli_s *pc = (camera_cli_s *)camera;
5844         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
5845
5846         if (!pc || !pc->cb_info || !rotation) {
5847                 CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
5848                 return CAMERA_ERROR_INVALID_PARAMETER;
5849         }
5850
5851         CAM_LOG_INFO("Enter");
5852
5853         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5854
5855         if (ret == CAMERA_ERROR_NONE)
5856                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_ROTATION];
5857
5858         CAM_LOG_INFO("ret : 0x%x", ret);
5859
5860         return ret;
5861 }
5862
5863
5864 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
5865 {
5866         int ret = CAMERA_ERROR_NONE;
5867         camera_cli_s *pc = (camera_cli_s *)camera;
5868         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
5869         camera_msg_param param;
5870         int set_flip = (int)flip;
5871
5872         if (!pc || !pc->cb_info) {
5873                 CAM_LOG_ERROR("NULL handle");
5874                 return CAMERA_ERROR_INVALID_PARAMETER;
5875         }
5876
5877         CAM_LOG_INFO("Enter");
5878
5879         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
5880
5881         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5882
5883         CAM_LOG_INFO("ret : 0x%x", ret);
5884
5885         return ret;
5886 }
5887
5888
5889 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
5890 {
5891         int ret = CAMERA_ERROR_NONE;
5892         camera_cli_s *pc = (camera_cli_s *)camera;
5893         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
5894
5895         if (!pc || !pc->cb_info || !flip) {
5896                 CAM_LOG_ERROR("NULL pointer %p %p", pc, flip);
5897                 return CAMERA_ERROR_INVALID_PARAMETER;
5898         }
5899
5900         CAM_LOG_INFO("Enter");
5901
5902         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5903
5904         if (ret == CAMERA_ERROR_NONE)
5905                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_FLIP];
5906
5907         CAM_LOG_INFO("ret : 0x%x", ret);
5908
5909         return ret;
5910 }
5911
5912 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
5913 {
5914         int ret = CAMERA_ERROR_NONE;
5915         camera_cli_s *pc = (camera_cli_s *)camera;
5916         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_MODE;
5917         camera_msg_param param;
5918         int set_mode = (int)mode;
5919
5920         if (!pc || !pc->cb_info) {
5921                 CAM_LOG_ERROR("NULL handle");
5922                 return CAMERA_ERROR_INVALID_PARAMETER;
5923         }
5924
5925         CAM_LOG_INFO("Enter");
5926
5927         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
5928
5929         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5930
5931         CAM_LOG_INFO("ret : 0x%x", ret);
5932
5933         return ret;
5934 }
5935
5936
5937 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
5938 {
5939         int ret = CAMERA_ERROR_NONE;
5940         camera_cli_s *pc = (camera_cli_s *)camera;
5941         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
5942
5943         if (!pc || !pc->cb_info || !mode) {
5944                 CAM_LOG_ERROR("NULL pointer %p %p", pc, mode);
5945                 return CAMERA_ERROR_INVALID_PARAMETER;
5946         }
5947
5948         CAM_LOG_INFO("Enter");
5949
5950         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5951
5952         if (ret == CAMERA_ERROR_NONE)
5953                 *mode = (camera_attr_hdr_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HDR_MODE];
5954
5955         CAM_LOG_INFO("ret : 0x%x", ret);
5956
5957         return ret;
5958 }
5959
5960
5961 bool camera_attr_is_supported_hdr_capture(camera_h camera)
5962 {
5963         int ret = CAMERA_ERROR_NONE;
5964         camera_cli_s *pc = (camera_cli_s *)camera;
5965         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE;
5966
5967         if (!pc || !pc->cb_info) {
5968                 CAM_LOG_ERROR("NULL handle");
5969                 return CAMERA_ERROR_INVALID_PARAMETER;
5970         }
5971
5972         CAM_LOG_INFO("Enter");
5973
5974         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5975
5976         if (ret < 0) {
5977                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
5978                 ret = false;
5979         }
5980
5981         CAM_LOG_INFO("ret : %d", ret);
5982
5983         return (bool)ret;
5984 }
5985
5986
5987 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
5988 {
5989         int ret = CAMERA_ERROR_NONE;
5990         camera_cli_s *pc = (camera_cli_s *)camera;
5991         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
5992
5993         if (!pc || !pc->cb_info) {
5994                 CAM_LOG_ERROR("NULL handle");
5995                 return CAMERA_ERROR_INVALID_PARAMETER;
5996         }
5997
5998         CAM_LOG_INFO("Enter");
5999
6000         if (!camera_attr_is_supported_hdr_capture(camera)) {
6001                 CAM_LOG_ERROR("HDR not supported");
6002                 return CAMERA_ERROR_NOT_SUPPORTED;
6003         }
6004
6005         if (!callback) {
6006                 CAM_LOG_ERROR("NULL callback");
6007                 return CAMERA_ERROR_INVALID_PARAMETER;
6008         }
6009
6010         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6011
6012         if (ret == CAMERA_ERROR_NONE) {
6013                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6014
6015                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
6016                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
6017
6018                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6019         }
6020
6021         CAM_LOG_INFO("ret : 0x%x", ret);
6022
6023         return ret;
6024 }
6025
6026
6027 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
6028 {
6029         int ret = CAMERA_ERROR_NONE;
6030         camera_cli_s *pc = (camera_cli_s *)camera;
6031         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
6032
6033         if (!pc || !pc->cb_info) {
6034                 CAM_LOG_ERROR("NULL handle");
6035                 return CAMERA_ERROR_INVALID_PARAMETER;
6036         }
6037
6038         CAM_LOG_INFO("Enter");
6039
6040         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6041
6042         if (ret == CAMERA_ERROR_NONE) {
6043                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6044
6045                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
6046                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
6047
6048                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6049         }
6050
6051         CAM_LOG_INFO("ret : 0x%x", ret);
6052
6053         return ret;
6054 }
6055
6056
6057 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
6058 {
6059         int ret = CAMERA_ERROR_NONE;
6060         camera_cli_s *pc = (camera_cli_s *)camera;
6061         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE;
6062         camera_msg_param param;
6063         int set_enable = (int)enable;
6064
6065         if (!pc || !pc->cb_info) {
6066                 CAM_LOG_ERROR("NULL handle");
6067                 return CAMERA_ERROR_INVALID_PARAMETER;
6068         }
6069
6070         CAM_LOG_INFO("Enter");
6071
6072         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6073
6074         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6075
6076         CAM_LOG_INFO("ret : 0x%x", ret);
6077
6078         return ret;
6079 }
6080
6081
6082 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
6083 {
6084         int ret = CAMERA_ERROR_NONE;
6085         camera_cli_s *pc = (camera_cli_s *)camera;
6086         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
6087
6088         if (!pc || !pc->cb_info || !enabled) {
6089                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
6090                 return CAMERA_ERROR_INVALID_PARAMETER;
6091         }
6092
6093         CAM_LOG_INFO("Enter");
6094
6095         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6096
6097         if (ret == CAMERA_ERROR_NONE)
6098                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE];
6099
6100         CAM_LOG_INFO("ret : 0x%x", ret);
6101
6102         return ret;
6103 }
6104
6105
6106 bool camera_attr_is_supported_anti_shake(camera_h camera)
6107 {
6108         int ret = CAMERA_ERROR_NONE;
6109         camera_cli_s *pc = (camera_cli_s *)camera;
6110         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE;
6111
6112         if (!pc || !pc->cb_info) {
6113                 CAM_LOG_ERROR("NULL handle");
6114                 return CAMERA_ERROR_INVALID_PARAMETER;
6115         }
6116
6117         CAM_LOG_INFO("Enter");
6118
6119         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6120
6121         if (ret < 0) {
6122                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
6123                 ret = false;
6124         }
6125
6126         CAM_LOG_INFO("ret : %d", ret);
6127
6128         return (bool)ret;
6129 }
6130
6131
6132 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
6133 {
6134         int ret = CAMERA_ERROR_NONE;
6135         camera_cli_s *pc = (camera_cli_s *)camera;
6136         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION;
6137         camera_msg_param param;
6138         int set_enable = (int)enable;
6139
6140         if (!pc || !pc->cb_info) {
6141                 CAM_LOG_ERROR("NULL handle");
6142                 return CAMERA_ERROR_INVALID_PARAMETER;
6143         }
6144
6145         CAM_LOG_INFO("Enter");
6146
6147         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6148
6149         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6150
6151         CAM_LOG_INFO("ret : 0x%x", ret);
6152
6153         return ret;
6154 }
6155
6156
6157 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
6158 {
6159         int ret = CAMERA_ERROR_NONE;
6160         camera_cli_s *pc = (camera_cli_s *)camera;
6161         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
6162
6163         if (!pc || !pc->cb_info || !enabled) {
6164                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
6165                 return CAMERA_ERROR_INVALID_PARAMETER;
6166         }
6167
6168         CAM_LOG_INFO("Enter");
6169
6170         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6171
6172         if (ret == CAMERA_ERROR_NONE)
6173                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION];
6174
6175         CAM_LOG_INFO("ret : 0x%x", ret);
6176
6177         return ret;
6178 }
6179
6180
6181 bool camera_attr_is_supported_video_stabilization(camera_h camera)
6182 {
6183         int ret = CAMERA_ERROR_NONE;
6184         camera_cli_s *pc = (camera_cli_s *)camera;
6185         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION;
6186
6187         if (!pc || !pc->cb_info) {
6188                 CAM_LOG_ERROR("NULL handle");
6189                 return CAMERA_ERROR_INVALID_PARAMETER;
6190         }
6191
6192         CAM_LOG_INFO("Enter");
6193
6194         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6195
6196         if (ret < 0) {
6197                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
6198                 ret = false;
6199         }
6200
6201         CAM_LOG_INFO("ret : %d", ret);
6202
6203         return (bool)ret;
6204 }
6205
6206
6207 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
6208 {
6209         int ret = CAMERA_ERROR_NONE;
6210         camera_cli_s *pc = (camera_cli_s *)camera;
6211         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST;
6212         camera_msg_param param;
6213         int set_enable = (int)enable;
6214
6215         if (!pc || !pc->cb_info) {
6216                 CAM_LOG_ERROR("NULL handle");
6217                 return CAMERA_ERROR_INVALID_PARAMETER;
6218         }
6219
6220         CAM_LOG_INFO("Enter");
6221
6222         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6223
6224         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6225
6226         CAM_LOG_INFO("ret : 0x%x", ret);
6227
6228         return ret;
6229 }
6230
6231
6232 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
6233 {
6234         int ret = CAMERA_ERROR_NONE;
6235         camera_cli_s *pc = (camera_cli_s *)camera;
6236         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
6237
6238         if (!pc || !pc->cb_info || !enabled) {
6239                 CAM_LOG_ERROR("NULL pointer %p %p", pc, enabled);
6240                 return CAMERA_ERROR_INVALID_PARAMETER;
6241         }
6242
6243         CAM_LOG_INFO("Enter");
6244
6245         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6246
6247         if (ret == CAMERA_ERROR_NONE)
6248                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST];
6249
6250         CAM_LOG_INFO("ret : 0x%x", ret);
6251
6252         return ret;
6253 }
6254
6255
6256 bool camera_attr_is_supported_auto_contrast(camera_h camera)
6257 {
6258         int ret = CAMERA_ERROR_NONE;
6259         camera_cli_s *pc = (camera_cli_s *)camera;
6260         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST;
6261
6262         if (!pc || !pc->cb_info) {
6263                 CAM_LOG_ERROR("NULL handle");
6264                 return CAMERA_ERROR_INVALID_PARAMETER;
6265         }
6266
6267         CAM_LOG_INFO("Enter");
6268
6269         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6270
6271         if (ret < 0) {
6272                 CAM_LOG_ERROR("error is occurred 0x%x", ret);
6273                 ret = false;
6274         }
6275
6276         CAM_LOG_INFO("ret : %d", ret);
6277
6278         return (bool)ret;
6279 }
6280
6281
6282 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
6283 {
6284         int ret = CAMERA_ERROR_NONE;
6285         camera_cli_s *pc = (camera_cli_s *)camera;
6286         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
6287         camera_msg_param param;
6288         int set_disable = (int)disable;
6289
6290         if (!pc || !pc->cb_info) {
6291                 CAM_LOG_ERROR("NULL handle");
6292                 return CAMERA_ERROR_INVALID_PARAMETER;
6293         }
6294
6295         CAM_LOG_INFO("Enter");
6296
6297         CAMERA_MSG_PARAM_SET(param, INT, set_disable);
6298
6299         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6300
6301         CAM_LOG_INFO("ret : 0x%x", ret);
6302
6303         return ret;
6304 }
6305
6306
6307 int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type, int pan_step)
6308 {
6309         int ret = CAMERA_ERROR_NONE;
6310         camera_cli_s *pc = (camera_cli_s *)camera;
6311         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
6312         camera_msg_param param0;
6313         camera_msg_param param1;
6314
6315         if (!pc || !pc->cb_info) {
6316                 CAM_LOG_ERROR("NULL handle");
6317                 return CAMERA_ERROR_INVALID_PARAMETER;
6318         }
6319
6320         CAM_LOG_INFO("Enter");
6321
6322         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6323         CAMERA_MSG_PARAM_SET(param1, INT, pan_step);
6324
6325         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6326                 &param0, &param1, CAMERA_CB_TIMEOUT);
6327
6328         CAM_LOG_INFO("ret : 0x%x", ret);
6329
6330         return ret;
6331 }
6332
6333
6334 int camera_attr_get_pan(camera_h camera, int *pan_step)
6335 {
6336         int ret = CAMERA_ERROR_NONE;
6337         camera_cli_s *pc = (camera_cli_s *)camera;
6338         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
6339
6340         if (!pc || !pc->cb_info || !pan_step) {
6341                 CAM_LOG_ERROR("NULL pointer %p %p", pc, pan_step);
6342                 return CAMERA_ERROR_INVALID_PARAMETER;
6343         }
6344
6345         CAM_LOG_INFO("Enter");
6346
6347         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6348
6349         if (ret == CAMERA_ERROR_NONE)
6350                 *pan_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PAN];
6351
6352         CAM_LOG_INFO("ret : 0x%x", ret);
6353
6354         return ret;
6355 }
6356
6357
6358 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
6359 {
6360         int ret = CAMERA_ERROR_NONE;
6361         camera_cli_s *pc = (camera_cli_s *)camera;
6362         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
6363
6364         if (!pc || !pc->cb_info || !min || !max) {
6365                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
6366                 return CAMERA_ERROR_INVALID_PARAMETER;
6367         }
6368
6369         CAM_LOG_INFO("Enter");
6370
6371         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6372
6373         if (ret == CAMERA_ERROR_NONE) {
6374                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
6375                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
6376         }
6377
6378         CAM_LOG_INFO("ret : 0x%x", ret);
6379
6380         return ret;
6381 }
6382
6383
6384 int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type, int tilt_step)
6385 {
6386         int ret = CAMERA_ERROR_NONE;
6387         camera_cli_s *pc = (camera_cli_s *)camera;
6388         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
6389         camera_msg_param param0;
6390         camera_msg_param param1;
6391
6392         if (!pc || !pc->cb_info) {
6393                 CAM_LOG_ERROR("NULL handle");
6394                 return CAMERA_ERROR_INVALID_PARAMETER;
6395         }
6396
6397         CAM_LOG_INFO("Enter");
6398
6399         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6400         CAMERA_MSG_PARAM_SET(param1, INT, tilt_step);
6401
6402         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6403                 &param0, &param1, CAMERA_CB_TIMEOUT);
6404
6405         CAM_LOG_INFO("ret : 0x%x", ret);
6406
6407         return ret;
6408 }
6409
6410
6411 int camera_attr_get_tilt(camera_h camera, int *tilt_step)
6412 {
6413         int ret = CAMERA_ERROR_NONE;
6414         camera_cli_s *pc = (camera_cli_s *)camera;
6415         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
6416
6417         if (!pc || !pc->cb_info || !tilt_step) {
6418                 CAM_LOG_ERROR("NULL pointer %p %p", pc, tilt_step);
6419                 return CAMERA_ERROR_INVALID_PARAMETER;
6420         }
6421
6422         CAM_LOG_INFO("Enter");
6423
6424         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6425
6426         if (ret == CAMERA_ERROR_NONE)
6427                 *tilt_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TILT];
6428
6429         CAM_LOG_INFO("ret : 0x%x", ret);
6430
6431         return ret;
6432 }
6433
6434
6435 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
6436 {
6437         int ret = CAMERA_ERROR_NONE;
6438         camera_cli_s *pc = (camera_cli_s *)camera;
6439         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
6440
6441         if (!pc || !pc->cb_info || !min || !max) {
6442                 CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
6443                 return CAMERA_ERROR_INVALID_PARAMETER;
6444         }
6445
6446         CAM_LOG_INFO("Enter");
6447
6448         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6449
6450         if (ret == CAMERA_ERROR_NONE) {
6451                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
6452                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
6453         }
6454
6455         CAM_LOG_INFO("ret : 0x%x", ret);
6456
6457         return ret;
6458 }
6459
6460
6461 int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
6462 {
6463         int ret = CAMERA_ERROR_NONE;
6464         camera_cli_s *pc = (camera_cli_s *)camera;
6465         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
6466         camera_msg_param param;
6467         int set_ptz_type = (int)ptz_type;
6468
6469         if (!pc || !pc->cb_info) {
6470                 CAM_LOG_ERROR("NULL handle");
6471                 return CAMERA_ERROR_INVALID_PARAMETER;
6472         }
6473
6474         CAM_LOG_INFO("Enter");
6475
6476         CAMERA_MSG_PARAM_SET(param, INT, set_ptz_type);
6477
6478         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6479
6480         CAM_LOG_INFO("ret : 0x%x", ret);
6481
6482         return ret;
6483 }
6484
6485
6486 int camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data)
6487 {
6488         int ret = CAMERA_ERROR_NONE;
6489         camera_cli_s *pc = (camera_cli_s *)camera;
6490         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
6491
6492         if (!pc || !pc->cb_info || !foreach_cb) {
6493                 CAM_LOG_ERROR("NULL pointer %p %p", pc, foreach_cb);
6494                 return CAMERA_ERROR_INVALID_PARAMETER;
6495         }
6496
6497         CAM_LOG_INFO("Enter");
6498
6499         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = foreach_cb;
6500         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = user_data;
6501
6502         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6503
6504         CAM_LOG_INFO("ret : 0x%x", ret);
6505
6506         return ret;
6507 }
6508
6509
6510 int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, int height)
6511 {
6512         int ret = CAMERA_ERROR_NONE;
6513         camera_cli_s *pc = (camera_cli_s *)camera;
6514         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
6515         int set_display_roi_area[4] = {x, y, width, height};
6516         char *msg = NULL;
6517         int length = 0;
6518         int send_ret = 0;
6519
6520         if (!pc || !pc->cb_info) {
6521                 CAM_LOG_ERROR("NULL handle");
6522                 return CAMERA_ERROR_INVALID_PARAMETER;
6523         }
6524
6525         CAM_LOG_INFO("Enter");
6526
6527         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
6528                 ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
6529                 if (ret != MM_ERROR_NONE) {
6530                         CAM_LOG_ERROR("mm_evas_renderer_set_roi_area error 0x%x", ret);
6531                         return CAMERA_ERROR_INVALID_OPERATION;
6532                 }
6533         }
6534
6535         length = sizeof(set_display_roi_area) / sizeof(int) + \
6536                 (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
6537
6538         msg = muse_core_msg_new(api,
6539                 MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
6540                 NULL);
6541         if (!msg) {
6542                 CAM_LOG_ERROR("msg creation failed: api %d", api);
6543                 return CAMERA_ERROR_OUT_OF_MEMORY;
6544         }
6545
6546         if (pc->cb_info->is_server_connected) {
6547                 __camera_update_api_waiting(pc->cb_info, api, 1);
6548
6549                 g_mutex_lock(&pc->cb_info->fd_lock);
6550                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
6551                 g_mutex_unlock(&pc->cb_info->fd_lock);
6552         }
6553
6554         if (send_ret < 0) {
6555                 CAM_LOG_ERROR("message send failed");
6556                 ret = CAMERA_ERROR_INVALID_OPERATION;
6557         } else {
6558                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
6559         }
6560
6561         __camera_update_api_waiting(pc->cb_info, api, -1);
6562
6563         muse_core_msg_free(msg);
6564
6565         CAM_LOG_INFO("ret : 0x%x", ret);
6566
6567         return ret;
6568 }
6569
6570
6571 int camera_attr_get_display_roi_area(camera_h camera, int *x, int *y, int *width, int *height)
6572 {
6573         camera_cli_s *pc = (camera_cli_s *)camera;
6574         int ret = CAMERA_ERROR_NONE;
6575         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
6576
6577         if (!pc || !pc->cb_info || !x || !y || !width || !height) {
6578                 CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, x, y, width, height);
6579                 return CAMERA_ERROR_INVALID_PARAMETER;
6580         }
6581
6582         CAM_LOG_INFO("Enter");
6583
6584         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6585
6586         if (ret == CAMERA_ERROR_NONE) {
6587                 *x = pc->cb_info->get_display_roi_area[0];
6588                 *y = pc->cb_info->get_display_roi_area[1];
6589                 *width = pc->cb_info->get_display_roi_area[2];
6590                 *height = pc->cb_info->get_display_roi_area[3];
6591         }
6592
6593         CAM_LOG_INFO("ret : 0x%x", ret);
6594
6595         return ret;
6596 }
6597
6598
6599 int camera_get_device_state(camera_device_e device, camera_device_state_e *state)
6600 {
6601         int ret = CAMERA_ERROR_NONE;
6602         int get_device_state = 0;
6603
6604         if (!state) {
6605                 CAM_LOG_ERROR("NULL pointer");
6606                 return CAMERA_ERROR_INVALID_PARAMETER;
6607         }
6608
6609         ret = _camera_independent_request(MUSE_CAMERA_API_GET_DEVICE_STATE,
6610                 (int)device, "get_device_state", &get_device_state);
6611
6612         if (ret == CAMERA_ERROR_NONE) {
6613                 *state = (camera_device_state_e)get_device_state;
6614                 CAM_LOG_INFO("device state %d", *state);
6615         } else {
6616                 CAM_LOG_ERROR("failed 0x%x", ret);
6617         }
6618
6619         return ret;
6620 }
6621
6622
6623 int camera_add_device_state_changed_cb(camera_device_state_changed_cb callback, void *user_data, int *cb_id)
6624 {
6625         int ret = CAMERA_ERROR_NONE;
6626         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6627         camera_cb_info *info = NULL;
6628
6629         if (!callback || !cb_id) {
6630                 CAM_LOG_ERROR("invalid pointer %p %p", callback, cb_id);
6631                 return CAMERA_ERROR_INVALID_PARAMETER;
6632         }
6633
6634         /* check camera support */
6635         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6636         if (ret != CAMERA_ERROR_NONE) {
6637                 CAM_LOG_ERROR("get device state failed");
6638                 return ret;
6639         }
6640
6641         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6642
6643         info = g_new0(camera_cb_info, 1);
6644         if (!info) {
6645                 CAM_LOG_ERROR("info failed");
6646                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
6647                 goto _DONE;
6648         }
6649
6650         info->id = ++g_cam_dev_state_changed_cb_id;
6651         info->callback = (void *)callback;
6652         info->user_data = user_data;
6653
6654         *cb_id = info->id;
6655
6656         /* subscribe dbus signal for camera state change */
6657         if (!g_cam_dev_state_changed_cb_conn) {
6658                 g_cam_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
6659                 if (!g_cam_dev_state_changed_cb_conn) {
6660                         CAM_LOG_ERROR("failed to get gdbus connection");
6661                         ret = CAMERA_ERROR_INVALID_OPERATION;
6662                         goto _DONE;
6663                 }
6664
6665                 CAM_LOG_INFO("subscribe signal %s - %s - %s",
6666                         MM_CAMCORDER_DBUS_OBJECT,
6667                         MM_CAMCORDER_DBUS_INTERFACE_CAMERA,
6668                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
6669
6670                 g_cam_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_cam_dev_state_changed_cb_conn,
6671                         NULL, MM_CAMCORDER_DBUS_INTERFACE_CAMERA, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
6672                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__camera_device_state_changed_cb, NULL, NULL);
6673                 if (!g_cam_dev_state_changed_cb_subscribe_id) {
6674                         CAM_LOG_ERROR("failed to get gdbus connection");
6675                         ret = CAMERA_ERROR_INVALID_OPERATION;
6676                         goto _DONE;
6677                 }
6678
6679                 CAM_LOG_INFO("signal subscribe id %u", g_cam_dev_state_changed_cb_subscribe_id);
6680         }
6681
6682         g_cam_dev_state_changed_cb_list = g_list_prepend(g_cam_dev_state_changed_cb_list, (gpointer)info);
6683
6684         CAM_LOG_INFO("callback id %d", info->id);
6685
6686 _DONE:
6687         if (ret != CAMERA_ERROR_NONE) {
6688                 if (info) {
6689                         g_free(info);
6690                         info = NULL;
6691                 }
6692
6693                 if (g_cam_dev_state_changed_cb_conn) {
6694                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6695                         g_cam_dev_state_changed_cb_conn = NULL;
6696                 }
6697         }
6698
6699         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6700
6701         return ret;
6702 }
6703
6704
6705 int camera_remove_device_state_changed_cb(int cb_id)
6706 {
6707         int ret = CAMERA_ERROR_NONE;
6708         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6709         GList *tmp_list = NULL;
6710         camera_cb_info *info = NULL;
6711
6712         /* check camera support */
6713         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6714         if (ret != CAMERA_ERROR_NONE) {
6715                 CAM_LOG_ERROR("get device state failed");
6716                 return ret;
6717         }
6718
6719         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6720
6721         if (!g_cam_dev_state_changed_cb_list) {
6722                 CAM_LOG_ERROR("there is no callback info");
6723                 ret = CAMERA_ERROR_INVALID_OPERATION;
6724                 goto _DONE;
6725         }
6726
6727         tmp_list = g_cam_dev_state_changed_cb_list;
6728
6729         do {
6730                 info = tmp_list->data;
6731                 tmp_list = tmp_list->next;
6732
6733                 if (!info) {
6734                         CAM_LOG_WARNING("NULL info");
6735                         continue;
6736                 }
6737
6738                 if (info->id == cb_id) {
6739                         g_cam_dev_state_changed_cb_list = g_list_remove(g_cam_dev_state_changed_cb_list, info);
6740
6741                         g_free(info);
6742                         info = NULL;
6743
6744                         if (!g_cam_dev_state_changed_cb_list) {
6745                                 /* no remained callback */
6746                                 if (g_cam_dev_state_changed_cb_conn) {
6747                                         /* unsubscribe signal */
6748                                         g_dbus_connection_signal_unsubscribe(g_cam_dev_state_changed_cb_conn, g_cam_dev_state_changed_cb_subscribe_id);
6749                                         g_cam_dev_state_changed_cb_subscribe_id = 0;
6750
6751                                         /* unref connection */
6752                                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6753                                         g_cam_dev_state_changed_cb_conn = NULL;
6754                                 }
6755                         }
6756
6757                         CAM_LOG_INFO("id %d callback removed", cb_id);
6758                         ret = CAMERA_ERROR_NONE;
6759
6760                         goto _DONE;
6761                 }
6762         } while (tmp_list);
6763
6764         CAM_LOG_ERROR("id %d callback not found", cb_id);
6765         ret = CAMERA_ERROR_INVALID_PARAMETER;
6766
6767 _DONE:
6768         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6769
6770         return ret;
6771 }