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