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