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