Do not call unnecessary function
[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
3200                         LOGD("current setting : flip %d, mode %d, rotation %d, visible %d",
3201                                 flip, mode, rotation, visible);
3202
3203                         mm_ret = mm_display_interface_evas_set_flip(cb_info->dp_interface, flip);
3204                         mm_ret |= mm_display_interface_evas_set_mode(cb_info->dp_interface, mode);
3205                         mm_ret |= mm_display_interface_evas_set_rotation(cb_info->dp_interface, rotation);
3206                         mm_ret |= mm_display_interface_evas_set_visible(cb_info->dp_interface, visible);
3207
3208                         if (mode == CAMERA_DISPLAY_MODE_CUSTOM_ROI) {
3209                                 camera_attr_get_display_roi_area(camera, &x, &y, &width, &height);
3210                                 LOGD("current setting : roi %d,%d,%dx%d", x, y, width, height);
3211                                 mm_ret |= mm_display_interface_evas_set_roi_area(cb_info->dp_interface, x, y, width, height);
3212                         }
3213 //LCOV_EXCL_STOP
3214                 }
3215         }
3216
3217         if (mm_ret != MM_ERROR_NONE) {
3218                 LOGE("mm_ret 0x%x failed", mm_ret);
3219                 return CAMERA_ERROR_INVALID_OPERATION;
3220         }
3221
3222         dp_info->type = type;
3223
3224         CAMERA_MSG_PARAM_SET_ARRAY(param, ARRAY, dp_info, sizeof(muse_camera_display_info_s));
3225
3226         _camera_msg_send_param1(api, cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3227
3228         if (ret == CAMERA_ERROR_NONE) {
3229                 if (type == MM_DISPLAY_TYPE_EVAS)
3230                         SET_PREVIEW_CB_TYPE(cb_info, PREVIEW_CB_TYPE_EVAS);
3231         }
3232
3233         return ret;
3234 }
3235
3236
3237 int camera_set_display(camera_h camera, camera_display_type_e type, camera_display_h display)
3238 {
3239         LOGD("type %d, display %p", type, display);
3240         return _camera_set_display(camera, (mm_display_type_e)type, display);
3241 }
3242
3243
3244 int camera_set_preview_resolution(camera_h camera, int width, int height)
3245 {
3246         int ret = CAMERA_ERROR_NONE;
3247         camera_state_e current_state = CAMERA_STATE_NONE;
3248         camera_cli_s *pc = (camera_cli_s *)camera;
3249         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
3250         camera_msg_param param;
3251         int value = 0;
3252
3253         if (!pc || !pc->cb_info) {
3254                 LOGE("NULL handle");
3255                 return CAMERA_ERROR_INVALID_PARAMETER;
3256         }
3257
3258         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3259                 ret = camera_get_state(camera, &current_state);
3260                 if (ret != CAMERA_ERROR_NONE) {
3261                         LOGE("failed to get current state 0x%x", ret);
3262                         return ret;
3263                 }
3264
3265                 if (current_state == CAMERA_STATE_PREVIEW) {
3266                         ret = _camera_stop_evas_rendering(camera, true);
3267                         if (ret != CAMERA_ERROR_NONE)
3268                                 return ret;
3269                 }
3270         }
3271
3272         value = (width << 16) | height;
3273         CAMERA_MSG_PARAM_SET(param, INT, value);
3274
3275         LOGD("%dx%d -> 0x%x", width, height, value);
3276
3277         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3278
3279         LOGD("ret : 0x%x", ret);
3280
3281         if (current_state == CAMERA_STATE_PREVIEW) {
3282                 LOGW("restart evas rendering");
3283                 _camera_start_evas_rendering(camera);
3284         }
3285
3286         return ret;
3287 }
3288
3289
3290 int camera_set_capture_resolution(camera_h camera, int width, int height)
3291 {
3292         int ret = CAMERA_ERROR_NONE;
3293         camera_cli_s *pc = (camera_cli_s *)camera;
3294         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION;
3295         camera_msg_param param;
3296         int value = 0;
3297
3298         if (!pc || !pc->cb_info) {
3299                 LOGE("NULL handle");
3300                 return CAMERA_ERROR_INVALID_PARAMETER;
3301         }
3302
3303         LOGD("Enter");
3304
3305         value = (width << 16) | height;
3306         CAMERA_MSG_PARAM_SET(param, INT, value);
3307
3308         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3309
3310         LOGD("ret : 0x%x", ret);
3311
3312         return ret;
3313 }
3314
3315
3316 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
3317 {
3318         int ret = CAMERA_ERROR_NONE;
3319         int set_format = (int)format;
3320         camera_cli_s *pc = (camera_cli_s *)camera;
3321         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
3322         camera_msg_param param;
3323
3324         if (!pc || !pc->cb_info) {
3325                 LOGE("NULL handle");
3326                 return CAMERA_ERROR_INVALID_PARAMETER;
3327         }
3328
3329         LOGD("Enter - format %d", set_format);
3330
3331         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3332
3333         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3334
3335         LOGD("ret : 0x%x", ret);
3336
3337         return ret;
3338 }
3339
3340
3341 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
3342 {
3343         int ret = CAMERA_ERROR_NONE;
3344         int set_format = (int)format;
3345         camera_msg_param param;
3346         camera_cli_s *pc = (camera_cli_s *)camera;
3347         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
3348
3349         if (!pc || !pc->cb_info) {
3350                 LOGE("NULL handle");
3351                 return CAMERA_ERROR_INVALID_PARAMETER;
3352         }
3353
3354         LOGD("Enter - format %d", set_format);
3355
3356         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3357
3358         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3359
3360         if (ret == CAMERA_ERROR_NONE)
3361                 pc->cb_info->preview_format = set_format;
3362
3363         LOGD("ret : 0x%x", ret);
3364
3365         return ret;
3366 }
3367
3368
3369 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
3370 {
3371         int ret = CAMERA_ERROR_NONE;
3372         camera_cli_s *pc = (camera_cli_s *)camera;
3373         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
3374
3375         if (!pc || !pc->cb_info || !width || !height) {
3376                 LOGE("NULL pointer %p %p %p", pc, width, height);
3377                 return CAMERA_ERROR_INVALID_PARAMETER;
3378         }
3379
3380         LOGD("Enter");
3381
3382         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3383
3384         if (ret == CAMERA_ERROR_NONE) {
3385                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION] >> 16;
3386                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION];
3387         }
3388
3389         LOGD("ret : 0x%x", ret);
3390
3391         return ret;
3392 }
3393
3394
3395 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
3396 {
3397         int ret = CAMERA_ERROR_NONE;
3398         int set_rotation = (int)rotation;
3399         camera_cli_s *pc = (camera_cli_s *)camera;
3400         camera_msg_param param;
3401
3402         if (!pc || !pc->cb_info) {
3403                 LOGE("NULL handle");
3404                 return CAMERA_ERROR_INVALID_PARAMETER;
3405         }
3406
3407         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3408                 ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
3409                 if (ret != MM_ERROR_NONE) {
3410                         LOGE("failed to set rotation for evas surface 0x%x", ret);
3411                         return CAMERA_ERROR_INVALID_OPERATION;
3412                 }
3413         }
3414
3415         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
3416
3417         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_ROTATION, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3418
3419         return ret;
3420 }
3421
3422
3423 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
3424 {
3425         int ret = CAMERA_ERROR_NONE;
3426         camera_cli_s *pc = (camera_cli_s *)camera;
3427
3428         if (!pc || !pc->cb_info || !rotation) {
3429                 LOGE("NULL pointer %p %p", pc, rotation);
3430                 return CAMERA_ERROR_INVALID_PARAMETER;
3431         }
3432
3433         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_ROTATION, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3434
3435         if (ret == CAMERA_ERROR_NONE)
3436                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_ROTATION];
3437
3438         return ret;
3439 }
3440
3441
3442 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
3443 {
3444         int ret = CAMERA_ERROR_NONE;
3445         int set_flip = (int)flip;
3446         camera_cli_s *pc = (camera_cli_s *)camera;
3447         camera_msg_param param;
3448
3449         if (!pc || !pc->cb_info) {
3450                 LOGE("NULL handle");
3451                 return CAMERA_ERROR_INVALID_PARAMETER;
3452         }
3453
3454         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3455                 ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
3456                 if (ret != MM_ERROR_NONE) {
3457                         LOGE("failed to set flip for evas surface 0x%x", ret);
3458                         return CAMERA_ERROR_INVALID_OPERATION;
3459                 }
3460         }
3461
3462         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
3463
3464         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_FLIP, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3465
3466         return ret;
3467 }
3468
3469
3470 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
3471 {
3472         int ret = CAMERA_ERROR_NONE;
3473         camera_cli_s *pc = (camera_cli_s *)camera;
3474
3475         if (!pc || !pc->cb_info || !flip) {
3476                 LOGE("NULL pointer %p %p", pc, flip);
3477                 return CAMERA_ERROR_INVALID_PARAMETER;
3478         }
3479
3480         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_FLIP, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3481
3482         if (ret == CAMERA_ERROR_NONE)
3483                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_FLIP];
3484
3485         return ret;
3486 }
3487
3488
3489 int camera_set_display_visible(camera_h camera, bool visible)
3490 {
3491         int ret = CAMERA_ERROR_NONE;
3492         int set_visible = (int)visible;
3493         camera_cli_s *pc = (camera_cli_s *)camera;
3494         camera_msg_param param;
3495
3496         if (!pc || !pc->cb_info) {
3497                 LOGE("NULL handle");
3498                 return CAMERA_ERROR_INVALID_PARAMETER;
3499         }
3500
3501         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3502                 ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
3503                 if (ret != MM_ERROR_NONE) {
3504                         LOGE("failed to set visible for evas surface 0x%x", ret);
3505                         return CAMERA_ERROR_INVALID_OPERATION;
3506                 }
3507         }
3508
3509         CAMERA_MSG_PARAM_SET(param, INT, set_visible);
3510
3511         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3512
3513         return ret;
3514 }
3515
3516
3517 int camera_is_display_visible(camera_h camera, bool *visible)
3518 {
3519         int ret = CAMERA_ERROR_NONE;
3520         camera_cli_s *pc = (camera_cli_s *)camera;
3521
3522         if (!pc || !pc->cb_info || !visible) {
3523                 LOGE("NULL pointer %p %p", pc, visible);
3524                 return CAMERA_ERROR_INVALID_PARAMETER;
3525         }
3526
3527         _camera_msg_send(MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3528
3529         if (ret == CAMERA_ERROR_NONE)
3530                 *visible = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE];
3531
3532         return ret;
3533 }
3534
3535
3536 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
3537 {
3538         int ret = CAMERA_ERROR_NONE;
3539         int set_mode = (int)mode;
3540         camera_cli_s *pc = (camera_cli_s *)camera;
3541         camera_msg_param param;
3542
3543         if (!pc || !pc->cb_info) {
3544                 LOGE("NULL handle");
3545                 return CAMERA_ERROR_INVALID_PARAMETER;
3546         }
3547
3548         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3549                 ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
3550                 if (ret != MM_ERROR_NONE) {
3551                         LOGE("failed to set geometry for evas surface 0x%x", ret);
3552                         return CAMERA_ERROR_INVALID_OPERATION;
3553                 }
3554         }
3555
3556         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
3557
3558         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_MODE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3559
3560         return ret;
3561 }
3562
3563
3564 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
3565 {
3566         int ret = CAMERA_ERROR_NONE;
3567         camera_cli_s *pc = (camera_cli_s *)camera;
3568
3569         if (!pc || !pc->cb_info || !mode) {
3570                 LOGE("NULL pointer %p %p", pc, mode);
3571                 return CAMERA_ERROR_INVALID_PARAMETER;
3572         }
3573
3574         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_MODE, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3575
3576         if (ret == CAMERA_ERROR_NONE)
3577                 *mode = (camera_display_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_MODE];
3578
3579         return ret;
3580 }
3581
3582
3583 int camera_set_display_reuse_hint(camera_h camera, bool hint)
3584 {
3585         int ret = CAMERA_ERROR_NONE;
3586         int set_hint = (int)hint;
3587         camera_cli_s *pc = (camera_cli_s *)camera;
3588         camera_msg_param param;
3589
3590         if (!pc || !pc->cb_info) {
3591                 LOGE("NULL handle");
3592                 return CAMERA_ERROR_INVALID_PARAMETER;
3593         }
3594
3595         LOGD("Enter - hint %d", set_hint);
3596
3597         CAMERA_MSG_PARAM_SET(param, INT, set_hint);
3598
3599         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3600
3601         return ret;
3602 }
3603
3604
3605 int camera_get_display_reuse_hint(camera_h camera, bool *hint)
3606 {
3607         int ret = CAMERA_ERROR_NONE;
3608         camera_cli_s *pc = (camera_cli_s *)camera;
3609         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
3610
3611         if (!pc || !pc->cb_info || !hint) {
3612                 LOGE("NULL pointer %p %p", pc, hint);
3613                 return CAMERA_ERROR_INVALID_PARAMETER;
3614         }
3615
3616         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3617
3618         if (ret == CAMERA_ERROR_NONE) {
3619                 *hint = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT];
3620                 LOGD("display reuse hint %d", *hint);
3621         }
3622
3623         return ret;
3624 }
3625
3626
3627 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
3628 {
3629         int ret = CAMERA_ERROR_NONE;
3630         camera_cli_s *pc = (camera_cli_s *)camera;
3631         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
3632
3633         if (!pc || !pc->cb_info || !width || !height) {
3634                 LOGE("NULL pointer %p %p %p", pc, width, height);
3635                 return CAMERA_ERROR_INVALID_PARAMETER;
3636         }
3637
3638         LOGD("Enter");
3639
3640         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3641
3642         if (ret == CAMERA_ERROR_NONE) {
3643                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION] >> 16;
3644                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION];
3645         }
3646
3647         LOGD("ret : 0x%x", ret);
3648
3649         return ret;
3650 }
3651
3652
3653 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
3654 {
3655         int ret = CAMERA_ERROR_NONE;
3656         camera_cli_s *pc = (camera_cli_s *)camera;
3657         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
3658
3659         if (!pc || !pc->cb_info || !format) {
3660                 LOGE("NULL pointer %p %p", pc, format);
3661                 return CAMERA_ERROR_INVALID_PARAMETER;
3662         }
3663
3664         LOGD("Enter");
3665
3666         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3667
3668         if (ret == CAMERA_ERROR_NONE)
3669                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_FORMAT];
3670
3671         LOGD("ret : 0x%x", ret);
3672
3673         return ret;
3674 }
3675
3676
3677 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
3678 {
3679         int ret = CAMERA_ERROR_NONE;
3680         camera_cli_s *pc = (camera_cli_s *)camera;
3681         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
3682
3683         if (!pc || !pc->cb_info || !format) {
3684                 LOGE("NULL pointer %p %p", pc, format);
3685                 return CAMERA_ERROR_INVALID_PARAMETER;
3686         }
3687
3688         LOGD("Enter");
3689
3690         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3691
3692         if (ret == CAMERA_ERROR_NONE)
3693                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FORMAT];
3694
3695         LOGD("ret : 0x%x", ret);
3696
3697         return ret;
3698 }
3699
3700
3701 int camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction)
3702 {
3703         int ret = CAMERA_ERROR_NONE;
3704         camera_cli_s *pc = (camera_cli_s *)camera;
3705         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
3706
3707         if (!pc || !pc->cb_info || !facing_direction) {
3708                 LOGE("NULL pointer %p %p", pc, facing_direction);
3709                 return CAMERA_ERROR_INVALID_PARAMETER;
3710         }
3711
3712         LOGD("Enter");
3713
3714         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3715
3716         if (ret == CAMERA_ERROR_NONE)
3717                 *facing_direction = (camera_facing_direction_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FACING_DIRECTION];
3718
3719         LOGD("ret : 0x%x", ret);
3720
3721         return ret;
3722 }
3723
3724
3725 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
3726 {
3727         int ret = CAMERA_ERROR_NONE;
3728         camera_cli_s *pc = (camera_cli_s *)camera;
3729         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
3730
3731         if (!pc || !pc->cb_info || !callback) {
3732                 LOGE("NULL pointer %p %p", pc, callback);
3733                 return CAMERA_ERROR_INVALID_PARAMETER;
3734         }
3735
3736         LOGD("Enter");
3737
3738         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3739
3740         if (ret == CAMERA_ERROR_NONE) {
3741                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3742
3743                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
3744                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
3745
3746                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3747
3748                 SET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3749         }
3750
3751         LOGD("ret : 0x%x", ret);
3752
3753         return ret;
3754 }
3755
3756
3757 int camera_unset_preview_cb(camera_h camera)
3758 {
3759         int ret = CAMERA_ERROR_NONE;
3760         camera_cli_s *pc = (camera_cli_s *)camera;
3761         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
3762
3763         if (!pc || !pc->cb_info) {
3764                 LOGE("NULL handle");
3765                 return CAMERA_ERROR_INVALID_PARAMETER;
3766         }
3767
3768         LOGD("Enter");
3769
3770         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3771
3772         if (ret == CAMERA_ERROR_NONE) {
3773                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3774
3775                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3776                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3777
3778                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3779
3780                 UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3781         }
3782
3783         LOGD("ret : 0x%x", ret);
3784
3785         return ret;
3786 }
3787
3788
3789 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
3790 {
3791         int ret = CAMERA_ERROR_NONE;
3792         camera_cli_s *pc = (camera_cli_s *)camera;
3793         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
3794
3795         if (!pc || !pc->cb_info) {
3796                 LOGE("NULL handle");
3797                 return CAMERA_ERROR_INVALID_PARAMETER;
3798         }
3799
3800         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3801                 LOGE("NOT SUPPORTED");
3802                 return CAMERA_ERROR_NOT_SUPPORTED;
3803         }
3804
3805         if (callback == NULL) {
3806                 LOGE("NULL callback");
3807                 return CAMERA_ERROR_INVALID_PARAMETER;
3808         }
3809
3810         LOGD("Enter");
3811
3812         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3813
3814         if (ret == CAMERA_ERROR_NONE) {
3815                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3816
3817                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
3818                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
3819
3820                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3821         }
3822
3823         LOGD("ret : 0x%x", ret);
3824
3825         return ret;
3826 }
3827
3828
3829 int camera_unset_media_packet_preview_cb(camera_h camera)
3830 {
3831         int ret = CAMERA_ERROR_NONE;
3832         camera_cli_s *pc = (camera_cli_s *)camera;
3833         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
3834
3835         if (!pc || !pc->cb_info) {
3836                 LOGE("NULL handle");
3837                 return CAMERA_ERROR_INVALID_PARAMETER;
3838         }
3839
3840         LOGD("Enter");
3841
3842         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3843
3844         if (ret == CAMERA_ERROR_NONE) {
3845                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3846
3847                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3848                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3849
3850                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3851         }
3852
3853         LOGD("ret : 0x%x", ret);
3854
3855         return ret;
3856 }
3857
3858
3859 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
3860 {
3861         int ret = CAMERA_ERROR_NONE;
3862         camera_cli_s *pc = (camera_cli_s *)camera;
3863         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
3864
3865         if (!pc || !pc->cb_info || !callback) {
3866                 LOGE("NULL pointer %p %p", pc, callback);
3867                 return CAMERA_ERROR_INVALID_PARAMETER;
3868         }
3869
3870         LOGD("Enter");
3871
3872         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3873
3874         if (ret == CAMERA_ERROR_NONE) {
3875                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3876
3877                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
3878                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
3879
3880                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3881         }
3882
3883         LOGD("ret : 0x%x", ret);
3884
3885         return ret;
3886 }
3887
3888
3889 int camera_unset_state_changed_cb(camera_h camera)
3890 {
3891         int ret = CAMERA_ERROR_NONE;
3892         camera_cli_s *pc = (camera_cli_s *)camera;
3893         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
3894
3895         if (!pc || !pc->cb_info) {
3896                 LOGE("NULL handle");
3897                 return CAMERA_ERROR_INVALID_PARAMETER;
3898         }
3899
3900         LOGD("Enter");
3901
3902         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3903
3904         if (ret == CAMERA_ERROR_NONE) {
3905                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3906
3907                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3908                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3909
3910                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3911         }
3912
3913         LOGD("ret : 0x%x", ret);
3914
3915         return ret;
3916 }
3917
3918
3919 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
3920 {
3921         int ret = CAMERA_ERROR_NONE;
3922         camera_cli_s *pc = (camera_cli_s *)camera;
3923         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
3924
3925         if (!pc || !pc->cb_info || !callback) {
3926                 LOGE("NULL pointer %p %p", pc, callback);
3927                 return CAMERA_ERROR_INVALID_PARAMETER;
3928         }
3929
3930         LOGD("Enter");
3931
3932         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3933
3934         if (ret == CAMERA_ERROR_NONE) {
3935                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3936
3937                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
3938                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
3939
3940                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3941         }
3942
3943         LOGD("ret : 0x%x", ret);
3944
3945         return ret;
3946 }
3947
3948
3949 int camera_unset_interrupted_cb(camera_h camera)
3950 {
3951         int ret = CAMERA_ERROR_NONE;
3952         camera_cli_s *pc = (camera_cli_s *)camera;
3953         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
3954
3955         if (!pc || !pc->cb_info) {
3956                 LOGE("NULL handle");
3957                 return CAMERA_ERROR_INVALID_PARAMETER;
3958         }
3959
3960         LOGD("Enter");
3961
3962         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3963
3964         if (ret == CAMERA_ERROR_NONE) {
3965                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3966
3967                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3968                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3969
3970                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3971         }
3972
3973         LOGD("ret : 0x%x", ret);
3974
3975         return ret;
3976 }
3977
3978
3979 int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
3980 {
3981         int ret = CAMERA_ERROR_NONE;
3982         camera_cli_s *pc = (camera_cli_s *)camera;
3983         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
3984
3985         if (!pc || !pc->cb_info || !callback) {
3986                 LOGE("NULL pointer %p %p", pc, callback);
3987                 return CAMERA_ERROR_INVALID_PARAMETER;
3988         }
3989
3990         LOGD("Enter");
3991
3992         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3993
3994         if (ret == CAMERA_ERROR_NONE) {
3995                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3996
3997                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
3998                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
3999
4000                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4001         }
4002
4003         LOGD("ret : 0x%x", ret);
4004
4005         return ret;
4006 }
4007
4008
4009 int camera_unset_interrupt_started_cb(camera_h camera)
4010 {
4011         int ret = CAMERA_ERROR_NONE;
4012         camera_cli_s *pc = (camera_cli_s *)camera;
4013         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
4014
4015         if (!pc || !pc->cb_info) {
4016                 LOGE("NULL handle");
4017                 return CAMERA_ERROR_INVALID_PARAMETER;
4018         }
4019
4020         LOGD("Enter");
4021
4022         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4023
4024         if (ret == CAMERA_ERROR_NONE) {
4025                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4026
4027                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
4028                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
4029
4030                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
4031         }
4032
4033         LOGD("ret : 0x%x", ret);
4034
4035         return ret;
4036 }
4037
4038
4039 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
4040 {
4041         int ret = CAMERA_ERROR_NONE;
4042         camera_cli_s *pc = (camera_cli_s *)camera;
4043         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
4044
4045         if (!pc || !pc->cb_info || !callback) {
4046                 LOGE("NULL pointer %p %p", pc, callback);
4047                 return CAMERA_ERROR_INVALID_PARAMETER;
4048         }
4049
4050         LOGD("Enter");
4051
4052         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4053
4054         if (ret == CAMERA_ERROR_NONE) {
4055                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4056
4057                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
4058                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
4059
4060                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4061         }
4062
4063         LOGD("ret : 0x%x", ret);
4064
4065         return ret;
4066 }
4067
4068
4069 int camera_unset_focus_changed_cb(camera_h camera)
4070 {
4071         int ret = CAMERA_ERROR_NONE;
4072         camera_cli_s *pc = (camera_cli_s *)camera;
4073         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
4074
4075         if (!pc || !pc->cb_info) {
4076                 LOGE("NULL handle");
4077                 return CAMERA_ERROR_INVALID_PARAMETER;
4078         }
4079
4080         LOGD("Enter");
4081
4082         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4083
4084         if (ret == CAMERA_ERROR_NONE) {
4085                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4086
4087                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4088                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
4089
4090                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
4091         }
4092
4093         LOGD("ret : 0x%x", ret);
4094
4095         return ret;
4096 }
4097
4098
4099 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
4100 {
4101         int ret = CAMERA_ERROR_NONE;
4102         camera_cli_s *pc = (camera_cli_s *)camera;
4103         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
4104
4105         if (!pc || !pc->cb_info || !callback) {
4106                 LOGE("NULL pointer %p %p", pc, callback);
4107                 return CAMERA_ERROR_INVALID_PARAMETER;
4108         }
4109
4110         LOGD("Enter");
4111
4112         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4113
4114         if (ret == CAMERA_ERROR_NONE) {
4115                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4116
4117                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
4118                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
4119
4120                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4121         }
4122
4123         LOGD("ret : 0x%x", ret);
4124
4125         return ret;
4126 }
4127
4128
4129 int camera_unset_error_cb(camera_h camera)
4130 {
4131         int ret = CAMERA_ERROR_NONE;
4132         camera_cli_s *pc = (camera_cli_s *)camera;
4133         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
4134
4135         if (!pc || !pc->cb_info) {
4136                 LOGE("NULL handle");
4137                 return CAMERA_ERROR_INVALID_PARAMETER;
4138         }
4139
4140         LOGD("Enter");
4141
4142         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4143
4144         if (ret == CAMERA_ERROR_NONE) {
4145                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4146
4147                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4148                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
4149
4150                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
4151         }
4152
4153         LOGD("ret : 0x%x", ret);
4154
4155         return ret;
4156 }
4157
4158
4159 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
4160 {
4161         int ret = CAMERA_ERROR_NONE;
4162         camera_cli_s *pc = (camera_cli_s *)camera;
4163         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
4164
4165         if (!pc || !pc->cb_info || !foreach_cb) {
4166                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4167                 return CAMERA_ERROR_INVALID_PARAMETER;
4168         }
4169
4170         LOGD("Enter");
4171
4172         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = foreach_cb;
4173         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = user_data;
4174
4175         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4176
4177         LOGD("ret : 0x%x", ret);
4178
4179         return ret;
4180 }
4181
4182
4183 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
4184 {
4185         int ret = CAMERA_ERROR_NONE;
4186         camera_cli_s *pc = (camera_cli_s *)camera;
4187         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
4188
4189         if (!pc || !pc->cb_info || !foreach_cb) {
4190                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4191                 return CAMERA_ERROR_INVALID_PARAMETER;
4192         }
4193
4194         LOGD("Enter");
4195
4196         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = foreach_cb;
4197         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = user_data;
4198
4199         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4200
4201         LOGD("ret : 0x%x", ret);
4202
4203         return ret;
4204 }
4205
4206
4207 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
4208 {
4209         int ret = CAMERA_ERROR_NONE;
4210         camera_cli_s *pc = (camera_cli_s *)camera;
4211         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
4212
4213         if (!pc || !pc->cb_info || !foreach_cb) {
4214                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4215                 return CAMERA_ERROR_INVALID_PARAMETER;
4216         }
4217
4218         LOGD("Enter");
4219
4220         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = foreach_cb;
4221         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = user_data;
4222
4223         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4224
4225         LOGD("ret : 0x%x", ret);
4226
4227         return ret;
4228 }
4229
4230
4231 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
4232 {
4233         int ret = CAMERA_ERROR_NONE;
4234         camera_cli_s *pc = (camera_cli_s *)camera;
4235         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
4236
4237         if (!pc || !pc->cb_info || !foreach_cb) {
4238                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4239                 return CAMERA_ERROR_INVALID_PARAMETER;
4240         }
4241
4242         LOGD("Enter");
4243
4244         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = foreach_cb;
4245         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = user_data;
4246
4247         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4248
4249         LOGD("ret : 0x%x", ret);
4250
4251         return ret;
4252 }
4253
4254
4255 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
4256 {
4257         int ret = CAMERA_ERROR_NONE;
4258         camera_cli_s *pc = (camera_cli_s *)camera;
4259         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
4260
4261         if (!pc || !pc->cb_info || !width || !height) {
4262                 LOGE("NULL pointer %p %p %p", pc, width, height);
4263                 return CAMERA_ERROR_INVALID_PARAMETER;
4264         }
4265
4266         LOGD("Enter");
4267         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4268
4269         if (ret == CAMERA_ERROR_NONE) {
4270                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION] >> 16;
4271                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION];
4272         }
4273
4274         LOGD("ret : 0x%x", ret);
4275
4276         return ret;
4277 }
4278
4279
4280 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
4281 {
4282         int ret = CAMERA_ERROR_NONE;
4283         camera_cli_s *pc = (camera_cli_s *)camera;
4284         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
4285
4286         if (!pc || !pc->cb_info || !angle) {
4287                 LOGE("NULL pointer %p %p", pc, angle);
4288                 return CAMERA_ERROR_INVALID_PARAMETER;
4289         }
4290
4291         LOGD("Enter");
4292
4293         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4294
4295         if (ret == CAMERA_ERROR_NONE)
4296                 *angle = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_LENS_ORIENTATION];
4297
4298         LOGD("ret : 0x%x", ret);
4299
4300         return ret;
4301 }
4302
4303
4304 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
4305 {
4306         int ret = CAMERA_ERROR_NONE;
4307         camera_cli_s *pc = (camera_cli_s *)camera;
4308         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_THEATER_MODE;
4309         camera_msg_param param;
4310         int set_mode = (int)mode;
4311
4312         if (!pc || !pc->cb_info) {
4313                 LOGE("NULL handle");
4314                 return CAMERA_ERROR_INVALID_PARAMETER;
4315         }
4316
4317         LOGD("Enter");
4318
4319         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4320
4321         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4322
4323         LOGD("ret : 0x%x", ret);
4324
4325         return ret;
4326 }
4327
4328
4329 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
4330 {
4331         int ret = CAMERA_ERROR_NONE;
4332         camera_cli_s *pc = (camera_cli_s *)camera;
4333         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
4334
4335         if (!pc || !pc->cb_info || !mode) {
4336                 LOGE("NULL pointer %p %p", pc, mode);
4337                 return CAMERA_ERROR_INVALID_PARAMETER;
4338         }
4339
4340         LOGD("Enter");
4341
4342         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4343
4344         if (ret == CAMERA_ERROR_NONE)
4345                 *mode = (camera_attr_theater_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_THEATER_MODE];
4346
4347         LOGD("ret : 0x%x", ret);
4348
4349         return ret;
4350 }
4351
4352
4353 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
4354 {
4355         int ret = CAMERA_ERROR_NONE;
4356         camera_cli_s *pc = (camera_cli_s *)camera;
4357         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
4358
4359         if (!pc || !pc->cb_info || !foreach_cb) {
4360                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4361                 return CAMERA_ERROR_INVALID_PARAMETER;
4362         }
4363
4364         LOGD("Enter");
4365
4366         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = foreach_cb;
4367         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = user_data;
4368
4369         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4370
4371         LOGD("Finish, return :%x", ret);
4372
4373         return ret;
4374 }
4375
4376
4377 int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
4378 {
4379         int ret = CAMERA_ERROR_NONE;
4380         camera_cli_s *pc = (camera_cli_s *)camera;
4381         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
4382         camera_msg_param param;
4383         int set_fps = (int)fps;
4384
4385         if (!pc || !pc->cb_info) {
4386                 LOGE("NULL handle");
4387                 return CAMERA_ERROR_INVALID_PARAMETER;
4388         }
4389
4390         LOGD("Enter");
4391
4392         CAMERA_MSG_PARAM_SET(param, INT, set_fps);
4393
4394         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4395
4396         LOGD("ret : 0x%x", ret);
4397
4398         return ret;
4399 }
4400
4401
4402 int camera_attr_set_image_quality(camera_h camera, int quality)
4403 {
4404         int ret = CAMERA_ERROR_NONE;
4405         camera_cli_s *pc = (camera_cli_s *)camera;
4406         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
4407         camera_msg_param param;
4408
4409         if (!pc || !pc->cb_info) {
4410                 LOGE("NULL handle");
4411                 return CAMERA_ERROR_INVALID_PARAMETER;
4412         }
4413
4414         LOGD("Enter");
4415
4416         CAMERA_MSG_PARAM_SET(param, INT, quality);
4417
4418         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4419
4420         LOGD("ret : 0x%x", ret);
4421
4422         return ret;
4423 }
4424
4425
4426 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
4427 {
4428         int ret = CAMERA_ERROR_NONE;
4429         camera_cli_s *pc = (camera_cli_s *)camera;
4430         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
4431
4432         if (!pc || !pc->cb_info || !fps) {
4433                 LOGE("NULL pointer %p %p", pc, fps);
4434                 return CAMERA_ERROR_INVALID_PARAMETER;
4435         }
4436
4437         LOGD("Enter");
4438
4439         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4440
4441         if (ret == CAMERA_ERROR_NONE)
4442                 *fps = (camera_attr_fps_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FPS];
4443
4444         LOGD("ret : 0x%x", ret);
4445
4446         return ret;
4447 }
4448
4449
4450 int camera_attr_get_image_quality(camera_h camera, int *quality)
4451 {
4452         int ret = CAMERA_ERROR_NONE;
4453         camera_cli_s *pc = (camera_cli_s *)camera;
4454         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
4455
4456         if (!pc || !pc->cb_info || !quality) {
4457                 LOGE("NULL pointer %p %p", pc, quality);
4458                 return CAMERA_ERROR_INVALID_PARAMETER;
4459         }
4460
4461         LOGD("Enter");
4462
4463         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4464
4465         if (ret == CAMERA_ERROR_NONE)
4466                 *quality = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_IMAGE_QUALITY];
4467
4468         LOGD("ret : 0x%x", ret);
4469
4470         return ret;
4471 }
4472
4473
4474 int camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate)
4475 {
4476         int ret = CAMERA_ERROR_NONE;
4477         camera_cli_s *pc = (camera_cli_s *)camera;
4478         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4479
4480         if (!pc || !pc->cb_info || !bitrate) {
4481                 LOGE("NULL pointer %p %p", pc, bitrate);
4482                 return CAMERA_ERROR_INVALID_PARAMETER;
4483         }
4484
4485         LOGD("Enter");
4486
4487         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4488
4489         if (ret == CAMERA_ERROR_NONE)
4490                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE];
4491
4492         LOGD("ret : 0x%x", ret);
4493
4494         return ret;
4495 }
4496
4497
4498 int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
4499 {
4500         int ret = CAMERA_ERROR_NONE;
4501         camera_cli_s *pc = (camera_cli_s *)camera;
4502         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4503         camera_msg_param param;
4504         int set_bitrate = bitrate;
4505
4506         if (!pc || !pc->cb_info) {
4507                 LOGE("NULL handle");
4508                 return CAMERA_ERROR_INVALID_PARAMETER;
4509         }
4510
4511         LOGD("Enter");
4512
4513         CAMERA_MSG_PARAM_SET(param, INT, set_bitrate);
4514
4515         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4516
4517         LOGD("ret : 0x%x", ret);
4518
4519         return ret;
4520 }
4521
4522
4523 int camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval)
4524 {
4525         int ret = CAMERA_ERROR_NONE;
4526         camera_cli_s *pc = (camera_cli_s *)camera;
4527         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4528
4529         if (!pc || !pc->cb_info || !interval) {
4530                 LOGE("NULL pointer %p %p", pc, interval);
4531                 return CAMERA_ERROR_INVALID_PARAMETER;
4532         }
4533
4534         LOGD("Enter");
4535
4536         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4537
4538         if (ret == CAMERA_ERROR_NONE)
4539                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL];
4540
4541         LOGD("ret : 0x%x", ret);
4542
4543         return ret;
4544 }
4545
4546
4547 int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
4548 {
4549         int ret = CAMERA_ERROR_NONE;
4550         camera_cli_s *pc = (camera_cli_s *)camera;
4551         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4552         camera_msg_param param;
4553         int set_gop_interval = interval;
4554
4555         if (!pc || !pc->cb_info) {
4556                 LOGE("NULL handle");
4557                 return CAMERA_ERROR_INVALID_PARAMETER;
4558         }
4559
4560         LOGD("Enter");
4561
4562         CAMERA_MSG_PARAM_SET(param, INT, set_gop_interval);
4563
4564         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4565
4566         LOGD("ret : 0x%x", ret);
4567
4568         return ret;
4569 }
4570
4571
4572 int camera_attr_set_zoom(camera_h camera, int zoom)
4573 {
4574         int ret = CAMERA_ERROR_NONE;
4575         camera_cli_s *pc = (camera_cli_s *)camera;
4576         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
4577         camera_msg_param param;
4578
4579         if (!pc || !pc->cb_info) {
4580                 LOGE("NULL handle");
4581                 return CAMERA_ERROR_INVALID_PARAMETER;
4582         }
4583
4584         LOGD("Enter, remote_handle : %td", pc->remote_handle);
4585
4586         CAMERA_MSG_PARAM_SET(param, INT, zoom);
4587
4588         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4589
4590         LOGD("ret : 0x%x", ret);
4591
4592         return ret;
4593 }
4594
4595
4596 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
4597 {
4598         int ret = CAMERA_ERROR_NONE;
4599         camera_cli_s *pc = (camera_cli_s *)camera;
4600         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_MODE;
4601         camera_msg_param param;
4602         int set_mode = (int)mode;
4603
4604         if (!pc || !pc->cb_info) {
4605                 LOGE("NULL handle");
4606                 return CAMERA_ERROR_INVALID_PARAMETER;
4607         }
4608
4609         LOGD("Enter, remote_handle : %td", pc->remote_handle);
4610
4611         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4612
4613         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4614
4615         return ret;
4616 }
4617
4618
4619 int camera_attr_set_af_area(camera_h camera, int x, int y)
4620 {
4621         int ret = CAMERA_ERROR_NONE;
4622         camera_cli_s *pc = (camera_cli_s *)camera;
4623         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
4624         camera_msg_param param;
4625         int value = 0;
4626
4627         if (!pc || !pc->cb_info) {
4628                 LOGE("NULL handle");
4629                 return CAMERA_ERROR_INVALID_PARAMETER;
4630         }
4631
4632         LOGD("Enter - %d,%d", x, y);
4633
4634         value = (x << 16) | y;
4635         CAMERA_MSG_PARAM_SET(param, INT, value);
4636
4637         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4638
4639         LOGD("ret : 0x%x", ret);
4640
4641         return ret;
4642 }
4643
4644
4645 int camera_attr_clear_af_area(camera_h camera)
4646 {
4647         int ret = CAMERA_ERROR_NONE;
4648         camera_cli_s *pc = (camera_cli_s *)camera;
4649         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
4650
4651         if (!pc || !pc->cb_info) {
4652                 LOGE("NULL handle");
4653                 return CAMERA_ERROR_INVALID_PARAMETER;
4654         }
4655
4656         LOGD("Enter");
4657
4658         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4659
4660         LOGD("ret : 0x%x", ret);
4661
4662         return ret;
4663 }
4664
4665
4666 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
4667 {
4668         int ret = CAMERA_ERROR_NONE;
4669         camera_cli_s *pc = (camera_cli_s *)camera;
4670         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE;
4671         camera_msg_param param;
4672         int set_mode = (int)mode;
4673
4674         if (!pc || !pc->cb_info) {
4675                 LOGE("NULL handle");
4676                 return CAMERA_ERROR_INVALID_PARAMETER;
4677         }
4678
4679         LOGD("Enter");
4680
4681         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4682
4683         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4684
4685         LOGD("ret : 0x%x", ret);
4686
4687         return ret;
4688 }
4689
4690
4691 int camera_attr_set_exposure(camera_h camera, int value)
4692 {
4693         int ret = CAMERA_ERROR_NONE;
4694         camera_cli_s *pc = (camera_cli_s *)camera;
4695         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
4696         camera_msg_param param;
4697
4698         if (!pc || !pc->cb_info) {
4699                 LOGE("NULL handle");
4700                 return CAMERA_ERROR_INVALID_PARAMETER;
4701         }
4702
4703         LOGD("Enter");
4704
4705         CAMERA_MSG_PARAM_SET(param, INT, value);
4706
4707         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4708
4709         LOGD("ret : 0x%x", ret);
4710
4711         return ret;
4712 }
4713
4714
4715 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
4716 {
4717         int ret = CAMERA_ERROR_NONE;
4718         camera_cli_s *pc = (camera_cli_s *)camera;
4719         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
4720         camera_msg_param param;
4721         int set_iso = (int)iso;
4722
4723         if (!pc || !pc->cb_info) {
4724                 LOGE("NULL handle");
4725                 return CAMERA_ERROR_INVALID_PARAMETER;
4726         }
4727
4728         LOGD("Enter");
4729
4730         CAMERA_MSG_PARAM_SET(param, INT, set_iso);
4731
4732         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4733
4734         LOGD("ret : 0x%x", ret);
4735
4736         return ret;
4737 }
4738
4739
4740 int camera_attr_set_brightness(camera_h camera, int level)
4741 {
4742         int ret = CAMERA_ERROR_NONE;
4743         camera_cli_s *pc = (camera_cli_s *)camera;
4744         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
4745         camera_msg_param param;
4746
4747         if (!pc || !pc->cb_info) {
4748                 LOGE("NULL handle");
4749                 return CAMERA_ERROR_INVALID_PARAMETER;
4750         }
4751
4752         LOGD("Enter");
4753
4754         CAMERA_MSG_PARAM_SET(param, INT, level);
4755
4756         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4757
4758         LOGD("ret : 0x%x", ret);
4759
4760         return ret;
4761 }
4762
4763
4764 int camera_attr_set_contrast(camera_h camera, int level)
4765 {
4766         int ret = CAMERA_ERROR_NONE;
4767         camera_cli_s *pc = (camera_cli_s *)camera;
4768         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
4769         camera_msg_param param;
4770
4771         if (!pc || !pc->cb_info) {
4772                 LOGE("NULL handle");
4773                 return CAMERA_ERROR_INVALID_PARAMETER;
4774         }
4775
4776         LOGD("Enter");
4777
4778         CAMERA_MSG_PARAM_SET(param, INT, level);
4779
4780         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4781
4782         LOGD("ret : 0x%x", ret);
4783
4784         return ret;
4785 }
4786
4787
4788 int camera_attr_set_hue(camera_h camera, int level)
4789 {
4790         int ret = CAMERA_ERROR_NONE;
4791         camera_cli_s *pc = (camera_cli_s *)camera;
4792         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
4793         camera_msg_param param;
4794
4795         if (!pc || !pc->cb_info) {
4796                 LOGE("NULL handle");
4797                 return CAMERA_ERROR_INVALID_PARAMETER;
4798         }
4799
4800         LOGD("Enter");
4801
4802         CAMERA_MSG_PARAM_SET(param, INT, level);
4803
4804         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4805
4806         LOGD("ret : 0x%x", ret);
4807
4808         return ret;
4809 }
4810
4811
4812 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
4813 {
4814         int ret = CAMERA_ERROR_NONE;
4815         camera_cli_s *pc = (camera_cli_s *)camera;
4816         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
4817         camera_msg_param param;
4818         int set_whitebalance = (int)wb;
4819
4820         if (!pc || !pc->cb_info) {
4821                 LOGE("NULL handle");
4822                 return CAMERA_ERROR_INVALID_PARAMETER;
4823         }
4824
4825         LOGD("Enter");
4826
4827         CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
4828
4829         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4830
4831         LOGD("ret : 0x%x", ret);
4832
4833         return ret;
4834 }
4835
4836
4837 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
4838 {
4839         int ret = CAMERA_ERROR_NONE;
4840         camera_cli_s *pc = (camera_cli_s *)camera;
4841         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
4842         camera_msg_param param;
4843         int set_effect = (int)effect;
4844
4845         if (!pc || !pc->cb_info) {
4846                 LOGE("NULL handle");
4847                 return CAMERA_ERROR_INVALID_PARAMETER;
4848         }
4849
4850         LOGD("Enter");
4851
4852         CAMERA_MSG_PARAM_SET(param, INT, set_effect);
4853
4854         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4855
4856         LOGD("ret : 0x%x", ret);
4857
4858         return ret;
4859 }
4860
4861
4862 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
4863 {
4864         int ret = CAMERA_ERROR_NONE;
4865         camera_cli_s *pc = (camera_cli_s *)camera;
4866         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_SCENE_MODE;
4867         camera_msg_param param;
4868         int set_mode = (int)mode;
4869
4870         if (!pc || !pc->cb_info) {
4871                 LOGE("NULL handle");
4872                 return CAMERA_ERROR_INVALID_PARAMETER;
4873         }
4874
4875         LOGD("Enter");
4876
4877         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4878
4879         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4880
4881         LOGD("ret : 0x%x", ret);
4882
4883         return ret;
4884 }
4885
4886
4887 int camera_attr_enable_tag(camera_h camera, bool enable)
4888 {
4889         int ret = CAMERA_ERROR_NONE;
4890         camera_cli_s *pc = (camera_cli_s *)camera;
4891         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_TAG;
4892         camera_msg_param param;
4893         int set_enable = (int)enable;
4894
4895         if (!pc || !pc->cb_info) {
4896                 LOGE("NULL handle");
4897                 return CAMERA_ERROR_INVALID_PARAMETER;
4898         }
4899
4900         LOGD("Enter");
4901
4902         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
4903
4904         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4905
4906         LOGD("ret : 0x%x", ret);
4907
4908         return ret;
4909 }
4910
4911
4912 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
4913 {
4914         int ret = CAMERA_ERROR_NONE;
4915         camera_cli_s *pc = (camera_cli_s *)camera;
4916         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
4917         camera_msg_param param;
4918
4919         if (!pc || !pc->cb_info || !description) {
4920                 LOGE("NULL pointer %p %p", pc, description);
4921                 return CAMERA_ERROR_INVALID_PARAMETER;
4922         }
4923
4924         LOGD("Enter");
4925
4926         CAMERA_MSG_PARAM_SET(param, STRING, description);
4927
4928         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4929
4930         LOGD("ret : 0x%x", ret);
4931
4932         return ret;
4933 }
4934
4935
4936 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
4937 {
4938         int ret = CAMERA_ERROR_NONE;
4939         camera_cli_s *pc = (camera_cli_s *)camera;
4940         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
4941         camera_msg_param param;
4942         int set_orientation = (int)orientation;
4943
4944         if (!pc || !pc->cb_info) {
4945                 LOGE("NULL handle");
4946                 return CAMERA_ERROR_INVALID_PARAMETER;
4947         }
4948
4949         LOGD("Enter");
4950
4951         CAMERA_MSG_PARAM_SET(param, INT, set_orientation);
4952
4953         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4954
4955         LOGD("ret : 0x%x", ret);
4956
4957         return ret;
4958 }
4959
4960
4961 int camera_attr_set_tag_software(camera_h camera, const char *software)
4962 {
4963         int ret = CAMERA_ERROR_NONE;
4964         camera_cli_s *pc = (camera_cli_s *)camera;
4965         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
4966         camera_msg_param param;
4967
4968         if (!pc || !pc->cb_info || !software) {
4969                 LOGE("NULL pointer %p %p", pc, software);
4970                 return CAMERA_ERROR_INVALID_PARAMETER;
4971         }
4972
4973         LOGD("Enter, remote_handle : %td", pc->remote_handle);
4974
4975         CAMERA_MSG_PARAM_SET(param, STRING, software);
4976
4977         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4978
4979         LOGD("ret : 0x%x", ret);
4980
4981         return ret;
4982 }
4983
4984
4985 int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, double altitude)
4986 {
4987         int ret = CAMERA_ERROR_NONE;
4988         camera_cli_s *pc = (camera_cli_s *)camera;
4989         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
4990         double set_geotag[3] = {latitude, longitude, altitude};
4991         char *msg = NULL;
4992         int length = 0;
4993         int send_ret = 0;
4994
4995         if (!pc || !pc->cb_info) {
4996                 LOGE("NULL handle");
4997                 return CAMERA_ERROR_INVALID_PARAMETER;
4998         }
4999
5000         LOGD("Enter");
5001
5002         length = sizeof(set_geotag) / sizeof(int) + \
5003                 (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
5004
5005         msg = muse_core_msg_new(api,
5006                 MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
5007                 NULL);
5008         if (!msg) {
5009                 LOGE("msg creation failed: api %d", api);
5010                 return CAMERA_ERROR_OUT_OF_MEMORY;
5011         }
5012
5013         if (pc->cb_info->is_server_connected) {
5014                 __camera_update_api_waiting(pc->cb_info, api, 1);
5015
5016                 g_mutex_lock(&pc->cb_info->fd_lock);
5017                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
5018                 g_mutex_unlock(&pc->cb_info->fd_lock);
5019         }
5020
5021         if (send_ret < 0) {
5022                 LOGE("message send failed");
5023                 ret = CAMERA_ERROR_INVALID_OPERATION;
5024         } else {
5025                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
5026         }
5027
5028         __camera_update_api_waiting(pc->cb_info, api, -1);
5029
5030         muse_core_msg_free(msg);
5031
5032         LOGD("ret : 0x%x", ret);
5033
5034         return ret;
5035 }
5036
5037
5038 int camera_attr_remove_geotag(camera_h camera)
5039 {
5040         int ret = CAMERA_ERROR_NONE;
5041         camera_cli_s *pc = (camera_cli_s *)camera;
5042         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
5043
5044         if (!pc || !pc->cb_info) {
5045                 LOGE("NULL handle");
5046                 return CAMERA_ERROR_INVALID_PARAMETER;
5047         }
5048
5049         LOGD("Enter");
5050
5051         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5052
5053         LOGD("ret : 0x%x", ret);
5054
5055         return ret;
5056 }
5057
5058
5059 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
5060 {
5061         int ret = CAMERA_ERROR_NONE;
5062         camera_cli_s *pc = (camera_cli_s *)camera;
5063         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
5064         camera_msg_param param;
5065         int set_mode = (int)mode;
5066
5067         if (!pc || !pc->cb_info) {
5068                 LOGE("NULL handle");
5069                 return CAMERA_ERROR_INVALID_PARAMETER;
5070         }
5071
5072         LOGD("Enter");
5073
5074         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
5075
5076         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5077
5078         LOGD("ret : 0x%x", ret);
5079
5080         return ret;
5081 }
5082
5083
5084 int camera_attr_get_zoom(camera_h camera, int *zoom)
5085 {
5086         int ret = CAMERA_ERROR_NONE;
5087         camera_cli_s *pc = (camera_cli_s *)camera;
5088         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
5089
5090         if (!pc || !pc->cb_info || !zoom) {
5091                 LOGE("NULL pointer %p %p", pc, zoom);
5092                 return CAMERA_ERROR_INVALID_PARAMETER;
5093         }
5094
5095         LOGD("Enter");
5096
5097         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5098
5099         if (ret == CAMERA_ERROR_NONE)
5100                 *zoom = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ZOOM];
5101
5102         LOGD("ret : 0x%x", ret);
5103
5104         return ret;
5105 }
5106
5107
5108 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
5109 {
5110         int ret = CAMERA_ERROR_NONE;
5111         camera_cli_s *pc = (camera_cli_s *)camera;
5112         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
5113
5114         if (!pc || !pc->cb_info || !min || !max) {
5115                 LOGE("NULL pointer %p %p %p", pc, min, max);
5116                 return CAMERA_ERROR_INVALID_PARAMETER;
5117         }
5118
5119         LOGD("Enter");
5120
5121         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5122
5123         if (ret == CAMERA_ERROR_NONE) {
5124                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
5125                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
5126         }
5127
5128         LOGD("ret : 0x%x", ret);
5129
5130         return ret;
5131 }
5132
5133
5134 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
5135 {
5136         int ret = CAMERA_ERROR_NONE;
5137         camera_cli_s *pc = (camera_cli_s *)camera;
5138         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
5139
5140         if (!pc || !pc->cb_info || !mode) {
5141                 LOGE("NULL pointer %p %p", pc, mode);
5142                 return CAMERA_ERROR_INVALID_PARAMETER;
5143         }
5144
5145         LOGD("Enter");
5146
5147         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5148
5149         if (ret == CAMERA_ERROR_NONE)
5150                 *mode = (camera_attr_af_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_AF_MODE];
5151
5152         LOGD("ret : 0x%x", ret);
5153
5154         return ret;
5155 }
5156
5157
5158 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
5159 {
5160         int ret = CAMERA_ERROR_NONE;
5161         camera_cli_s *pc = (camera_cli_s *)camera;
5162         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
5163
5164         if (!pc || !pc->cb_info || !mode) {
5165                 LOGE("NULL pointer %p %p", pc, mode);
5166                 return CAMERA_ERROR_INVALID_PARAMETER;
5167         }
5168
5169         LOGD("Enter");
5170
5171         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5172
5173         if (ret == CAMERA_ERROR_NONE)
5174                 *mode = (camera_attr_exposure_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE_MODE];
5175
5176         LOGD("ret : 0x%x", ret);
5177
5178         return ret;
5179 }
5180
5181
5182 int camera_attr_get_exposure(camera_h camera, int *value)
5183 {
5184         int ret = CAMERA_ERROR_NONE;
5185         camera_cli_s *pc = (camera_cli_s *)camera;
5186         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
5187
5188         if (!pc || !pc->cb_info || !value) {
5189                 LOGE("NULL pointer %p %p", pc, value);
5190                 return CAMERA_ERROR_INVALID_PARAMETER;
5191         }
5192
5193         LOGD("Enter");
5194
5195         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5196
5197         if (ret == CAMERA_ERROR_NONE)
5198                 *value = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE];
5199
5200         LOGD("ret : 0x%x", ret);
5201
5202         return ret;
5203 }
5204
5205
5206 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
5207 {
5208         int ret = CAMERA_ERROR_NONE;
5209         camera_cli_s *pc = (camera_cli_s *)camera;
5210         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
5211
5212         if (!pc || !pc->cb_info || !min || !max) {
5213                 LOGE("NULL pointer %p %p %p", pc, min, max);
5214                 return CAMERA_ERROR_INVALID_PARAMETER;
5215         }
5216
5217         LOGD("Enter");
5218
5219         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5220
5221         if (ret == CAMERA_ERROR_NONE) {
5222                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
5223                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
5224         }
5225
5226         LOGD("ret : 0x%x", ret);
5227
5228         return ret;
5229 }
5230
5231
5232 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
5233 {
5234         int ret = CAMERA_ERROR_NONE;
5235         camera_cli_s *pc = (camera_cli_s *)camera;
5236         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
5237
5238         if (!pc || !pc->cb_info || !iso) {
5239                 LOGE("NULL pointer %p %p", pc, iso);
5240                 return CAMERA_ERROR_INVALID_PARAMETER;
5241         }
5242
5243         LOGD("Enter");
5244
5245         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5246
5247         if (ret == CAMERA_ERROR_NONE)
5248                 *iso = (camera_attr_iso_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ISO];
5249
5250         LOGD("ret : 0x%x", ret);
5251
5252         return ret;
5253 }
5254
5255
5256 int camera_attr_get_brightness(camera_h camera, int *level)
5257 {
5258         int ret = CAMERA_ERROR_NONE;
5259         camera_cli_s *pc = (camera_cli_s *)camera;
5260         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
5261
5262         if (!pc || !pc->cb_info || !level) {
5263                 LOGE("NULL pointer %p %p", pc, level);
5264                 return CAMERA_ERROR_INVALID_PARAMETER;
5265         }
5266
5267         LOGD("Enter");
5268
5269         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5270
5271         if (ret == CAMERA_ERROR_NONE)
5272                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
5273
5274         LOGD("ret : 0x%x", ret);
5275
5276         return ret;
5277 }
5278
5279
5280 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
5281 {
5282         int ret = CAMERA_ERROR_NONE;
5283         camera_cli_s *pc = (camera_cli_s *)camera;
5284         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
5285
5286         if (!pc || !pc->cb_info || !min || !max) {
5287                 LOGE("NULL pointer %p %p %p", pc, min, max);
5288                 return CAMERA_ERROR_INVALID_PARAMETER;
5289         }
5290
5291         LOGD("Enter");
5292
5293         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5294
5295         if (ret == CAMERA_ERROR_NONE) {
5296                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
5297                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
5298         }
5299
5300         LOGD("ret : 0x%x", ret);
5301
5302         return ret;
5303 }
5304
5305
5306 int camera_attr_get_contrast(camera_h camera, int *level)
5307 {
5308         int ret = CAMERA_ERROR_NONE;
5309         camera_cli_s *pc = (camera_cli_s *)camera;
5310         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
5311
5312         if (!pc || !pc->cb_info || !level) {
5313                 LOGE("NULL pointer %p %p", pc, level);
5314                 return CAMERA_ERROR_INVALID_PARAMETER;
5315         }
5316
5317         LOGD("Enter");
5318
5319         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5320
5321         if (ret == CAMERA_ERROR_NONE)
5322                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
5323
5324         LOGD("ret : 0x%x", ret);
5325
5326         return ret;
5327 }
5328
5329
5330 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
5331 {
5332         int ret = CAMERA_ERROR_NONE;
5333         camera_cli_s *pc = (camera_cli_s *)camera;
5334         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
5335
5336         if (!pc || !pc->cb_info || !min || !max) {
5337                 LOGE("NULL pointer %p %p %p", pc, min, max);
5338                 return CAMERA_ERROR_INVALID_PARAMETER;
5339         }
5340
5341         LOGD("Enter");
5342
5343         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5344
5345         if (ret == CAMERA_ERROR_NONE) {
5346                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
5347                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
5348                 LOGD("min %d, max %d", *min, *max);
5349         }
5350
5351         LOGD("ret : 0x%x", ret);
5352
5353         return ret;
5354 }
5355
5356
5357 int camera_attr_get_hue(camera_h camera, int *level)
5358 {
5359         int ret = CAMERA_ERROR_NONE;
5360         camera_cli_s *pc = (camera_cli_s *)camera;
5361         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
5362
5363         if (!pc || !pc->cb_info || !level) {
5364                 LOGE("NULL pointer %p %p", pc, level);
5365                 return CAMERA_ERROR_INVALID_PARAMETER;
5366         }
5367
5368         LOGD("Enter");
5369
5370         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5371
5372         if (ret == CAMERA_ERROR_NONE)
5373                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
5374
5375         LOGD("ret : 0x%x", ret);
5376
5377         return ret;
5378 }
5379
5380
5381 int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
5382 {
5383         int ret = CAMERA_ERROR_NONE;
5384         camera_cli_s *pc = (camera_cli_s *)camera;
5385         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
5386
5387         if (!pc || !pc->cb_info || !min || !max) {
5388                 LOGE("NULL pointer %p %p %p", pc, min, max);
5389                 return CAMERA_ERROR_INVALID_PARAMETER;
5390         }
5391
5392         LOGD("Enter");
5393
5394         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5395
5396         if (ret == CAMERA_ERROR_NONE) {
5397                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
5398                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
5399                 LOGD("min %d, max %d", *min, *max);
5400         }
5401
5402         LOGD("ret : 0x%x", ret);
5403
5404         return ret;
5405 }
5406
5407
5408 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
5409 {
5410         int ret = CAMERA_ERROR_NONE;
5411         camera_cli_s *pc = (camera_cli_s *)camera;
5412         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
5413
5414         if (!pc || !pc->cb_info || !wb) {
5415                 LOGE("NULL pointer %p %p", pc, wb);
5416                 return CAMERA_ERROR_INVALID_PARAMETER;
5417         }
5418
5419         LOGD("Enter");
5420
5421         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5422
5423         if (ret == CAMERA_ERROR_NONE)
5424                 *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
5425
5426         LOGD("ret : 0x%x", ret);
5427
5428         return ret;
5429 }
5430
5431
5432 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
5433 {
5434         int ret = CAMERA_ERROR_NONE;
5435         camera_cli_s *pc = (camera_cli_s *)camera;
5436         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
5437
5438         if (!pc || !pc->cb_info || !effect) {
5439                 LOGE("NULL pointer %p %p", pc, effect);
5440                 return CAMERA_ERROR_INVALID_PARAMETER;
5441         }
5442
5443         LOGD("Enter");
5444
5445         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5446
5447         if (ret == CAMERA_ERROR_NONE)
5448                 *effect = (camera_attr_effect_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EFFECT];
5449
5450         LOGD("ret : 0x%x", ret);
5451
5452         return ret;
5453 }
5454
5455
5456 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
5457 {
5458         int ret = CAMERA_ERROR_NONE;
5459         camera_cli_s *pc = (camera_cli_s *)camera;
5460         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
5461
5462         if (!pc || !pc->cb_info || !mode) {
5463                 LOGE("NULL pointer %p %p", pc, mode);
5464                 return CAMERA_ERROR_INVALID_PARAMETER;
5465         }
5466
5467         LOGD("Enter");
5468
5469         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5470
5471         if (ret == CAMERA_ERROR_NONE)
5472                 *mode = (camera_attr_scene_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_SCENE_MODE];
5473
5474         LOGD("ret : 0x%x", ret);
5475
5476         return ret;
5477 }
5478
5479
5480 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
5481 {
5482         int ret = CAMERA_ERROR_NONE;
5483         camera_cli_s *pc = (camera_cli_s *)camera;
5484         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
5485
5486         if (!pc || !pc->cb_info || !enable) {
5487                 LOGE("NULL pointer %p %p", pc, enable);
5488                 return CAMERA_ERROR_INVALID_PARAMETER;
5489         }
5490
5491         LOGD("Enter");
5492
5493         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5494
5495         if (ret == CAMERA_ERROR_NONE)
5496                 *enable = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_TAG];
5497
5498         LOGD("ret : 0x%x", ret);
5499
5500         return ret;
5501 }
5502
5503
5504 int camera_attr_get_tag_image_description(camera_h camera, char **description)
5505 {
5506         int ret = CAMERA_ERROR_NONE;
5507         camera_cli_s *pc = (camera_cli_s *)camera;
5508         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
5509
5510         if (!pc || !pc->cb_info || !description) {
5511                 LOGE("NULL pointer %p %p", pc, description);
5512                 return CAMERA_ERROR_INVALID_PARAMETER;
5513         }
5514
5515         LOGD("Enter");
5516
5517         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5518
5519         if (ret == CAMERA_ERROR_NONE)
5520                 *description = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION]);
5521
5522         LOGD("ret : 0x%x", ret);
5523
5524         return ret;
5525 }
5526
5527
5528 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
5529 {
5530         int ret = CAMERA_ERROR_NONE;
5531         camera_cli_s *pc = (camera_cli_s *)camera;
5532         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
5533
5534         if (!pc || !pc->cb_info || !orientation) {
5535                 LOGE("NULL pointer %p %p", pc, orientation);
5536                 return CAMERA_ERROR_INVALID_PARAMETER;
5537         }
5538
5539         LOGD("Enter");
5540
5541         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5542
5543         if (ret == CAMERA_ERROR_NONE)
5544                 *orientation = (camera_attr_tag_orientation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TAG_ORIENTATION];
5545
5546         LOGD("ret : 0x%x", ret);
5547
5548         return ret;
5549 }
5550
5551
5552 int camera_attr_get_tag_software(camera_h camera, char **software)
5553 {
5554         int ret = CAMERA_ERROR_NONE;
5555         camera_cli_s *pc = (camera_cli_s *)camera;
5556         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
5557
5558         if (!pc || !pc->cb_info || !software) {
5559                 LOGE("NULL pointer %p %p", pc, software);
5560                 return CAMERA_ERROR_INVALID_PARAMETER;
5561         }
5562
5563         LOGD("Enter");
5564
5565         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5566
5567         if (ret == CAMERA_ERROR_NONE)
5568                 *software = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_SOFTWARE]);
5569
5570         LOGD("ret : 0x%x", ret);
5571
5572         return ret;
5573 }
5574
5575
5576 int camera_attr_get_geotag(camera_h camera, double *latitude, double *longitude, double *altitude)
5577 {
5578         int ret = CAMERA_ERROR_NONE;
5579         camera_cli_s *pc = (camera_cli_s *)camera;
5580         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
5581
5582         if (!pc || !pc->cb_info || !latitude || !longitude || !altitude) {
5583                 LOGE("NULL pointer %p %p %p %p", pc, latitude, longitude, altitude);
5584                 return CAMERA_ERROR_INVALID_PARAMETER;
5585         }
5586
5587         LOGD("Enter");
5588
5589         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5590
5591         if (ret == CAMERA_ERROR_NONE) {
5592                 *latitude = pc->cb_info->get_geotag[0];
5593                 *longitude = pc->cb_info->get_geotag[1];
5594                 *altitude = pc->cb_info->get_geotag[2];
5595         }
5596
5597         LOGD("ret : 0x%x", ret);
5598
5599         return ret;
5600 }
5601
5602
5603 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
5604 {
5605         int ret = CAMERA_ERROR_NONE;
5606         camera_cli_s *pc = (camera_cli_s *)camera;
5607         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
5608
5609         if (!pc || !pc->cb_info || !mode) {
5610                 LOGE("NULL pointer %p %p", pc, mode);
5611                 return CAMERA_ERROR_INVALID_PARAMETER;
5612         }
5613
5614         LOGD("Enter");
5615
5616         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5617
5618         if (ret == CAMERA_ERROR_NONE)
5619                 *mode = (camera_attr_flash_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_MODE];
5620
5621         LOGD("ret : 0x%x", ret);
5622
5623         return ret;
5624 }
5625
5626
5627 int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state)
5628 {
5629         int ret = CAMERA_ERROR_NONE;
5630         int get_flash_state = 0;
5631
5632         if (!state) {
5633                 LOGE("NULL pointer");
5634                 return CAMERA_ERROR_INVALID_PARAMETER;
5635         }
5636
5637         ret = _camera_independent_request(MUSE_CAMERA_API_GET_FLASH_STATE,
5638                 (int)device, "get_flash_state", &get_flash_state);
5639
5640         if (ret == CAMERA_ERROR_NONE) {
5641                 *state = (camera_flash_state_e)get_flash_state;
5642                 LOGD("flash state %d", *state);
5643         } else {
5644                 LOGE("failed 0x%x", ret);
5645         }
5646
5647         return ret;
5648 }
5649
5650
5651 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
5652 {
5653         int ret = CAMERA_ERROR_NONE;
5654         camera_cli_s *pc = (camera_cli_s *)camera;
5655         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
5656
5657         if (!pc || !pc->cb_info || !foreach_cb) {
5658                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5659                 return CAMERA_ERROR_INVALID_PARAMETER;
5660         }
5661
5662         LOGD("Enter");
5663
5664         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = foreach_cb;
5665         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = user_data;
5666
5667         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5668
5669         LOGD("ret : 0x%x", ret);
5670
5671         return ret;
5672 }
5673
5674
5675 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
5676 {
5677         int ret = CAMERA_ERROR_NONE;
5678         camera_cli_s *pc = (camera_cli_s *)camera;
5679         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
5680
5681         if (!pc || !pc->cb_info || !foreach_cb) {
5682                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5683                 return CAMERA_ERROR_INVALID_PARAMETER;
5684         }
5685
5686         LOGD("Enter");
5687
5688         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = foreach_cb;
5689         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = user_data;
5690
5691         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5692
5693         LOGD("ret : 0x%x", ret);
5694
5695         return ret;
5696 }
5697
5698
5699 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
5700 {
5701         int ret = CAMERA_ERROR_NONE;
5702         camera_cli_s *pc = (camera_cli_s *)camera;
5703         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
5704
5705         if (!pc || !pc->cb_info || !foreach_cb) {
5706                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5707                 return CAMERA_ERROR_INVALID_PARAMETER;
5708         }
5709
5710         LOGD("Enter");
5711
5712         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = foreach_cb;
5713         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = user_data;
5714
5715         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5716
5717         LOGD("ret : 0x%x", ret);
5718
5719         return ret;
5720 }
5721
5722
5723 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
5724 {
5725         int ret = CAMERA_ERROR_NONE;
5726         camera_cli_s *pc = (camera_cli_s *)camera;
5727         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
5728
5729         if (!pc || !pc->cb_info || !foreach_cb) {
5730                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5731                 return CAMERA_ERROR_INVALID_PARAMETER;
5732         }
5733
5734         LOGD("Enter");
5735
5736         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = foreach_cb;
5737         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = user_data;
5738
5739         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5740
5741         LOGD("ret : 0x%x", ret);
5742
5743         return ret;
5744 }
5745
5746
5747 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
5748 {
5749         int ret = CAMERA_ERROR_NONE;
5750         camera_cli_s *pc = (camera_cli_s *)camera;
5751         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
5752
5753         if (!pc || !pc->cb_info || !foreach_cb) {
5754                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5755                 return CAMERA_ERROR_INVALID_PARAMETER;
5756         }
5757
5758         LOGD("Enter");
5759
5760         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = foreach_cb;
5761         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = user_data;
5762
5763         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5764
5765         LOGD("ret : 0x%x", ret);
5766
5767         return ret;
5768 }
5769
5770
5771 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
5772 {
5773         int ret = CAMERA_ERROR_NONE;
5774         camera_cli_s *pc = (camera_cli_s *)camera;
5775         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
5776
5777         if (!pc || !pc->cb_info || !foreach_cb) {
5778                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5779                 return CAMERA_ERROR_INVALID_PARAMETER;
5780         }
5781
5782         LOGD("Enter");
5783
5784         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = foreach_cb;
5785         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = user_data;
5786
5787         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5788
5789         LOGD("ret : 0x%x", ret);
5790
5791         return ret;
5792 }
5793
5794
5795 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
5796 {
5797         int ret = CAMERA_ERROR_NONE;
5798         camera_cli_s *pc = (camera_cli_s *)camera;
5799         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
5800
5801         if (!pc || !pc->cb_info || !foreach_cb) {
5802                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5803                 return CAMERA_ERROR_INVALID_PARAMETER;
5804         }
5805
5806         LOGD("Enter");
5807
5808         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = foreach_cb;
5809         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = user_data;
5810
5811         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5812
5813         LOGD("ret : 0x%x", ret);
5814
5815         return ret;
5816 }
5817
5818
5819 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5820 {
5821         int ret = CAMERA_ERROR_NONE;
5822         camera_cli_s *pc = (camera_cli_s *)camera;
5823         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
5824
5825         if (!pc || !pc->cb_info || !foreach_cb) {
5826                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5827                 return CAMERA_ERROR_INVALID_PARAMETER;
5828         }
5829
5830         LOGD("Enter");
5831
5832         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = foreach_cb;
5833         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = user_data;
5834
5835         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5836
5837         LOGD("Enter, handle :%td", pc->remote_handle);
5838
5839         return ret;
5840 }
5841
5842
5843 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)
5844 {
5845         int ret = CAMERA_ERROR_NONE;
5846         camera_cli_s *pc = (camera_cli_s *)camera;
5847         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
5848         camera_msg_param param;
5849         int value = 0;
5850
5851         if (!pc || !pc->cb_info || !foreach_cb) {
5852                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5853                 return CAMERA_ERROR_INVALID_PARAMETER;
5854         }
5855
5856         LOGD("Enter");
5857
5858         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = foreach_cb;
5859         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = user_data;
5860
5861         value = (width << 16) | height;
5862         CAMERA_MSG_PARAM_SET(param, INT, value);
5863
5864         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5865
5866         LOGD("ret : 0x%x", ret);
5867
5868         return ret;
5869 }
5870
5871
5872 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
5873 {
5874         int ret = CAMERA_ERROR_NONE;
5875         camera_cli_s *pc = (camera_cli_s *)camera;
5876         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
5877
5878         if (!pc || !pc->cb_info || !foreach_cb) {
5879                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5880                 return CAMERA_ERROR_INVALID_PARAMETER;
5881         }
5882
5883         LOGD("Enter");
5884
5885         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = foreach_cb;
5886         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = user_data;
5887
5888         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5889
5890         LOGD("ret : 0x%x", ret);
5891
5892         return ret;
5893 }
5894
5895
5896 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
5897 {
5898         int ret = CAMERA_ERROR_NONE;
5899         camera_cli_s *pc = (camera_cli_s *)camera;
5900         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
5901
5902         if (!pc || !pc->cb_info || !foreach_cb) {
5903                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5904                 return CAMERA_ERROR_INVALID_PARAMETER;
5905         }
5906
5907         LOGD("Enter");
5908
5909         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = foreach_cb;
5910         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = user_data;
5911
5912         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5913
5914         LOGD("ret : 0x%x", ret);
5915
5916         return ret;
5917 }
5918
5919
5920 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
5921 {
5922         int ret = CAMERA_ERROR_NONE;
5923         camera_cli_s *pc = (camera_cli_s *)camera;
5924         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
5925         camera_msg_param param;
5926         int set_rotation = (int)rotation;
5927
5928         if (!pc || !pc->cb_info) {
5929                 LOGE("NULL handle");
5930                 return CAMERA_ERROR_INVALID_PARAMETER;
5931         }
5932
5933         LOGD("Enter");
5934
5935         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
5936
5937         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5938
5939         LOGD("ret : 0x%x", ret);
5940
5941         return ret;
5942 }
5943
5944
5945 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
5946 {
5947         int ret = CAMERA_ERROR_NONE;
5948         camera_cli_s *pc = (camera_cli_s *)camera;
5949         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
5950
5951         if (!pc || !pc->cb_info || !rotation) {
5952                 LOGE("NULL pointer %p %p", pc, rotation);
5953                 return CAMERA_ERROR_INVALID_PARAMETER;
5954         }
5955
5956         LOGD("Enter");
5957
5958         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5959
5960         if (ret == CAMERA_ERROR_NONE)
5961                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_ROTATION];
5962
5963         LOGD("ret : 0x%x", ret);
5964
5965         return ret;
5966 }
5967
5968
5969 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
5970 {
5971         int ret = CAMERA_ERROR_NONE;
5972         camera_cli_s *pc = (camera_cli_s *)camera;
5973         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
5974         camera_msg_param param;
5975         int set_flip = (int)flip;
5976
5977         if (!pc || !pc->cb_info) {
5978                 LOGE("NULL handle");
5979                 return CAMERA_ERROR_INVALID_PARAMETER;
5980         }
5981
5982         LOGD("Enter");
5983
5984         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
5985
5986         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5987
5988         LOGD("ret : 0x%x", ret);
5989
5990         return ret;
5991 }
5992
5993
5994 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
5995 {
5996         int ret = CAMERA_ERROR_NONE;
5997         camera_cli_s *pc = (camera_cli_s *)camera;
5998         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
5999
6000         if (!pc || !pc->cb_info || !flip) {
6001                 LOGE("NULL pointer %p %p", pc, flip);
6002                 return CAMERA_ERROR_INVALID_PARAMETER;
6003         }
6004
6005         LOGD("Enter");
6006
6007         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6008
6009         if (ret == CAMERA_ERROR_NONE)
6010                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_FLIP];
6011
6012         LOGD("ret : 0x%x", ret);
6013
6014         return ret;
6015 }
6016
6017 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
6018 {
6019         int ret = CAMERA_ERROR_NONE;
6020         camera_cli_s *pc = (camera_cli_s *)camera;
6021         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_MODE;
6022         camera_msg_param param;
6023         int set_mode = (int)mode;
6024
6025         if (!pc || !pc->cb_info) {
6026                 LOGE("NULL handle");
6027                 return CAMERA_ERROR_INVALID_PARAMETER;
6028         }
6029
6030         LOGD("Enter");
6031
6032         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
6033
6034         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6035
6036         LOGD("ret : 0x%x", ret);
6037
6038         return ret;
6039 }
6040
6041
6042 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
6043 {
6044         int ret = CAMERA_ERROR_NONE;
6045         camera_cli_s *pc = (camera_cli_s *)camera;
6046         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
6047
6048         if (!pc || !pc->cb_info || !mode) {
6049                 LOGE("NULL pointer %p %p", pc, mode);
6050                 return CAMERA_ERROR_INVALID_PARAMETER;
6051         }
6052
6053         LOGD("Enter");
6054
6055         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6056
6057         if (ret == CAMERA_ERROR_NONE)
6058                 *mode = (camera_attr_hdr_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HDR_MODE];
6059
6060         LOGD("ret : 0x%x", ret);
6061
6062         return ret;
6063 }
6064
6065
6066 bool camera_attr_is_supported_hdr_capture(camera_h camera)
6067 {
6068         int ret = CAMERA_ERROR_NONE;
6069         camera_cli_s *pc = (camera_cli_s *)camera;
6070         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE;
6071
6072         if (!pc || !pc->cb_info) {
6073                 LOGE("NULL handle");
6074                 return CAMERA_ERROR_INVALID_PARAMETER;
6075         }
6076
6077         LOGD("Enter");
6078
6079         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6080
6081         if (ret < 0) {
6082                 LOGE("error is occurred 0x%x", ret);
6083                 ret = false;
6084         }
6085
6086         LOGD("ret : %d", ret);
6087
6088         return (bool)ret;
6089 }
6090
6091
6092 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
6093 {
6094         int ret = CAMERA_ERROR_NONE;
6095         camera_cli_s *pc = (camera_cli_s *)camera;
6096         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
6097
6098         if (!pc || !pc->cb_info) {
6099                 LOGE("NULL handle");
6100                 return CAMERA_ERROR_INVALID_PARAMETER;
6101         }
6102
6103         LOGD("Enter");
6104
6105         if (!camera_attr_is_supported_hdr_capture(camera)) {
6106                 LOGE("HDR not supported");
6107                 return CAMERA_ERROR_NOT_SUPPORTED;
6108         }
6109
6110         if (!callback) {
6111                 LOGE("NULL callback");
6112                 return CAMERA_ERROR_INVALID_PARAMETER;
6113         }
6114
6115         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6116
6117         if (ret == CAMERA_ERROR_NONE) {
6118                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6119
6120                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
6121                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
6122
6123                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6124         }
6125
6126         LOGD("ret : 0x%x", ret);
6127
6128         return ret;
6129 }
6130
6131
6132 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
6133 {
6134         int ret = CAMERA_ERROR_NONE;
6135         camera_cli_s *pc = (camera_cli_s *)camera;
6136         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
6137
6138         if (!pc || !pc->cb_info) {
6139                 LOGE("NULL handle");
6140                 return CAMERA_ERROR_INVALID_PARAMETER;
6141         }
6142
6143         LOGD("Enter");
6144
6145         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6146
6147         if (ret == CAMERA_ERROR_NONE) {
6148                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6149
6150                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
6151                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
6152
6153                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6154         }
6155
6156         LOGD("ret : 0x%x", ret);
6157
6158         return ret;
6159 }
6160
6161
6162 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
6163 {
6164         int ret = CAMERA_ERROR_NONE;
6165         camera_cli_s *pc = (camera_cli_s *)camera;
6166         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE;
6167         camera_msg_param param;
6168         int set_enable = (int)enable;
6169
6170         if (!pc || !pc->cb_info) {
6171                 LOGE("NULL handle");
6172                 return CAMERA_ERROR_INVALID_PARAMETER;
6173         }
6174
6175         LOGD("Enter");
6176
6177         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6178
6179         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6180
6181         LOGD("ret : 0x%x", ret);
6182
6183         return ret;
6184 }
6185
6186
6187 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
6188 {
6189         int ret = CAMERA_ERROR_NONE;
6190         camera_cli_s *pc = (camera_cli_s *)camera;
6191         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
6192
6193         if (!pc || !pc->cb_info || !enabled) {
6194                 LOGE("NULL pointer %p %p", pc, enabled);
6195                 return CAMERA_ERROR_INVALID_PARAMETER;
6196         }
6197
6198         LOGD("Enter");
6199
6200         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6201
6202         if (ret == CAMERA_ERROR_NONE)
6203                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE];
6204
6205         LOGD("ret : 0x%x", ret);
6206
6207         return ret;
6208 }
6209
6210
6211 bool camera_attr_is_supported_anti_shake(camera_h camera)
6212 {
6213         int ret = CAMERA_ERROR_NONE;
6214         camera_cli_s *pc = (camera_cli_s *)camera;
6215         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE;
6216
6217         if (!pc || !pc->cb_info) {
6218                 LOGE("NULL handle");
6219                 return CAMERA_ERROR_INVALID_PARAMETER;
6220         }
6221
6222         LOGD("Enter");
6223
6224         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6225
6226         if (ret < 0) {
6227                 LOGE("error is occurred 0x%x", ret);
6228                 ret = false;
6229         }
6230
6231         LOGD("ret : %d", ret);
6232
6233         return (bool)ret;
6234 }
6235
6236
6237 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
6238 {
6239         int ret = CAMERA_ERROR_NONE;
6240         camera_cli_s *pc = (camera_cli_s *)camera;
6241         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION;
6242         camera_msg_param param;
6243         int set_enable = (int)enable;
6244
6245         if (!pc || !pc->cb_info) {
6246                 LOGE("NULL handle");
6247                 return CAMERA_ERROR_INVALID_PARAMETER;
6248         }
6249
6250         LOGD("Enter");
6251
6252         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6253
6254         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6255
6256         LOGD("ret : 0x%x", ret);
6257
6258         return ret;
6259 }
6260
6261
6262 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
6263 {
6264         int ret = CAMERA_ERROR_NONE;
6265         camera_cli_s *pc = (camera_cli_s *)camera;
6266         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
6267
6268         if (!pc || !pc->cb_info || !enabled) {
6269                 LOGE("NULL pointer %p %p", pc, enabled);
6270                 return CAMERA_ERROR_INVALID_PARAMETER;
6271         }
6272
6273         LOGD("Enter");
6274
6275         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6276
6277         if (ret == CAMERA_ERROR_NONE)
6278                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION];
6279
6280         LOGD("ret : 0x%x", ret);
6281
6282         return ret;
6283 }
6284
6285
6286 bool camera_attr_is_supported_video_stabilization(camera_h camera)
6287 {
6288         int ret = CAMERA_ERROR_NONE;
6289         camera_cli_s *pc = (camera_cli_s *)camera;
6290         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION;
6291
6292         if (!pc || !pc->cb_info) {
6293                 LOGE("NULL handle");
6294                 return CAMERA_ERROR_INVALID_PARAMETER;
6295         }
6296
6297         LOGD("Enter");
6298
6299         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6300
6301         if (ret < 0) {
6302                 LOGE("error is occurred 0x%x", ret);
6303                 ret = false;
6304         }
6305
6306         LOGD("ret : %d", ret);
6307
6308         return (bool)ret;
6309 }
6310
6311
6312 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
6313 {
6314         int ret = CAMERA_ERROR_NONE;
6315         camera_cli_s *pc = (camera_cli_s *)camera;
6316         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST;
6317         camera_msg_param param;
6318         int set_enable = (int)enable;
6319
6320         if (!pc || !pc->cb_info) {
6321                 LOGE("NULL handle");
6322                 return CAMERA_ERROR_INVALID_PARAMETER;
6323         }
6324
6325         LOGD("Enter");
6326
6327         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6328
6329         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6330
6331         LOGD("ret : 0x%x", ret);
6332
6333         return ret;
6334 }
6335
6336
6337 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
6338 {
6339         int ret = CAMERA_ERROR_NONE;
6340         camera_cli_s *pc = (camera_cli_s *)camera;
6341         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
6342
6343         if (!pc || !pc->cb_info || !enabled) {
6344                 LOGE("NULL pointer %p %p", pc, enabled);
6345                 return CAMERA_ERROR_INVALID_PARAMETER;
6346         }
6347
6348         LOGD("Enter");
6349
6350         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6351
6352         if (ret == CAMERA_ERROR_NONE)
6353                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST];
6354
6355         LOGD("ret : 0x%x", ret);
6356
6357         return ret;
6358 }
6359
6360
6361 bool camera_attr_is_supported_auto_contrast(camera_h camera)
6362 {
6363         int ret = CAMERA_ERROR_NONE;
6364         camera_cli_s *pc = (camera_cli_s *)camera;
6365         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST;
6366
6367         if (!pc || !pc->cb_info) {
6368                 LOGE("NULL handle");
6369                 return CAMERA_ERROR_INVALID_PARAMETER;
6370         }
6371
6372         LOGD("Enter");
6373
6374         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6375
6376         if (ret < 0) {
6377                 LOGE("error is occurred 0x%x", ret);
6378                 ret = false;
6379         }
6380
6381         LOGD("ret : %d", ret);
6382
6383         return (bool)ret;
6384 }
6385
6386
6387 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
6388 {
6389         int ret = CAMERA_ERROR_NONE;
6390         camera_cli_s *pc = (camera_cli_s *)camera;
6391         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
6392         camera_msg_param param;
6393         int set_disable = (int)disable;
6394
6395         if (!pc || !pc->cb_info) {
6396                 LOGE("NULL handle");
6397                 return CAMERA_ERROR_INVALID_PARAMETER;
6398         }
6399
6400         LOGD("Enter");
6401
6402         CAMERA_MSG_PARAM_SET(param, INT, set_disable);
6403
6404         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6405
6406         LOGD("ret : 0x%x", ret);
6407
6408         return ret;
6409 }
6410
6411
6412 int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type, int pan_step)
6413 {
6414         int ret = CAMERA_ERROR_NONE;
6415         camera_cli_s *pc = (camera_cli_s *)camera;
6416         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
6417         camera_msg_param param0;
6418         camera_msg_param param1;
6419
6420         if (!pc || !pc->cb_info) {
6421                 LOGE("NULL handle");
6422                 return CAMERA_ERROR_INVALID_PARAMETER;
6423         }
6424
6425         LOGD("Enter");
6426
6427         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6428         CAMERA_MSG_PARAM_SET(param1, INT, pan_step);
6429
6430         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6431                 &param0, &param1, CAMERA_CB_TIMEOUT);
6432
6433         LOGD("ret : 0x%x", ret);
6434
6435         return ret;
6436 }
6437
6438
6439 int camera_attr_get_pan(camera_h camera, int *pan_step)
6440 {
6441         int ret = CAMERA_ERROR_NONE;
6442         camera_cli_s *pc = (camera_cli_s *)camera;
6443         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
6444
6445         if (!pc || !pc->cb_info || !pan_step) {
6446                 LOGE("NULL pointer %p %p", pc, pan_step);
6447                 return CAMERA_ERROR_INVALID_PARAMETER;
6448         }
6449
6450         LOGD("Enter");
6451
6452         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6453
6454         if (ret == CAMERA_ERROR_NONE)
6455                 *pan_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PAN];
6456
6457         LOGD("ret : 0x%x", ret);
6458
6459         return ret;
6460 }
6461
6462
6463 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
6464 {
6465         int ret = CAMERA_ERROR_NONE;
6466         camera_cli_s *pc = (camera_cli_s *)camera;
6467         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
6468
6469         if (!pc || !pc->cb_info || !min || !max) {
6470                 LOGE("NULL pointer %p %p %p", pc, min, max);
6471                 return CAMERA_ERROR_INVALID_PARAMETER;
6472         }
6473
6474         LOGD("Enter");
6475
6476         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6477
6478         if (ret == CAMERA_ERROR_NONE) {
6479                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
6480                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
6481         }
6482
6483         LOGD("ret : 0x%x", ret);
6484
6485         return ret;
6486 }
6487
6488
6489 int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type, int tilt_step)
6490 {
6491         int ret = CAMERA_ERROR_NONE;
6492         camera_cli_s *pc = (camera_cli_s *)camera;
6493         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
6494         camera_msg_param param0;
6495         camera_msg_param param1;
6496
6497         if (!pc || !pc->cb_info) {
6498                 LOGE("NULL handle");
6499                 return CAMERA_ERROR_INVALID_PARAMETER;
6500         }
6501
6502         LOGD("Enter");
6503
6504         CAMERA_MSG_PARAM_SET(param0, INT, move_type);
6505         CAMERA_MSG_PARAM_SET(param1, INT, tilt_step);
6506
6507         _camera_msg_send_param2_int(api, pc->cb_info, &ret,
6508                 &param0, &param1, CAMERA_CB_TIMEOUT);
6509
6510         LOGD("ret : 0x%x", ret);
6511
6512         return ret;
6513 }
6514
6515
6516 int camera_attr_get_tilt(camera_h camera, int *tilt_step)
6517 {
6518         int ret = CAMERA_ERROR_NONE;
6519         camera_cli_s *pc = (camera_cli_s *)camera;
6520         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
6521
6522         if (!pc || !pc->cb_info || !tilt_step) {
6523                 LOGE("NULL pointer %p %p", pc, tilt_step);
6524                 return CAMERA_ERROR_INVALID_PARAMETER;
6525         }
6526
6527         LOGD("Enter");
6528
6529         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6530
6531         if (ret == CAMERA_ERROR_NONE)
6532                 *tilt_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TILT];
6533
6534         LOGD("ret : 0x%x", ret);
6535
6536         return ret;
6537 }
6538
6539
6540 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
6541 {
6542         int ret = CAMERA_ERROR_NONE;
6543         camera_cli_s *pc = (camera_cli_s *)camera;
6544         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
6545
6546         if (!pc || !pc->cb_info || !min || !max) {
6547                 LOGE("NULL pointer %p %p %p", pc, min, max);
6548                 return CAMERA_ERROR_INVALID_PARAMETER;
6549         }
6550
6551         LOGD("Enter");
6552
6553         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6554
6555         if (ret == CAMERA_ERROR_NONE) {
6556                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
6557                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
6558         }
6559
6560         LOGD("ret : 0x%x", ret);
6561
6562         return ret;
6563 }
6564
6565
6566 int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
6567 {
6568         int ret = CAMERA_ERROR_NONE;
6569         camera_cli_s *pc = (camera_cli_s *)camera;
6570         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
6571         camera_msg_param param;
6572         int set_ptz_type = (int)ptz_type;
6573
6574         if (!pc || !pc->cb_info) {
6575                 LOGE("NULL handle");
6576                 return CAMERA_ERROR_INVALID_PARAMETER;
6577         }
6578
6579         LOGD("Enter");
6580
6581         CAMERA_MSG_PARAM_SET(param, INT, set_ptz_type);
6582
6583         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6584
6585         LOGD("ret : 0x%x", ret);
6586
6587         return ret;
6588 }
6589
6590
6591 int camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data)
6592 {
6593         int ret = CAMERA_ERROR_NONE;
6594         camera_cli_s *pc = (camera_cli_s *)camera;
6595         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
6596
6597         if (!pc || !pc->cb_info || !foreach_cb) {
6598                 LOGE("NULL pointer %p %p", pc, foreach_cb);
6599                 return CAMERA_ERROR_INVALID_PARAMETER;
6600         }
6601
6602         LOGD("Enter");
6603
6604         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = foreach_cb;
6605         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = user_data;
6606
6607         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6608
6609         LOGD("ret : 0x%x", ret);
6610
6611         return ret;
6612 }
6613
6614
6615 int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, int height)
6616 {
6617         int ret = CAMERA_ERROR_NONE;
6618         camera_cli_s *pc = (camera_cli_s *)camera;
6619         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
6620         int set_display_roi_area[4] = {x, y, width, height};
6621         char *msg = NULL;
6622         int length = 0;
6623         int send_ret = 0;
6624
6625         if (!pc || !pc->cb_info) {
6626                 LOGE("NULL handle");
6627                 return CAMERA_ERROR_INVALID_PARAMETER;
6628         }
6629
6630         LOGD("Enter");
6631
6632         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
6633                 ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
6634                 if (ret != MM_ERROR_NONE) {
6635                         LOGE("mm_evas_renderer_set_roi_area error 0x%x", ret);
6636                         return CAMERA_ERROR_INVALID_OPERATION;
6637                 }
6638         }
6639
6640         length = sizeof(set_display_roi_area) / sizeof(int) + \
6641                 (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
6642
6643         msg = muse_core_msg_new(api,
6644                 MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
6645                 NULL);
6646         if (!msg) {
6647                 LOGE("msg creation failed: api %d", api);
6648                 return CAMERA_ERROR_OUT_OF_MEMORY;
6649         }
6650
6651         if (pc->cb_info->is_server_connected) {
6652                 __camera_update_api_waiting(pc->cb_info, api, 1);
6653
6654                 g_mutex_lock(&pc->cb_info->fd_lock);
6655                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
6656                 g_mutex_unlock(&pc->cb_info->fd_lock);
6657         }
6658
6659         if (send_ret < 0) {
6660                 LOGE("message send failed");
6661                 ret = CAMERA_ERROR_INVALID_OPERATION;
6662         } else {
6663                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
6664         }
6665
6666         __camera_update_api_waiting(pc->cb_info, api, -1);
6667
6668         muse_core_msg_free(msg);
6669
6670         LOGD("ret : 0x%x", ret);
6671
6672         return ret;
6673 }
6674
6675
6676 int camera_attr_get_display_roi_area(camera_h camera, int *x, int *y, int *width, int *height)
6677 {
6678         camera_cli_s *pc = (camera_cli_s *)camera;
6679         int ret = CAMERA_ERROR_NONE;
6680         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
6681
6682         if (!pc || !pc->cb_info || !x || !y || !width || !height) {
6683                 LOGE("NULL pointer %p %p %p %p %p", pc, x, y, width, height);
6684                 return CAMERA_ERROR_INVALID_PARAMETER;
6685         }
6686
6687         LOGD("Enter");
6688
6689         _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6690
6691         if (ret == CAMERA_ERROR_NONE) {
6692                 *x = pc->cb_info->get_display_roi_area[0];
6693                 *y = pc->cb_info->get_display_roi_area[1];
6694                 *width = pc->cb_info->get_display_roi_area[2];
6695                 *height = pc->cb_info->get_display_roi_area[3];
6696         }
6697
6698         LOGD("ret : 0x%x", ret);
6699
6700         return ret;
6701 }
6702
6703
6704 int camera_get_device_state(camera_device_e device, camera_device_state_e *state)
6705 {
6706         int ret = CAMERA_ERROR_NONE;
6707         int get_device_state = 0;
6708
6709         if (!state) {
6710                 LOGE("NULL pointer");
6711                 return CAMERA_ERROR_INVALID_PARAMETER;
6712         }
6713
6714         ret = _camera_independent_request(MUSE_CAMERA_API_GET_DEVICE_STATE,
6715                 (int)device, "get_device_state", &get_device_state);
6716
6717         if (ret == CAMERA_ERROR_NONE) {
6718                 *state = (camera_device_state_e)get_device_state;
6719                 LOGD("device state %d", *state);
6720         } else {
6721                 LOGE("failed 0x%x", ret);
6722         }
6723
6724         return ret;
6725 }
6726
6727
6728 int camera_add_device_state_changed_cb(camera_device_state_changed_cb callback, void *user_data, int *cb_id)
6729 {
6730         int ret = CAMERA_ERROR_NONE;
6731         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6732         camera_cb_info *info = NULL;
6733
6734         if (!callback || !cb_id) {
6735                 LOGE("invalid pointer %p %p", callback, cb_id);
6736                 return CAMERA_ERROR_INVALID_PARAMETER;
6737         }
6738
6739         /* check camera support */
6740         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6741         if (ret != CAMERA_ERROR_NONE) {
6742                 LOGE("get device state failed");
6743                 return ret;
6744         }
6745
6746         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6747
6748         info = g_new0(camera_cb_info, 1);
6749         if (!info) {
6750                 LOGE("info failed");
6751                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
6752                 goto _DONE;
6753         }
6754
6755         info->id = ++g_cam_dev_state_changed_cb_id;
6756         info->callback = (void *)callback;
6757         info->user_data = user_data;
6758
6759         *cb_id = info->id;
6760
6761         /* subscribe dbus signal for camera state change */
6762         if (!g_cam_dev_state_changed_cb_conn) {
6763                 g_cam_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
6764                 if (!g_cam_dev_state_changed_cb_conn) {
6765                         LOGE("failed to get gdbus connection");
6766                         ret = CAMERA_ERROR_INVALID_OPERATION;
6767                         goto _DONE;
6768                 }
6769
6770                 LOGD("subscribe signal %s - %s - %s",
6771                         MM_CAMCORDER_DBUS_OBJECT,
6772                         MM_CAMCORDER_DBUS_INTERFACE_CAMERA,
6773                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
6774
6775                 g_cam_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_cam_dev_state_changed_cb_conn,
6776                         NULL, MM_CAMCORDER_DBUS_INTERFACE_CAMERA, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
6777                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__camera_device_state_changed_cb, NULL, NULL);
6778                 if (!g_cam_dev_state_changed_cb_subscribe_id) {
6779                         LOGE("failed to get gdbus connection");
6780                         ret = CAMERA_ERROR_INVALID_OPERATION;
6781                         goto _DONE;
6782                 }
6783
6784                 LOGD("signal subscribe id %u", g_cam_dev_state_changed_cb_subscribe_id);
6785         }
6786
6787         g_cam_dev_state_changed_cb_list = g_list_prepend(g_cam_dev_state_changed_cb_list, (gpointer)info);
6788
6789         LOGD("callback id %d", info->id);
6790
6791 _DONE:
6792         if (ret != CAMERA_ERROR_NONE) {
6793                 if (info) {
6794                         g_free(info);
6795                         info = NULL;
6796                 }
6797
6798                 if (g_cam_dev_state_changed_cb_conn) {
6799                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6800                         g_cam_dev_state_changed_cb_conn = NULL;
6801                 }
6802         }
6803
6804         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6805
6806         return ret;
6807 }
6808
6809
6810 int camera_remove_device_state_changed_cb(int cb_id)
6811 {
6812         int ret = CAMERA_ERROR_NONE;
6813         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6814         GList *tmp_list = NULL;
6815         camera_cb_info *info = NULL;
6816
6817         /* check camera support */
6818         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6819         if (ret != CAMERA_ERROR_NONE) {
6820                 LOGE("get device state failed");
6821                 return ret;
6822         }
6823
6824         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6825
6826         if (!g_cam_dev_state_changed_cb_list) {
6827                 LOGE("there is no callback info");
6828                 ret = CAMERA_ERROR_INVALID_OPERATION;
6829                 goto _DONE;
6830         }
6831
6832         tmp_list = g_cam_dev_state_changed_cb_list;
6833
6834         do {
6835                 info = tmp_list->data;
6836                 tmp_list = tmp_list->next;
6837
6838                 if (!info) {
6839                         LOGW("NULL info");
6840                         continue;
6841                 }
6842
6843                 if (info->id == cb_id) {
6844                         g_cam_dev_state_changed_cb_list = g_list_remove(g_cam_dev_state_changed_cb_list, info);
6845
6846                         g_free(info);
6847                         info = NULL;
6848
6849                         if (!g_cam_dev_state_changed_cb_list) {
6850                                 /* no remained callback */
6851                                 if (g_cam_dev_state_changed_cb_conn) {
6852                                         /* unsubscribe signal */
6853                                         g_dbus_connection_signal_unsubscribe(g_cam_dev_state_changed_cb_conn, g_cam_dev_state_changed_cb_subscribe_id);
6854                                         g_cam_dev_state_changed_cb_subscribe_id = 0;
6855
6856                                         /* unref connection */
6857                                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6858                                         g_cam_dev_state_changed_cb_conn = NULL;
6859                                 }
6860                         }
6861
6862                         LOGD("id %d callback removed", cb_id);
6863                         ret = CAMERA_ERROR_NONE;
6864
6865                         goto _DONE;
6866                 }
6867         } while (tmp_list);
6868
6869         LOGE("id %d callback not found", cb_id);
6870         ret = CAMERA_ERROR_INVALID_PARAMETER;
6871
6872 _DONE:
6873         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6874
6875         return ret;
6876 }