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