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