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