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