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