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