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