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