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