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