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