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