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