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