Support user buffer fd
[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 void *_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 void *_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->fd < 0) {
2062                         LOGE("fd is closed in client side");
2063                         goto CB_HANDLER_EXIT;
2064                 }
2065
2066                 /* send error msg for server disconnection */
2067                 error_msg = muse_core_msg_new(MUSE_CAMERA_CB_EVENT,
2068                         MUSE_TYPE_INT, "error", CAMERA_ERROR_SERVICE_DISCONNECTED,
2069                         MUSE_TYPE_INT, "current_state", CAMERA_STATE_NONE,
2070                         NULL);
2071
2072                 if (!error_msg) {
2073                         LOGE("error_msg failed");
2074                         goto CB_HANDLER_EXIT;
2075                 }
2076
2077                 __camera_add_msg_to_queue(cb_info,
2078                         MUSE_CAMERA_CB_EVENT,
2079                         MUSE_CAMERA_EVENT_TYPE_ERROR,
2080                         MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
2081                         error_msg,
2082                         NULL);
2083
2084                 muse_core_msg_free(error_msg);
2085                 error_msg = NULL;
2086
2087                 LOGE("add error msg for service disconnection done");
2088         }
2089
2090 CB_HANDLER_EXIT:
2091         return NULL;
2092 }
2093
2094
2095 static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
2096         int type, const char *thread_name, camera_cb_info_s *cb_info)
2097 {
2098         if (!handler_info || !thread_name || !cb_info) {
2099                 LOGE("t:%d NULL %p %p %p",
2100                         type, handler_info, thread_name, cb_info);
2101                 return false;
2102         }
2103
2104         LOGD("t:%d", type);
2105
2106         handler_info->type = type;
2107         handler_info->queue = g_queue_new();
2108         if (handler_info->queue == NULL) {
2109                 LOGE("t:%d queue failed", type);
2110                 return false;
2111         }
2112
2113         g_mutex_init(&handler_info->mutex);
2114         g_cond_init(&handler_info->cond);
2115
2116         handler_info->cb_info = (void *)cb_info;
2117         g_atomic_int_set(&handler_info->running, 1);
2118
2119         handler_info->thread = g_thread_try_new(thread_name,
2120                 _camera_msg_handler_func, (gpointer)handler_info, NULL);
2121         if (handler_info->thread == NULL) {
2122                 LOGE("t:%d thread failed", type);
2123
2124                 g_mutex_clear(&handler_info->mutex);
2125                 g_cond_clear(&handler_info->cond);
2126                 g_queue_free(handler_info->queue);
2127                 handler_info->queue = NULL;
2128
2129                 return false;
2130         }
2131
2132         LOGD("t:%d done", type);
2133
2134         return true;
2135 }
2136
2137
2138 static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info)
2139 {
2140         int type = 0;
2141
2142         if (!handler_info) {
2143                 LOGE("NULL handler");
2144                 return;
2145         }
2146
2147         if (!handler_info->thread) {
2148                 LOGW("thread is not created");
2149                 return;
2150         }
2151
2152         type = handler_info->type;
2153
2154         LOGD("t:%d thread %p", type, handler_info->thread);
2155
2156         g_mutex_lock(&handler_info->mutex);
2157         g_atomic_int_set(&handler_info->running, 0);
2158         g_cond_signal(&handler_info->cond);
2159         g_mutex_unlock(&handler_info->mutex);
2160
2161         g_thread_join(handler_info->thread);
2162         handler_info->thread = NULL;
2163
2164         g_mutex_clear(&handler_info->mutex);
2165         g_cond_clear(&handler_info->cond);
2166         g_queue_free(handler_info->queue);
2167         handler_info->queue = NULL;
2168
2169         LOGD("t:%d done", type);
2170
2171         return;
2172 }
2173
2174
2175 static camera_cb_info_s *_camera_client_callback_new(gint sockfd)
2176 {
2177         camera_cb_info_s *cb_info = NULL;
2178         gint i = 0;
2179
2180         g_return_val_if_fail(sockfd > 0, NULL);
2181
2182         cb_info = g_new0(camera_cb_info_s, 1);
2183         if (cb_info == NULL) {
2184                 LOGE("cb_info failed");
2185                 goto ErrorExit;
2186         }
2187
2188         cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 1;
2189
2190         for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2191                 g_mutex_init(&cb_info->api_mutex[i]);
2192                 g_cond_init(&cb_info->api_cond[i]);
2193         }
2194
2195         g_mutex_init(&cb_info->fd_lock);
2196         g_mutex_init(&cb_info->mp_data_mutex);
2197
2198         for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2199                 g_mutex_init(&cb_info->user_cb_mutex[i]);
2200
2201         /* message handler thread */
2202         if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
2203                 CAMERA_MESSAGE_HANDLER_TYPE_GENERAL, "camera_msg_handler", cb_info)) {
2204                 LOGE("msg_handler_info failed");
2205                 goto ErrorExit;
2206         }
2207
2208         /* message handler thread for preview callback */
2209         if (!__create_msg_handler_thread(&cb_info->preview_cb_info,
2210                 CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "camera_msg_handler:preview_cb", cb_info)) {
2211                 LOGE("preview_cb_info failed");
2212                 goto ErrorExit;
2213         }
2214
2215         /* message handler thread for capture callback */
2216         if (!__create_msg_handler_thread(&cb_info->capture_cb_info,
2217                 CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB, "camera_msg_handler:capture_cb", cb_info)) {
2218                 LOGE("capture_cb_info failed");
2219                 goto ErrorExit;
2220         }
2221
2222         cb_info->fd = sockfd;
2223         cb_info->preview_cb_flag = 0;
2224
2225         /* message receive thread */
2226         g_atomic_int_set(&cb_info->msg_recv_running, 1);
2227         cb_info->msg_recv_thread = g_thread_try_new("camera_msg_recv",
2228                 _camera_msg_recv_func, (gpointer)cb_info, NULL);
2229         if (cb_info->msg_recv_thread == NULL) {
2230                 LOGE("message receive thread creation failed");
2231                 goto ErrorExit;
2232         }
2233
2234         /* initialize fd */
2235         for (i = 0 ; i < MUSE_NUM_FD ; i++)
2236                 cb_info->fds[i] = -1;
2237
2238         cb_info->is_server_connected = TRUE;
2239
2240         return cb_info;
2241
2242 ErrorExit:
2243         if (cb_info) {
2244                 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
2245                 __destroy_msg_handler_thread(&cb_info->preview_cb_info);
2246                 __destroy_msg_handler_thread(&cb_info->capture_cb_info);
2247
2248                 for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2249                         g_mutex_clear(&cb_info->user_cb_mutex[i]);
2250
2251                 g_mutex_clear(&cb_info->fd_lock);
2252                 g_mutex_clear(&cb_info->mp_data_mutex);
2253
2254                 for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2255                         g_mutex_clear(&cb_info->api_mutex[i]);
2256                         g_cond_clear(&cb_info->api_cond[i]);
2257                 }
2258
2259                 g_free(cb_info);
2260                 cb_info = NULL;
2261         }
2262
2263         return NULL;
2264 }
2265
2266 static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
2267 {
2268         int i = 0;
2269
2270         g_return_if_fail(cb_info != NULL);
2271
2272         LOGD("msg_recv thread[%p] destroy", cb_info->msg_recv_thread);
2273
2274         g_thread_join(cb_info->msg_recv_thread);
2275         cb_info->msg_recv_thread = NULL;
2276
2277         LOGD("msg_recv thread removed");
2278
2279         /* destroy msg handler threads */
2280         __destroy_msg_handler_thread(&cb_info->msg_handler_info);
2281         __destroy_msg_handler_thread(&cb_info->preview_cb_info);
2282         __destroy_msg_handler_thread(&cb_info->capture_cb_info);
2283
2284         for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
2285                 g_mutex_clear(&cb_info->user_cb_mutex[i]);
2286
2287         g_mutex_clear(&cb_info->fd_lock);
2288         g_mutex_clear(&cb_info->mp_data_mutex);
2289
2290         for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
2291                 g_mutex_clear(&cb_info->api_mutex[i]);
2292                 g_cond_clear(&cb_info->api_cond[i]);
2293         }
2294
2295         if (cb_info->fd > -1) {
2296                 muse_client_close(cb_info->fd);
2297                 cb_info->fd = -1;
2298         }
2299
2300         if (cb_info->bufmgr) {
2301                 tbm_bufmgr_deinit(cb_info->bufmgr);
2302                 cb_info->bufmgr = NULL;
2303         }
2304         if (cb_info->pkt_fmt) {
2305                 media_format_unref(cb_info->pkt_fmt);
2306                 cb_info->pkt_fmt = NULL;
2307         }
2308
2309         if (cb_info->dp_interface) {
2310                 mm_display_interface_deinit(cb_info->dp_interface);
2311                 cb_info->dp_interface = NULL;
2312         }
2313
2314         cb_info->preview_cb_flag = 0;
2315
2316         g_free(cb_info);
2317         cb_info = NULL;
2318
2319         return;
2320 }
2321
2322
2323 int _camera_start_evas_rendering(camera_h camera)
2324 {
2325         camera_cli_s *pc = (camera_cli_s *)camera;
2326
2327         if (!pc || !pc->cb_info) {
2328                 LOGE("NULL handle");
2329                 return CAMERA_ERROR_INVALID_PARAMETER;
2330         }
2331
2332         LOGD("start");
2333
2334         if (!CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
2335                 LOGE("EVAS surface is not set");
2336                 return CAMERA_ERROR_NONE;
2337         }
2338
2339         /* set evas render flag as RUN */
2340         pc->cb_info->run_evas_render = true;
2341
2342         return CAMERA_ERROR_NONE;
2343 }
2344
2345
2346 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen)
2347 {
2348         int ret = CAMERA_ERROR_NONE;
2349         camera_cli_s *pc = (camera_cli_s *)camera;
2350
2351         if (!pc || !pc->cb_info) {
2352                 LOGE("NULL handle");
2353                 return CAMERA_ERROR_INVALID_PARAMETER;
2354         }
2355
2356         LOGD("stop - keep screen %d", keep_screen);
2357
2358         if (!CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
2359                 LOGE("EVAS surface is not set");
2360                 return CAMERA_ERROR_NONE;
2361         }
2362
2363         /* set evas render flag as STOP and release buffers */
2364         pc->cb_info->run_evas_render = false;
2365
2366         ret = mm_display_interface_evas_flush(pc->cb_info->dp_interface, keep_screen);
2367         if (ret == MM_ERROR_NONE) {
2368                 ret = CAMERA_ERROR_NONE;
2369         } else {
2370                 LOGE("mm_evas_renderer_retrieve_all_packets failed 0x%x", ret);
2371                 ret = CAMERA_ERROR_INVALID_OPERATION;
2372         }
2373
2374         return ret;
2375 }
2376
2377
2378 int _camera_independent_request(int api, int device_type, const char *key, int *value)
2379 {
2380         int ret = CAMERA_ERROR_NONE;
2381         int sock_fd = -1;
2382         int module_index = -1;
2383         char *msg = NULL;
2384         char recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH] = {'\0',};
2385
2386         /* create muse connection */
2387         if (!key || !value) {
2388                 LOGE("NULL pointer");
2389                 return CAMERA_ERROR_INVALID_PARAMETER;
2390         }
2391
2392         sock_fd = muse_client_new();
2393         if (sock_fd < 0) {
2394                 LOGE("muse_client_new failed");
2395                 return CAMERA_ERROR_INVALID_OPERATION;
2396         }
2397
2398         if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2399                 LOGE("muse client get module index failed");
2400                 ret = CAMERA_ERROR_INVALID_OPERATION;
2401                 goto _REQUEST_EXIT;
2402         }
2403
2404         msg = muse_core_msg_new(api,
2405                 MUSE_TYPE_INT, "module", module_index,
2406                 MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
2407                 0);
2408         if (!msg) {
2409                 LOGE("msg failed");
2410                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2411                 goto _REQUEST_EXIT;
2412         }
2413
2414         ret = muse_core_msg_send(sock_fd, msg);
2415
2416         muse_core_msg_free(msg);
2417         msg = NULL;
2418
2419         if (ret < 0) {
2420                 LOGE("send msg failed");
2421                 ret = CAMERA_ERROR_INVALID_OPERATION;
2422                 goto _REQUEST_EXIT;
2423         }
2424
2425         ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_CAMERA_MSG_MAX_LENGTH);
2426         if (ret <= 0) {
2427                 LOGE("recv msg failed %d", errno);
2428                 ret = CAMERA_ERROR_INVALID_OPERATION;
2429                 goto _REQUEST_EXIT;
2430         }
2431
2432         if (!muse_camera_msg_get(ret, recv_msg)) {
2433                 LOGE("failed to get return value from msg [%s]", recv_msg);
2434                 ret = CAMERA_ERROR_INVALID_OPERATION;
2435                 goto _REQUEST_EXIT;
2436         }
2437
2438         if (ret == CAMERA_ERROR_NONE)
2439                 muse_core_msg_deserialize(key, recv_msg, NULL, NULL, MUSE_TYPE_ANY, value);
2440
2441         LOGD("api %d - value %d", api, *value);
2442
2443 _REQUEST_EXIT:
2444         if (sock_fd > -1) {
2445                 muse_client_close(sock_fd);
2446                 sock_fd = -1;
2447         }
2448
2449         return ret;
2450 }
2451
2452
2453 int camera_create(camera_device_e device, camera_h *camera)
2454 {
2455         int sock_fd = -1;
2456         char *send_msg = NULL;
2457         int send_ret = 0;
2458         int ret = CAMERA_ERROR_NONE;
2459         int pid = 0;
2460         camera_cli_s *pc = NULL;
2461         tbm_bufmgr bufmgr = NULL;
2462
2463         muse_camera_api_e api = MUSE_CAMERA_API_CREATE;
2464         int module_index = -1;
2465         int device_type = (int)device;
2466
2467         if (!camera) {
2468                 LOGE("NULL pointer");
2469                 return CAMERA_ERROR_INVALID_PARAMETER;
2470         }
2471
2472         sock_fd = muse_client_new();
2473         if (sock_fd < 0) {
2474                 LOGE("muse_client_new failed - returned fd %d", sock_fd);
2475                 ret = CAMERA_ERROR_INVALID_OPERATION;
2476                 goto ErrorExit;
2477         }
2478
2479         pid = getpid();
2480
2481         if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
2482                 LOGE("muse client get module index failed");
2483                 ret = CAMERA_ERROR_INVALID_OPERATION;
2484                 goto ErrorExit;
2485         }
2486
2487         send_msg = muse_core_msg_new(api,
2488                 MUSE_TYPE_INT, "module", module_index,
2489                 MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
2490                 MUSE_TYPE_INT, "pid", pid,
2491                 0);
2492
2493         if (!send_msg) {
2494                 LOGE("NULL msg");
2495                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2496                 goto ErrorExit;
2497         }
2498
2499         send_ret = muse_core_msg_send(sock_fd, send_msg);
2500
2501         muse_core_msg_free(send_msg);
2502         send_msg = NULL;
2503
2504         if (send_ret < 0) {
2505                 LOGE("send msg failed %d", errno);
2506                 ret = CAMERA_ERROR_INVALID_OPERATION;
2507                 goto ErrorExit;
2508         }
2509
2510         pc = g_new0(camera_cli_s, 1);
2511         if (pc == NULL) {
2512                 LOGE("camera_cli_s alloc failed");
2513                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2514                 goto ErrorExit;
2515         }
2516
2517         bufmgr = tbm_bufmgr_init(-1);
2518         if (bufmgr == NULL) {
2519                 LOGE("get tbm bufmgr failed");
2520                 ret = CAMERA_ERROR_INVALID_OPERATION;
2521                 goto ErrorExit;
2522         }
2523
2524         pc->cb_info = _camera_client_callback_new(sock_fd);
2525         if (pc->cb_info == NULL) {
2526                 LOGE("cb_info alloc failed");
2527                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
2528                 goto ErrorExit;
2529         }
2530
2531         sock_fd = -1;
2532
2533         LOGD("cb info : %d", pc->cb_info->fd);
2534
2535         ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
2536
2537         pc->cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 0;
2538
2539         if (ret == CAMERA_ERROR_NONE) {
2540                 int preview_format = CAMERA_PIXEL_FORMAT_INVALID;
2541                 int user_buffer_supported = 0;
2542                 intptr_t handle = 0;
2543
2544                 muse_camera_msg_get_pointer(handle, pc->cb_info->recv_msg);
2545                 if (handle == 0) {
2546                         LOGE("Receiving Handle Failed!!");
2547                         ret = CAMERA_ERROR_INVALID_OPERATION;
2548                         goto ErrorExit;
2549                 }
2550
2551                 muse_camera_msg_get(preview_format, pc->cb_info->recv_msg);
2552                 muse_camera_msg_get(user_buffer_supported, pc->cb_info->recv_msg);
2553
2554                 pc->remote_handle = handle;
2555                 pc->cb_info->bufmgr = bufmgr;
2556                 pc->cb_info->preview_format = preview_format;
2557                 pc->cb_info->dp_type = CAMERA_DISPLAY_TYPE_NONE;
2558                 pc->cb_info->user_buffer_supported = (gboolean)user_buffer_supported;
2559
2560                 LOGD("default preview format %d, user buffer %d",
2561                         preview_format, user_buffer_supported);
2562
2563                 *camera = (camera_h)pc;
2564
2565                 /* get display interface handle */
2566                 if (mm_display_interface_init(&pc->cb_info->dp_interface) != MM_ERROR_NONE)
2567                         LOGW("display interface init failed");
2568         } else {
2569                 goto ErrorExit;
2570         }
2571
2572         return ret;
2573
2574 ErrorExit:
2575         if (bufmgr) {
2576                 tbm_bufmgr_deinit(bufmgr);
2577                 bufmgr = NULL;
2578         }
2579
2580         if (sock_fd > -1) {
2581                 muse_client_close(sock_fd);
2582                 sock_fd = -1;
2583         }
2584
2585         if (pc) {
2586                 if (pc->cb_info) {
2587                         int temp_fd = pc->cb_info->fd;
2588
2589                         /* pc->cb_info->fd should be closed,
2590                            because g_thread_join for msg_recv_thread is not returned
2591                            in _camera_client_callback_destroy. */
2592                         if (temp_fd > -1) {
2593                                 pc->cb_info->fd = -1;
2594                                 muse_client_close(temp_fd);
2595                         }
2596
2597                         _camera_client_callback_destroy(pc->cb_info);
2598                         pc->cb_info = NULL;
2599                 }
2600                 g_free(pc);
2601                 pc = NULL;
2602         }
2603
2604         LOGE("camera create error : 0x%x", ret);
2605
2606         return ret;
2607 }
2608
2609
2610 int camera_change_device(camera_h camera, camera_device_e device)
2611 {
2612         int i = 0;
2613         int ret = CAMERA_ERROR_NONE;
2614         muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
2615         camera_cli_s *pc = (camera_cli_s *)camera;
2616         camera_msg_param param;
2617
2618         if (!pc || !pc->cb_info) {
2619                 LOGE("NULL handle");
2620                 return CAMERA_ERROR_INVALID_PARAMETER;
2621         }
2622
2623         CAMERA_MSG_PARAM_SET(param, INT, device);
2624
2625         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2626
2627         if (ret == CAMERA_ERROR_NONE) {
2628                 /* reset callback and user data */
2629                 for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) {
2630                         pc->cb_info->user_cb[i] = NULL;
2631                         pc->cb_info->user_data[i] = NULL;
2632                 }
2633                 UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
2634         }
2635
2636         return ret;
2637 }
2638
2639
2640 int camera_destroy(camera_h camera)
2641 {
2642         int ret = CAMERA_ERROR_NONE;
2643         muse_camera_api_e api = MUSE_CAMERA_API_DESTROY;
2644         camera_cli_s *pc = (camera_cli_s *)camera;
2645
2646         if (!pc || !pc->cb_info) {
2647                 LOGE("NULL handle");
2648                 return CAMERA_ERROR_INVALID_PARAMETER;
2649         }
2650
2651         LOGD("Enter");
2652
2653         if (pc->cb_info->is_server_connected)
2654                 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2655         else
2656                 LOGW("server disconnected. release resource without send message.");
2657
2658         if (ret == CAMERA_ERROR_NONE) {
2659                 _camera_deactivate_idle_event_all(pc->cb_info);
2660                 _camera_client_callback_destroy(pc->cb_info);
2661                 pc->cb_info = NULL;
2662
2663                 g_free(pc);
2664                 pc = NULL;
2665         }
2666
2667         LOGD("ret : 0x%x", ret);
2668
2669         return ret;
2670 }
2671
2672 int camera_start_preview(camera_h camera)
2673 {
2674         int ret = CAMERA_ERROR_NONE;
2675         muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
2676         camera_cli_s *pc = (camera_cli_s *)camera;
2677         camera_state_e current_state = CAMERA_STATE_NONE;
2678
2679         if (!pc || !pc->cb_info) {
2680                 LOGE("NULL handle");
2681                 return CAMERA_ERROR_INVALID_PARAMETER;
2682         }
2683
2684         LOGD("Enter : preview format %d, display type %d",
2685                 pc->cb_info->preview_format, pc->cb_info->dp_type);
2686
2687         ret = camera_get_state(camera, &current_state);
2688         if (ret != CAMERA_ERROR_NONE) {
2689                 LOGE("failed to get current state 0x%x", ret);
2690                 return ret;
2691         }
2692
2693         if (pc->cb_info->preview_format == CAMERA_PIXEL_FORMAT_INVZ &&
2694                 pc->cb_info->dp_type != CAMERA_DISPLAY_TYPE_NONE) {
2695                 LOGE("CAMERA_DISPLAY_TYPE_NONE[current %d] should be set with INVZ format",
2696                         pc->cb_info->dp_type);
2697                 return CAMERA_ERROR_INVALID_OPERATION;
2698         }
2699
2700         if (current_state == CAMERA_STATE_CREATED && pc->cb_info->user_buffer_supported) {
2701                 if (!_camera_allocate_preview_buffer(camera))
2702                         return CAMERA_ERROR_INVALID_OPERATION;
2703
2704                 _camera_msg_send(api, pc->cb_info->fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
2705         } else {
2706                 _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
2707         }
2708
2709         if (ret == CAMERA_ERROR_NONE && CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
2710                 ret = _camera_start_evas_rendering(camera);
2711                 if (ret != CAMERA_ERROR_NONE) {
2712                         LOGE("stop preview because of error");
2713                         _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
2714                 }
2715         }
2716
2717         LOGD("ret : 0x%x", ret);
2718
2719         return ret;
2720 }
2721
2722
2723 int camera_stop_preview(camera_h camera)
2724 {
2725         int ret = CAMERA_ERROR_NONE;
2726         camera_cli_s *pc = (camera_cli_s *)camera;
2727         muse_camera_api_e api = MUSE_CAMERA_API_STOP_PREVIEW;
2728         camera_state_e current_state = CAMERA_STATE_NONE;
2729
2730         if (!pc || !pc->cb_info) {
2731                 LOGE("NULL handle");
2732                 return CAMERA_ERROR_INVALID_PARAMETER;
2733         }
2734
2735         LOGD("Enter");
2736
2737         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
2738                 ret = camera_get_state(camera, &current_state);
2739                 if (ret != CAMERA_ERROR_NONE) {
2740                         LOGE("failed to get current state 0x%x", ret);
2741                         return ret;
2742                 }
2743
2744                 if (current_state == CAMERA_STATE_PREVIEW) {
2745                         ret = _camera_stop_evas_rendering(camera, false);
2746                         if (ret != CAMERA_ERROR_NONE)
2747                                 return ret;
2748                 }
2749         }
2750
2751         /* send stop preview message */
2752         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2753
2754         if (ret == CAMERA_ERROR_NONE) {
2755                 if (pc->cb_info->user_buffer_supported)
2756                         _camera_release_preview_buffer(camera);
2757         } else if (current_state == CAMERA_STATE_PREVIEW) {
2758                 LOGW("restart evas rendering");
2759                 _camera_start_evas_rendering(camera);
2760         }
2761
2762         LOGD("ret : 0x%x", ret);
2763
2764         return ret;
2765 }
2766
2767
2768 int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data)
2769 {
2770         int ret = CAMERA_ERROR_NONE;
2771         camera_cli_s *pc = (camera_cli_s *)camera;
2772         muse_camera_api_e api = MUSE_CAMERA_API_START_CAPTURE;
2773
2774         if (!pc || !pc->cb_info) {
2775                 LOGE("NULL handle");
2776                 return CAMERA_ERROR_INVALID_PARAMETER;
2777         }
2778
2779         LOGD("Enter");
2780
2781         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
2782         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
2783
2784         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
2785         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
2786
2787         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2788
2789         LOGD("ret : 0x%x", ret);
2790
2791         return ret;
2792 }
2793
2794
2795 bool camera_is_supported_continuous_capture(camera_h camera)
2796 {
2797         int ret = CAMERA_ERROR_NONE;
2798         camera_cli_s *pc = (camera_cli_s *)camera;
2799         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE;
2800
2801         if (!pc || !pc->cb_info) {
2802                 LOGE("NULL handle");
2803                 return CAMERA_ERROR_INVALID_PARAMETER;
2804         }
2805
2806         LOGD("Enter");
2807
2808         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2809
2810         if (ret < 0) {
2811                 LOGE("error is occurred 0x%x", ret);
2812                 ret = false;
2813         }
2814
2815         LOGD("ret : %d", ret);
2816
2817         return (bool)ret;
2818 }
2819
2820
2821 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)
2822 {
2823         int ret = CAMERA_ERROR_NONE;
2824         camera_cli_s *pc = (camera_cli_s *)camera;
2825         muse_camera_api_e api = MUSE_CAMERA_API_START_CONTINUOUS_CAPTURE;
2826         camera_msg_param param;
2827         int value = 0;
2828
2829         if (!pc || !pc->cb_info) {
2830                 LOGE("NULL handle");
2831                 return CAMERA_ERROR_INVALID_PARAMETER;
2832         }
2833
2834         LOGD("Enter");
2835
2836         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = capturing_cb;
2837         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE] = user_data;
2838
2839         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = completed_cb;
2840         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE] = user_data;
2841
2842         value = (count << 16) | interval;
2843         CAMERA_MSG_PARAM_SET(param, INT, value);
2844
2845         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
2846
2847         LOGD("ret : 0x%x", ret);
2848
2849         return ret;
2850 }
2851
2852
2853 int camera_stop_continuous_capture(camera_h camera)
2854 {
2855         int ret = CAMERA_ERROR_NONE;
2856         camera_cli_s *pc = (camera_cli_s *)camera;
2857         muse_camera_api_e api = MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE;
2858
2859         if (!pc || !pc->cb_info) {
2860                 LOGE("NULL handle");
2861                 return CAMERA_ERROR_INVALID_PARAMETER;
2862         }
2863
2864         LOGD("Enter");
2865
2866         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2867
2868         LOGD("ret : 0x%x", ret);
2869
2870         return ret;
2871 }
2872
2873
2874 bool camera_is_supported_face_detection(camera_h camera)
2875 {
2876         int ret = CAMERA_ERROR_NONE;
2877         camera_cli_s *pc = (camera_cli_s *)camera;
2878         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_FACE_DETECTION;
2879
2880         if (!pc || !pc->cb_info) {
2881                 LOGE("NULL handle");
2882                 return CAMERA_ERROR_INVALID_PARAMETER;
2883         }
2884
2885         LOGD("Enter");
2886
2887         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2888
2889         if (ret < 0) {
2890                 LOGE("error is occurred 0x%x", ret);
2891                 ret = false;
2892         }
2893
2894         LOGD("ret : %d", ret);
2895
2896         return (bool)ret;
2897 }
2898
2899
2900 bool camera_is_supported_zero_shutter_lag(camera_h camera)
2901 {
2902         int ret = CAMERA_ERROR_NONE;
2903         camera_cli_s *pc = (camera_cli_s *)camera;
2904         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG;
2905
2906         if (!pc || !pc->cb_info) {
2907                 LOGE("NULL handle");
2908                 return CAMERA_ERROR_INVALID_PARAMETER;
2909         }
2910
2911         LOGD("Enter");
2912
2913         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2914
2915         if (ret < 0) {
2916                 LOGE("error is occurred 0x%x", ret);
2917                 ret = false;
2918         }
2919
2920         LOGD("ret : %d", ret);
2921
2922         return (bool)ret;
2923 }
2924
2925
2926 bool camera_is_supported_media_packet_preview_cb(camera_h camera)
2927 {
2928         int ret = CAMERA_ERROR_NONE;
2929         camera_cli_s *pc = (camera_cli_s *)camera;
2930         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB;
2931
2932         if (!pc || !pc->cb_info) {
2933                 LOGE("NULL handle");
2934                 return CAMERA_ERROR_INVALID_PARAMETER;
2935         }
2936
2937         LOGD("Enter");
2938
2939         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2940
2941         if (ret < 0) {
2942                 LOGE("error is occurred 0x%x", ret);
2943                 ret = false;
2944         }
2945
2946         LOGD("ret : %d", ret);
2947
2948         return (bool)ret;
2949 }
2950
2951 int camera_get_device_count(camera_h camera, int *device_count)
2952 {
2953         int ret = CAMERA_ERROR_NONE;
2954         camera_cli_s *pc = (camera_cli_s *)camera;
2955         muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
2956
2957         if (!pc || !pc->cb_info) {
2958                 LOGE("NULL handle");
2959                 return CAMERA_ERROR_INVALID_PARAMETER;
2960         }
2961
2962         LOGD("Enter");
2963
2964         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2965
2966         if (ret == CAMERA_ERROR_NONE)
2967                 *device_count = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DEVICE_COUNT];
2968
2969         LOGD("ret : 0x%x", ret);
2970
2971         return ret;
2972 }
2973
2974 int camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void *user_data)
2975 {
2976         int ret = CAMERA_ERROR_NONE;
2977         camera_cli_s *pc = (camera_cli_s *)camera;
2978         muse_camera_api_e api = MUSE_CAMERA_API_START_FACE_DETECTION;
2979
2980         if (!pc || !pc->cb_info) {
2981                 LOGE("NULL handle");
2982                 return CAMERA_ERROR_INVALID_PARAMETER;
2983         }
2984
2985         LOGD("Enter");
2986
2987         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
2988
2989         if (ret == CAMERA_ERROR_NONE) {
2990                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2991
2992                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = callback;
2993                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = user_data;
2994
2995                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
2996         }
2997
2998         LOGD("ret : 0x%x", ret);
2999
3000         return ret;
3001 }
3002
3003 int camera_stop_face_detection(camera_h camera)
3004 {
3005         int ret = CAMERA_ERROR_NONE;
3006         camera_cli_s *pc = (camera_cli_s *)camera;
3007         muse_camera_api_e api = MUSE_CAMERA_API_STOP_FACE_DETECTION;
3008
3009         if (!pc || !pc->cb_info) {
3010                 LOGE("NULL handle");
3011                 return CAMERA_ERROR_INVALID_PARAMETER;
3012         }
3013
3014         LOGD("Enter");
3015
3016         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3017
3018         if (ret == CAMERA_ERROR_NONE) {
3019                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3020
3021                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
3022                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
3023
3024                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
3025         }
3026
3027         LOGD("ret : 0x%x", ret);
3028
3029         return ret;
3030 }
3031
3032 int camera_get_state(camera_h camera, camera_state_e *state)
3033 {
3034         int ret = CAMERA_ERROR_NONE;
3035         camera_cli_s *pc = (camera_cli_s *)camera;
3036         muse_camera_api_e api = MUSE_CAMERA_API_GET_STATE;
3037
3038         if (!pc || !pc->cb_info || !state) {
3039                 LOGE("NULL pointer %p %p", pc, state);
3040                 return CAMERA_ERROR_INVALID_PARAMETER;
3041         }
3042
3043         LOGD("Enter");
3044
3045         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3046
3047         if (ret == CAMERA_ERROR_NONE)
3048                 *state = (camera_state_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STATE];
3049
3050         LOGD("ret : 0x%x", ret);
3051
3052         return ret;
3053 }
3054
3055 int camera_start_focusing(camera_h camera, bool continuous)
3056 {
3057         int ret = CAMERA_ERROR_NONE;
3058         camera_cli_s *pc = (camera_cli_s *)camera;
3059         muse_camera_api_e api = MUSE_CAMERA_API_START_FOCUSING;
3060         camera_msg_param param;
3061         int is_continuous = (int)continuous;
3062
3063         if (!pc || !pc->cb_info) {
3064                 LOGE("NULL handle");
3065                 return CAMERA_ERROR_INVALID_PARAMETER;
3066         }
3067
3068         LOGD("Enter");
3069
3070         CAMERA_MSG_PARAM_SET(param, INT, is_continuous);
3071
3072         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3073
3074         LOGD("ret : 0x%x", ret);
3075
3076         return ret;
3077 }
3078
3079 int camera_cancel_focusing(camera_h camera)
3080 {
3081         int ret = CAMERA_ERROR_NONE;
3082         camera_cli_s *pc = (camera_cli_s *)camera;
3083         muse_camera_api_e api = MUSE_CAMERA_API_CANCEL_FOCUSING;
3084
3085         if (!pc || !pc->cb_info) {
3086                 LOGE("NULL handle");
3087                 return CAMERA_ERROR_INVALID_PARAMETER;
3088         }
3089
3090         LOGD("Enter, remote_handle : %td", pc->remote_handle);
3091
3092         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3093
3094         LOGD("ret : 0x%x", ret);
3095
3096         return ret;
3097 }
3098
3099 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display)
3100 {
3101         int ret = CAMERA_ERROR_NONE;
3102         int parent_id = 0;
3103         camera_cli_s *pc = (camera_cli_s *)camera;
3104         camera_cb_info_s *cb_info = NULL;
3105         camera_state_e current_state = CAMERA_STATE_NONE;
3106         camera_msg_param param0;
3107         camera_msg_param param1;
3108         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY;
3109
3110         if (!pc || !pc->cb_info) {
3111                 LOGE("NULL handle");
3112                 return CAMERA_ERROR_INVALID_PARAMETER;
3113         }
3114
3115         if (type < CAMERA_DISPLAY_TYPE_OVERLAY || type > CAMERA_DISPLAY_TYPE_NONE) {
3116                 LOGE("invalid type %d", type);
3117                 return CAMERA_ERROR_INVALID_PARAMETER;
3118         }
3119
3120         if (type != CAMERA_DISPLAY_TYPE_NONE && display == NULL) {
3121                 LOGE("display type[%d] is not NONE, but display handle is NULL", type);
3122                 return CAMERA_ERROR_INVALID_PARAMETER;
3123         }
3124
3125         cb_info = (camera_cb_info_s *)pc->cb_info;
3126
3127         ret = camera_get_state(camera, &current_state);
3128         if (ret != CAMERA_ERROR_NONE) {
3129                 LOGE("failed to get current state 0x%x", ret);
3130                 return ret;
3131         }
3132
3133         if (current_state != CAMERA_STATE_CREATED) {
3134                 LOGE("INVALID_STATE : current %d", current_state);
3135                 return CAMERA_ERROR_INVALID_STATE;
3136         }
3137
3138         LOGD("Enter - type : %d, display : %p", type, display);
3139
3140         if (type != CAMERA_DISPLAY_TYPE_NONE) {
3141                 /* check display interface handle */
3142                 if (!cb_info->dp_interface) {
3143                         LOGE("display interface not supported");
3144                         return CAMERA_ERROR_NOT_SUPPORTED;
3145                 }
3146
3147                 ret = mm_display_interface_set_display(cb_info->dp_interface, type, display, &parent_id);
3148                 if (ret != MM_ERROR_NONE) {
3149                         LOGE("[INVALID_OPERATION] set display failed[0x%x]", ret);
3150                         return CAMERA_ERROR_INVALID_OPERATION;
3151                 }
3152
3153                 if (type == CAMERA_DISPLAY_TYPE_EVAS) {
3154                         camera_flip_e flip = CAMERA_FLIP_NONE;
3155                         camera_display_mode_e mode = CAMERA_DISPLAY_MODE_LETTER_BOX;
3156                         camera_rotation_e rotation = CAMERA_ROTATION_NONE;
3157                         bool visible = 0;
3158                         int x = 0;
3159                         int y = 0;
3160                         int width = 0;
3161                         int height = 0;
3162
3163                         camera_get_display_flip(camera, &flip);
3164                         camera_get_display_mode(camera, &mode);
3165                         camera_get_display_rotation(camera, &rotation);
3166                         camera_is_display_visible(camera, &visible);
3167                         camera_attr_get_display_roi_area(camera, &x, &y, &width, &height);
3168
3169                         LOGD("current setting : flip %d, mode %d, rotation %d, visible %d, roi %d,%d,%dx%d",
3170                                 flip, mode, rotation, visible, x, y, width, height);
3171
3172                         ret = mm_display_interface_evas_set_flip(cb_info->dp_interface, flip);
3173                         ret |= mm_display_interface_evas_set_mode(cb_info->dp_interface, mode);
3174                         ret |= mm_display_interface_evas_set_rotation(cb_info->dp_interface, rotation);
3175                         ret |= mm_display_interface_evas_set_visible(cb_info->dp_interface, visible);
3176
3177                         if (mode == CAMERA_DISPLAY_MODE_CUSTOM_ROI)
3178                                 ret |= mm_display_interface_evas_set_roi_area(cb_info->dp_interface, x, y, width, height);
3179                 }
3180         }
3181
3182         CAMERA_MSG_PARAM_SET(param0, INT, type);
3183         CAMERA_MSG_PARAM_SET(param1, INT, parent_id);
3184
3185         _camera_msg_send_param2_int(api, cb_info, &ret,
3186                 &param0, &param1, CAMERA_CB_TIMEOUT);
3187
3188         if (ret == CAMERA_ERROR_NONE) {
3189                 pc->cb_info->dp_type = type;
3190
3191                 if (type == CAMERA_DISPLAY_TYPE_EVAS)
3192                         SET_PREVIEW_CB_TYPE(cb_info, PREVIEW_CB_TYPE_EVAS);
3193         }
3194
3195         return ret;
3196 }
3197
3198
3199 int camera_set_preview_resolution(camera_h camera, int width, int height)
3200 {
3201         int ret = CAMERA_ERROR_NONE;
3202         camera_state_e current_state = CAMERA_STATE_NONE;
3203         camera_cli_s *pc = (camera_cli_s *)camera;
3204         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
3205         camera_msg_param param;
3206         int value = 0;
3207
3208         if (!pc || !pc->cb_info) {
3209                 LOGE("NULL handle");
3210                 return CAMERA_ERROR_INVALID_PARAMETER;
3211         }
3212
3213         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3214                 ret = camera_get_state(camera, &current_state);
3215                 if (ret != CAMERA_ERROR_NONE) {
3216                         LOGE("failed to get current state 0x%x", ret);
3217                         return ret;
3218                 }
3219
3220                 if (current_state == CAMERA_STATE_PREVIEW) {
3221                         ret = _camera_stop_evas_rendering(camera, true);
3222                         if (ret != CAMERA_ERROR_NONE)
3223                                 return ret;
3224                 }
3225         }
3226
3227         value = (width << 16) | height;
3228         CAMERA_MSG_PARAM_SET(param, INT, value);
3229
3230         LOGD("%dx%d -> 0x%x", width, height, value);
3231
3232         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3233
3234         LOGD("ret : 0x%x", ret);
3235
3236         if (current_state == CAMERA_STATE_PREVIEW) {
3237                 LOGW("restart evas rendering");
3238                 _camera_start_evas_rendering(camera);
3239         }
3240
3241         return ret;
3242 }
3243
3244
3245 int camera_set_capture_resolution(camera_h camera, int width, int height)
3246 {
3247         int ret = CAMERA_ERROR_NONE;
3248         camera_cli_s *pc = (camera_cli_s *)camera;
3249         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION;
3250         camera_msg_param param;
3251         int value = 0;
3252
3253         if (!pc || !pc->cb_info) {
3254                 LOGE("NULL handle");
3255                 return CAMERA_ERROR_INVALID_PARAMETER;
3256         }
3257
3258         LOGD("Enter");
3259
3260         value = (width << 16) | height;
3261         CAMERA_MSG_PARAM_SET(param, INT, value);
3262
3263         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3264
3265         LOGD("ret : 0x%x", ret);
3266
3267         return ret;
3268 }
3269
3270
3271 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
3272 {
3273         int ret = CAMERA_ERROR_NONE;
3274         int set_format = (int)format;
3275         camera_cli_s *pc = (camera_cli_s *)camera;
3276         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
3277         camera_msg_param param;
3278
3279         if (!pc || !pc->cb_info) {
3280                 LOGE("NULL handle");
3281                 return CAMERA_ERROR_INVALID_PARAMETER;
3282         }
3283
3284         LOGD("Enter - format %d", set_format);
3285
3286         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3287
3288         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3289
3290         LOGD("ret : 0x%x", ret);
3291
3292         return ret;
3293 }
3294
3295
3296 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
3297 {
3298         int ret = CAMERA_ERROR_NONE;
3299         int set_format = (int)format;
3300         camera_msg_param param;
3301         camera_cli_s *pc = (camera_cli_s *)camera;
3302         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
3303
3304         if (!pc || !pc->cb_info) {
3305                 LOGE("NULL handle");
3306                 return CAMERA_ERROR_INVALID_PARAMETER;
3307         }
3308
3309         LOGD("Enter - format %d", set_format);
3310
3311         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3312
3313         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3314
3315         if (ret == CAMERA_ERROR_NONE)
3316                 pc->cb_info->preview_format = set_format;
3317
3318         LOGD("ret : 0x%x", ret);
3319
3320         return ret;
3321 }
3322
3323
3324 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
3325 {
3326         int ret = CAMERA_ERROR_NONE;
3327         camera_cli_s *pc = (camera_cli_s *)camera;
3328         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
3329
3330         if (!pc || !pc->cb_info || !width || !height) {
3331                 LOGE("NULL pointer %p %p %p", pc, width, height);
3332                 return CAMERA_ERROR_INVALID_PARAMETER;
3333         }
3334
3335         LOGD("Enter");
3336
3337         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3338
3339         if (ret == CAMERA_ERROR_NONE) {
3340                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION] >> 16;
3341                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION];
3342         }
3343
3344         LOGD("ret : 0x%x", ret);
3345
3346         return ret;
3347 }
3348
3349
3350 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
3351 {
3352         int ret = CAMERA_ERROR_NONE;
3353         int set_rotation = (int)rotation;
3354         camera_cli_s *pc = (camera_cli_s *)camera;
3355         camera_msg_param param;
3356
3357         if (!pc || !pc->cb_info) {
3358                 LOGE("NULL handle");
3359                 return CAMERA_ERROR_INVALID_PARAMETER;
3360         }
3361
3362         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3363                 ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
3364                 if (ret != MM_ERROR_NONE) {
3365                         LOGE("failed to set rotation for evas surface 0x%x", ret);
3366                         return CAMERA_ERROR_INVALID_OPERATION;
3367                 }
3368         }
3369
3370         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
3371
3372         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_ROTATION, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3373
3374         return ret;
3375 }
3376
3377
3378 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
3379 {
3380         int ret = CAMERA_ERROR_NONE;
3381         camera_cli_s *pc = (camera_cli_s *)camera;
3382
3383         if (!pc || !pc->cb_info || !rotation) {
3384                 LOGE("NULL pointer %p %p", pc, rotation);
3385                 return CAMERA_ERROR_INVALID_PARAMETER;
3386         }
3387
3388         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_ROTATION, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3389
3390         if (ret == CAMERA_ERROR_NONE)
3391                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_ROTATION];
3392
3393         return ret;
3394 }
3395
3396
3397 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
3398 {
3399         int ret = CAMERA_ERROR_NONE;
3400         int set_flip = (int)flip;
3401         camera_cli_s *pc = (camera_cli_s *)camera;
3402         camera_msg_param param;
3403
3404         if (!pc || !pc->cb_info) {
3405                 LOGE("NULL handle");
3406                 return CAMERA_ERROR_INVALID_PARAMETER;
3407         }
3408
3409         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3410                 ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
3411                 if (ret != MM_ERROR_NONE) {
3412                         LOGE("failed to set flip for evas surface 0x%x", ret);
3413                         return CAMERA_ERROR_INVALID_OPERATION;
3414                 }
3415         }
3416
3417         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
3418
3419         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_FLIP, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3420
3421         return ret;
3422 }
3423
3424
3425 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
3426 {
3427         int ret = CAMERA_ERROR_NONE;
3428         camera_cli_s *pc = (camera_cli_s *)camera;
3429
3430         if (!pc || !pc->cb_info || !flip) {
3431                 LOGE("NULL pointer %p %p", pc, flip);
3432                 return CAMERA_ERROR_INVALID_PARAMETER;
3433         }
3434
3435         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_FLIP, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3436
3437         if (ret == CAMERA_ERROR_NONE)
3438                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_FLIP];
3439
3440         return ret;
3441 }
3442
3443
3444 int camera_set_display_visible(camera_h camera, bool visible)
3445 {
3446         int ret = CAMERA_ERROR_NONE;
3447         int set_visible = (int)visible;
3448         camera_cli_s *pc = (camera_cli_s *)camera;
3449         camera_msg_param param;
3450
3451         if (!pc || !pc->cb_info) {
3452                 LOGE("NULL handle");
3453                 return CAMERA_ERROR_INVALID_PARAMETER;
3454         }
3455
3456         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3457                 ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
3458                 if (ret != MM_ERROR_NONE) {
3459                         LOGE("failed to set visible for evas surface 0x%x", ret);
3460                         return CAMERA_ERROR_INVALID_OPERATION;
3461                 }
3462         }
3463
3464         CAMERA_MSG_PARAM_SET(param, INT, set_visible);
3465
3466         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3467
3468         return ret;
3469 }
3470
3471
3472 int camera_is_display_visible(camera_h camera, bool *visible)
3473 {
3474         int ret = CAMERA_ERROR_NONE;
3475         camera_cli_s *pc = (camera_cli_s *)camera;
3476
3477         if (!pc || !pc->cb_info || !visible) {
3478                 LOGE("NULL pointer %p %p", pc, visible);
3479                 return CAMERA_ERROR_INVALID_PARAMETER;
3480         }
3481
3482         _camera_msg_send(MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3483
3484         if (ret == CAMERA_ERROR_NONE)
3485                 *visible = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE];
3486
3487         return ret;
3488 }
3489
3490
3491 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
3492 {
3493         int ret = CAMERA_ERROR_NONE;
3494         int set_mode = (int)mode;
3495         camera_cli_s *pc = (camera_cli_s *)camera;
3496         camera_msg_param param;
3497
3498         if (!pc || !pc->cb_info) {
3499                 LOGE("NULL handle");
3500                 return CAMERA_ERROR_INVALID_PARAMETER;
3501         }
3502
3503         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3504                 ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
3505                 if (ret != MM_ERROR_NONE) {
3506                         LOGE("failed to set geometry for evas surface 0x%x", ret);
3507                         return CAMERA_ERROR_INVALID_OPERATION;
3508                 }
3509         }
3510
3511         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
3512
3513         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_MODE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3514
3515         return ret;
3516 }
3517
3518
3519 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
3520 {
3521         int ret = CAMERA_ERROR_NONE;
3522         camera_cli_s *pc = (camera_cli_s *)camera;
3523
3524         if (!pc || !pc->cb_info || !mode) {
3525                 LOGE("NULL pointer %p %p", pc, mode);
3526                 return CAMERA_ERROR_INVALID_PARAMETER;
3527         }
3528
3529         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_MODE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3530
3531         if (ret == CAMERA_ERROR_NONE)
3532                 *mode = (camera_display_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_MODE];
3533
3534         return ret;
3535 }
3536
3537
3538 int camera_set_display_reuse_hint(camera_h camera, bool hint)
3539 {
3540         int ret = CAMERA_ERROR_NONE;
3541         int set_hint = (int)hint;
3542         camera_cli_s *pc = (camera_cli_s *)camera;
3543         camera_msg_param param;
3544
3545         if (!pc || !pc->cb_info) {
3546                 LOGE("NULL handle");
3547                 return CAMERA_ERROR_INVALID_PARAMETER;
3548         }
3549
3550         LOGD("Enter - hint %d", set_hint);
3551
3552         CAMERA_MSG_PARAM_SET(param, INT, set_hint);
3553
3554         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3555
3556         return ret;
3557 }
3558
3559
3560 int camera_get_display_reuse_hint(camera_h camera, bool *hint)
3561 {
3562         int ret = CAMERA_ERROR_NONE;
3563         camera_cli_s *pc = (camera_cli_s *)camera;
3564         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
3565
3566         if (!pc || !pc->cb_info || !hint) {
3567                 LOGE("NULL pointer %p %p", pc, hint);
3568                 return CAMERA_ERROR_INVALID_PARAMETER;
3569         }
3570
3571         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3572
3573         if (ret == CAMERA_ERROR_NONE) {
3574                 *hint = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT];
3575                 LOGD("display reuse hint %d", *hint);
3576         }
3577
3578         return ret;
3579 }
3580
3581
3582 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
3583 {
3584         int ret = CAMERA_ERROR_NONE;
3585         camera_cli_s *pc = (camera_cli_s *)camera;
3586         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
3587
3588         if (!pc || !pc->cb_info || !width || !height) {
3589                 LOGE("NULL pointer %p %p %p", pc, width, height);
3590                 return CAMERA_ERROR_INVALID_PARAMETER;
3591         }
3592
3593         LOGD("Enter");
3594
3595         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3596
3597         if (ret == CAMERA_ERROR_NONE) {
3598                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION] >> 16;
3599                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION];
3600         }
3601
3602         LOGD("ret : 0x%x", ret);
3603
3604         return ret;
3605 }
3606
3607
3608 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
3609 {
3610         int ret = CAMERA_ERROR_NONE;
3611         camera_cli_s *pc = (camera_cli_s *)camera;
3612         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
3613
3614         if (!pc || !pc->cb_info || !format) {
3615                 LOGE("NULL pointer %p %p", pc, format);
3616                 return CAMERA_ERROR_INVALID_PARAMETER;
3617         }
3618
3619         LOGD("Enter");
3620
3621         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3622
3623         if (ret == CAMERA_ERROR_NONE)
3624                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_FORMAT];
3625
3626         LOGD("ret : 0x%x", ret);
3627
3628         return ret;
3629 }
3630
3631
3632 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
3633 {
3634         int ret = CAMERA_ERROR_NONE;
3635         camera_cli_s *pc = (camera_cli_s *)camera;
3636         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
3637
3638         if (!pc || !pc->cb_info || !format) {
3639                 LOGE("NULL pointer %p %p", pc, format);
3640                 return CAMERA_ERROR_INVALID_PARAMETER;
3641         }
3642
3643         LOGD("Enter");
3644
3645         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3646
3647         if (ret == CAMERA_ERROR_NONE)
3648                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FORMAT];
3649
3650         LOGD("ret : 0x%x", ret);
3651
3652         return ret;
3653 }
3654
3655
3656 int camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction)
3657 {
3658         int ret = CAMERA_ERROR_NONE;
3659         camera_cli_s *pc = (camera_cli_s *)camera;
3660         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
3661
3662         if (!pc || !pc->cb_info || !facing_direction) {
3663                 LOGE("NULL pointer %p %p", pc, facing_direction);
3664                 return CAMERA_ERROR_INVALID_PARAMETER;
3665         }
3666
3667         LOGD("Enter");
3668
3669         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3670
3671         if (ret == CAMERA_ERROR_NONE)
3672                 *facing_direction = (camera_facing_direction_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FACING_DIRECTION];
3673
3674         LOGD("ret : 0x%x", ret);
3675
3676         return ret;
3677 }
3678
3679
3680 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
3681 {
3682         int ret = CAMERA_ERROR_NONE;
3683         camera_cli_s *pc = (camera_cli_s *)camera;
3684         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
3685
3686         if (!pc || !pc->cb_info || !callback) {
3687                 LOGE("NULL pointer %p %p", pc, callback);
3688                 return CAMERA_ERROR_INVALID_PARAMETER;
3689         }
3690
3691         LOGD("Enter");
3692
3693         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3694
3695         if (ret == CAMERA_ERROR_NONE) {
3696                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3697
3698                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
3699                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
3700
3701                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3702
3703                 SET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3704         }
3705
3706         LOGD("ret : 0x%x", ret);
3707
3708         return ret;
3709 }
3710
3711
3712 int camera_unset_preview_cb(camera_h camera)
3713 {
3714         int ret = CAMERA_ERROR_NONE;
3715         camera_cli_s *pc = (camera_cli_s *)camera;
3716         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
3717
3718         if (!pc || !pc->cb_info) {
3719                 LOGE("NULL handle");
3720                 return CAMERA_ERROR_INVALID_PARAMETER;
3721         }
3722
3723         LOGD("Enter");
3724
3725         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3726
3727         if (ret == CAMERA_ERROR_NONE) {
3728                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3729
3730                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3731                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3732
3733                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3734
3735                 UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3736         }
3737
3738         LOGD("ret : 0x%x", ret);
3739
3740         return ret;
3741 }
3742
3743
3744 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
3745 {
3746         int ret = CAMERA_ERROR_NONE;
3747         camera_cli_s *pc = (camera_cli_s *)camera;
3748         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
3749
3750         if (!pc || !pc->cb_info) {
3751                 LOGE("NULL handle");
3752                 return CAMERA_ERROR_INVALID_PARAMETER;
3753         }
3754
3755         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3756                 LOGE("NOT SUPPORTED");
3757                 return CAMERA_ERROR_NOT_SUPPORTED;
3758         }
3759
3760         if (callback == NULL) {
3761                 LOGE("NULL callback");
3762                 return CAMERA_ERROR_INVALID_PARAMETER;
3763         }
3764
3765         LOGD("Enter");
3766
3767         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3768
3769         if (ret == CAMERA_ERROR_NONE) {
3770                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3771
3772                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
3773                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
3774
3775                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3776         }
3777
3778         LOGD("ret : 0x%x", ret);
3779
3780         return ret;
3781 }
3782
3783
3784 int camera_unset_media_packet_preview_cb(camera_h camera)
3785 {
3786         int ret = CAMERA_ERROR_NONE;
3787         camera_cli_s *pc = (camera_cli_s *)camera;
3788         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
3789
3790         if (!pc || !pc->cb_info) {
3791                 LOGE("NULL handle");
3792                 return CAMERA_ERROR_INVALID_PARAMETER;
3793         }
3794
3795         LOGD("Enter");
3796
3797         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3798
3799         if (ret == CAMERA_ERROR_NONE) {
3800                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3801
3802                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3803                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3804
3805                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3806         }
3807
3808         LOGD("ret : 0x%x", ret);
3809
3810         return ret;
3811 }
3812
3813
3814 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
3815 {
3816         int ret = CAMERA_ERROR_NONE;
3817         camera_cli_s *pc = (camera_cli_s *)camera;
3818         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
3819
3820         if (!pc || !pc->cb_info || !callback) {
3821                 LOGE("NULL pointer %p %p", pc, callback);
3822                 return CAMERA_ERROR_INVALID_PARAMETER;
3823         }
3824
3825         LOGD("Enter");
3826
3827         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3828
3829         if (ret == CAMERA_ERROR_NONE) {
3830                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3831
3832                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
3833                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
3834
3835                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3836         }
3837
3838         LOGD("ret : 0x%x", ret);
3839
3840         return ret;
3841 }
3842
3843
3844 int camera_unset_state_changed_cb(camera_h camera)
3845 {
3846         int ret = CAMERA_ERROR_NONE;
3847         camera_cli_s *pc = (camera_cli_s *)camera;
3848         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
3849
3850         if (!pc || !pc->cb_info) {
3851                 LOGE("NULL handle");
3852                 return CAMERA_ERROR_INVALID_PARAMETER;
3853         }
3854
3855         LOGD("Enter");
3856
3857         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3858
3859         if (ret == CAMERA_ERROR_NONE) {
3860                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3861
3862                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3863                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3864
3865                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3866         }
3867
3868         LOGD("ret : 0x%x", ret);
3869
3870         return ret;
3871 }
3872
3873
3874 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
3875 {
3876         int ret = CAMERA_ERROR_NONE;
3877         camera_cli_s *pc = (camera_cli_s *)camera;
3878         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
3879
3880         if (!pc || !pc->cb_info || !callback) {
3881                 LOGE("NULL pointer %p %p", pc, callback);
3882                 return CAMERA_ERROR_INVALID_PARAMETER;
3883         }
3884
3885         LOGD("Enter");
3886
3887         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3888
3889         if (ret == CAMERA_ERROR_NONE) {
3890                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3891
3892                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
3893                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
3894
3895                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3896         }
3897
3898         LOGD("ret : 0x%x", ret);
3899
3900         return ret;
3901 }
3902
3903
3904 int camera_unset_interrupted_cb(camera_h camera)
3905 {
3906         int ret = CAMERA_ERROR_NONE;
3907         camera_cli_s *pc = (camera_cli_s *)camera;
3908         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
3909
3910         if (!pc || !pc->cb_info) {
3911                 LOGE("NULL handle");
3912                 return CAMERA_ERROR_INVALID_PARAMETER;
3913         }
3914
3915         LOGD("Enter");
3916
3917         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3918
3919         if (ret == CAMERA_ERROR_NONE) {
3920                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3921
3922                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3923                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3924
3925                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3926         }
3927
3928         LOGD("ret : 0x%x", ret);
3929
3930         return ret;
3931 }
3932
3933
3934 int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
3935 {
3936         int ret = CAMERA_ERROR_NONE;
3937         camera_cli_s *pc = (camera_cli_s *)camera;
3938         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
3939
3940         if (!pc || !pc->cb_info || !callback) {
3941                 LOGE("NULL pointer %p %p", pc, callback);
3942                 return CAMERA_ERROR_INVALID_PARAMETER;
3943         }
3944
3945         LOGD("Enter");
3946
3947         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3948
3949         if (ret == CAMERA_ERROR_NONE) {
3950                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3951
3952                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
3953                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
3954
3955                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3956         }
3957
3958         LOGD("ret : 0x%x", ret);
3959
3960         return ret;
3961 }
3962
3963
3964 int camera_unset_interrupt_started_cb(camera_h camera)
3965 {
3966         int ret = CAMERA_ERROR_NONE;
3967         camera_cli_s *pc = (camera_cli_s *)camera;
3968         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
3969
3970         if (!pc || !pc->cb_info) {
3971                 LOGE("NULL handle");
3972                 return CAMERA_ERROR_INVALID_PARAMETER;
3973         }
3974
3975         LOGD("Enter");
3976
3977         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3978
3979         if (ret == CAMERA_ERROR_NONE) {
3980                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3981
3982                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3983                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3984
3985                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3986         }
3987
3988         LOGD("ret : 0x%x", ret);
3989
3990         return ret;
3991 }
3992
3993
3994 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
3995 {
3996         int ret = CAMERA_ERROR_NONE;
3997         camera_cli_s *pc = (camera_cli_s *)camera;
3998         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
3999
4000         if (!pc || !pc->cb_info || !callback) {
4001                 LOGE("NULL pointer %p %p", pc, callback);
4002                 return CAMERA_ERROR_INVALID_PARAMETER;
4003         }
4004
4005         LOGD("Enter");
4006
4007         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4008
4009         if (ret == CAMERA_ERROR_NONE) {
4010                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4011
4012                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
4013                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
4014
4015                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4016         }
4017
4018         LOGD("ret : 0x%x", ret);
4019
4020         return ret;
4021 }
4022
4023
4024 int camera_unset_focus_changed_cb(camera_h camera)
4025 {
4026         int ret = CAMERA_ERROR_NONE;
4027         camera_cli_s *pc = (camera_cli_s *)camera;
4028         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
4029
4030         if (!pc || !pc->cb_info) {
4031                 LOGE("NULL handle");
4032                 return CAMERA_ERROR_INVALID_PARAMETER;
4033         }
4034
4035         LOGD("Enter");
4036
4037         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4038
4039         if (ret == CAMERA_ERROR_NONE) {
4040                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4041
4042                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4043                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4044
4045                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4046         }
4047
4048         LOGD("ret : 0x%x", ret);
4049
4050         return ret;
4051 }
4052
4053
4054 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
4055 {
4056         int ret = CAMERA_ERROR_NONE;
4057         camera_cli_s *pc = (camera_cli_s *)camera;
4058         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
4059
4060         if (!pc || !pc->cb_info || !callback) {
4061                 LOGE("NULL pointer %p %p", pc, callback);
4062                 return CAMERA_ERROR_INVALID_PARAMETER;
4063         }
4064
4065         LOGD("Enter");
4066
4067         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4068
4069         if (ret == CAMERA_ERROR_NONE) {
4070                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4071
4072                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
4073                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
4074
4075                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4076         }
4077
4078         LOGD("ret : 0x%x", ret);
4079
4080         return ret;
4081 }
4082
4083
4084 int camera_unset_error_cb(camera_h camera)
4085 {
4086         int ret = CAMERA_ERROR_NONE;
4087         camera_cli_s *pc = (camera_cli_s *)camera;
4088         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
4089
4090         if (!pc || !pc->cb_info) {
4091                 LOGE("NULL handle");
4092                 return CAMERA_ERROR_INVALID_PARAMETER;
4093         }
4094
4095         LOGD("Enter");
4096
4097         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4098
4099         if (ret == CAMERA_ERROR_NONE) {
4100                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4101
4102                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4103                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4104
4105                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4106         }
4107
4108         LOGD("ret : 0x%x", ret);
4109
4110         return ret;
4111 }
4112
4113
4114 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
4115 {
4116         int ret = CAMERA_ERROR_NONE;
4117         camera_cli_s *pc = (camera_cli_s *)camera;
4118         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
4119
4120         if (!pc || !pc->cb_info || !foreach_cb) {
4121                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4122                 return CAMERA_ERROR_INVALID_PARAMETER;
4123         }
4124
4125         LOGD("Enter");
4126
4127         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = foreach_cb;
4128         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = user_data;
4129
4130         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4131
4132         LOGD("ret : 0x%x", ret);
4133
4134         return ret;
4135 }
4136
4137
4138 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
4139 {
4140         int ret = CAMERA_ERROR_NONE;
4141         camera_cli_s *pc = (camera_cli_s *)camera;
4142         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
4143
4144         if (!pc || !pc->cb_info || !foreach_cb) {
4145                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4146                 return CAMERA_ERROR_INVALID_PARAMETER;
4147         }
4148
4149         LOGD("Enter");
4150
4151         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = foreach_cb;
4152         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = user_data;
4153
4154         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4155
4156         LOGD("ret : 0x%x", ret);
4157
4158         return ret;
4159 }
4160
4161
4162 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
4163 {
4164         int ret = CAMERA_ERROR_NONE;
4165         camera_cli_s *pc = (camera_cli_s *)camera;
4166         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
4167
4168         if (!pc || !pc->cb_info || !foreach_cb) {
4169                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4170                 return CAMERA_ERROR_INVALID_PARAMETER;
4171         }
4172
4173         LOGD("Enter");
4174
4175         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = foreach_cb;
4176         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = user_data;
4177
4178         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4179
4180         LOGD("ret : 0x%x", ret);
4181
4182         return ret;
4183 }
4184
4185
4186 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
4187 {
4188         int ret = CAMERA_ERROR_NONE;
4189         camera_cli_s *pc = (camera_cli_s *)camera;
4190         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
4191
4192         if (!pc || !pc->cb_info || !foreach_cb) {
4193                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4194                 return CAMERA_ERROR_INVALID_PARAMETER;
4195         }
4196
4197         LOGD("Enter");
4198
4199         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = foreach_cb;
4200         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = user_data;
4201
4202         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4203
4204         LOGD("ret : 0x%x", ret);
4205
4206         return ret;
4207 }
4208
4209
4210 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
4211 {
4212         int ret = CAMERA_ERROR_NONE;
4213         camera_cli_s *pc = (camera_cli_s *)camera;
4214         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
4215
4216         if (!pc || !pc->cb_info || !width || !height) {
4217                 LOGE("NULL pointer %p %p %p", pc, width, height);
4218                 return CAMERA_ERROR_INVALID_PARAMETER;
4219         }
4220
4221         LOGD("Enter");
4222         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4223
4224         if (ret == CAMERA_ERROR_NONE) {
4225                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION] >> 16;
4226                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION];
4227         }
4228
4229         LOGD("ret : 0x%x", ret);
4230
4231         return ret;
4232 }
4233
4234
4235 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
4236 {
4237         int ret = CAMERA_ERROR_NONE;
4238         camera_cli_s *pc = (camera_cli_s *)camera;
4239         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
4240
4241         if (!pc || !pc->cb_info || !angle) {
4242                 LOGE("NULL pointer %p %p", pc, angle);
4243                 return CAMERA_ERROR_INVALID_PARAMETER;
4244         }
4245
4246         LOGD("Enter");
4247
4248         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4249
4250         if (ret == CAMERA_ERROR_NONE)
4251                 *angle = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_LENS_ORIENTATION];
4252
4253         LOGD("ret : 0x%x", ret);
4254
4255         return ret;
4256 }
4257
4258
4259 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
4260 {
4261         int ret = CAMERA_ERROR_NONE;
4262         camera_cli_s *pc = (camera_cli_s *)camera;
4263         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_THEATER_MODE;
4264         camera_msg_param param;
4265         int set_mode = (int)mode;
4266
4267         if (!pc || !pc->cb_info) {
4268                 LOGE("NULL handle");
4269                 return CAMERA_ERROR_INVALID_PARAMETER;
4270         }
4271
4272         LOGD("Enter");
4273
4274         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4275
4276         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4277
4278         LOGD("ret : 0x%x", ret);
4279
4280         return ret;
4281 }
4282
4283
4284 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
4285 {
4286         int ret = CAMERA_ERROR_NONE;
4287         camera_cli_s *pc = (camera_cli_s *)camera;
4288         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
4289
4290         if (!pc || !pc->cb_info || !mode) {
4291                 LOGE("NULL pointer %p %p", pc, mode);
4292                 return CAMERA_ERROR_INVALID_PARAMETER;
4293         }
4294
4295         LOGD("Enter");
4296
4297         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4298
4299         if (ret == CAMERA_ERROR_NONE)
4300                 *mode = (camera_attr_theater_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_THEATER_MODE];
4301
4302         LOGD("ret : 0x%x", ret);
4303
4304         return ret;
4305 }
4306
4307
4308 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
4309 {
4310         int ret = CAMERA_ERROR_NONE;
4311         camera_cli_s *pc = (camera_cli_s *)camera;
4312         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
4313
4314         if (!pc || !pc->cb_info || !foreach_cb) {
4315                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4316                 return CAMERA_ERROR_INVALID_PARAMETER;
4317         }
4318
4319         LOGD("Enter");
4320
4321         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = foreach_cb;
4322         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = user_data;
4323
4324         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4325
4326         LOGD("Finish, return :%x", ret);
4327
4328         return ret;
4329 }
4330
4331
4332 int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
4333 {
4334         int ret = CAMERA_ERROR_NONE;
4335         camera_cli_s *pc = (camera_cli_s *)camera;
4336         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
4337         camera_msg_param param;
4338         int set_fps = (int)fps;
4339
4340         if (!pc || !pc->cb_info) {
4341                 LOGE("NULL handle");
4342                 return CAMERA_ERROR_INVALID_PARAMETER;
4343         }
4344
4345         LOGD("Enter");
4346
4347         CAMERA_MSG_PARAM_SET(param, INT, set_fps);
4348
4349         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4350
4351         LOGD("ret : 0x%x", ret);
4352
4353         return ret;
4354 }
4355
4356
4357 int camera_attr_set_image_quality(camera_h camera, int quality)
4358 {
4359         int ret = CAMERA_ERROR_NONE;
4360         camera_cli_s *pc = (camera_cli_s *)camera;
4361         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
4362         camera_msg_param param;
4363
4364         if (!pc || !pc->cb_info) {
4365                 LOGE("NULL handle");
4366                 return CAMERA_ERROR_INVALID_PARAMETER;
4367         }
4368
4369         LOGD("Enter");
4370
4371         CAMERA_MSG_PARAM_SET(param, INT, quality);
4372
4373         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4374
4375         LOGD("ret : 0x%x", ret);
4376
4377         return ret;
4378 }
4379
4380
4381 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
4382 {
4383         int ret = CAMERA_ERROR_NONE;
4384         camera_cli_s *pc = (camera_cli_s *)camera;
4385         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
4386
4387         if (!pc || !pc->cb_info || !fps) {
4388                 LOGE("NULL pointer %p %p", pc, fps);
4389                 return CAMERA_ERROR_INVALID_PARAMETER;
4390         }
4391
4392         LOGD("Enter");
4393
4394         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4395
4396         if (ret == CAMERA_ERROR_NONE)
4397                 *fps = (camera_attr_fps_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FPS];
4398
4399         LOGD("ret : 0x%x", ret);
4400
4401         return ret;
4402 }
4403
4404
4405 int camera_attr_get_image_quality(camera_h camera, int *quality)
4406 {
4407         int ret = CAMERA_ERROR_NONE;
4408         camera_cli_s *pc = (camera_cli_s *)camera;
4409         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
4410
4411         if (!pc || !pc->cb_info || !quality) {
4412                 LOGE("NULL pointer %p %p", pc, quality);
4413                 return CAMERA_ERROR_INVALID_PARAMETER;
4414         }
4415
4416         LOGD("Enter");
4417
4418         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4419
4420         if (ret == CAMERA_ERROR_NONE)
4421                 *quality = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_IMAGE_QUALITY];
4422
4423         LOGD("ret : 0x%x", ret);
4424
4425         return ret;
4426 }
4427
4428
4429 int camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate)
4430 {
4431         int ret = CAMERA_ERROR_NONE;
4432         camera_cli_s *pc = (camera_cli_s *)camera;
4433         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4434
4435         if (!pc || !pc->cb_info || !bitrate) {
4436                 LOGE("NULL pointer %p %p", pc, bitrate);
4437                 return CAMERA_ERROR_INVALID_PARAMETER;
4438         }
4439
4440         LOGD("Enter");
4441
4442         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4443
4444         if (ret == CAMERA_ERROR_NONE)
4445                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE];
4446
4447         LOGD("ret : 0x%x", ret);
4448
4449         return ret;
4450 }
4451
4452
4453 int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
4454 {
4455         int ret = CAMERA_ERROR_NONE;
4456         camera_cli_s *pc = (camera_cli_s *)camera;
4457         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4458         camera_msg_param param;
4459         int set_bitrate = bitrate;
4460
4461         if (!pc || !pc->cb_info) {
4462                 LOGE("NULL handle");
4463                 return CAMERA_ERROR_INVALID_PARAMETER;
4464         }
4465
4466         LOGD("Enter");
4467
4468         CAMERA_MSG_PARAM_SET(param, INT, set_bitrate);
4469
4470         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4471
4472         LOGD("ret : 0x%x", ret);
4473
4474         return ret;
4475 }
4476
4477
4478 int camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval)
4479 {
4480         int ret = CAMERA_ERROR_NONE;
4481         camera_cli_s *pc = (camera_cli_s *)camera;
4482         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4483
4484         if (!pc || !pc->cb_info || !interval) {
4485                 LOGE("NULL pointer %p %p", pc, interval);
4486                 return CAMERA_ERROR_INVALID_PARAMETER;
4487         }
4488
4489         LOGD("Enter");
4490
4491         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4492
4493         if (ret == CAMERA_ERROR_NONE)
4494                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL];
4495
4496         LOGD("ret : 0x%x", ret);
4497
4498         return ret;
4499 }
4500
4501
4502 int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
4503 {
4504         int ret = CAMERA_ERROR_NONE;
4505         camera_cli_s *pc = (camera_cli_s *)camera;
4506         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4507         camera_msg_param param;
4508         int set_gop_interval = interval;
4509
4510         if (!pc || !pc->cb_info) {
4511                 LOGE("NULL handle");
4512                 return CAMERA_ERROR_INVALID_PARAMETER;
4513         }
4514
4515         LOGD("Enter");
4516
4517         CAMERA_MSG_PARAM_SET(param, INT, set_gop_interval);
4518
4519         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4520
4521         LOGD("ret : 0x%x", ret);
4522
4523         return ret;
4524 }
4525
4526
4527 int camera_attr_set_zoom(camera_h camera, int zoom)
4528 {
4529         int ret = CAMERA_ERROR_NONE;
4530         camera_cli_s *pc = (camera_cli_s *)camera;
4531         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
4532         camera_msg_param param;
4533
4534         if (!pc || !pc->cb_info) {
4535                 LOGE("NULL handle");
4536                 return CAMERA_ERROR_INVALID_PARAMETER;
4537         }
4538
4539         LOGD("Enter, remote_handle : %td", pc->remote_handle);
4540
4541         CAMERA_MSG_PARAM_SET(param, INT, zoom);
4542
4543         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4544
4545         LOGD("ret : 0x%x", ret);
4546
4547         return ret;
4548 }
4549
4550
4551 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
4552 {
4553         int ret = CAMERA_ERROR_NONE;
4554         camera_cli_s *pc = (camera_cli_s *)camera;
4555         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_MODE;
4556         camera_msg_param param;
4557         int set_mode = (int)mode;
4558
4559         if (!pc || !pc->cb_info) {
4560                 LOGE("NULL handle");
4561                 return CAMERA_ERROR_INVALID_PARAMETER;
4562         }
4563
4564         LOGD("Enter, remote_handle : %td", pc->remote_handle);
4565
4566         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4567
4568         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4569
4570         return ret;
4571 }
4572
4573
4574 int camera_attr_set_af_area(camera_h camera, int x, int y)
4575 {
4576         int ret = CAMERA_ERROR_NONE;
4577         camera_cli_s *pc = (camera_cli_s *)camera;
4578         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
4579         camera_msg_param param;
4580         int value = 0;
4581
4582         if (!pc || !pc->cb_info) {
4583                 LOGE("NULL handle");
4584                 return CAMERA_ERROR_INVALID_PARAMETER;
4585         }
4586
4587         LOGD("Enter - %d,%d", x, y);
4588
4589         value = (x << 16) | y;
4590         CAMERA_MSG_PARAM_SET(param, INT, value);
4591
4592         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4593
4594         LOGD("ret : 0x%x", ret);
4595
4596         return ret;
4597 }
4598
4599
4600 int camera_attr_clear_af_area(camera_h camera)
4601 {
4602         int ret = CAMERA_ERROR_NONE;
4603         camera_cli_s *pc = (camera_cli_s *)camera;
4604         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
4605
4606         if (!pc || !pc->cb_info) {
4607                 LOGE("NULL handle");
4608                 return CAMERA_ERROR_INVALID_PARAMETER;
4609         }
4610
4611         LOGD("Enter");
4612
4613         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4614
4615         LOGD("ret : 0x%x", ret);
4616
4617         return ret;
4618 }
4619
4620
4621 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
4622 {
4623         int ret = CAMERA_ERROR_NONE;
4624         camera_cli_s *pc = (camera_cli_s *)camera;
4625         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE;
4626         camera_msg_param param;
4627         int set_mode = (int)mode;
4628
4629         if (!pc || !pc->cb_info) {
4630                 LOGE("NULL handle");
4631                 return CAMERA_ERROR_INVALID_PARAMETER;
4632         }
4633
4634         LOGD("Enter");
4635
4636         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4637
4638         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4639
4640         LOGD("ret : 0x%x", ret);
4641
4642         return ret;
4643 }
4644
4645
4646 int camera_attr_set_exposure(camera_h camera, int value)
4647 {
4648         int ret = CAMERA_ERROR_NONE;
4649         camera_cli_s *pc = (camera_cli_s *)camera;
4650         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
4651         camera_msg_param param;
4652
4653         if (!pc || !pc->cb_info) {
4654                 LOGE("NULL handle");
4655                 return CAMERA_ERROR_INVALID_PARAMETER;
4656         }
4657
4658         LOGD("Enter");
4659
4660         CAMERA_MSG_PARAM_SET(param, INT, value);
4661
4662         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4663
4664         LOGD("ret : 0x%x", ret);
4665
4666         return ret;
4667 }
4668
4669
4670 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
4671 {
4672         int ret = CAMERA_ERROR_NONE;
4673         camera_cli_s *pc = (camera_cli_s *)camera;
4674         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
4675         camera_msg_param param;
4676         int set_iso = (int)iso;
4677
4678         if (!pc || !pc->cb_info) {
4679                 LOGE("NULL handle");
4680                 return CAMERA_ERROR_INVALID_PARAMETER;
4681         }
4682
4683         LOGD("Enter");
4684
4685         CAMERA_MSG_PARAM_SET(param, INT, set_iso);
4686
4687         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4688
4689         LOGD("ret : 0x%x", ret);
4690
4691         return ret;
4692 }
4693
4694
4695 int camera_attr_set_brightness(camera_h camera, int level)
4696 {
4697         int ret = CAMERA_ERROR_NONE;
4698         camera_cli_s *pc = (camera_cli_s *)camera;
4699         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
4700         camera_msg_param param;
4701
4702         if (!pc || !pc->cb_info) {
4703                 LOGE("NULL handle");
4704                 return CAMERA_ERROR_INVALID_PARAMETER;
4705         }
4706
4707         LOGD("Enter");
4708
4709         CAMERA_MSG_PARAM_SET(param, INT, level);
4710
4711         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4712
4713         LOGD("ret : 0x%x", ret);
4714
4715         return ret;
4716 }
4717
4718
4719 int camera_attr_set_contrast(camera_h camera, int level)
4720 {
4721         int ret = CAMERA_ERROR_NONE;
4722         camera_cli_s *pc = (camera_cli_s *)camera;
4723         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
4724         camera_msg_param param;
4725
4726         if (!pc || !pc->cb_info) {
4727                 LOGE("NULL handle");
4728                 return CAMERA_ERROR_INVALID_PARAMETER;
4729         }
4730
4731         LOGD("Enter");
4732
4733         CAMERA_MSG_PARAM_SET(param, INT, level);
4734
4735         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4736
4737         LOGD("ret : 0x%x", ret);
4738
4739         return ret;
4740 }
4741
4742
4743 int camera_attr_set_hue(camera_h camera, int level)
4744 {
4745         int ret = CAMERA_ERROR_NONE;
4746         camera_cli_s *pc = (camera_cli_s *)camera;
4747         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
4748         camera_msg_param param;
4749
4750         if (!pc || !pc->cb_info) {
4751                 LOGE("NULL handle");
4752                 return CAMERA_ERROR_INVALID_PARAMETER;
4753         }
4754
4755         LOGD("Enter");
4756
4757         CAMERA_MSG_PARAM_SET(param, INT, level);
4758
4759         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4760
4761         LOGD("ret : 0x%x", ret);
4762
4763         return ret;
4764 }
4765
4766
4767 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
4768 {
4769         int ret = CAMERA_ERROR_NONE;
4770         camera_cli_s *pc = (camera_cli_s *)camera;
4771         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
4772         camera_msg_param param;
4773         int set_whitebalance = (int)wb;
4774
4775         if (!pc || !pc->cb_info) {
4776                 LOGE("NULL handle");
4777                 return CAMERA_ERROR_INVALID_PARAMETER;
4778         }
4779
4780         LOGD("Enter");
4781
4782         CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
4783
4784         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4785
4786         LOGD("ret : 0x%x", ret);
4787
4788         return ret;
4789 }
4790
4791
4792 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
4793 {
4794         int ret = CAMERA_ERROR_NONE;
4795         camera_cli_s *pc = (camera_cli_s *)camera;
4796         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
4797         camera_msg_param param;
4798         int set_effect = (int)effect;
4799
4800         if (!pc || !pc->cb_info) {
4801                 LOGE("NULL handle");
4802                 return CAMERA_ERROR_INVALID_PARAMETER;
4803         }
4804
4805         LOGD("Enter");
4806
4807         CAMERA_MSG_PARAM_SET(param, INT, set_effect);
4808
4809         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4810
4811         LOGD("ret : 0x%x", ret);
4812
4813         return ret;
4814 }
4815
4816
4817 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
4818 {
4819         int ret = CAMERA_ERROR_NONE;
4820         camera_cli_s *pc = (camera_cli_s *)camera;
4821         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_SCENE_MODE;
4822         camera_msg_param param;
4823         int set_mode = (int)mode;
4824
4825         if (!pc || !pc->cb_info) {
4826                 LOGE("NULL handle");
4827                 return CAMERA_ERROR_INVALID_PARAMETER;
4828         }
4829
4830         LOGD("Enter");
4831
4832         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4833
4834         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4835
4836         LOGD("ret : 0x%x", ret);
4837
4838         return ret;
4839 }
4840
4841
4842 int camera_attr_enable_tag(camera_h camera, bool enable)
4843 {
4844         int ret = CAMERA_ERROR_NONE;
4845         camera_cli_s *pc = (camera_cli_s *)camera;
4846         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_TAG;
4847         camera_msg_param param;
4848         int set_enable = (int)enable;
4849
4850         if (!pc || !pc->cb_info) {
4851                 LOGE("NULL handle");
4852                 return CAMERA_ERROR_INVALID_PARAMETER;
4853         }
4854
4855         LOGD("Enter");
4856
4857         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
4858
4859         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4860
4861         LOGD("ret : 0x%x", ret);
4862
4863         return ret;
4864 }
4865
4866
4867 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
4868 {
4869         int ret = CAMERA_ERROR_NONE;
4870         camera_cli_s *pc = (camera_cli_s *)camera;
4871         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
4872         camera_msg_param param;
4873
4874         if (!pc || !pc->cb_info || !description) {
4875                 LOGE("NULL pointer %p %p", pc, description);
4876                 return CAMERA_ERROR_INVALID_PARAMETER;
4877         }
4878
4879         LOGD("Enter");
4880
4881         CAMERA_MSG_PARAM_SET(param, STRING, description);
4882
4883         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4884
4885         LOGD("ret : 0x%x", ret);
4886
4887         return ret;
4888 }
4889
4890
4891 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
4892 {
4893         int ret = CAMERA_ERROR_NONE;
4894         camera_cli_s *pc = (camera_cli_s *)camera;
4895         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
4896         camera_msg_param param;
4897         int set_orientation = (int)orientation;
4898
4899         if (!pc || !pc->cb_info) {
4900                 LOGE("NULL handle");
4901                 return CAMERA_ERROR_INVALID_PARAMETER;
4902         }
4903
4904         LOGD("Enter");
4905
4906         CAMERA_MSG_PARAM_SET(param, INT, set_orientation);
4907
4908         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4909
4910         LOGD("ret : 0x%x", ret);
4911
4912         return ret;
4913 }
4914
4915
4916 int camera_attr_set_tag_software(camera_h camera, const char *software)
4917 {
4918         int ret = CAMERA_ERROR_NONE;
4919         camera_cli_s *pc = (camera_cli_s *)camera;
4920         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
4921         camera_msg_param param;
4922
4923         if (!pc || !pc->cb_info || !software) {
4924                 LOGE("NULL pointer %p %p", pc, software);
4925                 return CAMERA_ERROR_INVALID_PARAMETER;
4926         }
4927
4928         LOGD("Enter, remote_handle : %td", pc->remote_handle);
4929
4930         CAMERA_MSG_PARAM_SET(param, STRING, software);
4931
4932         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4933
4934         LOGD("ret : 0x%x", ret);
4935
4936         return ret;
4937 }
4938
4939
4940 int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, double altitude)
4941 {
4942         int ret = CAMERA_ERROR_NONE;
4943         camera_cli_s *pc = (camera_cli_s *)camera;
4944         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
4945         double set_geotag[3] = {latitude, longitude, altitude};
4946         char *msg = NULL;
4947         int length = 0;
4948         int send_ret = 0;
4949
4950         if (!pc || !pc->cb_info) {
4951                 LOGE("NULL handle");
4952                 return CAMERA_ERROR_INVALID_PARAMETER;
4953         }
4954
4955         LOGD("Enter");
4956
4957         length = sizeof(set_geotag) / sizeof(int) + \
4958                 (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
4959
4960         msg = muse_core_msg_new(api,
4961                 MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
4962                 NULL);
4963         if (!msg) {
4964                 LOGE("msg creation failed: api %d", api);
4965                 return CAMERA_ERROR_OUT_OF_MEMORY;
4966         }
4967
4968         if (pc->cb_info->is_server_connected) {
4969                 __camera_update_api_waiting(pc->cb_info, api, 1);
4970
4971                 g_mutex_lock(&pc->cb_info->fd_lock);
4972                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
4973                 g_mutex_unlock(&pc->cb_info->fd_lock);
4974         }
4975
4976         if (send_ret < 0) {
4977                 LOGE("message send failed");
4978                 ret = CAMERA_ERROR_INVALID_OPERATION;
4979         } else {
4980                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
4981         }
4982
4983         __camera_update_api_waiting(pc->cb_info, api, -1);
4984
4985         muse_core_msg_free(msg);
4986
4987         LOGD("ret : 0x%x", ret);
4988
4989         return ret;
4990 }
4991
4992
4993 int camera_attr_remove_geotag(camera_h camera)
4994 {
4995         int ret = CAMERA_ERROR_NONE;
4996         camera_cli_s *pc = (camera_cli_s *)camera;
4997         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
4998
4999         if (!pc || !pc->cb_info) {
5000                 LOGE("NULL handle");
5001                 return CAMERA_ERROR_INVALID_PARAMETER;
5002         }
5003
5004         LOGD("Enter");
5005
5006         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5007
5008         LOGD("ret : 0x%x", ret);
5009
5010         return ret;
5011 }
5012
5013
5014 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
5015 {
5016         int ret = CAMERA_ERROR_NONE;
5017         camera_cli_s *pc = (camera_cli_s *)camera;
5018         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
5019         camera_msg_param param;
5020         int set_mode = (int)mode;
5021
5022         if (!pc || !pc->cb_info) {
5023                 LOGE("NULL handle");
5024                 return CAMERA_ERROR_INVALID_PARAMETER;
5025         }
5026
5027         LOGD("Enter");
5028
5029         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
5030
5031         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5032
5033         LOGD("ret : 0x%x", ret);
5034
5035         return ret;
5036 }
5037
5038
5039 int camera_attr_get_zoom(camera_h camera, int *zoom)
5040 {
5041         int ret = CAMERA_ERROR_NONE;
5042         camera_cli_s *pc = (camera_cli_s *)camera;
5043         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
5044
5045         if (!pc || !pc->cb_info || !zoom) {
5046                 LOGE("NULL pointer %p %p", pc, zoom);
5047                 return CAMERA_ERROR_INVALID_PARAMETER;
5048         }
5049
5050         LOGD("Enter");
5051
5052         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5053
5054         if (ret == CAMERA_ERROR_NONE)
5055                 *zoom = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ZOOM];
5056
5057         LOGD("ret : 0x%x", ret);
5058
5059         return ret;
5060 }
5061
5062
5063 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
5064 {
5065         int ret = CAMERA_ERROR_NONE;
5066         camera_cli_s *pc = (camera_cli_s *)camera;
5067         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
5068
5069         if (!pc || !pc->cb_info || !min || !max) {
5070                 LOGE("NULL pointer %p %p %p", pc, min, max);
5071                 return CAMERA_ERROR_INVALID_PARAMETER;
5072         }
5073
5074         LOGD("Enter");
5075
5076         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5077
5078         if (ret == CAMERA_ERROR_NONE) {
5079                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
5080                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
5081         }
5082
5083         LOGD("ret : 0x%x", ret);
5084
5085         return ret;
5086 }
5087
5088
5089 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
5090 {
5091         int ret = CAMERA_ERROR_NONE;
5092         camera_cli_s *pc = (camera_cli_s *)camera;
5093         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
5094
5095         if (!pc || !pc->cb_info || !mode) {
5096                 LOGE("NULL pointer %p %p", pc, mode);
5097                 return CAMERA_ERROR_INVALID_PARAMETER;
5098         }
5099
5100         LOGD("Enter");
5101
5102         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5103
5104         if (ret == CAMERA_ERROR_NONE)
5105                 *mode = (camera_attr_af_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_AF_MODE];
5106
5107         LOGD("ret : 0x%x", ret);
5108
5109         return ret;
5110 }
5111
5112
5113 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
5114 {
5115         int ret = CAMERA_ERROR_NONE;
5116         camera_cli_s *pc = (camera_cli_s *)camera;
5117         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
5118
5119         if (!pc || !pc->cb_info || !mode) {
5120                 LOGE("NULL pointer %p %p", pc, mode);
5121                 return CAMERA_ERROR_INVALID_PARAMETER;
5122         }
5123
5124         LOGD("Enter");
5125
5126         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5127
5128         if (ret == CAMERA_ERROR_NONE)
5129                 *mode = (camera_attr_exposure_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE_MODE];
5130
5131         LOGD("ret : 0x%x", ret);
5132
5133         return ret;
5134 }
5135
5136
5137 int camera_attr_get_exposure(camera_h camera, int *value)
5138 {
5139         int ret = CAMERA_ERROR_NONE;
5140         camera_cli_s *pc = (camera_cli_s *)camera;
5141         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
5142
5143         if (!pc || !pc->cb_info || !value) {
5144                 LOGE("NULL pointer %p %p", pc, value);
5145                 return CAMERA_ERROR_INVALID_PARAMETER;
5146         }
5147
5148         LOGD("Enter");
5149
5150         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5151
5152         if (ret == CAMERA_ERROR_NONE)
5153                 *value = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE];
5154
5155         LOGD("ret : 0x%x", ret);
5156
5157         return ret;
5158 }
5159
5160
5161 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
5162 {
5163         int ret = CAMERA_ERROR_NONE;
5164         camera_cli_s *pc = (camera_cli_s *)camera;
5165         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
5166
5167         if (!pc || !pc->cb_info || !min || !max) {
5168                 LOGE("NULL pointer %p %p %p", pc, min, max);
5169                 return CAMERA_ERROR_INVALID_PARAMETER;
5170         }
5171
5172         LOGD("Enter");
5173
5174         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5175
5176         if (ret == CAMERA_ERROR_NONE) {
5177                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
5178                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
5179         }
5180
5181         LOGD("ret : 0x%x", ret);
5182
5183         return ret;
5184 }
5185
5186
5187 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
5188 {
5189         int ret = CAMERA_ERROR_NONE;
5190         camera_cli_s *pc = (camera_cli_s *)camera;
5191         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
5192
5193         if (!pc || !pc->cb_info || !iso) {
5194                 LOGE("NULL pointer %p %p", pc, iso);
5195                 return CAMERA_ERROR_INVALID_PARAMETER;
5196         }
5197
5198         LOGD("Enter");
5199
5200         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5201
5202         if (ret == CAMERA_ERROR_NONE)
5203                 *iso = (camera_attr_iso_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ISO];
5204
5205         LOGD("ret : 0x%x", ret);
5206
5207         return ret;
5208 }
5209
5210
5211 int camera_attr_get_brightness(camera_h camera, int *level)
5212 {
5213         int ret = CAMERA_ERROR_NONE;
5214         camera_cli_s *pc = (camera_cli_s *)camera;
5215         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
5216
5217         if (!pc || !pc->cb_info || !level) {
5218                 LOGE("NULL pointer %p %p", pc, level);
5219                 return CAMERA_ERROR_INVALID_PARAMETER;
5220         }
5221
5222         LOGD("Enter");
5223
5224         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5225
5226         if (ret == CAMERA_ERROR_NONE)
5227                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
5228
5229         LOGD("ret : 0x%x", ret);
5230
5231         return ret;
5232 }
5233
5234
5235 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
5236 {
5237         int ret = CAMERA_ERROR_NONE;
5238         camera_cli_s *pc = (camera_cli_s *)camera;
5239         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
5240
5241         if (!pc || !pc->cb_info || !min || !max) {
5242                 LOGE("NULL pointer %p %p %p", pc, min, max);
5243                 return CAMERA_ERROR_INVALID_PARAMETER;
5244         }
5245
5246         LOGD("Enter");
5247
5248         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5249
5250         if (ret == CAMERA_ERROR_NONE) {
5251                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
5252                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
5253         }
5254
5255         LOGD("ret : 0x%x", ret);
5256
5257         return ret;
5258 }
5259
5260
5261 int camera_attr_get_contrast(camera_h camera, int *level)
5262 {
5263         int ret = CAMERA_ERROR_NONE;
5264         camera_cli_s *pc = (camera_cli_s *)camera;
5265         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
5266
5267         if (!pc || !pc->cb_info || !level) {
5268                 LOGE("NULL pointer %p %p", pc, level);
5269                 return CAMERA_ERROR_INVALID_PARAMETER;
5270         }
5271
5272         LOGD("Enter");
5273
5274         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5275
5276         if (ret == CAMERA_ERROR_NONE)
5277                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
5278
5279         LOGD("ret : 0x%x", ret);
5280
5281         return ret;
5282 }
5283
5284
5285 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
5286 {
5287         int ret = CAMERA_ERROR_NONE;
5288         camera_cli_s *pc = (camera_cli_s *)camera;
5289         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
5290
5291         if (!pc || !pc->cb_info || !min || !max) {
5292                 LOGE("NULL pointer %p %p %p", pc, min, max);
5293                 return CAMERA_ERROR_INVALID_PARAMETER;
5294         }
5295
5296         LOGD("Enter");
5297
5298         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5299
5300         if (ret == CAMERA_ERROR_NONE) {
5301                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
5302                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
5303                 LOGD("min %d, max %d", *min, *max);
5304         }
5305
5306         LOGD("ret : 0x%x", ret);
5307
5308         return ret;
5309 }
5310
5311
5312 int camera_attr_get_hue(camera_h camera, int *level)
5313 {
5314         int ret = CAMERA_ERROR_NONE;
5315         camera_cli_s *pc = (camera_cli_s *)camera;
5316         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
5317
5318         if (!pc || !pc->cb_info || !level) {
5319                 LOGE("NULL pointer %p %p", pc, level);
5320                 return CAMERA_ERROR_INVALID_PARAMETER;
5321         }
5322
5323         LOGD("Enter");
5324
5325         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5326
5327         if (ret == CAMERA_ERROR_NONE)
5328                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
5329
5330         LOGD("ret : 0x%x", ret);
5331
5332         return ret;
5333 }
5334
5335
5336 int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
5337 {
5338         int ret = CAMERA_ERROR_NONE;
5339         camera_cli_s *pc = (camera_cli_s *)camera;
5340         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
5341
5342         if (!pc || !pc->cb_info || !min || !max) {
5343                 LOGE("NULL pointer %p %p %p", pc, min, max);
5344                 return CAMERA_ERROR_INVALID_PARAMETER;
5345         }
5346
5347         LOGD("Enter");
5348
5349         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5350
5351         if (ret == CAMERA_ERROR_NONE) {
5352                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
5353                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
5354                 LOGD("min %d, max %d", *min, *max);
5355         }
5356
5357         LOGD("ret : 0x%x", ret);
5358
5359         return ret;
5360 }
5361
5362
5363 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
5364 {
5365         int ret = CAMERA_ERROR_NONE;
5366         camera_cli_s *pc = (camera_cli_s *)camera;
5367         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
5368
5369         if (!pc || !pc->cb_info || !wb) {
5370                 LOGE("NULL pointer %p %p", pc, wb);
5371                 return CAMERA_ERROR_INVALID_PARAMETER;
5372         }
5373
5374         LOGD("Enter");
5375
5376         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5377
5378         if (ret == CAMERA_ERROR_NONE)
5379                 *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
5380
5381         LOGD("ret : 0x%x", ret);
5382
5383         return ret;
5384 }
5385
5386
5387 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
5388 {
5389         int ret = CAMERA_ERROR_NONE;
5390         camera_cli_s *pc = (camera_cli_s *)camera;
5391         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
5392
5393         if (!pc || !pc->cb_info || !effect) {
5394                 LOGE("NULL pointer %p %p", pc, effect);
5395                 return CAMERA_ERROR_INVALID_PARAMETER;
5396         }
5397
5398         LOGD("Enter");
5399
5400         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5401
5402         if (ret == CAMERA_ERROR_NONE)
5403                 *effect = (camera_attr_effect_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EFFECT];
5404
5405         LOGD("ret : 0x%x", ret);
5406
5407         return ret;
5408 }
5409
5410
5411 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
5412 {
5413         int ret = CAMERA_ERROR_NONE;
5414         camera_cli_s *pc = (camera_cli_s *)camera;
5415         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
5416
5417         if (!pc || !pc->cb_info || !mode) {
5418                 LOGE("NULL pointer %p %p", pc, mode);
5419                 return CAMERA_ERROR_INVALID_PARAMETER;
5420         }
5421
5422         LOGD("Enter");
5423
5424         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5425
5426         if (ret == CAMERA_ERROR_NONE)
5427                 *mode = (camera_attr_scene_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_SCENE_MODE];
5428
5429         LOGD("ret : 0x%x", ret);
5430
5431         return ret;
5432 }
5433
5434
5435 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
5436 {
5437         int ret = CAMERA_ERROR_NONE;
5438         camera_cli_s *pc = (camera_cli_s *)camera;
5439         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
5440
5441         if (!pc || !pc->cb_info || !enable) {
5442                 LOGE("NULL pointer %p %p", pc, enable);
5443                 return CAMERA_ERROR_INVALID_PARAMETER;
5444         }
5445
5446         LOGD("Enter");
5447
5448         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5449
5450         if (ret == CAMERA_ERROR_NONE)
5451                 *enable = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_TAG];
5452
5453         LOGD("ret : 0x%x", ret);
5454
5455         return ret;
5456 }
5457
5458
5459 int camera_attr_get_tag_image_description(camera_h camera, char **description)
5460 {
5461         int ret = CAMERA_ERROR_NONE;
5462         camera_cli_s *pc = (camera_cli_s *)camera;
5463         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
5464
5465         if (!pc || !pc->cb_info || !description) {
5466                 LOGE("NULL pointer %p %p", pc, description);
5467                 return CAMERA_ERROR_INVALID_PARAMETER;
5468         }
5469
5470         LOGD("Enter");
5471
5472         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5473
5474         if (ret == CAMERA_ERROR_NONE)
5475                 *description = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION]);
5476
5477         LOGD("ret : 0x%x", ret);
5478
5479         return ret;
5480 }
5481
5482
5483 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
5484 {
5485         int ret = CAMERA_ERROR_NONE;
5486         camera_cli_s *pc = (camera_cli_s *)camera;
5487         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
5488
5489         if (!pc || !pc->cb_info || !orientation) {
5490                 LOGE("NULL pointer %p %p", pc, orientation);
5491                 return CAMERA_ERROR_INVALID_PARAMETER;
5492         }
5493
5494         LOGD("Enter");
5495
5496         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5497
5498         if (ret == CAMERA_ERROR_NONE)
5499                 *orientation = (camera_attr_tag_orientation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TAG_ORIENTATION];
5500
5501         LOGD("ret : 0x%x", ret);
5502
5503         return ret;
5504 }
5505
5506
5507 int camera_attr_get_tag_software(camera_h camera, char **software)
5508 {
5509         int ret = CAMERA_ERROR_NONE;
5510         camera_cli_s *pc = (camera_cli_s *)camera;
5511         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
5512
5513         if (!pc || !pc->cb_info || !software) {
5514                 LOGE("NULL pointer %p %p", pc, software);
5515                 return CAMERA_ERROR_INVALID_PARAMETER;
5516         }
5517
5518         LOGD("Enter");
5519
5520         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5521
5522         if (ret == CAMERA_ERROR_NONE)
5523                 *software = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_SOFTWARE]);
5524
5525         LOGD("ret : 0x%x", ret);
5526
5527         return ret;
5528 }
5529
5530
5531 int camera_attr_get_geotag(camera_h camera, double *latitude, double *longitude, double *altitude)
5532 {
5533         int ret = CAMERA_ERROR_NONE;
5534         camera_cli_s *pc = (camera_cli_s *)camera;
5535         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
5536
5537         if (!pc || !pc->cb_info || !latitude || !longitude || !altitude) {
5538                 LOGE("NULL pointer %p %p %p %p", pc, latitude, longitude, altitude);
5539                 return CAMERA_ERROR_INVALID_PARAMETER;
5540         }
5541
5542         LOGD("Enter");
5543
5544         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5545
5546         if (ret == CAMERA_ERROR_NONE) {
5547                 *latitude = pc->cb_info->get_geotag[0];
5548                 *longitude = pc->cb_info->get_geotag[1];
5549                 *altitude = pc->cb_info->get_geotag[2];
5550         }
5551
5552         LOGD("ret : 0x%x", ret);
5553
5554         return ret;
5555 }
5556
5557
5558 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
5559 {
5560         int ret = CAMERA_ERROR_NONE;
5561         camera_cli_s *pc = (camera_cli_s *)camera;
5562         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
5563
5564         if (!pc || !pc->cb_info || !mode) {
5565                 LOGE("NULL pointer %p %p", pc, mode);
5566                 return CAMERA_ERROR_INVALID_PARAMETER;
5567         }
5568
5569         LOGD("Enter");
5570
5571         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5572
5573         if (ret == CAMERA_ERROR_NONE)
5574                 *mode = (camera_attr_flash_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_MODE];
5575
5576         LOGD("ret : 0x%x", ret);
5577
5578         return ret;
5579 }
5580
5581
5582 int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state)
5583 {
5584         int ret = CAMERA_ERROR_NONE;
5585         int get_flash_state = 0;
5586
5587         if (!state) {
5588                 LOGE("NULL pointer");
5589                 return CAMERA_ERROR_INVALID_PARAMETER;
5590         }
5591
5592         ret = _camera_independent_request(MUSE_CAMERA_API_GET_FLASH_STATE,
5593                 (int)device, "get_flash_state", &get_flash_state);
5594
5595         if (ret == CAMERA_ERROR_NONE) {
5596                 *state = (camera_flash_state_e)get_flash_state;
5597                 LOGD("flash state %d", *state);
5598         } else {
5599                 LOGE("failed 0x%x", ret);
5600         }
5601
5602         return ret;
5603 }
5604
5605
5606 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
5607 {
5608         int ret = CAMERA_ERROR_NONE;
5609         camera_cli_s *pc = (camera_cli_s *)camera;
5610         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
5611
5612         if (!pc || !pc->cb_info || !foreach_cb) {
5613                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5614                 return CAMERA_ERROR_INVALID_PARAMETER;
5615         }
5616
5617         LOGD("Enter");
5618
5619         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = foreach_cb;
5620         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = user_data;
5621
5622         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5623
5624         LOGD("ret : 0x%x", ret);
5625
5626         return ret;
5627 }
5628
5629
5630 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
5631 {
5632         int ret = CAMERA_ERROR_NONE;
5633         camera_cli_s *pc = (camera_cli_s *)camera;
5634         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
5635
5636         if (!pc || !pc->cb_info || !foreach_cb) {
5637                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5638                 return CAMERA_ERROR_INVALID_PARAMETER;
5639         }
5640
5641         LOGD("Enter");
5642
5643         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = foreach_cb;
5644         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = user_data;
5645
5646         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5647
5648         LOGD("ret : 0x%x", ret);
5649
5650         return ret;
5651 }
5652
5653
5654 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
5655 {
5656         int ret = CAMERA_ERROR_NONE;
5657         camera_cli_s *pc = (camera_cli_s *)camera;
5658         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
5659
5660         if (!pc || !pc->cb_info || !foreach_cb) {
5661                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5662                 return CAMERA_ERROR_INVALID_PARAMETER;
5663         }
5664
5665         LOGD("Enter");
5666
5667         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = foreach_cb;
5668         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = user_data;
5669
5670         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5671
5672         LOGD("ret : 0x%x", ret);
5673
5674         return ret;
5675 }
5676
5677
5678 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
5679 {
5680         int ret = CAMERA_ERROR_NONE;
5681         camera_cli_s *pc = (camera_cli_s *)camera;
5682         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
5683
5684         if (!pc || !pc->cb_info || !foreach_cb) {
5685                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5686                 return CAMERA_ERROR_INVALID_PARAMETER;
5687         }
5688
5689         LOGD("Enter");
5690
5691         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = foreach_cb;
5692         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = user_data;
5693
5694         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5695
5696         LOGD("ret : 0x%x", ret);
5697
5698         return ret;
5699 }
5700
5701
5702 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
5703 {
5704         int ret = CAMERA_ERROR_NONE;
5705         camera_cli_s *pc = (camera_cli_s *)camera;
5706         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
5707
5708         if (!pc || !pc->cb_info || !foreach_cb) {
5709                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5710                 return CAMERA_ERROR_INVALID_PARAMETER;
5711         }
5712
5713         LOGD("Enter");
5714
5715         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = foreach_cb;
5716         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = user_data;
5717
5718         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5719
5720         LOGD("ret : 0x%x", ret);
5721
5722         return ret;
5723 }
5724
5725
5726 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
5727 {
5728         int ret = CAMERA_ERROR_NONE;
5729         camera_cli_s *pc = (camera_cli_s *)camera;
5730         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
5731
5732         if (!pc || !pc->cb_info || !foreach_cb) {
5733                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5734                 return CAMERA_ERROR_INVALID_PARAMETER;
5735         }
5736
5737         LOGD("Enter");
5738
5739         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = foreach_cb;
5740         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = user_data;
5741
5742         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5743
5744         LOGD("ret : 0x%x", ret);
5745
5746         return ret;
5747 }
5748
5749
5750 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
5751 {
5752         int ret = CAMERA_ERROR_NONE;
5753         camera_cli_s *pc = (camera_cli_s *)camera;
5754         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
5755
5756         if (!pc || !pc->cb_info || !foreach_cb) {
5757                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5758                 return CAMERA_ERROR_INVALID_PARAMETER;
5759         }
5760
5761         LOGD("Enter");
5762
5763         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = foreach_cb;
5764         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = user_data;
5765
5766         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5767
5768         LOGD("ret : 0x%x", ret);
5769
5770         return ret;
5771 }
5772
5773
5774 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5775 {
5776         int ret = CAMERA_ERROR_NONE;
5777         camera_cli_s *pc = (camera_cli_s *)camera;
5778         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
5779
5780         if (!pc || !pc->cb_info || !foreach_cb) {
5781                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5782                 return CAMERA_ERROR_INVALID_PARAMETER;
5783         }
5784
5785         LOGD("Enter");
5786
5787         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = foreach_cb;
5788         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = user_data;
5789
5790         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5791
5792         LOGD("Enter, handle :%td", pc->remote_handle);
5793
5794         return ret;
5795 }
5796
5797
5798 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)
5799 {
5800         int ret = CAMERA_ERROR_NONE;
5801         camera_cli_s *pc = (camera_cli_s *)camera;
5802         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
5803         camera_msg_param param;
5804         int value = 0;
5805
5806         if (!pc || !pc->cb_info || !foreach_cb) {
5807                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5808                 return CAMERA_ERROR_INVALID_PARAMETER;
5809         }
5810
5811         LOGD("Enter");
5812
5813         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = foreach_cb;
5814         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = user_data;
5815
5816         value = (width << 16) | height;
5817         CAMERA_MSG_PARAM_SET(param, INT, value);
5818
5819         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5820
5821         LOGD("ret : 0x%x", ret);
5822
5823         return ret;
5824 }
5825
5826
5827 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
5828 {
5829         int ret = CAMERA_ERROR_NONE;
5830         camera_cli_s *pc = (camera_cli_s *)camera;
5831         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
5832
5833         if (!pc || !pc->cb_info || !foreach_cb) {
5834                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5835                 return CAMERA_ERROR_INVALID_PARAMETER;
5836         }
5837
5838         LOGD("Enter");
5839
5840         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = foreach_cb;
5841         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = user_data;
5842
5843         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5844
5845         LOGD("ret : 0x%x", ret);
5846
5847         return ret;
5848 }
5849
5850
5851 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
5852 {
5853         int ret = CAMERA_ERROR_NONE;
5854         camera_cli_s *pc = (camera_cli_s *)camera;
5855         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
5856
5857         if (!pc || !pc->cb_info || !foreach_cb) {
5858                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5859                 return CAMERA_ERROR_INVALID_PARAMETER;
5860         }
5861
5862         LOGD("Enter");
5863
5864         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = foreach_cb;
5865         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = user_data;
5866
5867         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5868
5869         LOGD("ret : 0x%x", ret);
5870
5871         return ret;
5872 }
5873
5874
5875 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
5876 {
5877         int ret = CAMERA_ERROR_NONE;
5878         camera_cli_s *pc = (camera_cli_s *)camera;
5879         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
5880         camera_msg_param param;
5881         int set_rotation = (int)rotation;
5882
5883         if (!pc || !pc->cb_info) {
5884                 LOGE("NULL handle");
5885                 return CAMERA_ERROR_INVALID_PARAMETER;
5886         }
5887
5888         LOGD("Enter");
5889
5890         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
5891
5892         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5893
5894         LOGD("ret : 0x%x", ret);
5895
5896         return ret;
5897 }
5898
5899
5900 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
5901 {
5902         int ret = CAMERA_ERROR_NONE;
5903         camera_cli_s *pc = (camera_cli_s *)camera;
5904         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
5905
5906         if (!pc || !pc->cb_info || !rotation) {
5907                 LOGE("NULL pointer %p %p", pc, rotation);
5908                 return CAMERA_ERROR_INVALID_PARAMETER;
5909         }
5910
5911         LOGD("Enter");
5912
5913         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5914
5915         if (ret == CAMERA_ERROR_NONE)
5916                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_ROTATION];
5917
5918         LOGD("ret : 0x%x", ret);
5919
5920         return ret;
5921 }
5922
5923
5924 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
5925 {
5926         int ret = CAMERA_ERROR_NONE;
5927         camera_cli_s *pc = (camera_cli_s *)camera;
5928         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
5929         camera_msg_param param;
5930         int set_flip = (int)flip;
5931
5932         if (!pc || !pc->cb_info) {
5933                 LOGE("NULL handle");
5934                 return CAMERA_ERROR_INVALID_PARAMETER;
5935         }
5936
5937         LOGD("Enter");
5938
5939         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
5940
5941         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5942
5943         LOGD("ret : 0x%x", ret);
5944
5945         return ret;
5946 }
5947
5948
5949 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
5950 {
5951         int ret = CAMERA_ERROR_NONE;
5952         camera_cli_s *pc = (camera_cli_s *)camera;
5953         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
5954
5955         if (!pc || !pc->cb_info || !flip) {
5956                 LOGE("NULL pointer %p %p", pc, flip);
5957                 return CAMERA_ERROR_INVALID_PARAMETER;
5958         }
5959
5960         LOGD("Enter");
5961
5962         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5963
5964         if (ret == CAMERA_ERROR_NONE)
5965                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_FLIP];
5966
5967         LOGD("ret : 0x%x", ret);
5968
5969         return ret;
5970 }
5971
5972 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
5973 {
5974         int ret = CAMERA_ERROR_NONE;
5975         camera_cli_s *pc = (camera_cli_s *)camera;
5976         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_MODE;
5977         camera_msg_param param;
5978         int set_mode = (int)mode;
5979
5980         if (!pc || !pc->cb_info) {
5981                 LOGE("NULL handle");
5982                 return CAMERA_ERROR_INVALID_PARAMETER;
5983         }
5984
5985         LOGD("Enter");
5986
5987         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
5988
5989         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5990
5991         LOGD("ret : 0x%x", ret);
5992
5993         return ret;
5994 }
5995
5996
5997 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
5998 {
5999         int ret = CAMERA_ERROR_NONE;
6000         camera_cli_s *pc = (camera_cli_s *)camera;
6001         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
6002
6003         if (!pc || !pc->cb_info || !mode) {
6004                 LOGE("NULL pointer %p %p", pc, mode);
6005                 return CAMERA_ERROR_INVALID_PARAMETER;
6006         }
6007
6008         LOGD("Enter");
6009
6010         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6011
6012         if (ret == CAMERA_ERROR_NONE)
6013                 *mode = (camera_attr_hdr_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HDR_MODE];
6014
6015         LOGD("ret : 0x%x", ret);
6016
6017         return ret;
6018 }
6019
6020
6021 bool camera_attr_is_supported_hdr_capture(camera_h camera)
6022 {
6023         int ret = CAMERA_ERROR_NONE;
6024         camera_cli_s *pc = (camera_cli_s *)camera;
6025         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE;
6026
6027         if (!pc || !pc->cb_info) {
6028                 LOGE("NULL handle");
6029                 return CAMERA_ERROR_INVALID_PARAMETER;
6030         }
6031
6032         LOGD("Enter");
6033
6034         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6035
6036         if (ret < 0) {
6037                 LOGE("error is occurred 0x%x", ret);
6038                 ret = false;
6039         }
6040
6041         LOGD("ret : %d", ret);
6042
6043         return (bool)ret;
6044 }
6045
6046
6047 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
6048 {
6049         int ret = CAMERA_ERROR_NONE;
6050         camera_cli_s *pc = (camera_cli_s *)camera;
6051         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
6052
6053         if (!pc || !pc->cb_info) {
6054                 LOGE("NULL handle");
6055                 return CAMERA_ERROR_INVALID_PARAMETER;
6056         }
6057
6058         LOGD("Enter");
6059
6060         if (!camera_attr_is_supported_hdr_capture(camera)) {
6061                 LOGE("HDR not supported");
6062                 return CAMERA_ERROR_NOT_SUPPORTED;
6063         }
6064
6065         if (!callback) {
6066                 LOGE("NULL callback");
6067                 return CAMERA_ERROR_INVALID_PARAMETER;
6068         }
6069
6070         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6071
6072         if (ret == CAMERA_ERROR_NONE) {
6073                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6074
6075                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
6076                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
6077
6078                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6079         }
6080
6081         LOGD("ret : 0x%x", ret);
6082
6083         return ret;
6084 }
6085
6086
6087 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
6088 {
6089         int ret = CAMERA_ERROR_NONE;
6090         camera_cli_s *pc = (camera_cli_s *)camera;
6091         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
6092
6093         if (!pc || !pc->cb_info) {
6094                 LOGE("NULL handle");
6095                 return CAMERA_ERROR_INVALID_PARAMETER;
6096         }
6097
6098         LOGD("Enter");
6099
6100         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6101
6102         if (ret == CAMERA_ERROR_NONE) {
6103                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6104
6105                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
6106                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
6107
6108                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6109         }
6110
6111         LOGD("ret : 0x%x", ret);
6112
6113         return ret;
6114 }
6115
6116
6117 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
6118 {
6119         int ret = CAMERA_ERROR_NONE;
6120         camera_cli_s *pc = (camera_cli_s *)camera;
6121         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE;
6122         camera_msg_param param;
6123         int set_enable = (int)enable;
6124
6125         if (!pc || !pc->cb_info) {
6126                 LOGE("NULL handle");
6127                 return CAMERA_ERROR_INVALID_PARAMETER;
6128         }
6129
6130         LOGD("Enter");
6131
6132         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6133
6134         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6135
6136         LOGD("ret : 0x%x", ret);
6137
6138         return ret;
6139 }
6140
6141
6142 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
6143 {
6144         int ret = CAMERA_ERROR_NONE;
6145         camera_cli_s *pc = (camera_cli_s *)camera;
6146         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
6147
6148         if (!pc || !pc->cb_info || !enabled) {
6149                 LOGE("NULL pointer %p %p", pc, enabled);
6150                 return CAMERA_ERROR_INVALID_PARAMETER;
6151         }
6152
6153         LOGD("Enter");
6154
6155         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6156
6157         if (ret == CAMERA_ERROR_NONE)
6158                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE];
6159
6160         LOGD("ret : 0x%x", ret);
6161
6162         return ret;
6163 }
6164
6165
6166 bool camera_attr_is_supported_anti_shake(camera_h camera)
6167 {
6168         int ret = CAMERA_ERROR_NONE;
6169         camera_cli_s *pc = (camera_cli_s *)camera;
6170         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE;
6171
6172         if (!pc || !pc->cb_info) {
6173                 LOGE("NULL handle");
6174                 return CAMERA_ERROR_INVALID_PARAMETER;
6175         }
6176
6177         LOGD("Enter");
6178
6179         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6180
6181         if (ret < 0) {
6182                 LOGE("error is occurred 0x%x", ret);
6183                 ret = false;
6184         }
6185
6186         LOGD("ret : %d", ret);
6187
6188         return (bool)ret;
6189 }
6190
6191
6192 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
6193 {
6194         int ret = CAMERA_ERROR_NONE;
6195         camera_cli_s *pc = (camera_cli_s *)camera;
6196         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION;
6197         camera_msg_param param;
6198         int set_enable = (int)enable;
6199
6200         if (!pc || !pc->cb_info) {
6201                 LOGE("NULL handle");
6202                 return CAMERA_ERROR_INVALID_PARAMETER;
6203         }
6204
6205         LOGD("Enter");
6206
6207         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6208
6209         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6210
6211         LOGD("ret : 0x%x", ret);
6212
6213         return ret;
6214 }
6215
6216
6217 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
6218 {
6219         int ret = CAMERA_ERROR_NONE;
6220         camera_cli_s *pc = (camera_cli_s *)camera;
6221         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
6222
6223         if (!pc || !pc->cb_info || !enabled) {
6224                 LOGE("NULL pointer %p %p", pc, enabled);
6225                 return CAMERA_ERROR_INVALID_PARAMETER;
6226         }
6227
6228         LOGD("Enter");
6229
6230         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6231
6232         if (ret == CAMERA_ERROR_NONE)
6233                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION];
6234
6235         LOGD("ret : 0x%x", ret);
6236
6237         return ret;
6238 }
6239
6240
6241 bool camera_attr_is_supported_video_stabilization(camera_h camera)
6242 {
6243         int ret = CAMERA_ERROR_NONE;
6244         camera_cli_s *pc = (camera_cli_s *)camera;
6245         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION;
6246
6247         if (!pc || !pc->cb_info) {
6248                 LOGE("NULL handle");
6249                 return CAMERA_ERROR_INVALID_PARAMETER;
6250         }
6251
6252         LOGD("Enter");
6253
6254         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6255
6256         if (ret < 0) {
6257                 LOGE("error is occurred 0x%x", ret);
6258                 ret = false;
6259         }
6260
6261         LOGD("ret : %d", ret);
6262
6263         return (bool)ret;
6264 }
6265
6266
6267 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
6268 {
6269         int ret = CAMERA_ERROR_NONE;
6270         camera_cli_s *pc = (camera_cli_s *)camera;
6271         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST;
6272         camera_msg_param param;
6273         int set_enable = (int)enable;
6274
6275         if (!pc || !pc->cb_info) {
6276                 LOGE("NULL handle");
6277                 return CAMERA_ERROR_INVALID_PARAMETER;
6278         }
6279
6280         LOGD("Enter");
6281
6282         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6283
6284         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6285
6286         LOGD("ret : 0x%x", ret);
6287
6288         return ret;
6289 }
6290
6291
6292 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
6293 {
6294         int ret = CAMERA_ERROR_NONE;
6295         camera_cli_s *pc = (camera_cli_s *)camera;
6296         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
6297
6298         if (!pc || !pc->cb_info || !enabled) {
6299                 LOGE("NULL pointer %p %p", pc, enabled);
6300                 return CAMERA_ERROR_INVALID_PARAMETER;
6301         }
6302
6303         LOGD("Enter");
6304
6305         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6306
6307         if (ret == CAMERA_ERROR_NONE)
6308                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST];
6309
6310         LOGD("ret : 0x%x", ret);
6311
6312         return ret;
6313 }
6314
6315
6316 bool camera_attr_is_supported_auto_contrast(camera_h camera)
6317 {
6318         int ret = CAMERA_ERROR_NONE;
6319         camera_cli_s *pc = (camera_cli_s *)camera;
6320         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST;
6321
6322         if (!pc || !pc->cb_info) {
6323                 LOGE("NULL handle");
6324                 return CAMERA_ERROR_INVALID_PARAMETER;
6325         }
6326
6327         LOGD("Enter");
6328
6329         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6330
6331         if (ret < 0) {
6332                 LOGE("error is occurred 0x%x", ret);
6333                 ret = false;
6334         }
6335
6336         LOGD("ret : %d", ret);
6337
6338         return (bool)ret;
6339 }
6340
6341
6342 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
6343 {
6344         int ret = CAMERA_ERROR_NONE;
6345         camera_cli_s *pc = (camera_cli_s *)camera;
6346         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
6347         camera_msg_param param;
6348         int set_disable = (int)disable;
6349
6350         if (!pc || !pc->cb_info) {
6351                 LOGE("NULL handle");
6352                 return CAMERA_ERROR_INVALID_PARAMETER;
6353         }
6354
6355         LOGD("Enter");
6356
6357         CAMERA_MSG_PARAM_SET(param, INT, set_disable);
6358
6359         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6360
6361         LOGD("ret : 0x%x", ret);
6362
6363         return ret;
6364 }
6365
6366
6367 int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type, int pan_step)
6368 {
6369         int ret = CAMERA_ERROR_NONE;
6370         camera_cli_s *pc = (camera_cli_s *)camera;
6371         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
6372         camera_msg_param param;
6373         int set_move_type = (int)move_type;
6374         int value = 0;
6375
6376         if (!pc || !pc->cb_info) {
6377                 LOGE("NULL handle");
6378                 return CAMERA_ERROR_INVALID_PARAMETER;
6379         }
6380
6381         LOGD("Enter");
6382
6383         value = (set_move_type << 16) | pan_step;
6384         CAMERA_MSG_PARAM_SET(param, INT, value);
6385
6386         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6387
6388         LOGD("ret : 0x%x", ret);
6389
6390         return ret;
6391 }
6392
6393
6394 int camera_attr_get_pan(camera_h camera, int *pan_step)
6395 {
6396         int ret = CAMERA_ERROR_NONE;
6397         camera_cli_s *pc = (camera_cli_s *)camera;
6398         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
6399
6400         if (!pc || !pc->cb_info || !pan_step) {
6401                 LOGE("NULL pointer %p %p", pc, pan_step);
6402                 return CAMERA_ERROR_INVALID_PARAMETER;
6403         }
6404
6405         LOGD("Enter");
6406
6407         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6408
6409         if (ret == CAMERA_ERROR_NONE)
6410                 *pan_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PAN];
6411
6412         LOGD("ret : 0x%x", ret);
6413
6414         return ret;
6415 }
6416
6417
6418 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
6419 {
6420         int ret = CAMERA_ERROR_NONE;
6421         camera_cli_s *pc = (camera_cli_s *)camera;
6422         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
6423
6424         if (!pc || !pc->cb_info || !min || !max) {
6425                 LOGE("NULL pointer %p %p %p", pc, min, max);
6426                 return CAMERA_ERROR_INVALID_PARAMETER;
6427         }
6428
6429         LOGD("Enter");
6430
6431         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6432
6433         if (ret == CAMERA_ERROR_NONE) {
6434                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
6435                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
6436         }
6437
6438         LOGD("ret : 0x%x", ret);
6439
6440         return ret;
6441 }
6442
6443
6444 int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type, int tilt_step)
6445 {
6446         int ret = CAMERA_ERROR_NONE;
6447         camera_cli_s *pc = (camera_cli_s *)camera;
6448         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
6449         camera_msg_param param;
6450         int set_move_type = (int)move_type;
6451         int value = 0;
6452
6453         if (!pc || !pc->cb_info) {
6454                 LOGE("NULL handle");
6455                 return CAMERA_ERROR_INVALID_PARAMETER;
6456         }
6457
6458         LOGD("Enter");
6459
6460         value = (set_move_type << 16) | tilt_step;
6461         CAMERA_MSG_PARAM_SET(param, INT, value);
6462
6463         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6464
6465         LOGD("ret : 0x%x", ret);
6466
6467         return ret;
6468 }
6469
6470
6471 int camera_attr_get_tilt(camera_h camera, int *tilt_step)
6472 {
6473         int ret = CAMERA_ERROR_NONE;
6474         camera_cli_s *pc = (camera_cli_s *)camera;
6475         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
6476
6477         if (!pc || !pc->cb_info || !tilt_step) {
6478                 LOGE("NULL pointer %p %p", pc, tilt_step);
6479                 return CAMERA_ERROR_INVALID_PARAMETER;
6480         }
6481
6482         LOGD("Enter");
6483
6484         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6485
6486         if (ret == CAMERA_ERROR_NONE)
6487                 *tilt_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TILT];
6488
6489         LOGD("ret : 0x%x", ret);
6490
6491         return ret;
6492 }
6493
6494
6495 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
6496 {
6497         int ret = CAMERA_ERROR_NONE;
6498         camera_cli_s *pc = (camera_cli_s *)camera;
6499         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
6500
6501         if (!pc || !pc->cb_info || !min || !max) {
6502                 LOGE("NULL pointer %p %p %p", pc, min, max);
6503                 return CAMERA_ERROR_INVALID_PARAMETER;
6504         }
6505
6506         LOGD("Enter");
6507
6508         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6509
6510         if (ret == CAMERA_ERROR_NONE) {
6511                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
6512                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
6513         }
6514
6515         LOGD("ret : 0x%x", ret);
6516
6517         return ret;
6518 }
6519
6520
6521 int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
6522 {
6523         int ret = CAMERA_ERROR_NONE;
6524         camera_cli_s *pc = (camera_cli_s *)camera;
6525         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
6526         camera_msg_param param;
6527         int set_ptz_type = (int)ptz_type;
6528
6529         if (!pc || !pc->cb_info) {
6530                 LOGE("NULL handle");
6531                 return CAMERA_ERROR_INVALID_PARAMETER;
6532         }
6533
6534         LOGD("Enter");
6535
6536         CAMERA_MSG_PARAM_SET(param, INT, set_ptz_type);
6537
6538         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6539
6540         LOGD("ret : 0x%x", ret);
6541
6542         return ret;
6543 }
6544
6545
6546 int camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data)
6547 {
6548         int ret = CAMERA_ERROR_NONE;
6549         camera_cli_s *pc = (camera_cli_s *)camera;
6550         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
6551
6552         if (!pc || !pc->cb_info || !foreach_cb) {
6553                 LOGE("NULL pointer %p %p", pc, foreach_cb);
6554                 return CAMERA_ERROR_INVALID_PARAMETER;
6555         }
6556
6557         LOGD("Enter");
6558
6559         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = foreach_cb;
6560         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = user_data;
6561
6562         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6563
6564         LOGD("ret : 0x%x", ret);
6565
6566         return ret;
6567 }
6568
6569
6570 int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, int height)
6571 {
6572         int ret = CAMERA_ERROR_NONE;
6573         camera_cli_s *pc = (camera_cli_s *)camera;
6574         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
6575         int set_display_roi_area[4] = {x, y, width, height};
6576         char *msg = NULL;
6577         int length = 0;
6578         int send_ret = 0;
6579
6580         if (!pc || !pc->cb_info) {
6581                 LOGE("NULL handle");
6582                 return CAMERA_ERROR_INVALID_PARAMETER;
6583         }
6584
6585         LOGD("Enter");
6586
6587         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
6588                 ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
6589                 if (ret != MM_ERROR_NONE) {
6590                         LOGE("mm_evas_renderer_set_roi_area error 0x%x", ret);
6591                         return CAMERA_ERROR_INVALID_OPERATION;
6592                 }
6593         }
6594
6595         length = sizeof(set_display_roi_area) / sizeof(int) + \
6596                 (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
6597
6598         msg = muse_core_msg_new(api,
6599                 MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
6600                 NULL);
6601         if (!msg) {
6602                 LOGE("msg creation failed: api %d", api);
6603                 return CAMERA_ERROR_OUT_OF_MEMORY;
6604         }
6605
6606         if (pc->cb_info->is_server_connected) {
6607                 __camera_update_api_waiting(pc->cb_info, api, 1);
6608
6609                 g_mutex_lock(&pc->cb_info->fd_lock);
6610                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
6611                 g_mutex_unlock(&pc->cb_info->fd_lock);
6612         }
6613
6614         if (send_ret < 0) {
6615                 LOGE("message send failed");
6616                 ret = CAMERA_ERROR_INVALID_OPERATION;
6617         } else {
6618                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
6619         }
6620
6621         __camera_update_api_waiting(pc->cb_info, api, -1);
6622
6623         muse_core_msg_free(msg);
6624
6625         LOGD("ret : 0x%x", ret);
6626
6627         return ret;
6628 }
6629
6630
6631 int camera_attr_get_display_roi_area(camera_h camera, int *x, int *y, int *width, int *height)
6632 {
6633         camera_cli_s *pc = (camera_cli_s *)camera;
6634         int ret = CAMERA_ERROR_NONE;
6635         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
6636
6637         if (!pc || !pc->cb_info || !x || !y || !width || !height) {
6638                 LOGE("NULL pointer %p %p %p %p %p", pc, x, y, width, height);
6639                 return CAMERA_ERROR_INVALID_PARAMETER;
6640         }
6641
6642         LOGD("Enter");
6643
6644         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6645
6646         if (ret == CAMERA_ERROR_NONE) {
6647                 *x = pc->cb_info->get_display_roi_area[0];
6648                 *y = pc->cb_info->get_display_roi_area[1];
6649                 *width = pc->cb_info->get_display_roi_area[2];
6650                 *height = pc->cb_info->get_display_roi_area[3];
6651         }
6652
6653         LOGD("ret : 0x%x", ret);
6654
6655         return ret;
6656 }
6657
6658
6659 int camera_get_device_state(camera_device_e device, camera_device_state_e *state)
6660 {
6661         int ret = CAMERA_ERROR_NONE;
6662         int get_device_state = 0;
6663
6664         if (!state) {
6665                 LOGE("NULL pointer");
6666                 return CAMERA_ERROR_INVALID_PARAMETER;
6667         }
6668
6669         ret = _camera_independent_request(MUSE_CAMERA_API_GET_DEVICE_STATE,
6670                 (int)device, "get_device_state", &get_device_state);
6671
6672         if (ret == CAMERA_ERROR_NONE) {
6673                 *state = (camera_device_state_e)get_device_state;
6674                 LOGD("device state %d", *state);
6675         } else {
6676                 LOGE("failed 0x%x", ret);
6677         }
6678
6679         return ret;
6680 }
6681
6682
6683 int camera_add_device_state_changed_cb(camera_device_state_changed_cb callback, void *user_data, int *cb_id)
6684 {
6685         int ret = CAMERA_ERROR_NONE;
6686         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6687         camera_cb_info *info = NULL;
6688
6689         if (!callback || !cb_id) {
6690                 LOGE("invalid pointer %p %p", callback, cb_id);
6691                 return CAMERA_ERROR_INVALID_PARAMETER;
6692         }
6693
6694         /* check camera support */
6695         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6696         if (ret != CAMERA_ERROR_NONE) {
6697                 LOGE("get device state failed");
6698                 return ret;
6699         }
6700
6701         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6702
6703         info = g_new0(camera_cb_info, 1);
6704         if (!info) {
6705                 LOGE("info failed");
6706                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
6707                 goto _DONE;
6708         }
6709
6710         info->id = ++g_cam_dev_state_changed_cb_id;
6711         info->callback = (void *)callback;
6712         info->user_data = user_data;
6713
6714         *cb_id = info->id;
6715
6716         /* subscribe dbus signal for camera state change */
6717         if (!g_cam_dev_state_changed_cb_conn) {
6718                 g_cam_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
6719                 if (!g_cam_dev_state_changed_cb_conn) {
6720                         LOGE("failed to get gdbus connection");
6721                         ret = CAMERA_ERROR_INVALID_OPERATION;
6722                         goto _DONE;
6723                 }
6724
6725                 LOGD("subscribe signal %s - %s - %s",
6726                         MM_CAMCORDER_DBUS_OBJECT,
6727                         MM_CAMCORDER_DBUS_INTERFACE_CAMERA,
6728                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
6729
6730                 g_cam_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_cam_dev_state_changed_cb_conn,
6731                         NULL, MM_CAMCORDER_DBUS_INTERFACE_CAMERA, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
6732                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__camera_device_state_changed_cb, NULL, NULL);
6733                 if (!g_cam_dev_state_changed_cb_subscribe_id) {
6734                         LOGE("failed to get gdbus connection");
6735                         ret = CAMERA_ERROR_INVALID_OPERATION;
6736                         goto _DONE;
6737                 }
6738
6739                 LOGD("signal subscribe id %u", g_cam_dev_state_changed_cb_subscribe_id);
6740         }
6741
6742         g_cam_dev_state_changed_cb_list = g_list_prepend(g_cam_dev_state_changed_cb_list, (gpointer)info);
6743
6744         LOGD("callback id %d", info->id);
6745
6746 _DONE:
6747         if (ret != CAMERA_ERROR_NONE) {
6748                 if (info) {
6749                         g_free(info);
6750                         info = NULL;
6751                 }
6752
6753                 if (g_cam_dev_state_changed_cb_conn) {
6754                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6755                         g_cam_dev_state_changed_cb_conn = NULL;
6756                 }
6757         }
6758
6759         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6760
6761         return ret;
6762 }
6763
6764
6765 int camera_remove_device_state_changed_cb(int cb_id)
6766 {
6767         int ret = CAMERA_ERROR_NONE;
6768         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6769         GList *tmp_list = NULL;
6770         camera_cb_info *info = NULL;
6771
6772         /* check camera support */
6773         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6774         if (ret != CAMERA_ERROR_NONE) {
6775                 LOGE("get device state failed");
6776                 return ret;
6777         }
6778
6779         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6780
6781         if (!g_cam_dev_state_changed_cb_list) {
6782                 LOGE("there is no callback info");
6783                 ret = CAMERA_ERROR_INVALID_OPERATION;
6784                 goto _DONE;
6785         }
6786
6787         tmp_list = g_cam_dev_state_changed_cb_list;
6788
6789         do {
6790                 info = tmp_list->data;
6791                 tmp_list = tmp_list->next;
6792
6793                 if (!info) {
6794                         LOGW("NULL info");
6795                         continue;
6796                 }
6797
6798                 if (info->id == cb_id) {
6799                         g_cam_dev_state_changed_cb_list = g_list_remove(g_cam_dev_state_changed_cb_list, info);
6800
6801                         g_free(info);
6802                         info = NULL;
6803
6804                         if (!g_cam_dev_state_changed_cb_list) {
6805                                 /* no remained callback */
6806                                 if (g_cam_dev_state_changed_cb_conn) {
6807                                         /* unsubscribe signal */
6808                                         g_dbus_connection_signal_unsubscribe(g_cam_dev_state_changed_cb_conn, g_cam_dev_state_changed_cb_subscribe_id);
6809                                         g_cam_dev_state_changed_cb_subscribe_id = 0;
6810
6811                                         /* unref connection */
6812                                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6813                                         g_cam_dev_state_changed_cb_conn = NULL;
6814                                 }
6815                         }
6816
6817                         LOGD("id %d callback removed", cb_id);
6818                         ret = CAMERA_ERROR_NONE;
6819
6820                         goto _DONE;
6821                 }
6822         } while (tmp_list);
6823
6824         LOGE("id %d callback not found", cb_id);
6825         ret = CAMERA_ERROR_INVALID_PARAMETER;
6826
6827 _DONE:
6828         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6829
6830         return ret;
6831 }