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