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