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