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