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