Update code for display
[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         cb_info->parent_id = parent_id;
3072
3073         CAMERA_MSG_PARAM_SET(param0, INT, type);
3074         CAMERA_MSG_PARAM_SET(param1, INT, parent_id);
3075
3076         _camera_msg_send_param2_int(api, cb_info, &ret,
3077                 &param0, &param1, CAMERA_CB_TIMEOUT);
3078
3079         if (ret == CAMERA_ERROR_NONE) {
3080                 pc->cb_info->dp_type = type;
3081
3082                 if (type == CAMERA_DISPLAY_TYPE_EVAS)
3083                         SET_PREVIEW_CB_TYPE(cb_info, PREVIEW_CB_TYPE_EVAS);
3084         }
3085
3086         return ret;
3087 }
3088
3089
3090 int camera_set_preview_resolution(camera_h camera, int width, int height)
3091 {
3092         int ret = CAMERA_ERROR_NONE;
3093         camera_state_e current_state = CAMERA_STATE_NONE;
3094         camera_cli_s *pc = (camera_cli_s *)camera;
3095         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
3096         camera_msg_param param;
3097         int value = 0;
3098
3099         if (!pc || !pc->cb_info) {
3100                 LOGE("NULL handle");
3101                 return CAMERA_ERROR_INVALID_PARAMETER;
3102         }
3103
3104         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3105                 ret = camera_get_state(camera, &current_state);
3106                 if (ret != CAMERA_ERROR_NONE) {
3107                         LOGE("failed to get current state 0x%x", ret);
3108                         return ret;
3109                 }
3110
3111                 if (current_state == CAMERA_STATE_PREVIEW) {
3112                         ret = _camera_stop_evas_rendering(camera, true);
3113                         if (ret != CAMERA_ERROR_NONE)
3114                                 return ret;
3115                 }
3116         }
3117
3118         value = (width << 16) | height;
3119         CAMERA_MSG_PARAM_SET(param, INT, value);
3120
3121         LOGD("%dx%d -> 0x%x", width, height, value);
3122
3123         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3124
3125         LOGD("ret : 0x%x", ret);
3126
3127         if (current_state == CAMERA_STATE_PREVIEW) {
3128                 LOGW("restart evas rendering");
3129                 _camera_start_evas_rendering(camera);
3130         }
3131
3132         return ret;
3133 }
3134
3135
3136 int camera_set_capture_resolution(camera_h camera, int width, int height)
3137 {
3138         int ret = CAMERA_ERROR_NONE;
3139         camera_cli_s *pc = (camera_cli_s *)camera;
3140         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION;
3141         camera_msg_param param;
3142         int value = 0;
3143
3144         if (!pc || !pc->cb_info) {
3145                 LOGE("NULL handle");
3146                 return CAMERA_ERROR_INVALID_PARAMETER;
3147         }
3148
3149         LOGD("Enter");
3150
3151         value = (width << 16) | height;
3152         CAMERA_MSG_PARAM_SET(param, INT, value);
3153
3154         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3155
3156         LOGD("ret : 0x%x", ret);
3157
3158         return ret;
3159 }
3160
3161
3162 int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
3163 {
3164         int ret = CAMERA_ERROR_NONE;
3165         int set_format = (int)format;
3166         camera_cli_s *pc = (camera_cli_s *)camera;
3167         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
3168         camera_msg_param param;
3169
3170         if (!pc || !pc->cb_info) {
3171                 LOGE("NULL handle");
3172                 return CAMERA_ERROR_INVALID_PARAMETER;
3173         }
3174
3175         LOGD("Enter - format %d", set_format);
3176
3177         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3178
3179         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3180
3181         LOGD("ret : 0x%x", ret);
3182
3183         return ret;
3184 }
3185
3186
3187 int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
3188 {
3189         int ret = CAMERA_ERROR_NONE;
3190         int set_format = (int)format;
3191         camera_msg_param param;
3192         camera_cli_s *pc = (camera_cli_s *)camera;
3193         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
3194
3195         if (!pc || !pc->cb_info) {
3196                 LOGE("NULL handle");
3197                 return CAMERA_ERROR_INVALID_PARAMETER;
3198         }
3199
3200         LOGD("Enter - capture_format %d", set_format);
3201
3202         CAMERA_MSG_PARAM_SET(param, INT, set_format);
3203
3204         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3205
3206         if (ret == CAMERA_ERROR_NONE)
3207                 pc->cb_info->preview_format = set_format;
3208
3209         LOGD("ret : 0x%x", ret);
3210
3211         return ret;
3212 }
3213
3214
3215 int camera_get_preview_resolution(camera_h camera, int *width, int *height)
3216 {
3217         int ret = CAMERA_ERROR_NONE;
3218         camera_cli_s *pc = (camera_cli_s *)camera;
3219         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
3220
3221         if (!pc || !pc->cb_info || !width || !height) {
3222                 LOGE("NULL pointer %p %p %p", pc, width, height);
3223                 return CAMERA_ERROR_INVALID_PARAMETER;
3224         }
3225
3226         LOGD("Enter");
3227
3228         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3229
3230         if (ret == CAMERA_ERROR_NONE) {
3231                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION] >> 16;
3232                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION];
3233         }
3234
3235         LOGD("ret : 0x%x", ret);
3236
3237         return ret;
3238 }
3239
3240
3241 int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
3242 {
3243         int ret = CAMERA_ERROR_NONE;
3244         int set_rotation = (int)rotation;
3245         camera_cli_s *pc = (camera_cli_s *)camera;
3246         camera_msg_param param;
3247
3248         if (!pc || !pc->cb_info) {
3249                 LOGE("NULL handle");
3250                 return CAMERA_ERROR_INVALID_PARAMETER;
3251         }
3252
3253         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3254                 ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
3255                 if (ret != MM_ERROR_NONE) {
3256                         LOGE("failed to set rotation for evas surface 0x%x", ret);
3257                         return CAMERA_ERROR_INVALID_OPERATION;
3258                 }
3259         }
3260
3261         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
3262
3263         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_ROTATION, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3264
3265         return ret;
3266 }
3267
3268
3269 int camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation)
3270 {
3271         int ret = CAMERA_ERROR_NONE;
3272         camera_cli_s *pc = (camera_cli_s *)camera;
3273
3274         if (!pc || !pc->cb_info || !rotation) {
3275                 LOGE("NULL pointer %p %p", pc, rotation);
3276                 return CAMERA_ERROR_INVALID_PARAMETER;
3277         }
3278
3279         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_ROTATION, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3280
3281         if (ret == CAMERA_ERROR_NONE)
3282                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_ROTATION];
3283
3284         return ret;
3285 }
3286
3287
3288 int camera_set_display_flip(camera_h camera, camera_flip_e flip)
3289 {
3290         int ret = CAMERA_ERROR_NONE;
3291         int set_flip = (int)flip;
3292         camera_cli_s *pc = (camera_cli_s *)camera;
3293         camera_msg_param param;
3294
3295         if (!pc || !pc->cb_info) {
3296                 LOGE("NULL handle");
3297                 return CAMERA_ERROR_INVALID_PARAMETER;
3298         }
3299
3300         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3301                 ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
3302                 if (ret != MM_ERROR_NONE) {
3303                         LOGE("failed to set flip for evas surface 0x%x", ret);
3304                         return CAMERA_ERROR_INVALID_OPERATION;
3305                 }
3306         }
3307
3308         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
3309
3310         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_FLIP, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3311
3312         return ret;
3313 }
3314
3315
3316 int camera_get_display_flip(camera_h camera, camera_flip_e *flip)
3317 {
3318         int ret = CAMERA_ERROR_NONE;
3319         camera_cli_s *pc = (camera_cli_s *)camera;
3320
3321         if (!pc || !pc->cb_info || !flip) {
3322                 LOGE("NULL pointer %p %p", pc, flip);
3323                 return CAMERA_ERROR_INVALID_PARAMETER;
3324         }
3325
3326         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_FLIP, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3327
3328         if (ret == CAMERA_ERROR_NONE)
3329                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_FLIP];
3330
3331         return ret;
3332 }
3333
3334
3335 int camera_set_display_visible(camera_h camera, bool visible)
3336 {
3337         int ret = CAMERA_ERROR_NONE;
3338         int set_visible = (int)visible;
3339         camera_cli_s *pc = (camera_cli_s *)camera;
3340         camera_msg_param param;
3341
3342         if (!pc || !pc->cb_info) {
3343                 LOGE("NULL handle");
3344                 return CAMERA_ERROR_INVALID_PARAMETER;
3345         }
3346
3347         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3348                 ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
3349                 if (ret != MM_ERROR_NONE) {
3350                         LOGE("failed to set visible for evas surface 0x%x", ret);
3351                         return CAMERA_ERROR_INVALID_OPERATION;
3352                 }
3353         }
3354
3355         CAMERA_MSG_PARAM_SET(param, INT, set_visible);
3356
3357         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3358
3359         return ret;
3360 }
3361
3362
3363 int camera_is_display_visible(camera_h camera, bool *visible)
3364 {
3365         int ret = CAMERA_ERROR_NONE;
3366         camera_cli_s *pc = (camera_cli_s *)camera;
3367
3368         if (!pc || !pc->cb_info || !visible) {
3369                 LOGE("NULL pointer %p %p", pc, visible);
3370                 return CAMERA_ERROR_INVALID_PARAMETER;
3371         }
3372
3373         _camera_msg_send(MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3374
3375         if (ret == CAMERA_ERROR_NONE)
3376                 *visible = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE];
3377
3378         return ret;
3379 }
3380
3381
3382 int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
3383 {
3384         int ret = CAMERA_ERROR_NONE;
3385         int set_mode = (int)mode;
3386         camera_cli_s *pc = (camera_cli_s *)camera;
3387         camera_msg_param param;
3388
3389         if (!pc || !pc->cb_info) {
3390                 LOGE("NULL handle");
3391                 return CAMERA_ERROR_INVALID_PARAMETER;
3392         }
3393
3394         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
3395                 ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
3396                 if (ret != MM_ERROR_NONE) {
3397                         LOGE("failed to set geometry for evas surface 0x%x", ret);
3398                         return CAMERA_ERROR_INVALID_OPERATION;
3399                 }
3400         }
3401
3402         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
3403
3404         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_MODE, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3405
3406         return ret;
3407 }
3408
3409
3410 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
3411 {
3412         int ret = CAMERA_ERROR_NONE;
3413         camera_cli_s *pc = (camera_cli_s *)camera;
3414
3415         if (!pc || !pc->cb_info || !mode) {
3416                 LOGE("NULL pointer %p %p", pc, mode);
3417                 return CAMERA_ERROR_INVALID_PARAMETER;
3418         }
3419
3420         _camera_msg_send(MUSE_CAMERA_API_GET_DISPLAY_MODE, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3421
3422         if (ret == CAMERA_ERROR_NONE)
3423                 *mode = (camera_display_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_MODE];
3424
3425         return ret;
3426 }
3427
3428
3429 int camera_set_display_reuse_hint(camera_h camera, bool hint)
3430 {
3431         int ret = CAMERA_ERROR_NONE;
3432         int set_hint = (int)hint;
3433         camera_cli_s *pc = (camera_cli_s *)camera;
3434         camera_msg_param param;
3435
3436         if (!pc || !pc->cb_info) {
3437                 LOGE("NULL handle");
3438                 return CAMERA_ERROR_INVALID_PARAMETER;
3439         }
3440
3441         LOGD("Enter - hint %d", set_hint);
3442
3443         CAMERA_MSG_PARAM_SET(param, INT, set_hint);
3444
3445         _camera_msg_send_param1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
3446
3447         return ret;
3448 }
3449
3450
3451 int camera_get_display_reuse_hint(camera_h camera, bool *hint)
3452 {
3453         int ret = CAMERA_ERROR_NONE;
3454         camera_cli_s *pc = (camera_cli_s *)camera;
3455         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
3456
3457         if (!pc || !pc->cb_info || !hint) {
3458                 LOGE("NULL pointer %p %p", pc, hint);
3459                 return CAMERA_ERROR_INVALID_PARAMETER;
3460         }
3461
3462         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3463
3464         if (ret == CAMERA_ERROR_NONE) {
3465                 *hint = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT];
3466                 LOGD("display reuse hint %d", *hint);
3467         }
3468
3469         return ret;
3470 }
3471
3472
3473 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
3474 {
3475         int ret = CAMERA_ERROR_NONE;
3476         camera_cli_s *pc = (camera_cli_s *)camera;
3477         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
3478
3479         if (!pc || !pc->cb_info || !width || !height) {
3480                 LOGE("NULL pointer %p %p %p", pc, width, height);
3481                 return CAMERA_ERROR_INVALID_PARAMETER;
3482         }
3483
3484         LOGD("Enter");
3485
3486         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3487
3488         if (ret == CAMERA_ERROR_NONE) {
3489                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION] >> 16;
3490                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION];
3491         }
3492
3493         LOGD("ret : 0x%x", ret);
3494
3495         return ret;
3496 }
3497
3498
3499 int camera_get_capture_format(camera_h camera, camera_pixel_format_e *format)
3500 {
3501         int ret = CAMERA_ERROR_NONE;
3502         camera_cli_s *pc = (camera_cli_s *)camera;
3503         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
3504
3505         if (!pc || !pc->cb_info || !format) {
3506                 LOGE("NULL pointer %p %p", pc, format);
3507                 return CAMERA_ERROR_INVALID_PARAMETER;
3508         }
3509
3510         LOGD("Enter");
3511
3512         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3513
3514         if (ret == CAMERA_ERROR_NONE)
3515                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CAPTURE_FORMAT];
3516
3517         LOGD("ret : 0x%x", ret);
3518
3519         return ret;
3520 }
3521
3522
3523 int camera_get_preview_format(camera_h camera, camera_pixel_format_e *format)
3524 {
3525         int ret = CAMERA_ERROR_NONE;
3526         camera_cli_s *pc = (camera_cli_s *)camera;
3527         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
3528
3529         if (!pc || !pc->cb_info || !format) {
3530                 LOGE("NULL pointer %p %p", pc, format);
3531                 return CAMERA_ERROR_INVALID_PARAMETER;
3532         }
3533
3534         LOGD("Enter");
3535
3536         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3537
3538         if (ret == CAMERA_ERROR_NONE)
3539                 *format = (camera_pixel_format_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FORMAT];
3540
3541         LOGD("ret : 0x%x", ret);
3542
3543         return ret;
3544 }
3545
3546
3547 int camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction)
3548 {
3549         int ret = CAMERA_ERROR_NONE;
3550         camera_cli_s *pc = (camera_cli_s *)camera;
3551         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
3552
3553         if (!pc || !pc->cb_info || !facing_direction) {
3554                 LOGE("NULL pointer %p %p", pc, facing_direction);
3555                 return CAMERA_ERROR_INVALID_PARAMETER;
3556         }
3557
3558         LOGD("Enter");
3559
3560         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3561
3562         if (ret == CAMERA_ERROR_NONE)
3563                 *facing_direction = (camera_facing_direction_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FACING_DIRECTION];
3564
3565         LOGD("ret : 0x%x", ret);
3566
3567         return ret;
3568 }
3569
3570
3571 int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data)
3572 {
3573         int ret = CAMERA_ERROR_NONE;
3574         camera_cli_s *pc = (camera_cli_s *)camera;
3575         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
3576
3577         if (!pc || !pc->cb_info || !callback) {
3578                 LOGE("NULL pointer %p %p", pc, callback);
3579                 return CAMERA_ERROR_INVALID_PARAMETER;
3580         }
3581
3582         LOGD("Enter");
3583
3584         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3585
3586         if (ret == CAMERA_ERROR_NONE) {
3587                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3588
3589                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
3590                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
3591
3592                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3593
3594                 SET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3595         }
3596
3597         LOGD("ret : 0x%x", ret);
3598
3599         return ret;
3600 }
3601
3602
3603 int camera_unset_preview_cb(camera_h camera)
3604 {
3605         int ret = CAMERA_ERROR_NONE;
3606         camera_cli_s *pc = (camera_cli_s *)camera;
3607         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
3608
3609         if (!pc || !pc->cb_info) {
3610                 LOGE("NULL handle");
3611                 return CAMERA_ERROR_INVALID_PARAMETER;
3612         }
3613
3614         LOGD("Enter");
3615
3616         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3617
3618         if (ret == CAMERA_ERROR_NONE) {
3619                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3620
3621                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3622                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
3623
3624                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
3625
3626                 UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
3627         }
3628
3629         LOGD("ret : 0x%x", ret);
3630
3631         return ret;
3632 }
3633
3634
3635 int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_preview_cb callback, void *user_data)
3636 {
3637         int ret = CAMERA_ERROR_NONE;
3638         camera_cli_s *pc = (camera_cli_s *)camera;
3639         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
3640
3641         if (!pc || !pc->cb_info) {
3642                 LOGE("NULL handle");
3643                 return CAMERA_ERROR_INVALID_PARAMETER;
3644         }
3645
3646         if (camera_is_supported_media_packet_preview_cb(camera) == false) {
3647                 LOGE("NOT SUPPORTED");
3648                 return CAMERA_ERROR_NOT_SUPPORTED;
3649         }
3650
3651         if (callback == NULL) {
3652                 LOGE("NULL callback");
3653                 return CAMERA_ERROR_INVALID_PARAMETER;
3654         }
3655
3656         LOGD("Enter");
3657
3658         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3659
3660         if (ret == CAMERA_ERROR_NONE) {
3661                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3662
3663                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
3664                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
3665
3666                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3667         }
3668
3669         LOGD("ret : 0x%x", ret);
3670
3671         return ret;
3672 }
3673
3674
3675 int camera_unset_media_packet_preview_cb(camera_h camera)
3676 {
3677         int ret = CAMERA_ERROR_NONE;
3678         camera_cli_s *pc = (camera_cli_s *)camera;
3679         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
3680
3681         if (!pc || !pc->cb_info) {
3682                 LOGE("NULL handle");
3683                 return CAMERA_ERROR_INVALID_PARAMETER;
3684         }
3685
3686         LOGD("Enter");
3687
3688         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3689
3690         if (ret == CAMERA_ERROR_NONE) {
3691                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3692
3693                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3694                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
3695
3696                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
3697         }
3698
3699         LOGD("ret : 0x%x", ret);
3700
3701         return ret;
3702 }
3703
3704
3705 int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data)
3706 {
3707         int ret = CAMERA_ERROR_NONE;
3708         camera_cli_s *pc = (camera_cli_s *)camera;
3709         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
3710
3711         if (!pc || !pc->cb_info || !callback) {
3712                 LOGE("NULL pointer %p %p", pc, callback);
3713                 return CAMERA_ERROR_INVALID_PARAMETER;
3714         }
3715
3716         LOGD("Enter");
3717
3718         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3719
3720         if (ret == CAMERA_ERROR_NONE) {
3721                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3722
3723                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
3724                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
3725
3726                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3727         }
3728
3729         LOGD("ret : 0x%x", ret);
3730
3731         return ret;
3732 }
3733
3734
3735 int camera_unset_state_changed_cb(camera_h camera)
3736 {
3737         int ret = CAMERA_ERROR_NONE;
3738         camera_cli_s *pc = (camera_cli_s *)camera;
3739         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
3740
3741         if (!pc || !pc->cb_info) {
3742                 LOGE("NULL handle");
3743                 return CAMERA_ERROR_INVALID_PARAMETER;
3744         }
3745
3746         LOGD("Enter");
3747
3748         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3749
3750         if (ret == CAMERA_ERROR_NONE) {
3751                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3752
3753                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3754                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
3755
3756                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
3757         }
3758
3759         LOGD("ret : 0x%x", ret);
3760
3761         return ret;
3762 }
3763
3764
3765 int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data)
3766 {
3767         int ret = CAMERA_ERROR_NONE;
3768         camera_cli_s *pc = (camera_cli_s *)camera;
3769         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
3770
3771         if (!pc || !pc->cb_info || !callback) {
3772                 LOGE("NULL pointer %p %p", pc, callback);
3773                 return CAMERA_ERROR_INVALID_PARAMETER;
3774         }
3775
3776         LOGD("Enter");
3777
3778         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3779
3780         if (ret == CAMERA_ERROR_NONE) {
3781                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3782
3783                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
3784                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
3785
3786                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3787         }
3788
3789         LOGD("ret : 0x%x", ret);
3790
3791         return ret;
3792 }
3793
3794
3795 int camera_unset_interrupted_cb(camera_h camera)
3796 {
3797         int ret = CAMERA_ERROR_NONE;
3798         camera_cli_s *pc = (camera_cli_s *)camera;
3799         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
3800
3801         if (!pc || !pc->cb_info) {
3802                 LOGE("NULL handle");
3803                 return CAMERA_ERROR_INVALID_PARAMETER;
3804         }
3805
3806         LOGD("Enter");
3807
3808         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3809
3810         if (ret == CAMERA_ERROR_NONE) {
3811                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3812
3813                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3814                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
3815
3816                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
3817         }
3818
3819         LOGD("ret : 0x%x", ret);
3820
3821         return ret;
3822 }
3823
3824
3825 int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
3826 {
3827         int ret = CAMERA_ERROR_NONE;
3828         camera_cli_s *pc = (camera_cli_s *)camera;
3829         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
3830
3831         if (!pc || !pc->cb_info || !callback) {
3832                 LOGE("NULL pointer %p %p", pc, callback);
3833                 return CAMERA_ERROR_INVALID_PARAMETER;
3834         }
3835
3836         LOGD("Enter");
3837
3838         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3839
3840         if (ret == CAMERA_ERROR_NONE) {
3841                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3842
3843                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
3844                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
3845
3846                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3847         }
3848
3849         LOGD("ret : 0x%x", ret);
3850
3851         return ret;
3852 }
3853
3854
3855 int camera_unset_interrupt_started_cb(camera_h camera)
3856 {
3857         int ret = CAMERA_ERROR_NONE;
3858         camera_cli_s *pc = (camera_cli_s *)camera;
3859         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
3860
3861         if (!pc || !pc->cb_info) {
3862                 LOGE("NULL handle");
3863                 return CAMERA_ERROR_INVALID_PARAMETER;
3864         }
3865
3866         LOGD("Enter");
3867
3868         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3869
3870         if (ret == CAMERA_ERROR_NONE) {
3871                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3872
3873                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3874                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
3875
3876                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
3877         }
3878
3879         LOGD("ret : 0x%x", ret);
3880
3881         return ret;
3882 }
3883
3884
3885 int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data)
3886 {
3887         int ret = CAMERA_ERROR_NONE;
3888         camera_cli_s *pc = (camera_cli_s *)camera;
3889         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
3890
3891         if (!pc || !pc->cb_info || !callback) {
3892                 LOGE("NULL pointer %p %p", pc, callback);
3893                 return CAMERA_ERROR_INVALID_PARAMETER;
3894         }
3895
3896         LOGD("Enter");
3897
3898         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3899
3900         if (ret == CAMERA_ERROR_NONE) {
3901                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3902
3903                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
3904                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
3905
3906                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3907         }
3908
3909         LOGD("ret : 0x%x", ret);
3910
3911         return ret;
3912 }
3913
3914
3915 int camera_unset_focus_changed_cb(camera_h camera)
3916 {
3917         int ret = CAMERA_ERROR_NONE;
3918         camera_cli_s *pc = (camera_cli_s *)camera;
3919         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
3920
3921         if (!pc || !pc->cb_info) {
3922                 LOGE("NULL handle");
3923                 return CAMERA_ERROR_INVALID_PARAMETER;
3924         }
3925
3926         LOGD("Enter");
3927
3928         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3929
3930         if (ret == CAMERA_ERROR_NONE) {
3931                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3932
3933                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
3934                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
3935
3936                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
3937         }
3938
3939         LOGD("ret : 0x%x", ret);
3940
3941         return ret;
3942 }
3943
3944
3945 int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data)
3946 {
3947         int ret = CAMERA_ERROR_NONE;
3948         camera_cli_s *pc = (camera_cli_s *)camera;
3949         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
3950
3951         if (!pc || !pc->cb_info || !callback) {
3952                 LOGE("NULL pointer %p %p", pc, callback);
3953                 return CAMERA_ERROR_INVALID_PARAMETER;
3954         }
3955
3956         LOGD("Enter");
3957
3958         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3959
3960         if (ret == CAMERA_ERROR_NONE) {
3961                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
3962
3963                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
3964                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
3965
3966                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
3967         }
3968
3969         LOGD("ret : 0x%x", ret);
3970
3971         return ret;
3972 }
3973
3974
3975 int camera_unset_error_cb(camera_h camera)
3976 {
3977         int ret = CAMERA_ERROR_NONE;
3978         camera_cli_s *pc = (camera_cli_s *)camera;
3979         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
3980
3981         if (!pc || !pc->cb_info) {
3982                 LOGE("NULL handle");
3983                 return CAMERA_ERROR_INVALID_PARAMETER;
3984         }
3985
3986         LOGD("Enter");
3987
3988         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
3989
3990         if (ret == CAMERA_ERROR_NONE) {
3991                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
3992
3993                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
3994                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
3995
3996                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
3997         }
3998
3999         LOGD("ret : 0x%x", ret);
4000
4001         return ret;
4002 }
4003
4004
4005 int camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data)
4006 {
4007         int ret = CAMERA_ERROR_NONE;
4008         camera_cli_s *pc = (camera_cli_s *)camera;
4009         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
4010
4011         if (!pc || !pc->cb_info || !foreach_cb) {
4012                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4013                 return CAMERA_ERROR_INVALID_PARAMETER;
4014         }
4015
4016         LOGD("Enter");
4017
4018         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = foreach_cb;
4019         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION] = user_data;
4020
4021         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4022
4023         LOGD("ret : 0x%x", ret);
4024
4025         return ret;
4026 }
4027
4028
4029 int camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data)
4030 {
4031         int ret = CAMERA_ERROR_NONE;
4032         camera_cli_s *pc = (camera_cli_s *)camera;
4033         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
4034
4035         if (!pc || !pc->cb_info || !foreach_cb) {
4036                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4037                 return CAMERA_ERROR_INVALID_PARAMETER;
4038         }
4039
4040         LOGD("Enter");
4041
4042         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = foreach_cb;
4043         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION] = user_data;
4044
4045         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4046
4047         LOGD("ret : 0x%x", ret);
4048
4049         return ret;
4050 }
4051
4052
4053 int camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data)
4054 {
4055         int ret = CAMERA_ERROR_NONE;
4056         camera_cli_s *pc = (camera_cli_s *)camera;
4057         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
4058
4059         if (!pc || !pc->cb_info || !foreach_cb) {
4060                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4061                 return CAMERA_ERROR_INVALID_PARAMETER;
4062         }
4063
4064         LOGD("Enter");
4065
4066         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = foreach_cb;
4067         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT] = user_data;
4068
4069         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4070
4071         LOGD("ret : 0x%x", ret);
4072
4073         return ret;
4074 }
4075
4076
4077 int camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data)
4078 {
4079         int ret = CAMERA_ERROR_NONE;
4080         camera_cli_s *pc = (camera_cli_s *)camera;
4081         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
4082
4083         if (!pc || !pc->cb_info || !foreach_cb) {
4084                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4085                 return CAMERA_ERROR_INVALID_PARAMETER;
4086         }
4087
4088         LOGD("Enter");
4089
4090         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = foreach_cb;
4091         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT] = user_data;
4092
4093         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4094
4095         LOGD("ret : 0x%x", ret);
4096
4097         return ret;
4098 }
4099
4100
4101 int camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height)
4102 {
4103         int ret = CAMERA_ERROR_NONE;
4104         camera_cli_s *pc = (camera_cli_s *)camera;
4105         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
4106
4107         if (!pc || !pc->cb_info || !width || !height) {
4108                 LOGE("NULL pointer %p %p %p", pc, width, height);
4109                 return CAMERA_ERROR_INVALID_PARAMETER;
4110         }
4111
4112         LOGD("Enter");
4113         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4114
4115         if (ret == CAMERA_ERROR_NONE) {
4116                 *width = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION] >> 16;
4117                 *height = 0x0000ffff & pc->cb_info->get_int[MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION];
4118         }
4119
4120         LOGD("ret : 0x%x", ret);
4121
4122         return ret;
4123 }
4124
4125
4126 int camera_attr_get_lens_orientation(camera_h camera, int *angle)
4127 {
4128         int ret = CAMERA_ERROR_NONE;
4129         camera_cli_s *pc = (camera_cli_s *)camera;
4130         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
4131
4132         if (!pc || !pc->cb_info || !angle) {
4133                 LOGE("NULL pointer %p %p", pc, angle);
4134                 return CAMERA_ERROR_INVALID_PARAMETER;
4135         }
4136
4137         LOGD("Enter");
4138
4139         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4140
4141         if (ret == CAMERA_ERROR_NONE)
4142                 *angle = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_LENS_ORIENTATION];
4143
4144         LOGD("ret : 0x%x", ret);
4145
4146         return ret;
4147 }
4148
4149
4150 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
4151 {
4152         int ret = CAMERA_ERROR_NONE;
4153         camera_cli_s *pc = (camera_cli_s *)camera;
4154         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_THEATER_MODE;
4155         camera_msg_param param;
4156         int set_mode = (int)mode;
4157
4158         if (!pc || !pc->cb_info) {
4159                 LOGE("NULL handle");
4160                 return CAMERA_ERROR_INVALID_PARAMETER;
4161         }
4162
4163         LOGD("Enter");
4164
4165         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4166
4167         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4168
4169         LOGD("ret : 0x%x", ret);
4170
4171         return ret;
4172 }
4173
4174
4175 int camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode)
4176 {
4177         int ret = CAMERA_ERROR_NONE;
4178         camera_cli_s *pc = (camera_cli_s *)camera;
4179         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
4180
4181         if (!pc || !pc->cb_info || !mode) {
4182                 LOGE("NULL pointer %p %p", pc, mode);
4183                 return CAMERA_ERROR_INVALID_PARAMETER;
4184         }
4185
4186         LOGD("Enter");
4187
4188         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4189
4190         if (ret == CAMERA_ERROR_NONE)
4191                 *mode = (camera_attr_theater_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_THEATER_MODE];
4192
4193         LOGD("ret : 0x%x", ret);
4194
4195         return ret;
4196 }
4197
4198
4199 int camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data)
4200 {
4201         int ret = CAMERA_ERROR_NONE;
4202         camera_cli_s *pc = (camera_cli_s *)camera;
4203         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
4204
4205         if (!pc || !pc->cb_info || !foreach_cb) {
4206                 LOGE("NULL pointer %p %p", pc, foreach_cb);
4207                 return CAMERA_ERROR_INVALID_PARAMETER;
4208         }
4209
4210         LOGD("Enter");
4211
4212         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = foreach_cb;
4213         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE] = user_data;
4214
4215         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4216
4217         LOGD("Finish, return :%x", ret);
4218
4219         return ret;
4220 }
4221
4222
4223 int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
4224 {
4225         int ret = CAMERA_ERROR_NONE;
4226         camera_cli_s *pc = (camera_cli_s *)camera;
4227         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
4228         camera_msg_param param;
4229         int set_fps = (int)fps;
4230
4231         if (!pc || !pc->cb_info) {
4232                 LOGE("NULL handle");
4233                 return CAMERA_ERROR_INVALID_PARAMETER;
4234         }
4235
4236         LOGD("Enter");
4237
4238         CAMERA_MSG_PARAM_SET(param, INT, set_fps);
4239
4240         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4241
4242         LOGD("ret : 0x%x", ret);
4243
4244         return ret;
4245 }
4246
4247
4248 int camera_attr_set_image_quality(camera_h camera, int quality)
4249 {
4250         int ret = CAMERA_ERROR_NONE;
4251         camera_cli_s *pc = (camera_cli_s *)camera;
4252         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
4253         camera_msg_param param;
4254
4255         if (!pc || !pc->cb_info) {
4256                 LOGE("NULL handle");
4257                 return CAMERA_ERROR_INVALID_PARAMETER;
4258         }
4259
4260         LOGD("Enter");
4261
4262         CAMERA_MSG_PARAM_SET(param, INT, quality);
4263
4264         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4265
4266         LOGD("ret : 0x%x", ret);
4267
4268         return ret;
4269 }
4270
4271
4272 int camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps)
4273 {
4274         int ret = CAMERA_ERROR_NONE;
4275         camera_cli_s *pc = (camera_cli_s *)camera;
4276         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
4277
4278         if (!pc || !pc->cb_info || !fps) {
4279                 LOGE("NULL pointer %p %p", pc, fps);
4280                 return CAMERA_ERROR_INVALID_PARAMETER;
4281         }
4282
4283         LOGD("Enter");
4284
4285         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4286
4287         if (ret == CAMERA_ERROR_NONE)
4288                 *fps = (camera_attr_fps_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PREVIEW_FPS];
4289
4290         LOGD("ret : 0x%x", ret);
4291
4292         return ret;
4293 }
4294
4295
4296 int camera_attr_get_image_quality(camera_h camera, int *quality)
4297 {
4298         int ret = CAMERA_ERROR_NONE;
4299         camera_cli_s *pc = (camera_cli_s *)camera;
4300         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
4301
4302         if (!pc || !pc->cb_info || !quality) {
4303                 LOGE("NULL pointer %p %p", pc, quality);
4304                 return CAMERA_ERROR_INVALID_PARAMETER;
4305         }
4306
4307         LOGD("Enter");
4308
4309         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4310
4311         if (ret == CAMERA_ERROR_NONE)
4312                 *quality = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_IMAGE_QUALITY];
4313
4314         LOGD("ret : 0x%x", ret);
4315
4316         return ret;
4317 }
4318
4319
4320 int camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate)
4321 {
4322         int ret = CAMERA_ERROR_NONE;
4323         camera_cli_s *pc = (camera_cli_s *)camera;
4324         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4325
4326         if (!pc || !pc->cb_info || !bitrate) {
4327                 LOGE("NULL pointer %p %p", pc, bitrate);
4328                 return CAMERA_ERROR_INVALID_PARAMETER;
4329         }
4330
4331         LOGD("Enter");
4332
4333         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4334
4335         if (ret == CAMERA_ERROR_NONE)
4336                 *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE];
4337
4338         LOGD("ret : 0x%x", ret);
4339
4340         return ret;
4341 }
4342
4343
4344 int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
4345 {
4346         int ret = CAMERA_ERROR_NONE;
4347         camera_cli_s *pc = (camera_cli_s *)camera;
4348         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4349         camera_msg_param param;
4350         int set_bitrate = bitrate;
4351
4352         if (!pc || !pc->cb_info) {
4353                 LOGE("NULL handle");
4354                 return CAMERA_ERROR_INVALID_PARAMETER;
4355         }
4356
4357         LOGD("Enter");
4358
4359         CAMERA_MSG_PARAM_SET(param, INT, set_bitrate);
4360
4361         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4362
4363         LOGD("ret : 0x%x", ret);
4364
4365         return ret;
4366 }
4367
4368
4369 int camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval)
4370 {
4371         int ret = CAMERA_ERROR_NONE;
4372         camera_cli_s *pc = (camera_cli_s *)camera;
4373         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4374
4375         if (!pc || !pc->cb_info || !interval) {
4376                 LOGE("NULL pointer %p %p", pc, interval);
4377                 return CAMERA_ERROR_INVALID_PARAMETER;
4378         }
4379
4380         LOGD("Enter");
4381
4382         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4383
4384         if (ret == CAMERA_ERROR_NONE)
4385                 *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL];
4386
4387         LOGD("ret : 0x%x", ret);
4388
4389         return ret;
4390 }
4391
4392
4393 int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
4394 {
4395         int ret = CAMERA_ERROR_NONE;
4396         camera_cli_s *pc = (camera_cli_s *)camera;
4397         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4398         camera_msg_param param;
4399         int set_gop_interval = interval;
4400
4401         if (!pc || !pc->cb_info) {
4402                 LOGE("NULL handle");
4403                 return CAMERA_ERROR_INVALID_PARAMETER;
4404         }
4405
4406         LOGD("Enter");
4407
4408         CAMERA_MSG_PARAM_SET(param, INT, set_gop_interval);
4409
4410         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4411
4412         LOGD("ret : 0x%x", ret);
4413
4414         return ret;
4415 }
4416
4417
4418 int camera_attr_set_zoom(camera_h camera, int zoom)
4419 {
4420         int ret = CAMERA_ERROR_NONE;
4421         camera_cli_s *pc = (camera_cli_s *)camera;
4422         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
4423         camera_msg_param param;
4424
4425         if (!pc || !pc->cb_info) {
4426                 LOGE("NULL handle");
4427                 return CAMERA_ERROR_INVALID_PARAMETER;
4428         }
4429
4430         LOGD("Enter, remote_handle : %x", pc->remote_handle);
4431
4432         CAMERA_MSG_PARAM_SET(param, INT, zoom);
4433
4434         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4435
4436         LOGD("ret : 0x%x", ret);
4437
4438         return ret;
4439 }
4440
4441
4442 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
4443 {
4444         int ret = CAMERA_ERROR_NONE;
4445         camera_cli_s *pc = (camera_cli_s *)camera;
4446         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_MODE;
4447         camera_msg_param param;
4448         int set_mode = (int)mode;
4449
4450         if (!pc || !pc->cb_info) {
4451                 LOGE("NULL handle");
4452                 return CAMERA_ERROR_INVALID_PARAMETER;
4453         }
4454
4455         LOGD("Enter, remote_handle : %x", pc->remote_handle);
4456
4457         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4458
4459         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4460
4461         return ret;
4462 }
4463
4464
4465 int camera_attr_set_af_area(camera_h camera, int x, int y)
4466 {
4467         int ret = CAMERA_ERROR_NONE;
4468         camera_cli_s *pc = (camera_cli_s *)camera;
4469         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
4470         camera_msg_param param;
4471         int value = 0;
4472
4473         if (!pc || !pc->cb_info) {
4474                 LOGE("NULL handle");
4475                 return CAMERA_ERROR_INVALID_PARAMETER;
4476         }
4477
4478         LOGD("Enter - %d,%d", x, y);
4479
4480         value = (x << 16) | y;
4481         CAMERA_MSG_PARAM_SET(param, INT, value);
4482
4483         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4484
4485         LOGD("ret : 0x%x", ret);
4486
4487         return ret;
4488 }
4489
4490
4491 int camera_attr_clear_af_area(camera_h camera)
4492 {
4493         int ret = CAMERA_ERROR_NONE;
4494         camera_cli_s *pc = (camera_cli_s *)camera;
4495         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
4496
4497         if (!pc || !pc->cb_info) {
4498                 LOGE("NULL handle");
4499                 return CAMERA_ERROR_INVALID_PARAMETER;
4500         }
4501
4502         LOGD("Enter");
4503
4504         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4505
4506         LOGD("ret : 0x%x", ret);
4507
4508         return ret;
4509 }
4510
4511
4512 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
4513 {
4514         int ret = CAMERA_ERROR_NONE;
4515         camera_cli_s *pc = (camera_cli_s *)camera;
4516         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE;
4517         camera_msg_param param;
4518         int set_mode = (int)mode;
4519
4520         if (!pc || !pc->cb_info) {
4521                 LOGE("NULL handle");
4522                 return CAMERA_ERROR_INVALID_PARAMETER;
4523         }
4524
4525         LOGD("Enter");
4526
4527         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4528
4529         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4530
4531         LOGD("ret : 0x%x", ret);
4532
4533         return ret;
4534 }
4535
4536
4537 int camera_attr_set_exposure(camera_h camera, int value)
4538 {
4539         int ret = CAMERA_ERROR_NONE;
4540         camera_cli_s *pc = (camera_cli_s *)camera;
4541         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
4542         camera_msg_param param;
4543
4544         if (!pc || !pc->cb_info) {
4545                 LOGE("NULL handle");
4546                 return CAMERA_ERROR_INVALID_PARAMETER;
4547         }
4548
4549         LOGD("Enter");
4550
4551         CAMERA_MSG_PARAM_SET(param, INT, value);
4552
4553         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4554
4555         LOGD("ret : 0x%x", ret);
4556
4557         return ret;
4558 }
4559
4560
4561 int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
4562 {
4563         int ret = CAMERA_ERROR_NONE;
4564         camera_cli_s *pc = (camera_cli_s *)camera;
4565         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
4566         camera_msg_param param;
4567         int set_iso = (int)iso;
4568
4569         if (!pc || !pc->cb_info) {
4570                 LOGE("NULL handle");
4571                 return CAMERA_ERROR_INVALID_PARAMETER;
4572         }
4573
4574         LOGD("Enter");
4575
4576         CAMERA_MSG_PARAM_SET(param, INT, set_iso);
4577
4578         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4579
4580         LOGD("ret : 0x%x", ret);
4581
4582         return ret;
4583 }
4584
4585
4586 int camera_attr_set_brightness(camera_h camera, int level)
4587 {
4588         int ret = CAMERA_ERROR_NONE;
4589         camera_cli_s *pc = (camera_cli_s *)camera;
4590         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
4591         camera_msg_param param;
4592
4593         if (!pc || !pc->cb_info) {
4594                 LOGE("NULL handle");
4595                 return CAMERA_ERROR_INVALID_PARAMETER;
4596         }
4597
4598         LOGD("Enter");
4599
4600         CAMERA_MSG_PARAM_SET(param, INT, level);
4601
4602         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4603
4604         LOGD("ret : 0x%x", ret);
4605
4606         return ret;
4607 }
4608
4609
4610 int camera_attr_set_contrast(camera_h camera, int level)
4611 {
4612         int ret = CAMERA_ERROR_NONE;
4613         camera_cli_s *pc = (camera_cli_s *)camera;
4614         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
4615         camera_msg_param param;
4616
4617         if (!pc || !pc->cb_info) {
4618                 LOGE("NULL handle");
4619                 return CAMERA_ERROR_INVALID_PARAMETER;
4620         }
4621
4622         LOGD("Enter");
4623
4624         CAMERA_MSG_PARAM_SET(param, INT, level);
4625
4626         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4627
4628         LOGD("ret : 0x%x", ret);
4629
4630         return ret;
4631 }
4632
4633
4634 int camera_attr_set_hue(camera_h camera, int level)
4635 {
4636         int ret = CAMERA_ERROR_NONE;
4637         camera_cli_s *pc = (camera_cli_s *)camera;
4638         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
4639         camera_msg_param param;
4640
4641         if (!pc || !pc->cb_info) {
4642                 LOGE("NULL handle");
4643                 return CAMERA_ERROR_INVALID_PARAMETER;
4644         }
4645
4646         LOGD("Enter");
4647
4648         CAMERA_MSG_PARAM_SET(param, INT, level);
4649
4650         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4651
4652         LOGD("ret : 0x%x", ret);
4653
4654         return ret;
4655 }
4656
4657
4658 int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
4659 {
4660         int ret = CAMERA_ERROR_NONE;
4661         camera_cli_s *pc = (camera_cli_s *)camera;
4662         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
4663         camera_msg_param param;
4664         int set_whitebalance = (int)wb;
4665
4666         if (!pc || !pc->cb_info) {
4667                 LOGE("NULL handle");
4668                 return CAMERA_ERROR_INVALID_PARAMETER;
4669         }
4670
4671         LOGD("Enter");
4672
4673         CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
4674
4675         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4676
4677         LOGD("ret : 0x%x", ret);
4678
4679         return ret;
4680 }
4681
4682
4683 int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
4684 {
4685         int ret = CAMERA_ERROR_NONE;
4686         camera_cli_s *pc = (camera_cli_s *)camera;
4687         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
4688         camera_msg_param param;
4689         int set_effect = (int)effect;
4690
4691         if (!pc || !pc->cb_info) {
4692                 LOGE("NULL handle");
4693                 return CAMERA_ERROR_INVALID_PARAMETER;
4694         }
4695
4696         LOGD("Enter");
4697
4698         CAMERA_MSG_PARAM_SET(param, INT, set_effect);
4699
4700         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4701
4702         LOGD("ret : 0x%x", ret);
4703
4704         return ret;
4705 }
4706
4707
4708 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
4709 {
4710         int ret = CAMERA_ERROR_NONE;
4711         camera_cli_s *pc = (camera_cli_s *)camera;
4712         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_SCENE_MODE;
4713         camera_msg_param param;
4714         int set_mode = (int)mode;
4715
4716         if (!pc || !pc->cb_info) {
4717                 LOGE("NULL handle");
4718                 return CAMERA_ERROR_INVALID_PARAMETER;
4719         }
4720
4721         LOGD("Enter");
4722
4723         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4724
4725         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4726
4727         LOGD("ret : 0x%x", ret);
4728
4729         return ret;
4730 }
4731
4732
4733 int camera_attr_enable_tag(camera_h camera, bool enable)
4734 {
4735         int ret = CAMERA_ERROR_NONE;
4736         camera_cli_s *pc = (camera_cli_s *)camera;
4737         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_TAG;
4738         camera_msg_param param;
4739         int set_enable = (int)enable;
4740
4741         if (!pc || !pc->cb_info) {
4742                 LOGE("NULL handle");
4743                 return CAMERA_ERROR_INVALID_PARAMETER;
4744         }
4745
4746         LOGD("Enter");
4747
4748         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
4749
4750         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4751
4752         LOGD("ret : 0x%x", ret);
4753
4754         return ret;
4755 }
4756
4757
4758 int camera_attr_set_tag_image_description(camera_h camera, const char *description)
4759 {
4760         int ret = CAMERA_ERROR_NONE;
4761         camera_cli_s *pc = (camera_cli_s *)camera;
4762         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
4763         camera_msg_param param;
4764
4765         if (!pc || !pc->cb_info || !description) {
4766                 LOGE("NULL pointer %p %p", pc, description);
4767                 return CAMERA_ERROR_INVALID_PARAMETER;
4768         }
4769
4770         LOGD("Enter");
4771
4772         CAMERA_MSG_PARAM_SET(param, STRING, description);
4773
4774         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4775
4776         LOGD("ret : 0x%x", ret);
4777
4778         return ret;
4779 }
4780
4781
4782 int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation)
4783 {
4784         int ret = CAMERA_ERROR_NONE;
4785         camera_cli_s *pc = (camera_cli_s *)camera;
4786         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
4787         camera_msg_param param;
4788         int set_orientation = (int)orientation;
4789
4790         if (!pc || !pc->cb_info) {
4791                 LOGE("NULL handle");
4792                 return CAMERA_ERROR_INVALID_PARAMETER;
4793         }
4794
4795         LOGD("Enter");
4796
4797         CAMERA_MSG_PARAM_SET(param, INT, set_orientation);
4798
4799         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4800
4801         LOGD("ret : 0x%x", ret);
4802
4803         return ret;
4804 }
4805
4806
4807 int camera_attr_set_tag_software(camera_h camera, const char *software)
4808 {
4809         int ret = CAMERA_ERROR_NONE;
4810         camera_cli_s *pc = (camera_cli_s *)camera;
4811         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
4812         camera_msg_param param;
4813
4814         if (!pc || !pc->cb_info || !software) {
4815                 LOGE("NULL pointer %p %p", pc, software);
4816                 return CAMERA_ERROR_INVALID_PARAMETER;
4817         }
4818
4819         LOGD("Enter, remote_handle : %x", pc->remote_handle);
4820
4821         CAMERA_MSG_PARAM_SET(param, STRING, software);
4822
4823         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4824
4825         LOGD("ret : 0x%x", ret);
4826
4827         return ret;
4828 }
4829
4830
4831 int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, double altitude)
4832 {
4833         int ret = CAMERA_ERROR_NONE;
4834         camera_cli_s *pc = (camera_cli_s *)camera;
4835         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
4836         double set_geotag[3] = {latitude, longitude, altitude};
4837         char *msg = NULL;
4838         int length = 0;
4839         int send_ret = 0;
4840
4841         if (!pc || !pc->cb_info) {
4842                 LOGE("NULL handle");
4843                 return CAMERA_ERROR_INVALID_PARAMETER;
4844         }
4845
4846         LOGD("Enter");
4847
4848         length = sizeof(set_geotag) / sizeof(int) + \
4849                 (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
4850
4851         msg = muse_core_msg_new(api,
4852                 MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
4853                 NULL);
4854         if (!msg) {
4855                 LOGE("msg creation failed: api %d", api);
4856                 return CAMERA_ERROR_OUT_OF_MEMORY;
4857         }
4858
4859         if (pc->cb_info->is_server_connected) {
4860                 __camera_update_api_waiting(pc->cb_info, api, 1);
4861
4862                 g_mutex_lock(&pc->cb_info->fd_lock);
4863                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
4864                 g_mutex_unlock(&pc->cb_info->fd_lock);
4865         }
4866
4867         if (send_ret < 0) {
4868                 LOGE("message send failed");
4869                 ret = CAMERA_ERROR_INVALID_OPERATION;
4870         } else {
4871                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
4872         }
4873
4874         __camera_update_api_waiting(pc->cb_info, api, -1);
4875
4876         muse_core_msg_free(msg);
4877
4878         LOGD("ret : 0x%x", ret);
4879
4880         return ret;
4881 }
4882
4883
4884 int camera_attr_remove_geotag(camera_h camera)
4885 {
4886         int ret = CAMERA_ERROR_NONE;
4887         camera_cli_s *pc = (camera_cli_s *)camera;
4888         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
4889
4890         if (!pc || !pc->cb_info) {
4891                 LOGE("NULL handle");
4892                 return CAMERA_ERROR_INVALID_PARAMETER;
4893         }
4894
4895         LOGD("Enter");
4896
4897         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4898
4899         LOGD("ret : 0x%x", ret);
4900
4901         return ret;
4902 }
4903
4904
4905 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
4906 {
4907         int ret = CAMERA_ERROR_NONE;
4908         camera_cli_s *pc = (camera_cli_s *)camera;
4909         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
4910         camera_msg_param param;
4911         int set_mode = (int)mode;
4912
4913         if (!pc || !pc->cb_info) {
4914                 LOGE("NULL handle");
4915                 return CAMERA_ERROR_INVALID_PARAMETER;
4916         }
4917
4918         LOGD("Enter");
4919
4920         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
4921
4922         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
4923
4924         LOGD("ret : 0x%x", ret);
4925
4926         return ret;
4927 }
4928
4929
4930 int camera_attr_get_zoom(camera_h camera, int *zoom)
4931 {
4932         int ret = CAMERA_ERROR_NONE;
4933         camera_cli_s *pc = (camera_cli_s *)camera;
4934         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
4935
4936         if (!pc || !pc->cb_info || !zoom) {
4937                 LOGE("NULL pointer %p %p", pc, zoom);
4938                 return CAMERA_ERROR_INVALID_PARAMETER;
4939         }
4940
4941         LOGD("Enter");
4942
4943         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4944
4945         if (ret == CAMERA_ERROR_NONE)
4946                 *zoom = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ZOOM];
4947
4948         LOGD("ret : 0x%x", ret);
4949
4950         return ret;
4951 }
4952
4953
4954 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
4955 {
4956         int ret = CAMERA_ERROR_NONE;
4957         camera_cli_s *pc = (camera_cli_s *)camera;
4958         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
4959
4960         if (!pc || !pc->cb_info || !min || !max) {
4961                 LOGE("NULL pointer %p %p %p", pc, min, max);
4962                 return CAMERA_ERROR_INVALID_PARAMETER;
4963         }
4964
4965         LOGD("Enter");
4966
4967         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4968
4969         if (ret == CAMERA_ERROR_NONE) {
4970                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
4971                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
4972         }
4973
4974         LOGD("ret : 0x%x", ret);
4975
4976         return ret;
4977 }
4978
4979
4980 int camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode)
4981 {
4982         int ret = CAMERA_ERROR_NONE;
4983         camera_cli_s *pc = (camera_cli_s *)camera;
4984         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
4985
4986         if (!pc || !pc->cb_info || !mode) {
4987                 LOGE("NULL pointer %p %p", pc, mode);
4988                 return CAMERA_ERROR_INVALID_PARAMETER;
4989         }
4990
4991         LOGD("Enter");
4992
4993         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
4994
4995         if (ret == CAMERA_ERROR_NONE)
4996                 *mode = (camera_attr_af_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_AF_MODE];
4997
4998         LOGD("ret : 0x%x", ret);
4999
5000         return ret;
5001 }
5002
5003
5004 int camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode)
5005 {
5006         int ret = CAMERA_ERROR_NONE;
5007         camera_cli_s *pc = (camera_cli_s *)camera;
5008         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
5009
5010         if (!pc || !pc->cb_info || !mode) {
5011                 LOGE("NULL pointer %p %p", pc, mode);
5012                 return CAMERA_ERROR_INVALID_PARAMETER;
5013         }
5014
5015         LOGD("Enter");
5016
5017         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5018
5019         if (ret == CAMERA_ERROR_NONE)
5020                 *mode = (camera_attr_exposure_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE_MODE];
5021
5022         LOGD("ret : 0x%x", ret);
5023
5024         return ret;
5025 }
5026
5027
5028 int camera_attr_get_exposure(camera_h camera, int *value)
5029 {
5030         int ret = CAMERA_ERROR_NONE;
5031         camera_cli_s *pc = (camera_cli_s *)camera;
5032         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
5033
5034         if (!pc || !pc->cb_info || !value) {
5035                 LOGE("NULL pointer %p %p", pc, value);
5036                 return CAMERA_ERROR_INVALID_PARAMETER;
5037         }
5038
5039         LOGD("Enter");
5040
5041         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5042
5043         if (ret == CAMERA_ERROR_NONE)
5044                 *value = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXPOSURE];
5045
5046         LOGD("ret : 0x%x", ret);
5047
5048         return ret;
5049 }
5050
5051
5052 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
5053 {
5054         int ret = CAMERA_ERROR_NONE;
5055         camera_cli_s *pc = (camera_cli_s *)camera;
5056         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
5057
5058         if (!pc || !pc->cb_info || !min || !max) {
5059                 LOGE("NULL pointer %p %p %p", pc, min, max);
5060                 return CAMERA_ERROR_INVALID_PARAMETER;
5061         }
5062
5063         LOGD("Enter");
5064
5065         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5066
5067         if (ret == CAMERA_ERROR_NONE) {
5068                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
5069                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
5070         }
5071
5072         LOGD("ret : 0x%x", ret);
5073
5074         return ret;
5075 }
5076
5077
5078 int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
5079 {
5080         int ret = CAMERA_ERROR_NONE;
5081         camera_cli_s *pc = (camera_cli_s *)camera;
5082         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
5083
5084         if (!pc || !pc->cb_info || !iso) {
5085                 LOGE("NULL pointer %p %p", pc, iso);
5086                 return CAMERA_ERROR_INVALID_PARAMETER;
5087         }
5088
5089         LOGD("Enter");
5090
5091         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5092
5093         if (ret == CAMERA_ERROR_NONE)
5094                 *iso = (camera_attr_iso_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ISO];
5095
5096         LOGD("ret : 0x%x", ret);
5097
5098         return ret;
5099 }
5100
5101
5102 int camera_attr_get_brightness(camera_h camera, int *level)
5103 {
5104         int ret = CAMERA_ERROR_NONE;
5105         camera_cli_s *pc = (camera_cli_s *)camera;
5106         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
5107
5108         if (!pc || !pc->cb_info || !level) {
5109                 LOGE("NULL pointer %p %p", pc, level);
5110                 return CAMERA_ERROR_INVALID_PARAMETER;
5111         }
5112
5113         LOGD("Enter");
5114
5115         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5116
5117         if (ret == CAMERA_ERROR_NONE)
5118                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
5119
5120         LOGD("ret : 0x%x", ret);
5121
5122         return ret;
5123 }
5124
5125
5126 int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
5127 {
5128         int ret = CAMERA_ERROR_NONE;
5129         camera_cli_s *pc = (camera_cli_s *)camera;
5130         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
5131
5132         if (!pc || !pc->cb_info || !min || !max) {
5133                 LOGE("NULL pointer %p %p %p", pc, min, max);
5134                 return CAMERA_ERROR_INVALID_PARAMETER;
5135         }
5136
5137         LOGD("Enter");
5138
5139         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5140
5141         if (ret == CAMERA_ERROR_NONE) {
5142                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
5143                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
5144         }
5145
5146         LOGD("ret : 0x%x", ret);
5147
5148         return ret;
5149 }
5150
5151
5152 int camera_attr_get_contrast(camera_h camera, int *level)
5153 {
5154         int ret = CAMERA_ERROR_NONE;
5155         camera_cli_s *pc = (camera_cli_s *)camera;
5156         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
5157
5158         if (!pc || !pc->cb_info || !level) {
5159                 LOGE("NULL pointer %p %p", pc, level);
5160                 return CAMERA_ERROR_INVALID_PARAMETER;
5161         }
5162
5163         LOGD("Enter");
5164
5165         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5166
5167         if (ret == CAMERA_ERROR_NONE)
5168                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
5169
5170         LOGD("ret : 0x%x", ret);
5171
5172         return ret;
5173 }
5174
5175
5176 int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
5177 {
5178         int ret = CAMERA_ERROR_NONE;
5179         camera_cli_s *pc = (camera_cli_s *)camera;
5180         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
5181
5182         if (!pc || !pc->cb_info || !min || !max) {
5183                 LOGE("NULL pointer %p %p %p", pc, min, max);
5184                 return CAMERA_ERROR_INVALID_PARAMETER;
5185         }
5186
5187         LOGD("Enter");
5188
5189         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5190
5191         if (ret == CAMERA_ERROR_NONE) {
5192                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
5193                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
5194                 LOGD("min %d, max %d", *min, *max);
5195         }
5196
5197         LOGD("ret : 0x%x", ret);
5198
5199         return ret;
5200 }
5201
5202
5203 int camera_attr_get_hue(camera_h camera, int *level)
5204 {
5205         int ret = CAMERA_ERROR_NONE;
5206         camera_cli_s *pc = (camera_cli_s *)camera;
5207         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
5208
5209         if (!pc || !pc->cb_info || !level) {
5210                 LOGE("NULL pointer %p %p", pc, level);
5211                 return CAMERA_ERROR_INVALID_PARAMETER;
5212         }
5213
5214         LOGD("Enter");
5215
5216         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5217
5218         if (ret == CAMERA_ERROR_NONE)
5219                 *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
5220
5221         LOGD("ret : 0x%x", ret);
5222
5223         return ret;
5224 }
5225
5226
5227 int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
5228 {
5229         int ret = CAMERA_ERROR_NONE;
5230         camera_cli_s *pc = (camera_cli_s *)camera;
5231         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
5232
5233         if (!pc || !pc->cb_info || !min || !max) {
5234                 LOGE("NULL pointer %p %p %p", pc, min, max);
5235                 return CAMERA_ERROR_INVALID_PARAMETER;
5236         }
5237
5238         LOGD("Enter");
5239
5240         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5241
5242         if (ret == CAMERA_ERROR_NONE) {
5243                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
5244                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
5245                 LOGD("min %d, max %d", *min, *max);
5246         }
5247
5248         LOGD("ret : 0x%x", ret);
5249
5250         return ret;
5251 }
5252
5253
5254 int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
5255 {
5256         int ret = CAMERA_ERROR_NONE;
5257         camera_cli_s *pc = (camera_cli_s *)camera;
5258         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
5259
5260         if (!pc || !pc->cb_info || !wb) {
5261                 LOGE("NULL pointer %p %p", pc, wb);
5262                 return CAMERA_ERROR_INVALID_PARAMETER;
5263         }
5264
5265         LOGD("Enter");
5266
5267         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5268
5269         if (ret == CAMERA_ERROR_NONE)
5270                 *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
5271
5272         LOGD("ret : 0x%x", ret);
5273
5274         return ret;
5275 }
5276
5277
5278 int camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect)
5279 {
5280         int ret = CAMERA_ERROR_NONE;
5281         camera_cli_s *pc = (camera_cli_s *)camera;
5282         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
5283
5284         if (!pc || !pc->cb_info || !effect) {
5285                 LOGE("NULL pointer %p %p", pc, effect);
5286                 return CAMERA_ERROR_INVALID_PARAMETER;
5287         }
5288
5289         LOGD("Enter");
5290
5291         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5292
5293         if (ret == CAMERA_ERROR_NONE)
5294                 *effect = (camera_attr_effect_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EFFECT];
5295
5296         LOGD("ret : 0x%x", ret);
5297
5298         return ret;
5299 }
5300
5301
5302 int camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode)
5303 {
5304         int ret = CAMERA_ERROR_NONE;
5305         camera_cli_s *pc = (camera_cli_s *)camera;
5306         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
5307
5308         if (!pc || !pc->cb_info || !mode) {
5309                 LOGE("NULL pointer %p %p", pc, mode);
5310                 return CAMERA_ERROR_INVALID_PARAMETER;
5311         }
5312
5313         LOGD("Enter");
5314
5315         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5316
5317         if (ret == CAMERA_ERROR_NONE)
5318                 *mode = (camera_attr_scene_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_SCENE_MODE];
5319
5320         LOGD("ret : 0x%x", ret);
5321
5322         return ret;
5323 }
5324
5325
5326 int camera_attr_is_enabled_tag(camera_h camera, bool *enable)
5327 {
5328         int ret = CAMERA_ERROR_NONE;
5329         camera_cli_s *pc = (camera_cli_s *)camera;
5330         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
5331
5332         if (!pc || !pc->cb_info || !enable) {
5333                 LOGE("NULL pointer %p %p", pc, enable);
5334                 return CAMERA_ERROR_INVALID_PARAMETER;
5335         }
5336
5337         LOGD("Enter");
5338
5339         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5340
5341         if (ret == CAMERA_ERROR_NONE)
5342                 *enable = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_TAG];
5343
5344         LOGD("ret : 0x%x", ret);
5345
5346         return ret;
5347 }
5348
5349
5350 int camera_attr_get_tag_image_description(camera_h camera, char **description)
5351 {
5352         int ret = CAMERA_ERROR_NONE;
5353         camera_cli_s *pc = (camera_cli_s *)camera;
5354         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
5355
5356         if (!pc || !pc->cb_info || !description) {
5357                 LOGE("NULL pointer %p %p", pc, description);
5358                 return CAMERA_ERROR_INVALID_PARAMETER;
5359         }
5360
5361         LOGD("Enter");
5362
5363         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5364
5365         if (ret == CAMERA_ERROR_NONE)
5366                 *description = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION]);
5367
5368         LOGD("ret : 0x%x", ret);
5369
5370         return ret;
5371 }
5372
5373
5374 int camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation)
5375 {
5376         int ret = CAMERA_ERROR_NONE;
5377         camera_cli_s *pc = (camera_cli_s *)camera;
5378         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
5379
5380         if (!pc || !pc->cb_info || !orientation) {
5381                 LOGE("NULL pointer %p %p", pc, orientation);
5382                 return CAMERA_ERROR_INVALID_PARAMETER;
5383         }
5384
5385         LOGD("Enter");
5386
5387         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5388
5389         if (ret == CAMERA_ERROR_NONE)
5390                 *orientation = (camera_attr_tag_orientation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TAG_ORIENTATION];
5391
5392         LOGD("ret : 0x%x", ret);
5393
5394         return ret;
5395 }
5396
5397
5398 int camera_attr_get_tag_software(camera_h camera, char **software)
5399 {
5400         int ret = CAMERA_ERROR_NONE;
5401         camera_cli_s *pc = (camera_cli_s *)camera;
5402         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
5403
5404         if (!pc || !pc->cb_info || !software) {
5405                 LOGE("NULL pointer %p %p", pc, software);
5406                 return CAMERA_ERROR_INVALID_PARAMETER;
5407         }
5408
5409         LOGD("Enter");
5410
5411         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5412
5413         if (ret == CAMERA_ERROR_NONE)
5414                 *software = strdup(pc->cb_info->get_string[MUSE_CAMERA_GET_STRING_TAG_SOFTWARE]);
5415
5416         LOGD("ret : 0x%x", ret);
5417
5418         return ret;
5419 }
5420
5421
5422 int camera_attr_get_geotag(camera_h camera, double *latitude, double *longitude, double *altitude)
5423 {
5424         int ret = CAMERA_ERROR_NONE;
5425         camera_cli_s *pc = (camera_cli_s *)camera;
5426         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
5427
5428         if (!pc || !pc->cb_info || !latitude || !longitude || !altitude) {
5429                 LOGE("NULL pointer %p %p %p %p", pc, latitude, longitude, altitude);
5430                 return CAMERA_ERROR_INVALID_PARAMETER;
5431         }
5432
5433         LOGD("Enter");
5434
5435         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5436
5437         if (ret == CAMERA_ERROR_NONE) {
5438                 *latitude = pc->cb_info->get_geotag[0];
5439                 *longitude = pc->cb_info->get_geotag[1];
5440                 *altitude = pc->cb_info->get_geotag[2];
5441         }
5442
5443         LOGD("ret : 0x%x", ret);
5444
5445         return ret;
5446 }
5447
5448
5449 int camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode)
5450 {
5451         int ret = CAMERA_ERROR_NONE;
5452         camera_cli_s *pc = (camera_cli_s *)camera;
5453         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
5454
5455         if (!pc || !pc->cb_info || !mode) {
5456                 LOGE("NULL pointer %p %p", pc, mode);
5457                 return CAMERA_ERROR_INVALID_PARAMETER;
5458         }
5459
5460         LOGD("Enter");
5461
5462         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5463
5464         if (ret == CAMERA_ERROR_NONE)
5465                 *mode = (camera_attr_flash_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_MODE];
5466
5467         LOGD("ret : 0x%x", ret);
5468
5469         return ret;
5470 }
5471
5472
5473 int camera_get_flash_state(camera_device_e device, camera_flash_state_e *state)
5474 {
5475         int ret = CAMERA_ERROR_NONE;
5476         int get_flash_state = 0;
5477
5478         if (!state) {
5479                 LOGE("NULL pointer");
5480                 return CAMERA_ERROR_INVALID_PARAMETER;
5481         }
5482
5483         ret = _camera_independent_request(MUSE_CAMERA_API_GET_FLASH_STATE,
5484                 (int)device, "get_flash_state", &get_flash_state);
5485
5486         if (ret == CAMERA_ERROR_NONE) {
5487                 *state = (camera_flash_state_e)get_flash_state;
5488                 LOGD("flash state %d", *state);
5489         } else {
5490                 LOGE("failed 0x%x", ret);
5491         }
5492
5493         return ret;
5494 }
5495
5496
5497 int camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data)
5498 {
5499         int ret = CAMERA_ERROR_NONE;
5500         camera_cli_s *pc = (camera_cli_s *)camera;
5501         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
5502
5503         if (!pc || !pc->cb_info || !foreach_cb) {
5504                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5505                 return CAMERA_ERROR_INVALID_PARAMETER;
5506         }
5507
5508         LOGD("Enter");
5509
5510         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = foreach_cb;
5511         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE] = user_data;
5512
5513         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5514
5515         LOGD("ret : 0x%x", ret);
5516
5517         return ret;
5518 }
5519
5520
5521 int camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data)
5522 {
5523         int ret = CAMERA_ERROR_NONE;
5524         camera_cli_s *pc = (camera_cli_s *)camera;
5525         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
5526
5527         if (!pc || !pc->cb_info || !foreach_cb) {
5528                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5529                 return CAMERA_ERROR_INVALID_PARAMETER;
5530         }
5531
5532         LOGD("Enter");
5533
5534         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = foreach_cb;
5535         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE] = user_data;
5536
5537         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5538
5539         LOGD("ret : 0x%x", ret);
5540
5541         return ret;
5542 }
5543
5544
5545 int camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data)
5546 {
5547         int ret = CAMERA_ERROR_NONE;
5548         camera_cli_s *pc = (camera_cli_s *)camera;
5549         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
5550
5551         if (!pc || !pc->cb_info || !foreach_cb) {
5552                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5553                 return CAMERA_ERROR_INVALID_PARAMETER;
5554         }
5555
5556         LOGD("Enter");
5557
5558         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = foreach_cb;
5559         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO] = user_data;
5560
5561         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5562
5563         LOGD("ret : 0x%x", ret);
5564
5565         return ret;
5566 }
5567
5568
5569 int camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data)
5570 {
5571         int ret = CAMERA_ERROR_NONE;
5572         camera_cli_s *pc = (camera_cli_s *)camera;
5573         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
5574
5575         if (!pc || !pc->cb_info || !foreach_cb) {
5576                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5577                 return CAMERA_ERROR_INVALID_PARAMETER;
5578         }
5579
5580         LOGD("Enter");
5581
5582         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = foreach_cb;
5583         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE] = user_data;
5584
5585         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5586
5587         LOGD("ret : 0x%x", ret);
5588
5589         return ret;
5590 }
5591
5592
5593 int camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data)
5594 {
5595         int ret = CAMERA_ERROR_NONE;
5596         camera_cli_s *pc = (camera_cli_s *)camera;
5597         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
5598
5599         if (!pc || !pc->cb_info || !foreach_cb) {
5600                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5601                 return CAMERA_ERROR_INVALID_PARAMETER;
5602         }
5603
5604         LOGD("Enter");
5605
5606         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = foreach_cb;
5607         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT] = user_data;
5608
5609         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5610
5611         LOGD("ret : 0x%x", ret);
5612
5613         return ret;
5614 }
5615
5616
5617 int camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data)
5618 {
5619         int ret = CAMERA_ERROR_NONE;
5620         camera_cli_s *pc = (camera_cli_s *)camera;
5621         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
5622
5623         if (!pc || !pc->cb_info || !foreach_cb) {
5624                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5625                 return CAMERA_ERROR_INVALID_PARAMETER;
5626         }
5627
5628         LOGD("Enter");
5629
5630         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = foreach_cb;
5631         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE] = user_data;
5632
5633         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5634
5635         LOGD("ret : 0x%x", ret);
5636
5637         return ret;
5638 }
5639
5640
5641 int camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data)
5642 {
5643         int ret = CAMERA_ERROR_NONE;
5644         camera_cli_s *pc = (camera_cli_s *)camera;
5645         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
5646
5647         if (!pc || !pc->cb_info || !foreach_cb) {
5648                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5649                 return CAMERA_ERROR_INVALID_PARAMETER;
5650         }
5651
5652         LOGD("Enter");
5653
5654         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = foreach_cb;
5655         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE] = user_data;
5656
5657         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5658
5659         LOGD("ret : 0x%x", ret);
5660
5661         return ret;
5662 }
5663
5664
5665 int camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data)
5666 {
5667         int ret = CAMERA_ERROR_NONE;
5668         camera_cli_s *pc = (camera_cli_s *)camera;
5669         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
5670
5671         if (!pc || !pc->cb_info || !foreach_cb) {
5672                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5673                 return CAMERA_ERROR_INVALID_PARAMETER;
5674         }
5675
5676         LOGD("Enter");
5677
5678         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = foreach_cb;
5679         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS] = user_data;
5680
5681         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5682
5683         LOGD("Enter, handle :%x", pc->remote_handle);
5684
5685         return ret;
5686 }
5687
5688
5689 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)
5690 {
5691         int ret = CAMERA_ERROR_NONE;
5692         camera_cli_s *pc = (camera_cli_s *)camera;
5693         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
5694         camera_msg_param param;
5695         int value = 0;
5696
5697         if (!pc || !pc->cb_info || !foreach_cb) {
5698                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5699                 return CAMERA_ERROR_INVALID_PARAMETER;
5700         }
5701
5702         LOGD("Enter");
5703
5704         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = foreach_cb;
5705         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION] = user_data;
5706
5707         value = (width << 16) | height;
5708         CAMERA_MSG_PARAM_SET(param, INT, value);
5709
5710         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5711
5712         LOGD("ret : 0x%x", ret);
5713
5714         return ret;
5715 }
5716
5717
5718 int camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data)
5719 {
5720         int ret = CAMERA_ERROR_NONE;
5721         camera_cli_s *pc = (camera_cli_s *)camera;
5722         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
5723
5724         if (!pc || !pc->cb_info || !foreach_cb) {
5725                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5726                 return CAMERA_ERROR_INVALID_PARAMETER;
5727         }
5728
5729         LOGD("Enter");
5730
5731         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = foreach_cb;
5732         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP] = user_data;
5733
5734         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5735
5736         LOGD("ret : 0x%x", ret);
5737
5738         return ret;
5739 }
5740
5741
5742 int camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data)
5743 {
5744         int ret = CAMERA_ERROR_NONE;
5745         camera_cli_s *pc = (camera_cli_s *)camera;
5746         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
5747
5748         if (!pc || !pc->cb_info || !foreach_cb) {
5749                 LOGE("NULL pointer %p %p", pc, foreach_cb);
5750                 return CAMERA_ERROR_INVALID_PARAMETER;
5751         }
5752
5753         LOGD("Enter");
5754
5755         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = foreach_cb;
5756         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION] = user_data;
5757
5758         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5759
5760         LOGD("ret : 0x%x", ret);
5761
5762         return ret;
5763 }
5764
5765
5766 int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
5767 {
5768         int ret = CAMERA_ERROR_NONE;
5769         camera_cli_s *pc = (camera_cli_s *)camera;
5770         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
5771         camera_msg_param param;
5772         int set_rotation = (int)rotation;
5773
5774         if (!pc || !pc->cb_info) {
5775                 LOGE("NULL handle");
5776                 return CAMERA_ERROR_INVALID_PARAMETER;
5777         }
5778
5779         LOGD("Enter");
5780
5781         CAMERA_MSG_PARAM_SET(param, INT, set_rotation);
5782
5783         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5784
5785         LOGD("ret : 0x%x", ret);
5786
5787         return ret;
5788 }
5789
5790
5791 int camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation)
5792 {
5793         int ret = CAMERA_ERROR_NONE;
5794         camera_cli_s *pc = (camera_cli_s *)camera;
5795         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
5796
5797         if (!pc || !pc->cb_info || !rotation) {
5798                 LOGE("NULL pointer %p %p", pc, rotation);
5799                 return CAMERA_ERROR_INVALID_PARAMETER;
5800         }
5801
5802         LOGD("Enter");
5803
5804         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5805
5806         if (ret == CAMERA_ERROR_NONE)
5807                 *rotation = (camera_rotation_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_ROTATION];
5808
5809         LOGD("ret : 0x%x", ret);
5810
5811         return ret;
5812 }
5813
5814
5815 int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
5816 {
5817         int ret = CAMERA_ERROR_NONE;
5818         camera_cli_s *pc = (camera_cli_s *)camera;
5819         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
5820         camera_msg_param param;
5821         int set_flip = (int)flip;
5822
5823         if (!pc || !pc->cb_info) {
5824                 LOGE("NULL handle");
5825                 return CAMERA_ERROR_INVALID_PARAMETER;
5826         }
5827
5828         LOGD("Enter");
5829
5830         CAMERA_MSG_PARAM_SET(param, INT, set_flip);
5831
5832         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5833
5834         LOGD("ret : 0x%x", ret);
5835
5836         return ret;
5837 }
5838
5839
5840 int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
5841 {
5842         int ret = CAMERA_ERROR_NONE;
5843         camera_cli_s *pc = (camera_cli_s *)camera;
5844         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
5845
5846         if (!pc || !pc->cb_info || !flip) {
5847                 LOGE("NULL pointer %p %p", pc, flip);
5848                 return CAMERA_ERROR_INVALID_PARAMETER;
5849         }
5850
5851         LOGD("Enter");
5852
5853         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5854
5855         if (ret == CAMERA_ERROR_NONE)
5856                 *flip = (camera_flip_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_STREAM_FLIP];
5857
5858         LOGD("ret : 0x%x", ret);
5859
5860         return ret;
5861 }
5862
5863 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
5864 {
5865         int ret = CAMERA_ERROR_NONE;
5866         camera_cli_s *pc = (camera_cli_s *)camera;
5867         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_MODE;
5868         camera_msg_param param;
5869         int set_mode = (int)mode;
5870
5871         if (!pc || !pc->cb_info) {
5872                 LOGE("NULL handle");
5873                 return CAMERA_ERROR_INVALID_PARAMETER;
5874         }
5875
5876         LOGD("Enter");
5877
5878         CAMERA_MSG_PARAM_SET(param, INT, set_mode);
5879
5880         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
5881
5882         LOGD("ret : 0x%x", ret);
5883
5884         return ret;
5885 }
5886
5887
5888 int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
5889 {
5890         int ret = CAMERA_ERROR_NONE;
5891         camera_cli_s *pc = (camera_cli_s *)camera;
5892         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
5893
5894         if (!pc || !pc->cb_info || !mode) {
5895                 LOGE("NULL pointer %p %p", pc, mode);
5896                 return CAMERA_ERROR_INVALID_PARAMETER;
5897         }
5898
5899         LOGD("Enter");
5900
5901         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5902
5903         if (ret == CAMERA_ERROR_NONE)
5904                 *mode = (camera_attr_hdr_mode_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HDR_MODE];
5905
5906         LOGD("ret : 0x%x", ret);
5907
5908         return ret;
5909 }
5910
5911
5912 bool camera_attr_is_supported_hdr_capture(camera_h camera)
5913 {
5914         int ret = CAMERA_ERROR_NONE;
5915         camera_cli_s *pc = (camera_cli_s *)camera;
5916         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE;
5917
5918         if (!pc || !pc->cb_info) {
5919                 LOGE("NULL handle");
5920                 return CAMERA_ERROR_INVALID_PARAMETER;
5921         }
5922
5923         LOGD("Enter");
5924
5925         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5926
5927         if (ret < 0) {
5928                 LOGE("error is occurred 0x%x", ret);
5929                 ret = false;
5930         }
5931
5932         LOGD("ret : %d", ret);
5933
5934         return (bool)ret;
5935 }
5936
5937
5938 int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data)
5939 {
5940         int ret = CAMERA_ERROR_NONE;
5941         camera_cli_s *pc = (camera_cli_s *)camera;
5942         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
5943
5944         if (!pc || !pc->cb_info) {
5945                 LOGE("NULL handle");
5946                 return CAMERA_ERROR_INVALID_PARAMETER;
5947         }
5948
5949         LOGD("Enter");
5950
5951         if (!camera_attr_is_supported_hdr_capture(camera)) {
5952                 LOGE("HDR not supported");
5953                 return CAMERA_ERROR_NOT_SUPPORTED;
5954         }
5955
5956         if (!callback) {
5957                 LOGE("NULL callback");
5958                 return CAMERA_ERROR_INVALID_PARAMETER;
5959         }
5960
5961         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5962
5963         if (ret == CAMERA_ERROR_NONE) {
5964                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5965
5966                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
5967                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
5968
5969                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5970         }
5971
5972         LOGD("ret : 0x%x", ret);
5973
5974         return ret;
5975 }
5976
5977
5978 int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
5979 {
5980         int ret = CAMERA_ERROR_NONE;
5981         camera_cli_s *pc = (camera_cli_s *)camera;
5982         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
5983
5984         if (!pc || !pc->cb_info) {
5985                 LOGE("NULL handle");
5986                 return CAMERA_ERROR_INVALID_PARAMETER;
5987         }
5988
5989         LOGD("Enter");
5990
5991         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
5992
5993         if (ret == CAMERA_ERROR_NONE) {
5994                 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
5995
5996                 pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
5997                 pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
5998
5999                 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
6000         }
6001
6002         LOGD("ret : 0x%x", ret);
6003
6004         return ret;
6005 }
6006
6007
6008 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
6009 {
6010         int ret = CAMERA_ERROR_NONE;
6011         camera_cli_s *pc = (camera_cli_s *)camera;
6012         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE;
6013         camera_msg_param param;
6014         int set_enable = (int)enable;
6015
6016         if (!pc || !pc->cb_info) {
6017                 LOGE("NULL handle");
6018                 return CAMERA_ERROR_INVALID_PARAMETER;
6019         }
6020
6021         LOGD("Enter");
6022
6023         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6024
6025         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6026
6027         LOGD("ret : 0x%x", ret);
6028
6029         return ret;
6030 }
6031
6032
6033 int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
6034 {
6035         int ret = CAMERA_ERROR_NONE;
6036         camera_cli_s *pc = (camera_cli_s *)camera;
6037         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
6038
6039         if (!pc || !pc->cb_info || !enabled) {
6040                 LOGE("NULL pointer %p %p", pc, enabled);
6041                 return CAMERA_ERROR_INVALID_PARAMETER;
6042         }
6043
6044         LOGD("Enter");
6045
6046         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6047
6048         if (ret == CAMERA_ERROR_NONE)
6049                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE];
6050
6051         LOGD("ret : 0x%x", ret);
6052
6053         return ret;
6054 }
6055
6056
6057 bool camera_attr_is_supported_anti_shake(camera_h camera)
6058 {
6059         int ret = CAMERA_ERROR_NONE;
6060         camera_cli_s *pc = (camera_cli_s *)camera;
6061         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE;
6062
6063         if (!pc || !pc->cb_info) {
6064                 LOGE("NULL handle");
6065                 return CAMERA_ERROR_INVALID_PARAMETER;
6066         }
6067
6068         LOGD("Enter");
6069
6070         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6071
6072         if (ret < 0) {
6073                 LOGE("error is occurred 0x%x", ret);
6074                 ret = false;
6075         }
6076
6077         LOGD("ret : %d", ret);
6078
6079         return (bool)ret;
6080 }
6081
6082
6083 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
6084 {
6085         int ret = CAMERA_ERROR_NONE;
6086         camera_cli_s *pc = (camera_cli_s *)camera;
6087         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION;
6088         camera_msg_param param;
6089         int set_enable = (int)enable;
6090
6091         if (!pc || !pc->cb_info) {
6092                 LOGE("NULL handle");
6093                 return CAMERA_ERROR_INVALID_PARAMETER;
6094         }
6095
6096         LOGD("Enter");
6097
6098         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6099
6100         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6101
6102         LOGD("ret : 0x%x", ret);
6103
6104         return ret;
6105 }
6106
6107
6108 int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
6109 {
6110         int ret = CAMERA_ERROR_NONE;
6111         camera_cli_s *pc = (camera_cli_s *)camera;
6112         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
6113
6114         if (!pc || !pc->cb_info || !enabled) {
6115                 LOGE("NULL pointer %p %p", pc, enabled);
6116                 return CAMERA_ERROR_INVALID_PARAMETER;
6117         }
6118
6119         LOGD("Enter");
6120
6121         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6122
6123         if (ret == CAMERA_ERROR_NONE)
6124                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION];
6125
6126         LOGD("ret : 0x%x", ret);
6127
6128         return ret;
6129 }
6130
6131
6132 bool camera_attr_is_supported_video_stabilization(camera_h camera)
6133 {
6134         int ret = CAMERA_ERROR_NONE;
6135         camera_cli_s *pc = (camera_cli_s *)camera;
6136         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION;
6137
6138         if (!pc || !pc->cb_info) {
6139                 LOGE("NULL handle");
6140                 return CAMERA_ERROR_INVALID_PARAMETER;
6141         }
6142
6143         LOGD("Enter");
6144
6145         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6146
6147         if (ret < 0) {
6148                 LOGE("error is occurred 0x%x", ret);
6149                 ret = false;
6150         }
6151
6152         LOGD("ret : %d", ret);
6153
6154         return (bool)ret;
6155 }
6156
6157
6158 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
6159 {
6160         int ret = CAMERA_ERROR_NONE;
6161         camera_cli_s *pc = (camera_cli_s *)camera;
6162         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST;
6163         camera_msg_param param;
6164         int set_enable = (int)enable;
6165
6166         if (!pc || !pc->cb_info) {
6167                 LOGE("NULL handle");
6168                 return CAMERA_ERROR_INVALID_PARAMETER;
6169         }
6170
6171         LOGD("Enter");
6172
6173         CAMERA_MSG_PARAM_SET(param, INT, set_enable);
6174
6175         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6176
6177         LOGD("ret : 0x%x", ret);
6178
6179         return ret;
6180 }
6181
6182
6183 int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
6184 {
6185         int ret = CAMERA_ERROR_NONE;
6186         camera_cli_s *pc = (camera_cli_s *)camera;
6187         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
6188
6189         if (!pc || !pc->cb_info || !enabled) {
6190                 LOGE("NULL pointer %p %p", pc, enabled);
6191                 return CAMERA_ERROR_INVALID_PARAMETER;
6192         }
6193
6194         LOGD("Enter");
6195
6196         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6197
6198         if (ret == CAMERA_ERROR_NONE)
6199                 *enabled = (bool)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST];
6200
6201         LOGD("ret : 0x%x", ret);
6202
6203         return ret;
6204 }
6205
6206
6207 bool camera_attr_is_supported_auto_contrast(camera_h camera)
6208 {
6209         int ret = CAMERA_ERROR_NONE;
6210         camera_cli_s *pc = (camera_cli_s *)camera;
6211         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST;
6212
6213         if (!pc || !pc->cb_info) {
6214                 LOGE("NULL handle");
6215                 return CAMERA_ERROR_INVALID_PARAMETER;
6216         }
6217
6218         LOGD("Enter");
6219
6220         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6221
6222         if (ret < 0) {
6223                 LOGE("error is occurred 0x%x", ret);
6224                 ret = false;
6225         }
6226
6227         LOGD("ret : %d", ret);
6228
6229         return (bool)ret;
6230 }
6231
6232
6233 int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
6234 {
6235         int ret = CAMERA_ERROR_NONE;
6236         camera_cli_s *pc = (camera_cli_s *)camera;
6237         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
6238         camera_msg_param param;
6239         int set_disable = (int)disable;
6240
6241         if (!pc || !pc->cb_info) {
6242                 LOGE("NULL handle");
6243                 return CAMERA_ERROR_INVALID_PARAMETER;
6244         }
6245
6246         LOGD("Enter");
6247
6248         CAMERA_MSG_PARAM_SET(param, INT, set_disable);
6249
6250         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6251
6252         LOGD("ret : 0x%x", ret);
6253
6254         return ret;
6255 }
6256
6257
6258 int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type, int pan_step)
6259 {
6260         int ret = CAMERA_ERROR_NONE;
6261         camera_cli_s *pc = (camera_cli_s *)camera;
6262         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
6263         camera_msg_param param;
6264         int set_move_type = (int)move_type;
6265         int value = 0;
6266
6267         if (!pc || !pc->cb_info) {
6268                 LOGE("NULL handle");
6269                 return CAMERA_ERROR_INVALID_PARAMETER;
6270         }
6271
6272         LOGD("Enter");
6273
6274         value = (set_move_type << 16) | pan_step;
6275         CAMERA_MSG_PARAM_SET(param, INT, value);
6276
6277         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6278
6279         LOGD("ret : 0x%x", ret);
6280
6281         return ret;
6282 }
6283
6284
6285 int camera_attr_get_pan(camera_h camera, int *pan_step)
6286 {
6287         int ret = CAMERA_ERROR_NONE;
6288         camera_cli_s *pc = (camera_cli_s *)camera;
6289         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
6290
6291         if (!pc || !pc->cb_info || !pan_step) {
6292                 LOGE("NULL pointer %p %p", pc, pan_step);
6293                 return CAMERA_ERROR_INVALID_PARAMETER;
6294         }
6295
6296         LOGD("Enter");
6297
6298         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6299
6300         if (ret == CAMERA_ERROR_NONE)
6301                 *pan_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_PAN];
6302
6303         LOGD("ret : 0x%x", ret);
6304
6305         return ret;
6306 }
6307
6308
6309 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
6310 {
6311         int ret = CAMERA_ERROR_NONE;
6312         camera_cli_s *pc = (camera_cli_s *)camera;
6313         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
6314
6315         if (!pc || !pc->cb_info || !min || !max) {
6316                 LOGE("NULL pointer %p %p %p", pc, min, max);
6317                 return CAMERA_ERROR_INVALID_PARAMETER;
6318         }
6319
6320         LOGD("Enter");
6321
6322         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6323
6324         if (ret == CAMERA_ERROR_NONE) {
6325                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
6326                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
6327         }
6328
6329         LOGD("ret : 0x%x", ret);
6330
6331         return ret;
6332 }
6333
6334
6335 int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type, int tilt_step)
6336 {
6337         int ret = CAMERA_ERROR_NONE;
6338         camera_cli_s *pc = (camera_cli_s *)camera;
6339         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
6340         camera_msg_param param;
6341         int set_move_type = (int)move_type;
6342         int value = 0;
6343
6344         if (!pc || !pc->cb_info) {
6345                 LOGE("NULL handle");
6346                 return CAMERA_ERROR_INVALID_PARAMETER;
6347         }
6348
6349         LOGD("Enter");
6350
6351         value = (set_move_type << 16) | tilt_step;
6352         CAMERA_MSG_PARAM_SET(param, INT, value);
6353
6354         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6355
6356         LOGD("ret : 0x%x", ret);
6357
6358         return ret;
6359 }
6360
6361
6362 int camera_attr_get_tilt(camera_h camera, int *tilt_step)
6363 {
6364         int ret = CAMERA_ERROR_NONE;
6365         camera_cli_s *pc = (camera_cli_s *)camera;
6366         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
6367
6368         if (!pc || !pc->cb_info || !tilt_step) {
6369                 LOGE("NULL pointer %p %p", pc, tilt_step);
6370                 return CAMERA_ERROR_INVALID_PARAMETER;
6371         }
6372
6373         LOGD("Enter");
6374
6375         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6376
6377         if (ret == CAMERA_ERROR_NONE)
6378                 *tilt_step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_TILT];
6379
6380         LOGD("ret : 0x%x", ret);
6381
6382         return ret;
6383 }
6384
6385
6386 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
6387 {
6388         int ret = CAMERA_ERROR_NONE;
6389         camera_cli_s *pc = (camera_cli_s *)camera;
6390         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
6391
6392         if (!pc || !pc->cb_info || !min || !max) {
6393                 LOGE("NULL pointer %p %p %p", pc, min, max);
6394                 return CAMERA_ERROR_INVALID_PARAMETER;
6395         }
6396
6397         LOGD("Enter");
6398
6399         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6400
6401         if (ret == CAMERA_ERROR_NONE) {
6402                 *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
6403                 *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
6404         }
6405
6406         LOGD("ret : 0x%x", ret);
6407
6408         return ret;
6409 }
6410
6411
6412 int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
6413 {
6414         int ret = CAMERA_ERROR_NONE;
6415         camera_cli_s *pc = (camera_cli_s *)camera;
6416         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
6417         camera_msg_param param;
6418         int set_ptz_type = (int)ptz_type;
6419
6420         if (!pc || !pc->cb_info) {
6421                 LOGE("NULL handle");
6422                 return CAMERA_ERROR_INVALID_PARAMETER;
6423         }
6424
6425         LOGD("Enter");
6426
6427         CAMERA_MSG_PARAM_SET(param, INT, set_ptz_type);
6428
6429         _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
6430
6431         LOGD("ret : 0x%x", ret);
6432
6433         return ret;
6434 }
6435
6436
6437 int camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data)
6438 {
6439         int ret = CAMERA_ERROR_NONE;
6440         camera_cli_s *pc = (camera_cli_s *)camera;
6441         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
6442
6443         if (!pc || !pc->cb_info || !foreach_cb) {
6444                 LOGE("NULL pointer %p %p", pc, foreach_cb);
6445                 return CAMERA_ERROR_INVALID_PARAMETER;
6446         }
6447
6448         LOGD("Enter");
6449
6450         pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = foreach_cb;
6451         pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE] = user_data;
6452
6453         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6454
6455         LOGD("ret : 0x%x", ret);
6456
6457         return ret;
6458 }
6459
6460
6461 int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, int height)
6462 {
6463         int ret = CAMERA_ERROR_NONE;
6464         camera_cli_s *pc = (camera_cli_s *)camera;
6465         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
6466         int set_display_roi_area[4] = {x, y, width, height};
6467         char *msg = NULL;
6468         int length = 0;
6469         int send_ret = 0;
6470
6471         if (!pc || !pc->cb_info) {
6472                 LOGE("NULL handle");
6473                 return CAMERA_ERROR_INVALID_PARAMETER;
6474         }
6475
6476         LOGD("Enter");
6477
6478         if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
6479                 ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
6480                 if (ret != MM_ERROR_NONE) {
6481                         LOGE("mm_evas_renderer_set_roi_area error 0x%x", ret);
6482                         return CAMERA_ERROR_INVALID_OPERATION;
6483                 }
6484         }
6485
6486         length = sizeof(set_display_roi_area) / sizeof(int) + \
6487                 (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
6488
6489         msg = muse_core_msg_new(api,
6490                 MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
6491                 NULL);
6492         if (!msg) {
6493                 LOGE("msg creation failed: api %d", api);
6494                 return CAMERA_ERROR_OUT_OF_MEMORY;
6495         }
6496
6497         if (pc->cb_info->is_server_connected) {
6498                 __camera_update_api_waiting(pc->cb_info, api, 1);
6499
6500                 g_mutex_lock(&pc->cb_info->fd_lock);
6501                 send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
6502                 g_mutex_unlock(&pc->cb_info->fd_lock);
6503         }
6504
6505         if (send_ret < 0) {
6506                 LOGE("message send failed");
6507                 ret = CAMERA_ERROR_INVALID_OPERATION;
6508         } else {
6509                 ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
6510         }
6511
6512         __camera_update_api_waiting(pc->cb_info, api, -1);
6513
6514         muse_core_msg_free(msg);
6515
6516         LOGD("ret : 0x%x", ret);
6517
6518         return ret;
6519 }
6520
6521
6522 int camera_attr_get_display_roi_area(camera_h camera, int *x, int *y, int *width, int *height)
6523 {
6524         camera_cli_s *pc = (camera_cli_s *)camera;
6525         int ret = CAMERA_ERROR_NONE;
6526         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
6527
6528         if (!pc || !pc->cb_info || !x || !y || !width || !height) {
6529                 LOGE("NULL pointer %p %p %p %p %p", pc, x, y, width, height);
6530                 return CAMERA_ERROR_INVALID_PARAMETER;
6531         }
6532
6533         LOGD("Enter");
6534
6535         _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
6536
6537         if (ret == CAMERA_ERROR_NONE) {
6538                 *x = pc->cb_info->get_display_roi_area[0];
6539                 *y = pc->cb_info->get_display_roi_area[1];
6540                 *width = pc->cb_info->get_display_roi_area[2];
6541                 *height = pc->cb_info->get_display_roi_area[3];
6542         }
6543
6544         LOGD("ret : 0x%x", ret);
6545
6546         return ret;
6547 }
6548
6549
6550 int camera_get_device_state(camera_device_e device, camera_device_state_e *state)
6551 {
6552         int ret = CAMERA_ERROR_NONE;
6553         int get_device_state = 0;
6554
6555         if (!state) {
6556                 LOGE("NULL pointer");
6557                 return CAMERA_ERROR_INVALID_PARAMETER;
6558         }
6559
6560         ret = _camera_independent_request(MUSE_CAMERA_API_GET_DEVICE_STATE,
6561                 (int)device, "get_device_state", &get_device_state);
6562
6563         if (ret == CAMERA_ERROR_NONE) {
6564                 *state = (camera_device_state_e)get_device_state;
6565                 LOGD("device state %d", *state);
6566         } else {
6567                 LOGE("failed 0x%x", ret);
6568         }
6569
6570         return ret;
6571 }
6572
6573
6574 int camera_add_device_state_changed_cb(camera_device_state_changed_cb callback, void *user_data, int *cb_id)
6575 {
6576         int ret = CAMERA_ERROR_NONE;
6577         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6578         camera_cb_info *info = NULL;
6579
6580         if (!callback || !cb_id) {
6581                 LOGE("invalid pointer %p %p", callback, cb_id);
6582                 return CAMERA_ERROR_INVALID_PARAMETER;
6583         }
6584
6585         /* check camera support */
6586         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6587         if (ret != CAMERA_ERROR_NONE) {
6588                 LOGE("get device state failed");
6589                 return ret;
6590         }
6591
6592         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6593
6594         info = g_new0(camera_cb_info, 1);
6595         if (!info) {
6596                 LOGE("info failed");
6597                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
6598                 goto _DONE;
6599         }
6600
6601         info->id = ++g_cam_dev_state_changed_cb_id;
6602         info->callback = (void *)callback;
6603         info->user_data = user_data;
6604
6605         *cb_id = info->id;
6606
6607         /* subscribe dbus signal for camera state change */
6608         if (!g_cam_dev_state_changed_cb_conn) {
6609                 g_cam_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
6610                 if (!g_cam_dev_state_changed_cb_conn) {
6611                         LOGE("failed to get gdbus connection");
6612                         ret = CAMERA_ERROR_INVALID_OPERATION;
6613                         goto _DONE;
6614                 }
6615
6616                 LOGD("subscribe signal %s - %s - %s",
6617                         MM_CAMCORDER_DBUS_OBJECT,
6618                         MM_CAMCORDER_DBUS_INTERFACE_CAMERA,
6619                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
6620
6621                 g_cam_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_cam_dev_state_changed_cb_conn,
6622                         NULL, MM_CAMCORDER_DBUS_INTERFACE_CAMERA, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
6623                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__camera_device_state_changed_cb, NULL, NULL);
6624                 if (!g_cam_dev_state_changed_cb_subscribe_id) {
6625                         LOGE("failed to get gdbus connection");
6626                         ret = CAMERA_ERROR_INVALID_OPERATION;
6627                         goto _DONE;
6628                 }
6629
6630                 LOGD("signal subscribe id %u", g_cam_dev_state_changed_cb_subscribe_id);
6631         }
6632
6633         g_cam_dev_state_changed_cb_list = g_list_prepend(g_cam_dev_state_changed_cb_list, (gpointer)info);
6634
6635         LOGD("callback id %d", info->id);
6636
6637 _DONE:
6638         if (ret != CAMERA_ERROR_NONE) {
6639                 if (info) {
6640                         g_free(info);
6641                         info = NULL;
6642                 }
6643
6644                 if (g_cam_dev_state_changed_cb_conn) {
6645                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6646                         g_cam_dev_state_changed_cb_conn = NULL;
6647                 }
6648         }
6649
6650         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6651
6652         return ret;
6653 }
6654
6655
6656 int camera_remove_device_state_changed_cb(int cb_id)
6657 {
6658         int ret = CAMERA_ERROR_NONE;
6659         camera_device_state_e state = CAMERA_DEVICE_STATE_NULL;
6660         GList *tmp_list = NULL;
6661         camera_cb_info *info = NULL;
6662
6663         /* check camera support */
6664         ret = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &state);
6665         if (ret != CAMERA_ERROR_NONE) {
6666                 LOGE("get device state failed");
6667                 return ret;
6668         }
6669
6670         g_mutex_lock(&g_cam_dev_state_changed_cb_lock);
6671
6672         if (!g_cam_dev_state_changed_cb_list) {
6673                 LOGE("there is no callback info");
6674                 ret = CAMERA_ERROR_INVALID_OPERATION;
6675                 goto _DONE;
6676         }
6677
6678         tmp_list = g_cam_dev_state_changed_cb_list;
6679
6680         do {
6681                 info = tmp_list->data;
6682                 tmp_list = tmp_list->next;
6683
6684                 if (!info) {
6685                         LOGW("NULL info");
6686                         continue;
6687                 }
6688
6689                 if (info->id == cb_id) {
6690                         g_cam_dev_state_changed_cb_list = g_list_remove(g_cam_dev_state_changed_cb_list, info);
6691
6692                         g_free(info);
6693                         info = NULL;
6694
6695                         if (!g_cam_dev_state_changed_cb_list) {
6696                                 /* no remained callback */
6697                                 if (g_cam_dev_state_changed_cb_conn) {
6698                                         /* unsubscribe signal */
6699                                         g_dbus_connection_signal_unsubscribe(g_cam_dev_state_changed_cb_conn, g_cam_dev_state_changed_cb_subscribe_id);
6700                                         g_cam_dev_state_changed_cb_subscribe_id = 0;
6701
6702                                         /* unref connection */
6703                                         g_object_unref(g_cam_dev_state_changed_cb_conn);
6704                                         g_cam_dev_state_changed_cb_conn = NULL;
6705                                 }
6706                         }
6707
6708                         LOGD("id %d callback removed", cb_id);
6709                         ret = CAMERA_ERROR_NONE;
6710
6711                         goto _DONE;
6712                 }
6713         } while (tmp_list);
6714
6715         LOGE("id %d callback not found", cb_id);
6716         ret = CAMERA_ERROR_INVALID_PARAMETER;
6717
6718 _DONE:
6719         g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
6720
6721         return ret;
6722 }