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