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