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