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