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