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