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