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