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