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