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