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