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