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