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