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