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