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