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