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