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