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