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