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