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