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