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