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