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