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