37c6c0bcdfd7b1ede91a2be346c707947e43aacd
[platform/core/multimedia/mmsvc-camera.git] / muse / src / muse_camera_dispatcher.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 #include <stdlib.h>
18 #include <string.h>
19 #include <errno.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/un.h>
23 #include <stdio.h>
24 #include <dlog.h>
25 #include "muse_camera_msg.h"
26 #include "muse_camera_internal.h"
27 #include <mm_types.h>
28 #include <muse_core_security.h>
29 #include <gst/gst.h>
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34 #define LOG_TAG "MUSED_CAMERA"
35 #define KEY_LENGTH 24
36
37 #define CAMERA_PRIVILEGE_NAME "http://tizen.org/privilege/camera"
38 #define MUSED_KEY_DEVICE_STATE_CHECK  "camera_get_device_state_is_called"
39 #define MUSED_KEY_DEVICE_STATE_RETURN "camera_get_device_state_return"
40 #define MUSED_KEY_FLASH_STATE_CHECK   "camera_get_flash_state_is_called"
41 #define MUSED_KEY_FLASH_STATE_RETURN  "camera_get_flash_state_return"
42 #define MUSED_KEY_FLASH_STATE_COUNT   "camera_get_flash_state_count"
43
44 static int _camera_remove_export_data(muse_module_h module, int key, int remove_all);
45
46 static void __camera_dispatcher_send_msg(muse_module_h module, char *msg)
47 {
48         int len = 0;
49
50         if (!msg) {
51                 LOGE("NULL msg");
52                 return;
53         }
54
55         if (!module) {
56                 LOGE("NULL module");
57                 goto _DONE;
58         }
59
60         /*LOGD("msg [%s]", msg);*/
61
62         len = muse_core_ipc_send_msg(muse_core_client_get_msg_fd(module), msg);
63         if (len <= 0)
64                 LOGE("sending message[%s] failed. errno %d", msg, errno);
65
66 _DONE:
67         muse_core_msg_json_factory_free(msg);
68
69         return;
70 }
71
72 static void muse_camera_msg_return(int api, int class, int ret, muse_module_h module)
73 {
74         char *send_msg = muse_core_msg_json_factory_new(api,
75                 MUSE_TYPE_INT, PARAM_API_CLASS, class,
76                 MUSE_TYPE_INT, PARAM_RET, ret,
77                 MUSE_TYPE_INT, PARAM_GET_TYPE, MUSE_CAMERA_GET_TYPE_NONE,
78                 0);
79
80         __camera_dispatcher_send_msg(module, send_msg);
81
82         return;
83 }
84
85 static void muse_camera_msg_return1(int api, int class, int ret, muse_module_h module,
86         int get_type, int index, const char *name, int value_int, void *value_pointer)
87 {
88         char *send_msg = NULL;
89
90         if (get_type == MUSE_CAMERA_GET_TYPE_INT) {
91                 send_msg = muse_core_msg_json_factory_new(api,
92                         MUSE_TYPE_INT, PARAM_API_CLASS, class,
93                         MUSE_TYPE_INT, PARAM_RET, ret,
94                         MUSE_TYPE_INT, PARAM_GET_TYPE, get_type,
95                         MUSE_TYPE_INT, PARAM_GET_INDEX, index,
96                         MUSE_TYPE_INT, name, value_int,
97                         0);
98         } else if (get_type == MUSE_CAMERA_GET_TYPE_STRING) {
99                 send_msg = muse_core_msg_json_factory_new(api,
100                         MUSE_TYPE_INT, PARAM_API_CLASS, class,
101                         MUSE_TYPE_INT, PARAM_RET, ret,
102                         MUSE_TYPE_INT, PARAM_GET_TYPE, get_type,
103                         MUSE_TYPE_INT, PARAM_GET_INDEX, index,
104                         MUSE_TYPE_STRING, name, value_pointer,
105                         0);
106         } else if (get_type == MUSE_CAMERA_GET_TYPE_POINTER) {
107                 send_msg = muse_core_msg_json_factory_new(api,
108                         MUSE_TYPE_INT, PARAM_API_CLASS, class,
109                         MUSE_TYPE_INT, PARAM_RET, ret,
110                         MUSE_TYPE_INT, PARAM_GET_TYPE, get_type,
111                         MUSE_TYPE_INT, PARAM_GET_INDEX, index,
112                         MUSE_TYPE_POINTER, name, value_pointer,
113                         0);
114         } else {
115                 LOGW("unknown type %d", get_type);
116         }
117
118         __camera_dispatcher_send_msg(module, send_msg);
119
120         return;
121 }
122
123
124 static void muse_camera_msg_return2(int api, int class, int ret, muse_module_h module,
125         int get_type, int index, int value0, int value1)
126 {
127         char *send_msg = muse_core_msg_json_factory_new(api,
128                 MUSE_TYPE_INT, PARAM_API_CLASS, class,
129                 MUSE_TYPE_INT, PARAM_RET, ret,
130                 MUSE_TYPE_INT, PARAM_GET_TYPE, get_type,
131                 MUSE_TYPE_INT, PARAM_GET_INDEX, index,
132                 MUSE_TYPE_INT, "get_value0", value0,
133                 MUSE_TYPE_INT, "get_value1", value1,
134                 0);
135
136         __camera_dispatcher_send_msg(module, send_msg);
137
138         return;
139 }
140
141
142 static void muse_camera_msg_event1(int api, int event, int class, muse_module_h module, const char *name, int value)
143 {
144         char *send_msg = muse_core_msg_json_factory_new(api,
145                 MUSE_TYPE_INT, PARAM_EVENT, event,
146                 MUSE_TYPE_INT, PARAM_EVENT_CLASS, class,
147                 MUSE_TYPE_INT, name, value,
148                 0);
149
150         __camera_dispatcher_send_msg(module, send_msg);
151
152         return;
153 }
154
155
156 static void muse_camera_msg_event2(int api, int event, int class, muse_module_h module,
157         const char *name0, int value0, const char *name1, int value1)
158 {
159         char *send_msg = muse_core_msg_json_factory_new(api,
160                 MUSE_TYPE_INT, PARAM_EVENT, event,
161                 MUSE_TYPE_INT, PARAM_EVENT_CLASS, class,
162                 MUSE_TYPE_INT, name0, value0,
163                 MUSE_TYPE_INT, name1, value1,
164                 0);
165
166         __camera_dispatcher_send_msg(module, send_msg);
167
168         return;
169 }
170
171
172 static void muse_camera_msg_event3(int api, int event, int class, muse_module_h module,
173         const char *name0, int value0, const char *name1, int value1, const char *name2, int value2)
174 {
175         char *send_msg = muse_core_msg_json_factory_new(api,
176                 MUSE_TYPE_INT, PARAM_EVENT, event,
177                 MUSE_TYPE_INT, PARAM_EVENT_CLASS, class,
178                 MUSE_TYPE_INT, name0, value0,
179                 MUSE_TYPE_INT, name1, value1,
180                 MUSE_TYPE_INT, name2, value2,
181                 0);
182
183         __camera_dispatcher_send_msg(module, send_msg);
184
185         return;
186 }
187
188
189 void _camera_dispatcher_callback_supported_theater_mode(int param1, void *user_data)
190 {
191         muse_module_h module = (muse_module_h)user_data;
192
193         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
194                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE,
195                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
196                 module, "param1", param1);
197
198         return;
199 }
200
201 void _camera_dispatcher_callback_supported_af_mode(int param1, void *user_data)
202 {
203         muse_module_h module = (muse_module_h)user_data;
204
205         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
206                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE,
207                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
208                 module, "param1", param1);
209
210         return;
211 }
212
213 void _camera_dispatcher_callback_supported_exposure_mode(int param1, void *user_data)
214 {
215         muse_module_h module = (muse_module_h)user_data;
216
217         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
218                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE,
219                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
220                 module, "param1", param1);
221
222         return;
223 }
224
225 void _camera_dispatcher_callback_supported_iso_mode(int param1, void *user_data)
226 {
227         muse_module_h module = (muse_module_h)user_data;
228
229         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
230                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO,
231                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
232                 module, "param1", param1);
233
234         return;
235 }
236
237 void _camera_dispatcher_callback_supported_whitebalance(int param1, void *user_data)
238 {
239         muse_module_h module = (muse_module_h)user_data;
240
241         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
242                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE,
243                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
244                 module, "param1", param1);
245
246         return;
247 }
248
249 void _camera_dispatcher_callback_supported_effect(int param1, void *user_data)
250 {
251         muse_module_h module = (muse_module_h)user_data;
252
253         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
254                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT,
255                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
256                 module, "param1", param1);
257
258         return;
259 }
260
261 void _camera_dispatcher_callback_supported_scene_mode(int param1, void *user_data)
262 {
263         muse_module_h module = (muse_module_h)user_data;
264
265         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
266                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE,
267                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
268                 module, "param1", param1);
269
270         return;
271 }
272
273 void _camera_dispatcher_callback_supported_flash_mode(int param1, void *user_data)
274 {
275         muse_module_h module = (muse_module_h)user_data;
276
277         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
278                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE,
279                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
280                 module, "param1", param1);
281
282         return;
283 }
284
285 int _camera_dispatcher_callback_supported_flash_mode2(int param1, void *user_data)
286 {
287         int *count = (int *)user_data;
288
289         if (count)
290                 (*count)++;
291
292         return true;
293 }
294
295 void _camera_dispatcher_callback_supported_fps(int param1, void *user_data)
296 {
297         muse_module_h module = (muse_module_h)user_data;
298
299         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
300                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS,
301                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
302                 module, "param1", param1);
303
304         return;
305 }
306
307 void _camera_dispatcher_callback_supported_fps_by_resolution(int param1, void *user_data)
308 {
309         muse_module_h module = (muse_module_h)user_data;
310
311         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
312                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION,
313                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
314                 module, "param1", param1);
315
316         return;
317 }
318
319 void _camera_dispatcher_callback_supported_stream_flip(int param1, void *user_data)
320 {
321         muse_module_h module = (muse_module_h)user_data;
322
323         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
324                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP,
325                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
326                 module, "param1", param1);
327
328         return;
329 }
330
331 void _camera_dispatcher_callback_supported_stream_rotation(int param1, void *user_data)
332 {
333         muse_module_h module = (muse_module_h)user_data;
334
335         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
336                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION,
337                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
338                 module, "param1", param1);
339
340         return;
341 }
342
343 void _camera_dispatcher_callback_supported_capture_format(int param1, void *user_data)
344 {
345         muse_module_h module = (muse_module_h)user_data;
346
347         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
348                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT,
349                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
350                 module, "param1", param1);
351
352         return;
353 }
354
355 void _camera_dispatcher_callback_supported_preview_format(int param1, void *user_data)
356 {
357         muse_module_h module = (muse_module_h)user_data;
358
359         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
360                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT,
361                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
362                 module, "param1", param1);
363
364         return;
365 }
366
367 void _camera_dispatcher_callback_supported_preview_resolution(int param1, int param2, void *user_data)
368 {
369         muse_module_h module = (muse_module_h)user_data;
370
371         muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT,
372                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION,
373                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
374                 module, "param1", param1, "param2", param2);
375
376         return;
377 }
378
379 void _camera_dispatcher_callback_supported_capture_resolution(int param1, int param2, void *user_data)
380 {
381         muse_module_h module = (muse_module_h)user_data;
382
383         muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT,
384                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION,
385                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
386                 module, "param1", param1, "param2", param2);
387
388         return;
389 }
390
391 void _camera_dispatcher_callback_supported_ptz_type(int param1, void *user_data)
392 {
393         muse_module_h module = (muse_module_h)user_data;
394
395         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
396                 MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE,
397                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
398                 module, "param1", param1);
399
400         return;
401 }
402
403 static int _camera_remove_export_data(muse_module_h module, int key, int remove_all)
404 {
405         muse_camera_handle_s *muse_camera = NULL;
406         GList *tmp_list = NULL;
407         muse_camera_export_data *export_data = NULL;
408
409         if (module == NULL || (key <= 0 && remove_all == FALSE)) {
410                 LOGE("invalid parameter %p, %d", module, key);
411                 return FALSE;
412         }
413
414         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
415         if (muse_camera == NULL) {
416                 LOGE("NULL handle");
417                 return FALSE;
418         }
419
420         g_mutex_lock(&muse_camera->list_lock);
421
422         tmp_list = muse_camera->data_list;
423
424         while (tmp_list) {
425                 export_data = (muse_camera_export_data *)tmp_list->data;
426                 tmp_list = tmp_list->next;
427                 if (export_data) {
428                         if (export_data->key == key || remove_all) {
429                                 /*LOGD("key %d matched, remove it (remove_all %d)", key, remove_all);*/
430
431                                 if (remove_all) {
432                                         LOGW("remove remained export data key %d, internal buffer %p",
433                                                 export_data->key, export_data->internal_buffer);
434                                 }
435
436                                 if (export_data->is_capture) {
437                                         LOGD("capture callback is done");
438                                         g_cond_signal(&muse_camera->list_cond);
439                                 }
440
441                                 if (export_data->bo) {
442                                         tbm_bo_unref(export_data->bo);
443                                         export_data->bo = NULL;
444                                 } else {
445                                         LOGW("bo for key %d is NULL", key);
446                                 }
447
448                                 export_data->key = 0;
449
450                                 if (export_data->internal_buffer) {
451                                         gst_buffer_unref((GstBuffer *)export_data->internal_buffer);
452                                         export_data->internal_buffer = NULL;
453                                 }
454
455                                 if (export_data->data_bo) {
456                                         tbm_bo_unref(export_data->data_bo);
457                                         export_data->data_bo = NULL;
458                                 }
459
460                                 muse_camera->data_list = g_list_remove(muse_camera->data_list, export_data);
461
462                                 g_free(export_data);
463                                 export_data = NULL;
464
465                                 if (remove_all == FALSE) {
466                                         /*LOGD("key %d, remove done");*/
467                                         g_mutex_unlock(&muse_camera->list_lock);
468                                         return TRUE;
469                                 } else {
470                                         LOGD("check next data");
471                                 }
472                         }
473                 } else {
474                         LOGW("NULL data");
475                 }
476         }
477
478         g_mutex_unlock(&muse_camera->list_lock);
479
480         if (remove_all) {
481                 LOGW("remove all done");
482         } else {
483                 LOGE("should not be reached here - key %d", key);
484         }
485
486         return FALSE;
487 }
488
489
490 void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
491 {
492         muse_camera_handle_s *muse_camera = NULL;
493         int data_size_main = 0;
494         int data_size_post = 0;
495         int data_size_thumb = 0;
496         tbm_bo bo_main = NULL;
497         tbm_bo bo_post = NULL;
498         tbm_bo bo_thumb = NULL;
499         tbm_bo_handle bo_main_handle = {.ptr = NULL};
500         tbm_bo_handle bo_post_handle = {.ptr = NULL};
501         tbm_bo_handle bo_thumb_handle = {.ptr = NULL};
502         muse_camera_export_data *export_data_main = NULL;
503         muse_camera_export_data *export_data_post = NULL;
504         muse_camera_export_data *export_data_thumb = NULL;
505         int tbm_key_main = 0;
506         int tbm_key_post = 0;
507         int tbm_key_thumb = 0;
508         muse_module_h module = (muse_module_h)user_data;
509         unsigned char *buf_pos = NULL;
510         gint64 end_time = 0;
511
512         LOGD("Enter!!");
513
514         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
515         if (!muse_camera || !image) {
516                 LOGE("invalid ptr %p %p", muse_camera, image);
517                 return;
518         }
519
520         /* main image */
521         export_data_main = g_new0(muse_camera_export_data, 1);
522         if (export_data_main == NULL) {
523                 LOGE("alloc export_data failed");
524                 return;
525         }
526
527         data_size_main = sizeof(camera_image_data_s) + image->size;
528         if (image->exif && image->exif_size > 0)
529                 data_size_main += image->exif_size;
530
531         /* alloc bo */
532         bo_main = tbm_bo_alloc(muse_camera->bufmgr, data_size_main, TBM_BO_DEFAULT);
533         if (bo_main == NULL) {
534                 LOGE("bo alloc failed");
535                 goto main_image_error;
536         }
537
538         bo_main_handle = tbm_bo_map(bo_main, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
539         if (bo_main_handle.ptr == NULL) {
540                 LOGE("bo map Error!");
541                 goto main_image_error;
542         }
543
544         buf_pos = (unsigned char *)bo_main_handle.ptr;
545         memcpy(buf_pos, image, sizeof(camera_image_data_s));
546         buf_pos += sizeof(camera_image_data_s);
547         memcpy(buf_pos, image->data, image->size);
548         if (image->exif && image->exif_size > 0) {
549                 buf_pos += image->size;
550                 memcpy(buf_pos, image->exif, image->exif_size);
551         }
552
553         tbm_bo_unmap(bo_main);
554
555         tbm_key_main = tbm_bo_export(bo_main);
556         if (tbm_key_main == 0) {
557                 LOGE("Create key_info ERROR!!");
558                 goto main_image_error;
559         }
560
561         LOGD("bo %p, vaddr %p, size %d, key %d",
562                 bo_main, bo_main_handle.ptr, data_size_main, tbm_key_main);
563
564         /* set bo info */
565         export_data_main->key = tbm_key_main;
566         export_data_main->bo = bo_main;
567         export_data_main->is_capture = true;
568
569         /* postview image */
570         if (postview && postview->size > 0) {
571                 data_size_post = sizeof(camera_image_data_s) + postview->size;
572
573                 export_data_post = g_new0(muse_camera_export_data, 1);
574                 if (export_data_post == NULL) {
575                         LOGE("alloc export_data failed");
576                         goto postview_image_error;
577                 }
578
579                 /* alloc bo */
580                 bo_post = tbm_bo_alloc(muse_camera->bufmgr, data_size_post, TBM_BO_DEFAULT);
581                 if (bo_post == NULL) {
582                         LOGE("bo alloc failed");
583                         goto postview_image_error;
584                 }
585
586                 bo_post_handle = tbm_bo_map(bo_post, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
587                 if (bo_post_handle.ptr == NULL) {
588                         LOGE("bo map Error!");
589                         goto postview_image_error;
590                 }
591
592                 buf_pos = (unsigned char *)bo_post_handle.ptr;
593                 memcpy(buf_pos, postview, sizeof(camera_image_data_s));
594                 buf_pos += sizeof(camera_image_data_s);
595                 memcpy(buf_pos, postview->data, postview->size);
596                 tbm_bo_unmap(bo_post);
597
598                 tbm_key_post = tbm_bo_export(bo_post);
599                 if (tbm_key_post == 0) {
600                         LOGE("Create key_info ERROR!!");
601                         goto postview_image_error;
602                 }
603
604                 /* set bo info */
605                 export_data_post->key = tbm_key_post;
606                 export_data_post->bo = bo_post;
607         }
608
609         /* thumbnail image */
610         if (thumbnail && thumbnail->size > 0) {
611                 data_size_thumb = sizeof(camera_image_data_s) + thumbnail->size;
612
613                 export_data_thumb = g_new0(muse_camera_export_data, 1);
614                 if (export_data_thumb == NULL) {
615                         LOGE("alloc export_data failed");
616                         goto thumbnail_image_error;
617                 }
618
619                 /* alloc bo */
620                 bo_thumb = tbm_bo_alloc(muse_camera->bufmgr, data_size_thumb, TBM_BO_DEFAULT);
621                 if (bo_thumb == NULL) {
622                         LOGE("bo alloc failed");
623                         goto thumbnail_image_error;
624                 }
625
626                 bo_thumb_handle = tbm_bo_map(bo_thumb, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
627                 if (bo_thumb_handle.ptr == NULL) {
628                         LOGE("bo map Error!");
629                         goto thumbnail_image_error;
630                 }
631
632                 buf_pos = (unsigned char *)bo_thumb_handle.ptr;
633                 memcpy(buf_pos, thumbnail, sizeof(camera_image_data_s));
634                 buf_pos += sizeof(camera_image_data_s);
635                 memcpy(buf_pos, thumbnail->data, thumbnail->size);
636                 tbm_bo_unmap(bo_thumb);
637
638                 tbm_key_thumb = tbm_bo_export(bo_thumb);
639                 if (tbm_key_thumb == 0) {
640                         LOGE("Create key_info ERROR!!");
641                         goto thumbnail_image_error;
642                 }
643
644                 /* set bo info */
645                 export_data_thumb->key = tbm_key_thumb;
646                 export_data_thumb->bo = bo_thumb;
647         }
648
649         /* add bo info to list */
650         g_mutex_lock(&muse_camera->list_lock);
651
652         muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_main);
653
654         if (export_data_post)
655                 muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_post);
656
657         if (export_data_thumb)
658                 muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_thumb);
659
660         /* send message */
661         muse_camera_msg_event3(MUSE_CAMERA_CB_EVENT,
662                 MUSE_CAMERA_EVENT_TYPE_CAPTURE,
663                 MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
664                 module, "tbm_key_main", tbm_key_main, "tbm_key_post", tbm_key_post, "tbm_key_thumb", tbm_key_thumb);
665
666         /* wait for capture callback return */
667         end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND * 3;
668         if (!g_cond_wait_until(&muse_camera->list_cond, &muse_camera->list_lock, end_time)) {
669                 LOGW("capture callback return timeout");
670         } else {
671                 LOGD("capture callback return");
672         }
673
674         g_mutex_unlock(&muse_camera->list_lock);
675
676         return;
677
678 thumbnail_image_error:
679         if (bo_thumb) {
680                 tbm_bo_unref(bo_thumb);
681                 bo_thumb = NULL;
682         }
683
684         if (export_data_thumb) {
685                 g_free(export_data_thumb);
686                 export_data_thumb = NULL;
687         }
688
689 postview_image_error:
690         if (bo_post) {
691                 tbm_bo_unref(bo_post);
692                 bo_post = NULL;
693         }
694
695         if (export_data_post) {
696                 g_free(export_data_post);
697                 export_data_post = NULL;
698         }
699
700 main_image_error:
701         if (bo_main) {
702                 tbm_bo_unref(bo_main);
703                 bo_main = NULL;
704         }
705
706         if (export_data_main) {
707                 g_free(export_data_main);
708                 export_data_main = NULL;
709         }
710
711         return;
712 }
713
714 void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
715 {
716         muse_module_h module = (muse_module_h)user_data;
717         muse_camera_handle_s *muse_camera = NULL;
718         camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
719         char value_key[KEY_LENGTH] = {'\0',};
720         int ret = CAMERA_ERROR_NONE;
721         int set_value = -1;
722
723         LOGD("Enter - previous %d, current %d, by_policy %d",
724              previous, current, by_policy);
725
726         muse_camera_msg_event3(MUSE_CAMERA_CB_EVENT,
727                 MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE,
728                 MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
729                 module, "previous", previous, "current", current, "by_policy", by_policy);
730
731         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
732         if (!muse_camera) {
733                 LOGW("NULL muse camera handle");
734                 return;
735         }
736
737         ret = legacy_camera_get_device_type(muse_camera->camera_handle, &device_type);
738         if (ret != CAMERA_ERROR_NONE) {
739                 LOGE("get device type failed 0x%x", ret);
740                 return;
741         }
742
743         snprintf(value_key, KEY_LENGTH, "device_state_camera%d", device_type);
744         if (previous == CAMERA_STATE_CREATED && current == CAMERA_STATE_PREVIEW)
745                 set_value = CAMERA_DEVICE_STATE_WORKING;
746         else if (previous == CAMERA_STATE_PREVIEW && current == CAMERA_STATE_CREATED)
747                 set_value = CAMERA_DEVICE_STATE_NULL;
748
749         if (set_value != -1) {
750                 LOGD("device[%s] state set : %d", value_key, set_value);
751                 muse_core_client_set_value(module, value_key, set_value);
752         }
753
754         return;
755 }
756
757 void _camera_dispatcher_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
758 {
759         muse_module_h module = (muse_module_h)user_data;
760
761         LOGD("Enter - policy %d, state previous %d, current %d", policy, previous, current);
762
763         muse_camera_msg_event3(MUSE_CAMERA_CB_EVENT,
764                 MUSE_CAMERA_EVENT_TYPE_INTERRUPTED,
765                 MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
766                 module, "policy", policy, "previous", previous, "current", current);
767
768         return;
769 }
770
771 void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void *user_data)
772 {
773         muse_camera_handle_s *muse_camera = NULL;
774         int data_size = 0;
775         tbm_bo bo = NULL;
776         tbm_bo data_bo = NULL;
777         tbm_bo_handle bo_handle = {.ptr = NULL};
778         tbm_bo_handle data_bo_handle = {.ptr = NULL};
779         muse_camera_export_data *export_data = NULL;
780         int i = 0;
781         int tbm_key = 0;
782         int data_key = 0;
783         int buffer_key[BUFFER_MAX_PLANE_NUM] = {0, };
784         int num_buffer_key = 0;
785         int send_ret = 0;
786         muse_module_h module = (muse_module_h)user_data;
787         unsigned char *buf_pos = NULL;
788         char *send_message = NULL;
789
790         /*LOGD("Enter");*/
791
792         if (module == NULL || stream == NULL) {
793                 LOGE("NULL data %p, %p", module, stream);
794                 return;
795         }
796
797         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
798         if (muse_camera == NULL) {
799                 LOGE("NULL handle");
800                 return;
801         }
802
803         export_data = g_new0(muse_camera_export_data, 1);
804         if (export_data == NULL) {
805                 LOGE("alloc export_data failed");
806                 return;
807         }
808
809         data_size = sizeof(MMCamcorderVideoStreamDataType);
810
811         bo = tbm_bo_alloc(muse_camera->bufmgr, data_size, TBM_BO_DEFAULT);
812         if (bo == NULL) {
813                 LOGE("bo alloc failed");
814                 goto _PREVIEW_CB_ERROR;
815         }
816
817         bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
818         if (bo_handle.ptr == NULL) {
819                 LOGE("bo map Error!");
820                 goto _PREVIEW_CB_ERROR;
821         }
822
823         buf_pos = (unsigned char *)bo_handle.ptr;
824
825         memcpy(buf_pos, stream, sizeof(MMCamcorderVideoStreamDataType));
826
827         tbm_bo_unmap(bo);
828
829         if (stream->bo[0] == NULL) {
830                 /* non-zero copy */
831                 switch (stream->data_type) {
832                 case MM_CAM_STREAM_DATA_YUV420:
833                         data_size = stream->data.yuv420.length_yuv;
834                         break;
835                 case MM_CAM_STREAM_DATA_YUV422:
836                         data_size = stream->data.yuv422.length_yuv;
837                         break;
838                 case MM_CAM_STREAM_DATA_YUV420SP:
839                         data_size = stream->data.yuv420sp.length_y;
840                         data_size += stream->data.yuv420sp.length_uv;
841                         break;
842                 case MM_CAM_STREAM_DATA_YUV420P:
843                         data_size = stream->data.yuv420p.length_y;
844                         data_size += stream->data.yuv420p.length_u;
845                         data_size += stream->data.yuv420p.length_v;
846                         break;
847                 case MM_CAM_STREAM_DATA_YUV422P:
848                         data_size = stream->data.yuv422p.length_y;
849                         data_size += stream->data.yuv422p.length_u;
850                         data_size += stream->data.yuv422p.length_v;
851                         break;
852                 case MM_CAM_STREAM_DATA_ENCODED:
853                         data_size = stream->data.encoded.length_data;
854                         break;
855                 default:
856                         LOGW("unknown data type %d", stream->data_type);
857                         break;
858                 }
859
860                 data_bo = tbm_bo_alloc(muse_camera->bufmgr, data_size, TBM_BO_DEFAULT);
861                 if (data_bo == NULL) {
862                         LOGE("data_bo alloc failed");
863                         goto _PREVIEW_CB_ERROR;
864                 }
865
866                 data_bo_handle = tbm_bo_map(data_bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
867                 if (data_bo_handle.ptr == NULL) {
868                         LOGE("data_bo map Error!");
869                         goto _PREVIEW_CB_ERROR;
870                 }
871
872                 buf_pos = (unsigned char *)data_bo_handle.ptr;
873
874                 switch (stream->data_type) {
875                 case MM_CAM_STREAM_DATA_YUV420:
876                         memcpy(buf_pos, stream->data.yuv420.yuv, stream->data.yuv420.length_yuv);
877                         break;
878                 case MM_CAM_STREAM_DATA_YUV422:
879                         memcpy(buf_pos, stream->data.yuv422.yuv, stream->data.yuv422.length_yuv);
880                         break;
881                 case MM_CAM_STREAM_DATA_YUV420SP:
882                         memcpy(buf_pos, stream->data.yuv420sp.y, stream->data.yuv420sp.length_y);
883                         memcpy(buf_pos + stream->data.yuv420sp.length_y, stream->data.yuv420sp.uv, stream->data.yuv420sp.length_uv);
884                         break;
885                 case MM_CAM_STREAM_DATA_YUV420P:
886                         memcpy(buf_pos, stream->data.yuv420p.y, stream->data.yuv420p.length_y);
887                         memcpy(buf_pos + stream->data.yuv420p.length_y, stream->data.yuv420p.u, stream->data.yuv420p.length_u);
888                         memcpy(buf_pos + stream->data.yuv420p.length_y + stream->data.yuv420p.length_u, stream->data.yuv420p.v, stream->data.yuv420p.length_v);
889                         break;
890                 case MM_CAM_STREAM_DATA_YUV422P:
891                         memcpy(buf_pos, stream->data.yuv422p.y, stream->data.yuv422p.length_y);
892                         memcpy(buf_pos + stream->data.yuv422p.length_y, stream->data.yuv422p.u, stream->data.yuv422p.length_u);
893                         memcpy(buf_pos + stream->data.yuv422p.length_y + stream->data.yuv422p.length_u, stream->data.yuv422p.v, stream->data.yuv422p.length_v);
894                         break;
895                 case MM_CAM_STREAM_DATA_ENCODED:
896                         memcpy(buf_pos, stream->data.encoded.data, stream->data.encoded.length_data);
897                         break;
898                 default:
899                         break;
900                 }
901
902                 tbm_bo_unmap(data_bo);
903         } else {
904                 /* zero copy */
905                 for (i = 0 ; i < BUFFER_MAX_PLANE_NUM ; i++) {
906                         if (stream->bo[i]) {
907                                 buffer_key[i] = tbm_bo_export(stream->bo[i]);
908                                 if (buffer_key[i] == 0) {
909                                         LOGE("failed to export bo %p", stream->bo[i]);
910                                         goto _PREVIEW_CB_ERROR;
911                                 }
912                                 num_buffer_key++;
913                         } else {
914                                 /*LOGD("num_buffer_key %d", num_buffer_key);*/
915                                 break;
916                         }
917                 }
918         }
919
920         tbm_key = tbm_bo_export(bo);
921         if (tbm_key == 0) {
922                 LOGE("Create key_info ERROR!!");
923                 goto _PREVIEW_CB_ERROR;
924         }
925
926         /*
927         LOGD("bo %p, vaddr %p, size %d, key %d",
928              bo, bo_handle.ptr, data_size, tbm_key);
929         */
930
931         /* set bo info */
932         export_data->key = tbm_key;
933         export_data->bo = bo;
934         if (stream->internal_buffer) {
935                 export_data->internal_buffer = stream->internal_buffer;
936                 gst_buffer_ref((GstBuffer *)export_data->internal_buffer);
937         }
938         if (data_bo) {
939                 export_data->data_bo = data_bo;
940                 data_key = tbm_bo_export(data_bo);
941                 if (data_key == 0) {
942                         LOGE("Create key_info for data_bo ERROR!!");
943                         goto _PREVIEW_CB_ERROR;
944                 }
945         }
946
947         /* add bo info to list */
948         g_mutex_lock(&muse_camera->list_lock);
949
950         muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data);
951
952         if (muse_camera->is_shutting_down) {
953                 LOGW("now shutting down.. skip this buffer");
954                 g_mutex_unlock(&muse_camera->list_lock);
955                 _camera_remove_export_data(module, tbm_key, FALSE);
956                 return;
957         }
958
959         g_mutex_unlock(&muse_camera->list_lock);
960
961         g_mutex_lock(&muse_camera->preview_cb_lock);
962
963         /* send message */
964         send_message = muse_core_msg_json_factory_new(MUSE_CAMERA_CB_EVENT,
965                 MUSE_TYPE_INT, PARAM_EVENT, MUSE_CAMERA_EVENT_TYPE_PREVIEW,
966                 MUSE_TYPE_INT, PARAM_EVENT_CLASS, MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
967                 MUSE_TYPE_INT, "tbm_key", tbm_key,
968                 MUSE_TYPE_INT, "num_buffer_key", num_buffer_key,
969                 MUSE_TYPE_INT, "data_key", data_key,
970                 MUSE_TYPE_ARRAY, "buffer_key", BUFFER_MAX_PLANE_NUM, buffer_key,
971                 0);
972
973         send_ret = muse_core_ipc_send_msg(muse_core_client_get_msg_fd(module), send_message);
974
975         muse_core_msg_json_factory_free(send_message);
976
977         /*LOGD("wait preview callback return message");*/
978
979         if (!CHECK_PREVIEW_CB(muse_camera, PREVIEW_CB_TYPE_EVAS) && send_ret > 0) {
980                 gint64 end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND;
981
982                 if (!g_cond_wait_until(&muse_camera->preview_cb_cond, &muse_camera->preview_cb_lock, end_time)) {
983                         LOGW("preview callback return message timeout");
984                 } else {
985                         /*LOGD("preview callback return message received");*/
986                 }
987         }
988
989         g_mutex_unlock(&muse_camera->preview_cb_lock);
990
991         return;
992
993 _PREVIEW_CB_ERROR:
994         if (bo) {
995                 tbm_bo_unref(bo);
996                 bo = NULL;
997         }
998         if (data_bo) {
999                 tbm_bo_unref(data_bo);
1000                 data_bo = NULL;
1001         }
1002         if (export_data) {
1003                 g_free(export_data);
1004                 export_data = NULL;
1005         }
1006
1007         return;
1008 }
1009
1010 void _camera_dispatcher_capture_completed_cb(void *user_data)
1011 {
1012         muse_module_h module = (muse_module_h)user_data;
1013
1014         LOGD("Enter");
1015
1016         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
1017                 MUSE_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE,
1018                 MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
1019                 module, "none", 0);
1020
1021         return;
1022 }
1023
1024 void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int count, void *user_data)
1025 {
1026         muse_module_h module = (muse_module_h)user_data;
1027         muse_camera_handle_s *muse_camera = NULL;
1028         tbm_bo bo = NULL;
1029         tbm_bo_handle bo_handle = {NULL, };
1030         int bo_size = sizeof(camera_detected_face_s) * count;
1031         int tbm_key = 0;
1032         muse_camera_export_data *export_data = NULL;
1033
1034         if (count >= 0) {
1035                 if (module == NULL) {
1036                         LOGE("NULL module");
1037                         return;
1038                 }
1039
1040                 if (bo_size > 0) {
1041                         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1042                         if (muse_camera == NULL) {
1043                                 LOGE("NULL handle");
1044                                 return;
1045                         }
1046
1047                         export_data = g_new0(muse_camera_export_data, 1);
1048                         if (export_data == NULL) {
1049                                 LOGE("alloc export_data failed");
1050                                 return;
1051                         }
1052
1053                         bo = tbm_bo_alloc(muse_camera->bufmgr, bo_size, TBM_BO_DEFAULT);
1054                         if (bo == NULL) {
1055                                 LOGE("tbm_bo_alloc failed");
1056
1057                                 g_free(export_data);
1058                                 export_data = NULL;
1059
1060                                 return;
1061                         }
1062
1063                         bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
1064                         if (bo_handle.ptr == NULL) {
1065                                 LOGE("bo map Error!");
1066
1067                                 tbm_bo_unref(bo);
1068                                 bo = NULL;
1069
1070                                 g_free(export_data);
1071                                 export_data = NULL;
1072
1073                                 return;
1074                         }
1075
1076                         /* copy face detection info */
1077                         memcpy(bo_handle.ptr, faces, bo_size);
1078
1079                         tbm_bo_unmap(bo);
1080
1081                         /* export bo */
1082                         tbm_key = tbm_bo_export(bo);
1083                         if (tbm_key == 0) {
1084                                 LOGE("failed to export bo for face detection info");
1085
1086                                 tbm_bo_unref(bo);
1087                                 bo = NULL;
1088
1089                                 g_free(export_data);
1090                                 export_data = NULL;
1091
1092                                 return;
1093                         }
1094
1095                         /* set export data */
1096                         export_data->bo = bo;
1097                         export_data->key = tbm_key;
1098
1099                         /* add bo info to list */
1100                         g_mutex_lock(&muse_camera->list_lock);
1101                         muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data);
1102                         g_mutex_unlock(&muse_camera->list_lock);
1103                 }
1104
1105                 LOGD("face - count %d, buffer size %d, key %d", count, bo_size, tbm_key);
1106
1107                 /* send message */
1108                 muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT,
1109                         MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION,
1110                         MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
1111                         module, "count", count, "tbm_key", tbm_key);
1112         } else {
1113                 LOGW("invalid count for face detection - %d", count);
1114         }
1115
1116         return;
1117 }
1118
1119 void _camera_dispatcher_focus_changed_cb(camera_focus_state_e state, void *user_data)
1120 {
1121         muse_module_h module = (muse_module_h)user_data;
1122
1123         LOGD("Enter - state %d", state);
1124
1125         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
1126                 MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE,
1127                 MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
1128                 module, "state", state);
1129
1130         return;
1131 }
1132
1133 void _camera_dispatcher_error_cb(camera_error_e error, camera_state_e current_state, void *user_data)
1134 {
1135         muse_module_h module = (muse_module_h)user_data;
1136
1137         LOGD("Enter - error 0x%x, current_state %d", error, current_state);
1138
1139         muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT,
1140                 MUSE_CAMERA_EVENT_TYPE_ERROR,
1141                 MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
1142                 module, "error", error, "current_state", current_state);
1143
1144         return;
1145 }
1146
1147 void _camera_dispatcher_hdr_progress_cb(int percent, void *user_data)
1148 {
1149         muse_module_h module = (muse_module_h)user_data;
1150
1151         LOGD("Enter");
1152
1153         muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT,
1154                 MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS,
1155                 MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
1156                 module, "percent", percent);
1157
1158         return;
1159 }
1160
1161
1162 static void _camera_task_add_job(muse_camera_handle_s *muse_camera, int api, int class, int value)
1163 {
1164         muse_camera_task_job_s *job = NULL;
1165
1166         if (!muse_camera) {
1167                 LOGE("NULL handle");
1168                 return;
1169         }
1170
1171         job = g_new0(muse_camera_task_job_s, 1);
1172         if (!job) {
1173                 LOGE("job alloc failed");
1174                 muse_camera_msg_return(api, class, CAMERA_ERROR_INVALID_OPERATION, muse_camera->module);
1175                 return;
1176         }
1177
1178         job->api = api;
1179         job->class = class;
1180         job->value = value;
1181
1182         LOGD("push job - api %d", api);
1183
1184         g_mutex_lock(&muse_camera->task_lock);
1185         g_queue_push_tail(&muse_camera->task_queue, (gpointer)job);
1186         g_cond_signal(&muse_camera->task_cond);
1187         g_mutex_unlock(&muse_camera->task_lock);
1188
1189         return;
1190 }
1191
1192
1193 static void __camera_task_process_job(muse_camera_handle_s *muse_camera, muse_camera_task_job_s *job)
1194 {
1195         int ret = CAMERA_ERROR_NONE;
1196
1197         if (!muse_camera) {
1198                 LOGE("NULL handle");
1199                 goto _PROCESS_DONE;
1200         }
1201
1202         LOGD("job start - api %d, value 0x%x", job->api, job->value);
1203
1204         switch (job->api) {
1205         case MUSE_CAMERA_API_STOP_PREVIEW:
1206                 ret = legacy_camera_stop_preview(muse_camera->camera_handle);
1207                 break;
1208         case MUSE_CAMERA_API_START_CAPTURE:
1209                 ret = legacy_camera_start_capture(muse_camera->camera_handle,
1210                         (camera_capturing_cb)_camera_dispatcher_capturing_cb,
1211                         (camera_capture_completed_cb)_camera_dispatcher_capture_completed_cb,
1212                         (void *)muse_camera->module);
1213                 break;
1214         case MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION:
1215                 ret = legacy_camera_set_preview_resolution(muse_camera->camera_handle, \
1216                         job->value >> 16, 0x0000ffff & job->value);
1217                 break;
1218         case MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION:
1219                 ret = legacy_camera_set_capture_resolution(muse_camera->camera_handle, \
1220                         job->value >> 16, 0x0000ffff & job->value);
1221                 break;
1222         case MUSE_CAMERA_API_ATTR_SET_HDR_MODE:
1223                 ret = legacy_camera_attr_set_hdr_mode(muse_camera->camera_handle, \
1224                         (camera_attr_hdr_mode_e)job->value);
1225                 break;
1226         default:
1227                 LOGE("unhandled task - api %d", job->api);
1228                 goto _PROCESS_DONE;
1229         }
1230
1231         LOGD("job done - api %d, ret 0x%x", job->api, ret);
1232
1233         muse_camera_msg_return(job->api, job->class, ret, muse_camera->module);
1234
1235 _PROCESS_DONE:
1236         g_free(job);
1237         job = NULL;
1238
1239         return;
1240 }
1241
1242
1243 static void *_camera_dispatcher_task_func(gpointer data)
1244 {
1245         muse_camera_handle_s *muse_camera = (muse_camera_handle_s *)data;
1246         muse_camera_task_job_s *job = NULL;
1247         gint64 end_time = 0;
1248         bool is_signaled = false;
1249         bool use_wait_until = false;
1250
1251         if (!muse_camera) {
1252                 LOGE("NULL handle");
1253                 return NULL;
1254         }
1255
1256         LOGW("enter");
1257
1258         g_mutex_lock(&muse_camera->task_lock);
1259
1260         while (muse_camera->task_run) {
1261                 if (g_queue_is_empty(&muse_camera->task_queue)) {
1262                         LOGD("empty queue. wait signal [wait until %d]", use_wait_until);
1263
1264                         if (use_wait_until) {
1265                                 end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND;
1266                                 is_signaled = g_cond_wait_until(&muse_camera->task_cond, &muse_camera->task_lock, end_time);
1267                         } else {
1268                                 g_cond_wait(&muse_camera->task_cond, &muse_camera->task_lock);
1269                                 is_signaled = true;
1270                         }
1271
1272                         /*LOGD("is_signaled %d", is_signaled);*/
1273                 }
1274
1275                 if (!muse_camera->task_run) {
1276                         LOGW("stop task thread : is_signaled %d", is_signaled);
1277                         break;
1278                 }
1279
1280                 job = (muse_camera_task_job_s *)g_queue_pop_head(&muse_camera->task_queue);
1281                 if (!job) {
1282                         if (is_signaled)
1283                                 LOGE("signal received, but no job");
1284
1285                         continue;
1286                 }
1287
1288                 if (job->api == MUSE_CAMERA_API_STOP_PREVIEW)
1289                         use_wait_until = true;
1290                 else
1291                         use_wait_until = false;
1292
1293                 g_mutex_unlock(&muse_camera->task_lock);
1294
1295                 __camera_task_process_job(muse_camera, job);
1296
1297                 g_mutex_lock(&muse_camera->task_lock);
1298         }
1299
1300         while (!g_queue_is_empty(&muse_camera->task_queue)) {
1301                 job = (muse_camera_task_job_s *)g_queue_pop_head(&muse_camera->task_queue);
1302                 if (job) {
1303                         LOGW("remained job - api %d", job->api);
1304                         __camera_task_process_job(muse_camera, job);
1305                 }
1306         }
1307
1308         g_mutex_unlock(&muse_camera->task_lock);
1309
1310         LOGW("leave");
1311
1312         return NULL;
1313 }
1314
1315
1316 static void _camera_dispatcher_release_resource(muse_module_h module)
1317 {
1318         muse_camera_handle_s *muse_camera = NULL;
1319
1320         if (!module) {
1321                 LOGE("NULL handle");
1322                 return;
1323         }
1324
1325         LOGW("enter");
1326
1327         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1328
1329         _camera_remove_export_data(module, 0, TRUE);
1330
1331         g_mutex_clear(&muse_camera->list_lock);
1332         g_cond_clear(&muse_camera->list_cond);
1333         g_mutex_clear(&muse_camera->preview_cb_lock);
1334         g_cond_clear(&muse_camera->preview_cb_cond);
1335
1336         muse_camera->bufmgr = NULL;
1337
1338         if (muse_camera->task_thread) {
1339                 LOGW("task thread exiting start");
1340
1341                 g_mutex_lock(&muse_camera->task_lock);
1342                 muse_camera->task_run = false;
1343                 g_cond_signal(&muse_camera->task_cond);
1344                 g_mutex_unlock(&muse_camera->task_lock);
1345
1346                 LOGW("wait task thread join");
1347
1348                 g_thread_join(muse_camera->task_thread);
1349                 muse_camera->task_thread = NULL;
1350
1351                 LOGW("task thread exiting end");
1352         }
1353
1354         g_mutex_clear(&muse_camera->task_lock);
1355         g_cond_clear(&muse_camera->task_cond);
1356         g_queue_clear(&muse_camera->task_queue);
1357
1358         free(muse_camera);
1359         muse_camera = NULL;
1360
1361         LOGW("leave");
1362
1363         return;
1364 }
1365
1366
1367 int camera_dispatcher_create(muse_module_h module)
1368 {
1369         int ret = CAMERA_ERROR_NONE;
1370         int device_type;
1371         int client_fd = -1;
1372         int pid = 0;
1373         void *gdbus_connection = NULL;
1374         muse_camera_handle_s *muse_camera = NULL;
1375         muse_camera_api_e api = MUSE_CAMERA_API_CREATE;
1376         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1377
1378         muse_camera_msg_get(device_type, muse_core_client_get_msg(module));
1379         muse_camera_msg_get(pid, muse_core_client_get_msg(module));
1380
1381         LOGD("device type : %d, client pid : %d", device_type, pid);
1382
1383         /* privilege check */
1384         client_fd = muse_core_client_get_msg_fd(module);
1385         if (!muse_core_security_check_cynara(client_fd, CAMERA_PRIVILEGE_NAME)) {
1386                 ret = CAMERA_ERROR_PERMISSION_DENIED;
1387                 LOGE("security check failed 0x%x", ret);
1388                 muse_camera_msg_return(api, class, ret, module);
1389                 return MUSE_CAMERA_ERROR_NONE;
1390         }
1391
1392         /* init handle */
1393         muse_camera = (muse_camera_handle_s *)malloc(sizeof(muse_camera_handle_s));
1394         if (muse_camera == NULL) {
1395                 ret = CAMERA_ERROR_OUT_OF_MEMORY;
1396                 LOGE("handle alloc failed 0x%x", ret);
1397                 muse_camera_msg_return(api, class, ret, module);
1398                 return MUSE_CAMERA_ERROR_NONE;
1399         }
1400
1401         memset(muse_camera, 0x0, sizeof(muse_camera_handle_s));
1402
1403         if (muse_core_ipc_get_bufmgr(&muse_camera->bufmgr) != MM_ERROR_NONE ||
1404                 muse_core_ipc_get_gdbus_connection((GDBusConnection **)&gdbus_connection) != MM_ERROR_NONE) {
1405                 LOGE("tbm bufmgr or gdbus conntection failed %p %p", muse_camera->bufmgr, gdbus_connection);
1406
1407                 free(muse_camera);
1408                 muse_camera = NULL;
1409
1410                 ret = CAMERA_ERROR_INVALID_OPERATION;
1411                 muse_camera_msg_return(api, class, ret, module);
1412
1413                 return MUSE_CAMERA_ERROR_NONE;
1414         }
1415
1416         ret = legacy_camera_create((camera_device_e)device_type, &muse_camera->camera_handle);
1417         if (ret != CAMERA_ERROR_NONE) {
1418                 free(muse_camera);
1419                 muse_camera = NULL;
1420                 muse_camera_msg_return(api, class, ret, module);
1421
1422                 return MUSE_CAMERA_ERROR_NONE;
1423         }
1424
1425         g_mutex_init(&muse_camera->task_lock);
1426         g_cond_init(&muse_camera->task_cond);
1427         g_queue_init(&muse_camera->task_queue);
1428
1429         muse_camera->task_run = true;
1430         muse_camera->task_thread = g_thread_try_new("camera_task_thread",
1431                 _camera_dispatcher_task_func, (gpointer)muse_camera, NULL);
1432         if (!muse_camera->task_thread) {
1433                 LOGE("failed to create new thread for task");
1434                 goto _CREATE_ERROR;
1435         }
1436
1437         ret = legacy_camera_set_state_changed_cb(muse_camera->camera_handle,
1438                 (camera_state_changed_cb)_camera_dispatcher_state_changed_cb,
1439                 (void *)module);
1440         if (ret != CAMERA_ERROR_NONE) {
1441                 LOGE("legacy_camera_set_state_changed_cb failed : 0x%x", ret);
1442                 goto _CREATE_ERROR;
1443         }
1444
1445         ret = legacy_camera_set_client_pid(muse_camera->camera_handle, pid);
1446         if (ret != CAMERA_ERROR_NONE) {
1447                 LOGE("legacy_camera_set_client_pid failed : 0x%x", ret);
1448                 goto _CREATE_ERROR;
1449         }
1450
1451         ret = legacy_camera_set_gdbus_connection(muse_camera->camera_handle, gdbus_connection);
1452         if (ret != CAMERA_ERROR_NONE) {
1453                 LOGE("legacy_camera_set_gdbus_connection failed : 0x%x", ret);
1454                 goto _CREATE_ERROR;
1455         }
1456
1457         g_mutex_init(&muse_camera->list_lock);
1458         g_cond_init(&muse_camera->list_cond);
1459         g_mutex_init(&muse_camera->preview_cb_lock);
1460         g_cond_init(&muse_camera->preview_cb_cond);
1461         muse_camera->preview_cb_flag = 0;
1462         muse_camera->module = module;
1463
1464         LOGD("handle : 0x%x", muse_camera);
1465
1466         muse_core_ipc_set_handle(module, (intptr_t)muse_camera);
1467         muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_POINTER, -1, "handle", 0, muse_camera);
1468
1469         return MUSE_CAMERA_ERROR_NONE;
1470
1471 _CREATE_ERROR:
1472         if (muse_camera->task_thread) {
1473                 g_mutex_lock(&muse_camera->task_lock);
1474                 muse_camera->task_run = false;
1475                 g_cond_signal(&muse_camera->task_cond);
1476                 g_mutex_unlock(&muse_camera->task_lock);
1477
1478                 LOGE("task thread join");
1479
1480                 g_thread_join(muse_camera->task_thread);
1481                 muse_camera->task_thread = NULL;
1482         }
1483
1484         g_mutex_clear(&muse_camera->task_lock);
1485         g_cond_clear(&muse_camera->task_cond);
1486         g_queue_clear(&muse_camera->task_queue);
1487
1488         legacy_camera_destroy(muse_camera->camera_handle);
1489         muse_camera->camera_handle = NULL;
1490
1491         free(muse_camera);
1492         muse_camera = NULL;
1493         muse_camera_msg_return(api, class, ret, module);
1494
1495         return MUSE_CAMERA_ERROR_NONE;
1496 }
1497
1498
1499 int camera_dispatcher_change_device(muse_module_h module)
1500 {
1501         int ret = CAMERA_ERROR_NONE;
1502         int device = CAMERA_DEVICE_CAMERA0;
1503         muse_camera_handle_s *muse_camera = NULL;
1504         muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
1505         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1506
1507         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1508
1509         muse_camera_msg_get(device, muse_core_client_get_msg(module));
1510
1511         LOGD("change device to %d", device);
1512
1513         ret = legacy_camera_change_device(&muse_camera->camera_handle, device,
1514                 CHECK_PREVIEW_CB(muse_camera, PREVIEW_CB_TYPE_EVAS));
1515
1516         muse_camera_msg_return(api, class, ret, module);
1517
1518         return MUSE_CAMERA_ERROR_NONE;
1519 }
1520
1521
1522 int camera_dispatcher_destroy(muse_module_h module)
1523 {
1524         int ret = CAMERA_ERROR_NONE;
1525         muse_camera_handle_s *muse_camera = NULL;
1526         muse_camera_api_e api = MUSE_CAMERA_API_DESTROY;
1527         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1528
1529         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1530
1531         LOGD("Enter, handle : %p", muse_camera);
1532
1533         ret = legacy_camera_destroy(muse_camera->camera_handle);
1534         if (ret == CAMERA_ERROR_NONE)
1535                 _camera_dispatcher_release_resource(module);
1536
1537         muse_camera_msg_return(api, class, ret, module);
1538
1539         return MUSE_CAMERA_ERROR_NONE;
1540 }
1541
1542 int camera_dispatcher_start_preview(muse_module_h module)
1543 {
1544         int ret = CAMERA_ERROR_NONE;
1545         muse_camera_handle_s *muse_camera = NULL;
1546         muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
1547         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1548
1549         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1550
1551         LOGD("handle : %p", muse_camera);
1552
1553         ret = legacy_camera_start_preview(muse_camera->camera_handle);
1554
1555         muse_camera_msg_return(api, class, ret, module);
1556
1557         return MUSE_CAMERA_ERROR_NONE;
1558 }
1559
1560 int camera_dispatcher_stop_preview(muse_module_h module)
1561 {
1562         muse_camera_handle_s *muse_camera = NULL;
1563
1564         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1565
1566         LOGD("handle : %p", muse_camera);
1567
1568         _camera_task_add_job(muse_camera, MUSE_CAMERA_API_STOP_PREVIEW,
1569                 MUSE_CAMERA_API_CLASS_IMMEDIATE, 0);
1570
1571         return MUSE_CAMERA_ERROR_NONE;
1572 }
1573
1574 int camera_dispatcher_start_capture(muse_module_h module)
1575 {
1576         muse_camera_handle_s *muse_camera = NULL;
1577
1578         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1579
1580         LOGD("handle : %p", muse_camera);
1581
1582         _camera_task_add_job(muse_camera, MUSE_CAMERA_API_START_CAPTURE,
1583                 MUSE_CAMERA_API_CLASS_IMMEDIATE, 0);
1584
1585         return MUSE_CAMERA_ERROR_NONE;
1586 }
1587
1588 int camera_dispatcher_is_supported_continuous_capture(muse_module_h module)
1589 {
1590         int ret = CAMERA_ERROR_NONE;
1591         muse_camera_handle_s *muse_camera = NULL;
1592         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE;
1593         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1594
1595         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1596
1597         LOGD("handle : %p", muse_camera);
1598
1599         ret = legacy_camera_is_supported_continuous_capture(muse_camera->camera_handle);
1600
1601         LOGD("is supported ret : %d", ret);
1602
1603         muse_camera_msg_return(api, class, ret, module);
1604
1605         return MUSE_CAMERA_ERROR_NONE;
1606 }
1607
1608 int camera_dispatcher_start_continuous_capture(muse_module_h module)
1609 {
1610         int ret = CAMERA_ERROR_NONE;
1611         muse_camera_handle_s *muse_camera = NULL;
1612         int value = 0;
1613         int count = 0;
1614         int interval = 0;
1615         muse_camera_api_e api = MUSE_CAMERA_API_START_CONTINUOUS_CAPTURE;
1616         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1617
1618         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1619
1620         muse_camera_msg_get(value, muse_core_client_get_msg(module));
1621
1622         count = value >> 16;
1623         interval = 0x0000ffff & value;
1624
1625         LOGD("Enter - count %d, interval %d", count, interval);
1626
1627         ret = legacy_camera_start_continuous_capture(muse_camera->camera_handle,
1628                 count,
1629                 interval,
1630                 (camera_capturing_cb)_camera_dispatcher_capturing_cb,
1631                 (camera_capture_completed_cb)_camera_dispatcher_capture_completed_cb,
1632                 (void *)module);
1633
1634         muse_camera_msg_return(api, class, ret, module);
1635
1636         return MUSE_CAMERA_ERROR_NONE;
1637 }
1638
1639 int camera_dispatcher_stop_continuous_capture(muse_module_h module)
1640 {
1641         int ret = CAMERA_ERROR_NONE;
1642         muse_camera_handle_s *muse_camera = NULL;
1643         muse_camera_api_e api = MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE;
1644         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1645
1646         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1647
1648         LOGD("handle : %p", muse_camera);
1649
1650         ret = legacy_camera_stop_continuous_capture(muse_camera->camera_handle);
1651
1652         muse_camera_msg_return(api, class, ret, module);
1653
1654         return MUSE_CAMERA_ERROR_NONE;
1655 }
1656
1657 int camera_dispatcher_is_supported_face_detection(muse_module_h module)
1658 {
1659         int ret = CAMERA_ERROR_NONE;
1660         muse_camera_handle_s *muse_camera = NULL;
1661         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_FACE_DETECTION;
1662         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1663
1664         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1665
1666         LOGD("handle : %p", muse_camera);
1667
1668         ret = legacy_camera_is_supported_face_detection(muse_camera->camera_handle);
1669
1670         LOGD("is supported ret : %d", ret);
1671
1672         muse_camera_msg_return(api, class, ret, module);
1673
1674         return MUSE_CAMERA_ERROR_NONE;
1675 }
1676
1677 int camera_dispatcher_is_supported_zero_shutter_lag(muse_module_h module)
1678 {
1679         int ret = CAMERA_ERROR_NONE;
1680         muse_camera_handle_s *muse_camera = NULL;
1681         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG;
1682         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1683
1684         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1685
1686         LOGD("handle : %p", muse_camera);
1687
1688         ret = legacy_camera_is_supported_zero_shutter_lag(muse_camera->camera_handle);
1689
1690         LOGD("is supported ret : %d", ret);
1691
1692         muse_camera_msg_return(api, class, ret, module);
1693
1694         return MUSE_CAMERA_ERROR_NONE;
1695 }
1696
1697 int camera_dispatcher_is_supported_media_packet_preview_cb(muse_module_h module)
1698 {
1699         int ret = CAMERA_ERROR_NONE;
1700         muse_camera_handle_s *muse_camera = NULL;
1701         muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB;
1702         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1703
1704         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1705
1706         LOGD("handle : %p", muse_camera);
1707
1708         ret = legacy_camera_is_supported_media_packet_preview_cb(muse_camera->camera_handle);
1709
1710         LOGD("is supported ret : %d", ret);
1711
1712         muse_camera_msg_return(api, class, ret, module);
1713
1714         return MUSE_CAMERA_ERROR_NONE;
1715 }
1716
1717 int camera_dispatcher_get_device_count(muse_module_h module)
1718 {
1719         int ret = CAMERA_ERROR_NONE;
1720         muse_camera_handle_s *muse_camera = NULL;
1721         int get_value = 0;
1722         muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
1723         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1724
1725         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1726
1727         LOGD("handle : %p", muse_camera);
1728
1729         ret = legacy_camera_get_device_count(muse_camera->camera_handle, &get_value);
1730         if (ret == CAMERA_ERROR_NONE) {
1731                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
1732                         MUSE_CAMERA_GET_INT_DEVICE_COUNT, "get_value", get_value, NULL);
1733         } else {
1734                 muse_camera_msg_return(api, class, ret, module);
1735         }
1736
1737         return MUSE_CAMERA_ERROR_NONE;
1738 }
1739
1740 int camera_dispatcher_start_face_detection(muse_module_h module)
1741 {
1742         int ret = CAMERA_ERROR_NONE;
1743         muse_camera_handle_s *muse_camera = NULL;
1744         muse_camera_api_e api = MUSE_CAMERA_API_START_FACE_DETECTION;
1745         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1746
1747         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1748
1749         LOGD("Enter, handle : 0x%x, module : %d", muse_camera, module);
1750
1751         ret = legacy_camera_start_face_detection(muse_camera->camera_handle,
1752                 (camera_face_detected_cb)_camera_dispatcher_face_detected_cb,
1753                 (void *)module);
1754
1755         muse_camera_msg_return(api, class, ret, module);
1756
1757         return MUSE_CAMERA_ERROR_NONE;
1758 }
1759
1760 int camera_dispatcher_stop_face_detection(muse_module_h module)
1761 {
1762         int ret = CAMERA_ERROR_NONE;
1763         muse_camera_handle_s *muse_camera = NULL;
1764         muse_camera_api_e api = MUSE_CAMERA_API_STOP_FACE_DETECTION;
1765         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1766
1767         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1768
1769         LOGD("handle : %p", muse_camera);
1770
1771         ret = legacy_camera_stop_face_detection(muse_camera->camera_handle);
1772
1773         muse_camera_msg_return(api, class, ret, module);
1774
1775         return MUSE_CAMERA_ERROR_NONE;
1776 }
1777
1778 int camera_dispatcher_get_state(muse_module_h module)
1779 {
1780         int ret = CAMERA_ERROR_NONE;
1781         muse_camera_handle_s *muse_camera = NULL;
1782         camera_state_e get_value = CAMERA_STATE_NONE;
1783         muse_camera_api_e api = MUSE_CAMERA_API_GET_STATE;
1784         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1785
1786         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1787
1788         LOGD("handle : %p", muse_camera);
1789
1790         ret = legacy_camera_get_state(muse_camera->camera_handle, &get_value);
1791         if (ret == CAMERA_ERROR_NONE) {
1792                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
1793                         MUSE_CAMERA_GET_INT_STATE, "get_value", get_value, NULL);
1794         } else {
1795                 muse_camera_msg_return(api, class, ret, module);
1796         }
1797
1798         return MUSE_CAMERA_ERROR_NONE;
1799 }
1800
1801 int camera_dispatcher_start_focusing(muse_module_h module)
1802 {
1803         int ret = CAMERA_ERROR_NONE;
1804         muse_camera_handle_s *muse_camera = NULL;
1805         int is_continuous;
1806         muse_camera_api_e api = MUSE_CAMERA_API_START_FOCUSING;
1807         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1808
1809         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1810
1811         muse_camera_msg_get(is_continuous, muse_core_client_get_msg(module));
1812
1813         LOGD("Enter, handle : 0x%x, module : %d", muse_camera, module);
1814
1815         ret = legacy_camera_start_focusing(muse_camera->camera_handle, (bool)is_continuous);
1816
1817         muse_camera_msg_return(api, class, ret, module);
1818
1819         return MUSE_CAMERA_ERROR_NONE;
1820 }
1821
1822 int camera_dispatcher_stop_focusing(muse_module_h module)
1823 {
1824         int ret = CAMERA_ERROR_NONE;
1825         muse_camera_handle_s *muse_camera = NULL;
1826         muse_camera_api_e api = MUSE_CAMERA_API_CANCEL_FOCUSING;
1827         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1828
1829         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1830
1831         LOGD("handle : %p", muse_camera);
1832
1833         ret = legacy_camera_cancel_focusing(muse_camera->camera_handle);
1834
1835         muse_camera_msg_return(api, class, ret, module);
1836
1837         return MUSE_CAMERA_ERROR_NONE;
1838 }
1839
1840 int camera_dispatcher_set_display(muse_module_h module)
1841 {
1842         int ret = CAMERA_ERROR_NONE;
1843         muse_camera_handle_s *muse_camera = NULL;
1844         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY;
1845         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1846         MMCamWaylandInfo *wl_info = NULL;
1847         camera_display_type_e type = CAMERA_DISPLAY_TYPE_NONE;
1848         camera_h camera = NULL;;
1849
1850         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1851
1852         LOGD("handle : 0x%x", muse_camera);
1853
1854         camera = muse_camera->camera_handle;
1855
1856         muse_camera_msg_get(type, muse_core_client_get_msg(module));
1857
1858         LOGD("type %d", type);
1859
1860         if (type == CAMERA_DISPLAY_TYPE_OVERLAY) {
1861                 wl_info = &muse_camera->wl_info;
1862                 muse_camera_msg_get_array(wl_info, muse_core_client_get_msg(module));
1863
1864                 LOGD("wayland global surface id : %d, window : %d,%d,%dx%d",
1865                         wl_info->global_surface_id, wl_info->window_x, wl_info->window_y,
1866                         wl_info->window_width, wl_info->window_height);
1867
1868                 ret = legacy_camera_set_display(muse_camera->camera_handle, type, (void *)wl_info);
1869
1870                 muse_camera_msg_return(api, class, ret, module);
1871         } else {
1872                 LOGD("NOT overlay type. set NONE type.");
1873
1874                 if (type == CAMERA_DISPLAY_TYPE_EVAS) {
1875                         ret = legacy_camera_set_preview_cb(muse_camera->camera_handle,
1876                                 (camera_preview_cb)_camera_dispatcher_preview_cb,
1877                                 (void *)module);
1878
1879                         if (ret == CAMERA_ERROR_NONE)
1880                                 SET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_EVAS);
1881                 }
1882
1883                 ret = legacy_camera_set_display(muse_camera->camera_handle, CAMERA_DISPLAY_TYPE_NONE, NULL);
1884
1885                 muse_camera_msg_return(api, class, ret, module);
1886         }
1887
1888         return MUSE_CAMERA_ERROR_NONE;
1889 }
1890
1891 int camera_dispatcher_set_preview_resolution(muse_module_h module)
1892 {
1893         int value = 0;
1894         muse_camera_handle_s *muse_camera = NULL;
1895
1896         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1897
1898         muse_camera_msg_get(value, muse_core_client_get_msg(module));
1899
1900         _camera_task_add_job(muse_camera, MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION,
1901                 MUSE_CAMERA_API_CLASS_IMMEDIATE, value);
1902
1903         return MUSE_CAMERA_ERROR_NONE;
1904 }
1905
1906 int camera_dispatcher_set_capture_resolution(muse_module_h module)
1907 {
1908         int value = 0;
1909         muse_camera_handle_s *muse_camera = NULL;
1910
1911         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1912
1913         muse_camera_msg_get(value, muse_core_client_get_msg(module));
1914
1915         _camera_task_add_job(muse_camera, MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION,
1916                 MUSE_CAMERA_API_CLASS_IMMEDIATE, value);
1917
1918         return MUSE_CAMERA_ERROR_NONE;
1919 }
1920
1921 int camera_dispatcher_set_capture_format(muse_module_h module)
1922 {
1923         int ret = CAMERA_ERROR_NONE;
1924         muse_camera_handle_s *muse_camera = NULL;
1925         int set_format;
1926         muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
1927         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1928
1929         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1930
1931         muse_camera_msg_get(set_format, muse_core_client_get_msg(module));
1932
1933         LOGD("handle : 0x%x, set_format : %d", muse_camera, set_format);
1934
1935         ret = legacy_camera_set_capture_format(muse_camera->camera_handle, (camera_pixel_format_e)set_format);
1936
1937         muse_camera_msg_return(api, class, ret, module);
1938
1939         return MUSE_CAMERA_ERROR_NONE;
1940 }
1941
1942 int camera_dispatcher_set_preview_format(muse_module_h module)
1943 {
1944         int ret = CAMERA_ERROR_NONE;
1945         muse_camera_handle_s *muse_camera = NULL;
1946         int set_format;
1947         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
1948         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1949
1950         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1951
1952         muse_camera_msg_get(set_format, muse_core_client_get_msg(module));
1953
1954         LOGD("handle : 0x%x, set_format : %d", muse_camera, set_format);
1955
1956         ret = legacy_camera_set_preview_format(muse_camera->camera_handle, (camera_pixel_format_e)set_format);
1957
1958         muse_camera_msg_return(api, class, ret, module);
1959
1960         return MUSE_CAMERA_ERROR_NONE;
1961 }
1962
1963 int camera_dispatcher_get_preview_resolution(muse_module_h module)
1964 {
1965         int ret = CAMERA_ERROR_NONE;
1966         muse_camera_handle_s *muse_camera = NULL;
1967         int get_width = 0;
1968         int get_height = 0;
1969         int get_value = 0;
1970         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION;
1971         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1972
1973         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1974
1975         LOGD("handle : %p", muse_camera);
1976
1977         ret = legacy_camera_get_preview_resolution(muse_camera->camera_handle, &get_width, &get_height);
1978         if (ret == CAMERA_ERROR_NONE) {
1979                 get_value = get_width << 16 | get_height;
1980                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
1981                         MUSE_CAMERA_GET_INT_PREVIEW_RESOLUTION, "get_value", get_value, NULL);
1982         } else {
1983                 muse_camera_msg_return(api, class, ret, module);
1984         }
1985
1986         return MUSE_CAMERA_ERROR_NONE;
1987 }
1988
1989 int camera_dispatcher_set_display_rotation(muse_module_h module)
1990 {
1991         int ret = CAMERA_ERROR_NONE;
1992         muse_camera_handle_s *muse_camera = NULL;
1993         int set_rotation;
1994         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROTATION;
1995         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
1996
1997         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
1998
1999         muse_camera_msg_get(set_rotation, muse_core_client_get_msg(module));
2000
2001         LOGD("handle : 0x%x, set_rotation : %d", muse_camera, set_rotation);
2002
2003         ret = legacy_camera_set_display_rotation(muse_camera->camera_handle, (camera_rotation_e)set_rotation);
2004
2005         muse_camera_msg_return(api, class, ret, module);
2006
2007         return MUSE_CAMERA_ERROR_NONE;
2008 }
2009
2010 int camera_dispatcher_get_display_rotation(muse_module_h module)
2011 {
2012         int ret = CAMERA_ERROR_NONE;
2013         muse_camera_handle_s *muse_camera = NULL;
2014         camera_rotation_e get_value = CAMERA_ROTATION_NONE;
2015         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROTATION;
2016         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2017
2018         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2019
2020         LOGD("handle : %p", muse_camera);
2021
2022         ret = legacy_camera_get_display_rotation(muse_camera->camera_handle, &get_value);
2023         if (ret == CAMERA_ERROR_NONE) {
2024                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2025                         MUSE_CAMERA_GET_INT_DISPLAY_ROTATION, "get_value", get_value, NULL);
2026         } else {
2027                 muse_camera_msg_return(api, class, ret, module);
2028         }
2029
2030         return MUSE_CAMERA_ERROR_NONE;
2031 }
2032
2033 int camera_dispatcher_set_display_flip(muse_module_h module)
2034 {
2035         int ret = CAMERA_ERROR_NONE;
2036         muse_camera_handle_s *muse_camera = NULL;
2037         int set_flip;
2038         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_FLIP;
2039         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2040
2041         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2042
2043         muse_camera_msg_get(set_flip, muse_core_client_get_msg(module));
2044
2045         LOGD("handle : 0x%x, set_flip : %d", muse_camera, set_flip);
2046
2047         ret = legacy_camera_set_display_flip(muse_camera->camera_handle, (camera_flip_e)set_flip);
2048
2049         muse_camera_msg_return(api, class, ret, module);
2050
2051         return MUSE_CAMERA_ERROR_NONE;
2052 }
2053
2054 int camera_dispatcher_get_display_flip(muse_module_h module)
2055 {
2056         int ret = CAMERA_ERROR_NONE;
2057         muse_camera_handle_s *muse_camera = NULL;
2058         camera_flip_e get_value = CAMERA_FLIP_NONE;
2059         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_FLIP;
2060         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2061
2062         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2063
2064         LOGD("handle : %p", muse_camera);
2065
2066         ret = legacy_camera_get_display_flip(muse_camera->camera_handle, &get_value);
2067         if (ret == CAMERA_ERROR_NONE) {
2068                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2069                         MUSE_CAMERA_GET_INT_DISPLAY_FLIP, "get_value", get_value, NULL);
2070         } else {
2071                 muse_camera_msg_return(api, class, ret, module);
2072         }
2073
2074         return MUSE_CAMERA_ERROR_NONE;
2075 }
2076
2077 int camera_dispatcher_set_display_visible(muse_module_h module)
2078 {
2079         int ret = CAMERA_ERROR_NONE;
2080         muse_camera_handle_s *muse_camera = NULL;
2081         int set_visible;
2082         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_VISIBLE;
2083         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2084
2085         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2086
2087         muse_camera_msg_get(set_visible, muse_core_client_get_msg(module));
2088
2089         LOGD("handle : 0x%x, set_visible : %d", muse_camera, set_visible);
2090
2091         ret = legacy_camera_set_display_visible(muse_camera->camera_handle, (bool)set_visible);
2092
2093         muse_camera_msg_return(api, class, ret, module);
2094
2095         return MUSE_CAMERA_ERROR_NONE;
2096 }
2097
2098 int camera_dispatcher_is_display_visible(muse_module_h module)
2099 {
2100         int ret = CAMERA_ERROR_NONE;
2101         muse_camera_handle_s *muse_camera = NULL;
2102         bool get_value = true;
2103         muse_camera_api_e api = MUSE_CAMERA_API_IS_DISPLAY_VISIBLE;
2104         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2105
2106         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2107
2108         LOGD("handle : %p", muse_camera);
2109
2110         ret = legacy_camera_is_display_visible(muse_camera->camera_handle, &get_value);
2111         if (ret == CAMERA_ERROR_NONE) {
2112                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2113                         MUSE_CAMERA_GET_INT_DISPLAY_VISIBLE, "get_value", get_value, NULL);
2114         } else {
2115                 muse_camera_msg_return(api, class, ret, module);
2116         }
2117
2118         return MUSE_CAMERA_ERROR_NONE;
2119 }
2120
2121 int camera_dispatcher_set_display_mode(muse_module_h module)
2122 {
2123         int ret = CAMERA_ERROR_NONE;
2124         muse_camera_handle_s *muse_camera = NULL;
2125         int set_mode;
2126         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_MODE;
2127         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2128
2129         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2130
2131         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
2132
2133         LOGD("handle : 0x%x, display_mode : %d", muse_camera, set_mode);
2134
2135         ret = legacy_camera_set_display_mode(muse_camera->camera_handle, (camera_display_mode_e)set_mode);
2136
2137         LOGD("ret : 0x%x", ret);
2138
2139         muse_camera_msg_return(api, class, ret, module);
2140
2141         return MUSE_CAMERA_ERROR_NONE;
2142 }
2143
2144 int camera_dispatcher_get_display_mode(muse_module_h module)
2145 {
2146         int ret = CAMERA_ERROR_NONE;
2147         muse_camera_handle_s *muse_camera = NULL;
2148         camera_display_mode_e get_value = CAMERA_DISPLAY_MODE_LETTER_BOX;
2149         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_MODE;
2150         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2151
2152         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2153
2154         LOGD("handle : %p", muse_camera);
2155
2156         ret = legacy_camera_get_display_mode(muse_camera->camera_handle, &get_value);
2157         if (ret == CAMERA_ERROR_NONE) {
2158                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2159                         MUSE_CAMERA_GET_INT_DISPLAY_MODE, "get_value", get_value, NULL);
2160         } else {
2161                 muse_camera_msg_return(api, class, ret, module);
2162         }
2163
2164         return MUSE_CAMERA_ERROR_NONE;
2165 }
2166
2167 int camera_dispatcher_get_capture_resolution(muse_module_h module)
2168 {
2169         int ret = CAMERA_ERROR_NONE;
2170         muse_camera_handle_s *muse_camera = NULL;
2171         int get_width = 0;
2172         int get_height = 0;
2173         int get_value = 0;
2174         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION;
2175         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2176
2177         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2178
2179         LOGD("handle : %p", muse_camera);
2180
2181         ret = legacy_camera_get_capture_resolution(muse_camera->camera_handle, &get_width, &get_height);
2182         if (ret == CAMERA_ERROR_NONE) {
2183                 get_value = get_width << 16 | get_height;
2184                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2185                         MUSE_CAMERA_GET_INT_CAPTURE_RESOLUTION, "get_value", get_value, NULL);
2186         } else {
2187                 muse_camera_msg_return(api, class, ret, module);
2188         }
2189
2190         return MUSE_CAMERA_ERROR_NONE;
2191 }
2192
2193 int camera_dispatcher_get_capture_format(muse_module_h module)
2194 {
2195         int ret = CAMERA_ERROR_NONE;
2196         muse_camera_handle_s *muse_camera = NULL;
2197         camera_pixel_format_e get_value = CAMERA_PIXEL_FORMAT_NV12;
2198         muse_camera_api_e api = MUSE_CAMERA_API_GET_CAPTURE_FORMAT;
2199         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2200
2201         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2202
2203         LOGD("handle : %p", muse_camera);
2204
2205         ret = legacy_camera_get_capture_format(muse_camera->camera_handle, &get_value);
2206         if (ret == CAMERA_ERROR_NONE) {
2207                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2208                         MUSE_CAMERA_GET_INT_CAPTURE_FORMAT, "get_value", get_value, NULL);
2209         } else {
2210                 muse_camera_msg_return(api, class, ret, module);
2211         }
2212
2213         return MUSE_CAMERA_ERROR_NONE;
2214 }
2215
2216 int camera_dispatcher_get_preview_format(muse_module_h module)
2217 {
2218         int ret = CAMERA_ERROR_NONE;
2219         muse_camera_handle_s *muse_camera = NULL;
2220         camera_pixel_format_e get_value = CAMERA_PIXEL_FORMAT_NV12;
2221         muse_camera_api_e api = MUSE_CAMERA_API_GET_PREVIEW_FORMAT;
2222         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2223
2224         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2225
2226         LOGD("handle : %p", muse_camera);
2227
2228         ret = legacy_camera_get_preview_format(muse_camera->camera_handle, &get_value);
2229         if (ret == CAMERA_ERROR_NONE) {
2230                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2231                         MUSE_CAMERA_GET_INT_PREVIEW_FORMAT, "get_value", get_value, NULL);
2232         } else {
2233                 muse_camera_msg_return(api, class, ret, module);
2234         }
2235
2236         return MUSE_CAMERA_ERROR_NONE;
2237 }
2238
2239 int camera_dispatcher_get_facing_direction(muse_module_h module)
2240 {
2241         int ret = CAMERA_ERROR_NONE;
2242         muse_camera_handle_s *muse_camera = NULL;
2243         camera_facing_direction_e get_value = CAMERA_FACING_DIRECTION_REAR;
2244         muse_camera_api_e api = MUSE_CAMERA_API_GET_FACING_DIRECTION;
2245         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2246
2247         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2248
2249         LOGD("handle : %p", muse_camera);
2250
2251         ret = legacy_camera_get_facing_direction(muse_camera->camera_handle, &get_value);
2252         if (ret == CAMERA_ERROR_NONE) {
2253                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2254                         MUSE_CAMERA_GET_INT_FACING_DIRECTION, "get_value", get_value, NULL);
2255         } else {
2256                 muse_camera_msg_return(api, class, ret, module);
2257         }
2258
2259         return MUSE_CAMERA_ERROR_NONE;
2260 }
2261
2262 int camera_dispatcher_get_flash_state(muse_module_h module)
2263 {
2264         int ret = CAMERA_ERROR_NONE;
2265         int count = 0;
2266         bool is_called = false;
2267         char value_key[KEY_LENGTH] = {'\0',};
2268         camera_h camera = NULL;
2269         camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
2270         camera_flash_state_e get_flash_state = CAMERA_FLASH_STATE_NOT_USED;
2271         muse_camera_api_e api = MUSE_CAMERA_API_GET_FLASH_STATE;
2272         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2273
2274         muse_camera_msg_get(device_type, muse_core_client_get_msg(module));
2275
2276         if (device_type < CAMERA_DEVICE_CAMERA0 || device_type > CAMERA_DEVICE_CAMERA1) {
2277                 LOGE("invalid device %d", device_type);
2278
2279                 ret = CAMERA_ERROR_INVALID_PARAMETER;
2280                 muse_camera_msg_return(api, class, ret, module);
2281
2282                 return MUSE_CAMERA_ERROR_NONE;
2283         }
2284
2285         muse_core_client_get_value(module, MUSED_KEY_FLASH_STATE_CHECK, (int *)&is_called);
2286
2287         if (!is_called) {
2288                 ret = legacy_camera_create(device_type, &camera);
2289                 if (camera) {
2290                         legacy_camera_attr_foreach_supported_flash_mode(camera,
2291                                 (camera_attr_supported_flash_mode_cb)_camera_dispatcher_callback_supported_flash_mode2,
2292                                 (void *)&count);
2293
2294                         legacy_camera_destroy(camera);
2295                         camera = NULL;
2296                 }
2297
2298                 muse_core_client_set_value(module, MUSED_KEY_FLASH_STATE_RETURN, ret);
2299                 muse_core_client_set_value(module, MUSED_KEY_FLASH_STATE_COUNT, count);
2300                 muse_core_client_set_value(module, MUSED_KEY_FLASH_STATE_CHECK, (int)true);
2301         } else {
2302                 muse_core_client_get_value(module, MUSED_KEY_FLASH_STATE_RETURN, &ret);
2303                 muse_core_client_get_value(module, MUSED_KEY_FLASH_STATE_COUNT, &count);
2304         }
2305
2306         LOGD("is_called %d, ret 0x%x, count %d", is_called, ret, count);
2307
2308         if (ret != CAMERA_ERROR_NONE) {
2309                 LOGE("failed to create or get camera info 0x%x", ret);
2310
2311                 muse_camera_msg_return(api, class, ret, module);
2312
2313                 return MUSE_CAMERA_ERROR_NONE;
2314         }
2315
2316         if (count < 2) {
2317                 LOGE("count[%d] of supported flash mode is too small, so return NOT_SUPPORTED", count);
2318
2319                 ret = CAMERA_ERROR_NOT_SUPPORTED;
2320                 muse_camera_msg_return(api, class, ret, module);
2321
2322                 return MUSE_CAMERA_ERROR_NONE;
2323         }
2324
2325         snprintf(value_key, KEY_LENGTH, "flash_state_camera%d", device_type);
2326         muse_core_client_get_value(module, value_key, (int *)&get_flash_state);
2327
2328         LOGD("[%d] flash state : %d", device_type, get_flash_state);
2329
2330         muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2331                         -1, "get_flash_state", get_flash_state, NULL);
2332
2333         return MUSE_CAMERA_ERROR_NONE;
2334 }
2335
2336 int camera_dispatcher_set_preview_cb(muse_module_h module)
2337 {
2338         int ret = CAMERA_ERROR_NONE;
2339         muse_camera_handle_s *muse_camera = NULL;
2340         muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_CB;
2341         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2342
2343         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2344
2345         LOGD("handle : %p", muse_camera);
2346
2347         ret = legacy_camera_set_preview_cb(muse_camera->camera_handle,
2348                 (camera_preview_cb)_camera_dispatcher_preview_cb,
2349                 (void *)module);
2350
2351         if (ret == CAMERA_ERROR_NONE)
2352                 SET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_USER);
2353
2354         LOGD("ret : 0x%x", ret);
2355
2356         muse_camera_msg_return(api, class, ret, module);
2357
2358         return MUSE_CAMERA_ERROR_NONE;
2359 }
2360
2361 int camera_dispatcher_unset_preview_cb(muse_module_h module)
2362 {
2363         int ret = CAMERA_ERROR_NONE;
2364         muse_camera_handle_s *muse_camera = NULL;
2365         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
2366         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2367
2368         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2369
2370         LOGD("handle : %p", muse_camera);
2371
2372         UNSET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_USER);
2373         if (CHECK_PREVIEW_CB(muse_camera, PREVIEW_CB_TYPE_EVAS))
2374                 LOGD("Preview callback for evas surface is remained.");
2375         else
2376                 ret = legacy_camera_unset_preview_cb(muse_camera->camera_handle);
2377
2378         LOGD("ret : 0x%x", ret);
2379
2380         muse_camera_msg_return(api, class, ret, module);
2381
2382         return MUSE_CAMERA_ERROR_NONE;
2383 }
2384
2385 int camera_dispatcher_set_media_packet_preview_cb(muse_module_h module)
2386 {
2387         int ret = CAMERA_ERROR_NONE;
2388         muse_camera_handle_s *muse_camera = NULL;
2389         muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
2390         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2391
2392         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2393
2394         LOGD("handle : %p", muse_camera);
2395
2396         ret = legacy_camera_set_media_packet_preview_cb(muse_camera->camera_handle,
2397                 (camera_preview_cb)_camera_dispatcher_preview_cb,
2398                 (void *)module);
2399
2400         LOGD("ret : 0x%x", ret);
2401
2402         muse_camera_msg_return(api, class, ret, module);
2403
2404         return MUSE_CAMERA_ERROR_NONE;
2405 }
2406
2407 int camera_dispatcher_unset_media_packet_preview_cb(muse_module_h module)
2408 {
2409         int ret = CAMERA_ERROR_NONE;
2410         muse_camera_handle_s *muse_camera = NULL;
2411         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
2412         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2413
2414         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2415
2416         LOGD("handle : %p", muse_camera);
2417
2418         ret = legacy_camera_unset_media_packet_preview_cb(muse_camera->camera_handle);
2419
2420         LOGD("ret : 0x%x", ret);
2421
2422         muse_camera_msg_return(api, class, ret, module);
2423
2424         return MUSE_CAMERA_ERROR_NONE;
2425 }
2426
2427 int camera_dispatcher_set_state_changed_cb(muse_module_h module)
2428 {
2429         int ret = CAMERA_ERROR_NONE;
2430         muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
2431         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2432
2433         LOGD("Enter");
2434
2435         muse_camera_msg_return(api, class, ret, module);
2436
2437         return MUSE_CAMERA_ERROR_NONE;
2438 }
2439
2440 int camera_dispatcher_unset_state_changed_cb(muse_module_h module)
2441 {
2442         int ret = CAMERA_ERROR_NONE;
2443         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
2444         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2445
2446         LOGD("Enter");
2447
2448         muse_camera_msg_return(api, class, ret, module);
2449
2450         return MUSE_CAMERA_ERROR_NONE;
2451 }
2452
2453 int camera_dispatcher_set_interrupted_cb(muse_module_h module)
2454 {
2455         int ret = CAMERA_ERROR_NONE;
2456         muse_camera_handle_s *muse_camera = NULL;
2457         muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPTED_CB;
2458         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2459
2460         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2461
2462         LOGD("handle : %p", muse_camera);
2463
2464         ret = legacy_camera_set_interrupted_cb(muse_camera->camera_handle,
2465                 (camera_interrupted_cb)_camera_dispatcher_interrupted_cb,
2466                 (void *)module);
2467
2468         LOGD("ret : 0x%x", ret);
2469
2470         muse_camera_msg_return(api, class, ret, module);
2471
2472         return MUSE_CAMERA_ERROR_NONE;
2473 }
2474
2475 int camera_dispatcher_unset_interrupted_cb(muse_module_h module)
2476 {
2477         int ret = CAMERA_ERROR_NONE;
2478         muse_camera_handle_s *muse_camera = NULL;
2479         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
2480         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2481
2482         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2483
2484         LOGD("handle : %p", muse_camera);
2485
2486         ret = legacy_camera_unset_interrupted_cb(muse_camera->camera_handle);
2487
2488         LOGD("ret : 0x%x", ret);
2489
2490         muse_camera_msg_return(api, class, ret, module);
2491
2492         return MUSE_CAMERA_ERROR_NONE;
2493 }
2494
2495 int camera_dispatcher_set_focus_changed_cb(muse_module_h module)
2496 {
2497         int ret = CAMERA_ERROR_NONE;
2498         muse_camera_handle_s *muse_camera = NULL;
2499         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB;
2500         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2501
2502         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2503
2504         LOGD("handle : %p", muse_camera);
2505
2506         ret = legacy_camera_set_focus_changed_cb(muse_camera->camera_handle,
2507                 (camera_focus_changed_cb)_camera_dispatcher_focus_changed_cb,
2508                 (void *)module);
2509
2510         LOGD("ret : 0x%x", ret);
2511
2512         muse_camera_msg_return(api, class, ret, module);
2513
2514         return MUSE_CAMERA_ERROR_NONE;
2515 }
2516
2517 int camera_dispatcher_unset_focus_changed_cb(muse_module_h module)
2518 {
2519         int ret = CAMERA_ERROR_NONE;
2520         muse_camera_handle_s *muse_camera = NULL;
2521         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
2522         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2523
2524         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2525
2526         LOGD("handle : %p", muse_camera);
2527
2528         ret = legacy_camera_unset_focus_changed_cb(muse_camera->camera_handle);
2529
2530         LOGD("ret : 0x%x", ret);
2531
2532         muse_camera_msg_return(api, class, ret, module);
2533
2534         return MUSE_CAMERA_ERROR_NONE;
2535 }
2536
2537 int camera_dispatcher_set_error_cb(muse_module_h module)
2538 {
2539         int ret = CAMERA_ERROR_NONE;
2540         muse_camera_handle_s *muse_camera = NULL;
2541         muse_camera_api_e api = MUSE_CAMERA_API_SET_ERROR_CB;
2542         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2543
2544         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2545
2546         LOGD("handle : %p", muse_camera);
2547
2548         ret = legacy_camera_set_error_cb(muse_camera->camera_handle,
2549                 (camera_error_cb)_camera_dispatcher_error_cb,
2550                 (void *)module);
2551
2552         LOGD("ret : 0x%x", ret);
2553
2554         muse_camera_msg_return(api, class, ret, module);
2555
2556         return MUSE_CAMERA_ERROR_NONE;
2557 }
2558
2559 int camera_dispatcher_unset_error_cb(muse_module_h module)
2560 {
2561         int ret = CAMERA_ERROR_NONE;
2562         muse_camera_handle_s *muse_camera = NULL;
2563         muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
2564         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2565
2566         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2567
2568         LOGD("handle : %p", muse_camera);
2569
2570         ret = legacy_camera_unset_error_cb(muse_camera->camera_handle);
2571
2572         LOGD("ret : 0x%x", ret);
2573
2574         muse_camera_msg_return(api, class, ret, module);
2575
2576         return MUSE_CAMERA_ERROR_NONE;
2577 }
2578
2579 int camera_dispatcher_foreach_supported_preview_resolution(muse_module_h module)
2580 {
2581         int ret = CAMERA_ERROR_NONE;
2582         muse_camera_handle_s *muse_camera = NULL;
2583         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION;
2584         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
2585
2586         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2587
2588         LOGD("handle : %p", muse_camera);
2589
2590         ret = legacy_camera_foreach_supported_preview_resolution(muse_camera->camera_handle,
2591                 (camera_supported_preview_resolution_cb)_camera_dispatcher_callback_supported_preview_resolution,
2592                 (void *)module);
2593
2594         LOGD("ret : 0x%x", ret);
2595
2596         muse_camera_msg_return(api, class, ret, module);
2597
2598         return MUSE_CAMERA_ERROR_NONE;
2599 }
2600
2601 int camera_dispatcher_foreach_supported_capture_resolution(muse_module_h module)
2602 {
2603         int ret = CAMERA_ERROR_NONE;
2604         muse_camera_handle_s *muse_camera = NULL;
2605         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION;
2606         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
2607
2608         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2609
2610         LOGD("handle : %p", muse_camera);
2611
2612         ret = legacy_camera_foreach_supported_capture_resolution(muse_camera->camera_handle,
2613                 (camera_supported_capture_resolution_cb)_camera_dispatcher_callback_supported_capture_resolution,
2614                 (void *)module);
2615
2616         LOGD("ret : 0x%x", ret);
2617
2618         muse_camera_msg_return(api, class, ret, module);
2619
2620         return MUSE_CAMERA_ERROR_NONE;
2621 }
2622
2623 int camera_dispatcher_foreach_supported_capture_format(muse_module_h module)
2624 {
2625         int ret = CAMERA_ERROR_NONE;
2626         muse_camera_handle_s *muse_camera = NULL;
2627         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT;
2628         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
2629
2630         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2631
2632         LOGD("handle : %p", muse_camera);
2633
2634         ret = legacy_camera_foreach_supported_capture_format(muse_camera->camera_handle,
2635                 (camera_supported_capture_format_cb)_camera_dispatcher_callback_supported_capture_format,
2636                 (void *)module);
2637
2638         LOGD("ret : 0x%x", ret);
2639
2640         muse_camera_msg_return(api, class, ret, module);
2641
2642         return MUSE_CAMERA_ERROR_NONE;
2643 }
2644
2645 int camera_dispatcher_foreach_supported_preview_format(muse_module_h module)
2646 {
2647         int ret = CAMERA_ERROR_NONE;
2648         muse_camera_handle_s *muse_camera = NULL;
2649         muse_camera_api_e api = MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT;
2650         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
2651
2652         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2653
2654         LOGD("handle : %p", muse_camera);
2655
2656         ret = legacy_camera_foreach_supported_preview_format(muse_camera->camera_handle,
2657                 (camera_supported_preview_format_cb)_camera_dispatcher_callback_supported_preview_format,
2658                 (void *)module);
2659
2660         LOGD("ret : 0x%x", ret);
2661
2662         muse_camera_msg_return(api, class, ret, module);
2663
2664         return MUSE_CAMERA_ERROR_NONE;
2665 }
2666
2667 int camera_dispatcher_get_recommended_preview_resolution(muse_module_h module)
2668 {
2669         int ret = CAMERA_ERROR_NONE;
2670         muse_camera_handle_s *muse_camera = NULL;
2671         int get_width = 0;
2672         int get_height = 0;
2673         int get_value = 0;
2674         muse_camera_api_e api = MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION;
2675         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2676
2677         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2678
2679         LOGD("handle : %p", muse_camera);
2680
2681         ret = legacy_camera_get_recommended_preview_resolution(muse_camera->camera_handle, &get_width, &get_height);
2682         if (ret == CAMERA_ERROR_NONE) {
2683                 get_value = get_width << 16 | get_height;
2684                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2685                         MUSE_CAMERA_GET_INT_RECOMMENDED_PREVIEW_RESOLUTION, "get_value", get_value, NULL);
2686         } else {
2687                 muse_camera_msg_return(api, class, ret, module);
2688         }
2689
2690         return MUSE_CAMERA_ERROR_NONE;
2691 }
2692
2693 int camera_dispatcher_attr_get_lens_orientation(muse_module_h module)
2694 {
2695         int ret = CAMERA_ERROR_NONE;
2696         muse_camera_handle_s *muse_camera = NULL;
2697         int get_value = 0;
2698         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION;
2699         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2700
2701         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2702
2703         LOGD("handle : %p", muse_camera);
2704
2705         ret = legacy_camera_attr_get_lens_orientation(muse_camera->camera_handle, &get_value);
2706         if (ret == CAMERA_ERROR_NONE) {
2707                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2708                         MUSE_CAMERA_GET_INT_LENS_ORIENTATION, "get_value", get_value, NULL);
2709         } else {
2710                 muse_camera_msg_return(api, class, ret, module);
2711         }
2712
2713         return MUSE_CAMERA_ERROR_NONE;
2714 }
2715
2716 int camera_dispatcher_attr_set_theater_mode(muse_module_h module)
2717 {
2718         int ret = CAMERA_ERROR_NONE;
2719         muse_camera_handle_s *muse_camera = NULL;
2720         int set_mode;
2721         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_THEATER_MODE;
2722         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2723
2724         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2725
2726         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
2727
2728         LOGD("handle : %p", muse_camera);
2729
2730         ret = legacy_camera_attr_set_theater_mode(muse_camera->camera_handle, (camera_attr_theater_mode_e)set_mode);
2731
2732         muse_camera_msg_return(api, class, ret, module);
2733
2734         return MUSE_CAMERA_ERROR_NONE;
2735 }
2736
2737 int camera_dispatcher_attr_get_theater_mode(muse_module_h module)
2738 {
2739         int ret = CAMERA_ERROR_NONE;
2740         muse_camera_handle_s *muse_camera = NULL;
2741         camera_attr_theater_mode_e get_value = CAMERA_ATTR_THEATER_MODE_DISABLE;
2742         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_THEATER_MODE;
2743         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2744
2745         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2746
2747         LOGD("handle : %p", muse_camera);
2748
2749         ret = legacy_camera_attr_get_theater_mode(muse_camera->camera_handle, &get_value);
2750         if (ret == CAMERA_ERROR_NONE) {
2751                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2752                         MUSE_CAMERA_GET_INT_THEATER_MODE, "get_value", get_value, NULL);
2753         } else {
2754                 muse_camera_msg_return(api, class, ret, module);
2755         }
2756
2757         return MUSE_CAMERA_ERROR_NONE;
2758 }
2759
2760 int camera_dispatcher_attr_foreach_supported_theater_mode(muse_module_h module)
2761 {
2762         int ret = CAMERA_ERROR_NONE;
2763         muse_camera_handle_s *muse_camera = NULL;
2764         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE;
2765         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
2766
2767         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2768         LOGD("handle : %p", muse_camera);
2769
2770         ret = legacy_camera_attr_foreach_supported_theater_mode(muse_camera->camera_handle,
2771                 (camera_attr_supported_theater_mode_cb)_camera_dispatcher_callback_supported_theater_mode,
2772                 (void *)module);
2773
2774         muse_camera_msg_return(api, class, ret, module);
2775
2776         return MUSE_CAMERA_ERROR_NONE;
2777 }
2778
2779 int camera_dispatcher_attr_set_preview_fps(muse_module_h module)
2780 {
2781         int ret = CAMERA_ERROR_NONE;
2782         muse_camera_handle_s *muse_camera = NULL;
2783         int set_fps;
2784         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS;
2785         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2786
2787         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2788
2789         muse_camera_msg_get(set_fps, muse_core_client_get_msg(module));
2790
2791         LOGD("handle : %p", muse_camera);
2792
2793         ret = legacy_camera_attr_set_preview_fps(muse_camera->camera_handle, (camera_attr_fps_e)set_fps);
2794
2795         muse_camera_msg_return(api, class, ret, module);
2796
2797         return MUSE_CAMERA_ERROR_NONE;
2798 }
2799
2800 int camera_dispatcher_attr_set_image_quality(muse_module_h module)
2801 {
2802         int ret = CAMERA_ERROR_NONE;
2803         muse_camera_handle_s *muse_camera = NULL;
2804         int quality;
2805         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
2806         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2807
2808         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2809
2810         muse_camera_msg_get(quality, muse_core_client_get_msg(module));
2811
2812         LOGD("handle : 0x%x, image_quality : %d", muse_camera, quality);
2813
2814         ret = legacy_camera_attr_set_image_quality(muse_camera->camera_handle, quality);
2815
2816         LOGD("ret : 0x%x", ret);
2817
2818         muse_camera_msg_return(api, class, ret, module);
2819
2820         return MUSE_CAMERA_ERROR_NONE;
2821 }
2822
2823 int camera_dispatcher_attr_get_preview_fps(muse_module_h module)
2824 {
2825         int ret = CAMERA_ERROR_NONE;
2826         muse_camera_handle_s *muse_camera = NULL;
2827         camera_attr_fps_e get_value = CAMERA_ATTR_FPS_AUTO;
2828         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS;
2829         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2830
2831         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2832
2833         LOGD("handle : %p", muse_camera);
2834
2835         ret = legacy_camera_attr_get_preview_fps(muse_camera->camera_handle, &get_value);
2836         if (ret == CAMERA_ERROR_NONE) {
2837                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2838                         MUSE_CAMERA_GET_INT_PREVIEW_FPS, "get_value", get_value, NULL);
2839         } else {
2840                 muse_camera_msg_return(api, class, ret, module);
2841         }
2842
2843         return MUSE_CAMERA_ERROR_NONE;
2844 }
2845
2846 int camera_dispatcher_attr_get_image_quality(muse_module_h module)
2847 {
2848         int ret = CAMERA_ERROR_NONE;
2849         muse_camera_handle_s *muse_camera = NULL;
2850         int get_value = 0;
2851         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY;
2852         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2853
2854         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2855
2856         LOGD("handle : %p", muse_camera);
2857
2858         ret = legacy_camera_attr_get_image_quality(muse_camera->camera_handle, &get_value);
2859         if (ret == CAMERA_ERROR_NONE) {
2860                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
2861                         MUSE_CAMERA_GET_INT_IMAGE_QUALITY, "get_value", get_value, NULL);
2862         } else {
2863                 muse_camera_msg_return(api, class, ret, module);
2864         }
2865
2866         return MUSE_CAMERA_ERROR_NONE;
2867 }
2868
2869 int camera_dispatcher_attr_set_zoom(muse_module_h module)
2870 {
2871         int ret = CAMERA_ERROR_NONE;
2872         muse_camera_handle_s *muse_camera = NULL;
2873         int zoom;
2874         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
2875         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2876
2877         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2878
2879         muse_camera_msg_get(zoom, muse_core_client_get_msg(module));
2880
2881         LOGD("handle : 0x%x, zoom : %d", muse_camera, zoom);
2882
2883         ret = legacy_camera_attr_set_zoom(muse_camera->camera_handle, zoom);
2884
2885         LOGD("ret : 0x%x", ret);
2886
2887         muse_camera_msg_return(api, class, ret, module);
2888
2889         return MUSE_CAMERA_ERROR_NONE;
2890 }
2891
2892 int camera_dispatcher_attr_set_af_mode(muse_module_h module)
2893 {
2894         int ret = CAMERA_ERROR_NONE;
2895         muse_camera_handle_s *muse_camera = NULL;
2896         int set_mode;
2897         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_MODE;
2898         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2899
2900         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2901
2902         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
2903
2904         LOGD("handle : 0x%x, set_mode : %d", muse_camera, set_mode);
2905
2906         ret = legacy_camera_attr_set_af_mode(muse_camera->camera_handle, (camera_attr_af_mode_e)set_mode);
2907
2908         LOGD("ret : 0x%x", ret);
2909
2910         muse_camera_msg_return(api, class, ret, module);
2911
2912         return MUSE_CAMERA_ERROR_NONE;
2913 }
2914
2915 int camera_dispatcher_attr_set_af_area(muse_module_h module)
2916 {
2917         int ret = CAMERA_ERROR_NONE;
2918         muse_camera_handle_s *muse_camera = NULL;
2919         int value = 0;
2920         int x = 0;
2921         int y = 0;
2922         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_AREA;
2923         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2924
2925         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2926
2927         muse_camera_msg_get(value, muse_core_client_get_msg(module));
2928
2929         x = value >> 16;
2930         y = 0x0000ffff & value;
2931
2932         LOGD("AF area - %d, %d", x, y);
2933
2934         ret = legacy_camera_attr_set_af_area(muse_camera->camera_handle, x, y);
2935
2936         LOGD("ret : 0x%x", ret);
2937
2938         muse_camera_msg_return(api, class, ret, module);
2939
2940         return MUSE_CAMERA_ERROR_NONE;
2941 }
2942
2943 int camera_dispatcher_attr_clear_af_area(muse_module_h module)
2944 {
2945         int ret = CAMERA_ERROR_NONE;
2946         muse_camera_handle_s *muse_camera = NULL;
2947         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
2948         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2949
2950         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2951
2952         LOGD("handle : %p", muse_camera);
2953
2954         ret = legacy_camera_attr_clear_af_area(muse_camera->camera_handle);
2955
2956         LOGD("ret : 0x%x", ret);
2957
2958         muse_camera_msg_return(api, class, ret, module);
2959
2960         return MUSE_CAMERA_ERROR_NONE;
2961 }
2962
2963 int camera_dispatcher_attr_set_exposure_mode(muse_module_h module)
2964 {
2965         int ret = CAMERA_ERROR_NONE;
2966         muse_camera_handle_s *muse_camera = NULL;
2967         int set_mode;
2968         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE;
2969         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2970
2971         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2972
2973         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
2974
2975         LOGD("handle : 0x%x, set_mode : %d", muse_camera, set_mode);
2976
2977         ret = legacy_camera_attr_set_exposure_mode(muse_camera->camera_handle, (camera_attr_exposure_mode_e)set_mode);
2978
2979         LOGD("ret : 0x%x", ret);
2980
2981         muse_camera_msg_return(api, class, ret, module);
2982
2983         return MUSE_CAMERA_ERROR_NONE;
2984 }
2985
2986 int camera_dispatcher_attr_set_exposure(muse_module_h module)
2987 {
2988         int ret = CAMERA_ERROR_NONE;
2989         muse_camera_handle_s *muse_camera = NULL;
2990         int value;
2991         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
2992         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
2993
2994         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
2995
2996         muse_camera_msg_get(value, muse_core_client_get_msg(module));
2997
2998         LOGD("handle : 0x%x, value : %d", muse_camera, value);
2999
3000         ret = legacy_camera_attr_set_exposure(muse_camera->camera_handle, value);
3001
3002         LOGD("ret : 0x%x", ret);
3003
3004         muse_camera_msg_return(api, class, ret, module);
3005
3006         return MUSE_CAMERA_ERROR_NONE;
3007 }
3008
3009 int camera_dispatcher_attr_set_iso(muse_module_h module)
3010 {
3011         int ret = CAMERA_ERROR_NONE;
3012         muse_camera_handle_s *muse_camera = NULL;
3013         int set_iso;
3014         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ISO;
3015         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3016
3017         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3018
3019         muse_camera_msg_get(set_iso, muse_core_client_get_msg(module));
3020
3021         LOGD("handle : 0x%x, set_iso : %d", muse_camera, set_iso);
3022
3023         ret = legacy_camera_attr_set_iso(muse_camera->camera_handle, (camera_attr_iso_e)set_iso);
3024
3025         LOGD("ret : 0x%x", ret);
3026
3027         muse_camera_msg_return(api, class, ret, module);
3028
3029         return MUSE_CAMERA_ERROR_NONE;
3030 }
3031
3032 int camera_dispatcher_attr_set_brightness(muse_module_h module)
3033 {
3034         int ret = CAMERA_ERROR_NONE;
3035         muse_camera_handle_s *muse_camera = NULL;
3036         int level;
3037         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
3038         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3039
3040         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3041
3042         muse_camera_msg_get(level, muse_core_client_get_msg(module));
3043
3044         LOGD("handle : 0x%x, level : %d", muse_camera, level);
3045
3046         ret = legacy_camera_attr_set_brightness(muse_camera->camera_handle, level);
3047
3048         LOGD("ret : 0x%x", ret);
3049
3050         muse_camera_msg_return(api, class, ret, module);
3051
3052         return MUSE_CAMERA_ERROR_NONE;
3053 }
3054
3055 int camera_dispatcher_attr_set_contrast(muse_module_h module)
3056 {
3057         int ret = CAMERA_ERROR_NONE;
3058         muse_camera_handle_s *muse_camera = NULL;
3059         int level;
3060         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
3061         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3062
3063         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3064
3065         muse_camera_msg_get(level, muse_core_client_get_msg(module));
3066
3067         LOGD("handle : 0x%x, level : %d", muse_camera, level);
3068
3069         ret = legacy_camera_attr_set_contrast(muse_camera->camera_handle, level);
3070
3071         LOGD("ret : 0x%x", ret);
3072
3073         muse_camera_msg_return(api, class, ret, module);
3074
3075         return MUSE_CAMERA_ERROR_NONE;
3076 }
3077
3078 int camera_dispatcher_attr_set_whitebalance(muse_module_h module)
3079 {
3080         int ret = CAMERA_ERROR_NONE;
3081         muse_camera_handle_s *muse_camera = NULL;
3082         int set_whitebalance;
3083         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
3084         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3085
3086         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3087
3088         muse_camera_msg_get(set_whitebalance, muse_core_client_get_msg(module));
3089
3090         LOGD("handle : 0x%x, set_whitebalance : %d", muse_camera, set_whitebalance);
3091
3092         ret = legacy_camera_attr_set_whitebalance(muse_camera->camera_handle, (camera_attr_whitebalance_e)set_whitebalance);
3093
3094         LOGD("ret : 0x%x", ret);
3095
3096         muse_camera_msg_return(api, class, ret, module);
3097
3098         return MUSE_CAMERA_ERROR_NONE;
3099 }
3100
3101 int camera_dispatcher_attr_set_effect(muse_module_h module)
3102 {
3103         int ret = CAMERA_ERROR_NONE;
3104         muse_camera_handle_s *muse_camera = NULL;
3105         int set_effect;
3106         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EFFECT;
3107         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3108
3109         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3110
3111         muse_camera_msg_get(set_effect, muse_core_client_get_msg(module));
3112
3113         LOGD("handle : 0x%x, set_effect : %d", muse_camera, set_effect);
3114
3115         ret = legacy_camera_attr_set_effect(muse_camera->camera_handle, (camera_attr_effect_mode_e)set_effect);
3116
3117         LOGD("ret : 0x%x", ret);
3118
3119         muse_camera_msg_return(api, class, ret, module);
3120
3121         return MUSE_CAMERA_ERROR_NONE;
3122 }
3123
3124 int camera_dispatcher_attr_set_scene_mode(muse_module_h module)
3125 {
3126         int ret = CAMERA_ERROR_NONE;
3127         muse_camera_handle_s *muse_camera = NULL;
3128         int set_mode;
3129         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_SCENE_MODE;
3130         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3131
3132         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3133
3134         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
3135
3136         LOGD("handle : 0x%x, set_mode : %d", muse_camera, set_mode);
3137
3138         ret = legacy_camera_attr_set_scene_mode(muse_camera->camera_handle, (camera_attr_scene_mode_e)set_mode);
3139
3140         LOGD("ret : 0x%x", ret);
3141
3142         muse_camera_msg_return(api, class, ret, module);
3143
3144         return MUSE_CAMERA_ERROR_NONE;
3145 }
3146
3147 int camera_dispatcher_attr_enable_tag(muse_module_h module)
3148 {
3149         int ret = CAMERA_ERROR_NONE;
3150         muse_camera_handle_s *muse_camera = NULL;
3151         int set_enable;
3152         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_TAG;
3153         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3154
3155         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3156
3157         muse_camera_msg_get(set_enable, muse_core_client_get_msg(module));
3158
3159         LOGD("handle : 0x%x, set_enable : %d", muse_camera, set_enable);
3160
3161         ret = legacy_camera_attr_enable_tag(muse_camera->camera_handle, (bool)set_enable);
3162
3163         LOGD("ret : 0x%x", ret);
3164
3165         muse_camera_msg_return(api, class, ret, module);
3166
3167         return MUSE_CAMERA_ERROR_NONE;
3168 }
3169
3170 int camera_dispatcher_attr_set_tag_image_description(muse_module_h module)
3171 {
3172         int ret = CAMERA_ERROR_NONE;
3173         muse_camera_handle_s *muse_camera = NULL;
3174         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION;
3175         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3176         char description[MUSE_CAMERA_MSG_MAX_LENGTH] = {0,};
3177
3178         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3179
3180         muse_camera_msg_get_string(description, muse_core_client_get_msg(module));
3181
3182         LOGD("handle : 0x%x, description : %s", muse_camera, description);
3183
3184         ret = legacy_camera_attr_set_tag_image_description(muse_camera->camera_handle, description);
3185
3186         LOGD("ret : 0x%x", ret);
3187
3188         muse_camera_msg_return(api, class, ret, module);
3189
3190         return MUSE_CAMERA_ERROR_NONE;
3191 }
3192
3193 int camera_dispatcher_attr_set_tag_orientation(muse_module_h module)
3194 {
3195         int ret = CAMERA_ERROR_NONE;
3196         muse_camera_handle_s *muse_camera = NULL;
3197         int set_orientation;
3198         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION;
3199         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3200
3201         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3202
3203         muse_camera_msg_get(set_orientation, muse_core_client_get_msg(module));
3204
3205         LOGD("handle : 0x%x, set_orientation : %d", muse_camera, set_orientation);
3206
3207         ret = legacy_camera_attr_set_tag_orientation(muse_camera->camera_handle, (camera_attr_tag_orientation_e)set_orientation);
3208
3209         LOGD("ret : 0x%x", ret);
3210
3211         muse_camera_msg_return(api, class, ret, module);
3212
3213         return MUSE_CAMERA_ERROR_NONE;
3214 }
3215
3216 int camera_dispatcher_attr_set_tag_software(muse_module_h module)
3217 {
3218         int ret = CAMERA_ERROR_NONE;
3219         muse_camera_handle_s *muse_camera = NULL;
3220         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE;
3221         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3222         char software[MUSE_CAMERA_MSG_MAX_LENGTH] = {0,};
3223
3224         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3225
3226         muse_camera_msg_get_string(software, muse_core_client_get_msg(module));
3227
3228         LOGD("handle : 0x%x, software : %s", muse_camera, software);
3229
3230         ret = legacy_camera_attr_set_tag_software(muse_camera->camera_handle, software);
3231
3232         LOGD("ret : 0x%x", ret);
3233
3234         muse_camera_msg_return(api, class, ret, module);
3235
3236         return MUSE_CAMERA_ERROR_NONE;
3237 }
3238
3239 int camera_dispatcher_attr_set_geotag(muse_module_h module)
3240 {
3241         int ret = CAMERA_ERROR_NONE;
3242         muse_camera_handle_s *muse_camera = NULL;
3243         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_GEOTAG;
3244         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3245         double set_geotag[3] = {0,};
3246
3247         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3248
3249         muse_camera_msg_get_array(set_geotag, muse_core_client_get_msg(module));
3250
3251         LOGD("handle : 0x%x, set_geotag1 : %d, set_geotag2 : %d, set_geotag3 : %d",
3252              muse_camera, set_geotag[0], set_geotag[1], set_geotag[2]);
3253
3254         ret = legacy_camera_attr_set_geotag(muse_camera->camera_handle, set_geotag[0], set_geotag[1], set_geotag[2]);
3255
3256         LOGD("ret : 0x%x", ret);
3257
3258         muse_camera_msg_return(api, class, ret, module);
3259
3260         return MUSE_CAMERA_ERROR_NONE;
3261 }
3262
3263 int camera_dispatcher_attr_remove_geotag(muse_module_h module)
3264 {
3265         int ret = CAMERA_ERROR_NONE;
3266         muse_camera_handle_s *muse_camera = NULL;
3267         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
3268         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3269
3270         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3271
3272         LOGD("handle : %p", muse_camera);
3273
3274         ret = legacy_camera_attr_remove_geotag(muse_camera->camera_handle);
3275
3276         LOGD("ret : 0x%x", ret);
3277
3278         muse_camera_msg_return(api, class, ret, module);
3279
3280         return MUSE_CAMERA_ERROR_NONE;
3281 }
3282
3283 int camera_dispatcher_attr_set_flash_mode(muse_module_h module)
3284 {
3285         int ret = CAMERA_ERROR_NONE;
3286         int set_mode = 0;;
3287         char value_key[KEY_LENGTH] = {'\0',};
3288         muse_camera_handle_s *muse_camera = NULL;
3289         camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
3290         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
3291         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3292
3293         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3294
3295         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
3296
3297         LOGD("handle : 0x%x, set_mode : %d", muse_camera, set_mode);
3298
3299         ret = legacy_camera_attr_set_flash_mode(muse_camera->camera_handle, (camera_attr_flash_mode_e)set_mode);
3300         if (ret == CAMERA_ERROR_NONE) {
3301                 ret = legacy_camera_get_device_type(muse_camera->camera_handle, &device_type);
3302                 if (ret == CAMERA_ERROR_NONE) {
3303                         snprintf(value_key, KEY_LENGTH, "flash_state_camera%d", device_type);
3304                         muse_core_client_set_value(module, value_key, set_mode > 0 ? 1 : 0);
3305                 }
3306         }
3307
3308         LOGD("ret : 0x%x", ret);
3309
3310         muse_camera_msg_return(api, class, ret, module);
3311
3312         return MUSE_CAMERA_ERROR_NONE;
3313 }
3314
3315 int camera_dispatcher_attr_get_zoom(muse_module_h module)
3316 {
3317         int ret = CAMERA_ERROR_NONE;
3318         muse_camera_handle_s *muse_camera = NULL;
3319         int get_value = 0;
3320         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM;
3321         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3322
3323         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3324
3325         LOGD("handle : %p", muse_camera);
3326
3327         ret = legacy_camera_attr_get_zoom(muse_camera->camera_handle, &get_value);
3328         if (ret == CAMERA_ERROR_NONE) {
3329                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3330                         MUSE_CAMERA_GET_INT_ZOOM, "get_value", get_value, NULL);
3331         } else {
3332                 muse_camera_msg_return(api, class, ret, module);
3333         }
3334
3335         return MUSE_CAMERA_ERROR_NONE;
3336 }
3337
3338 int camera_dispatcher_attr_get_zoom_range(muse_module_h module)
3339 {
3340         int ret = CAMERA_ERROR_NONE;
3341         muse_camera_handle_s *muse_camera = NULL;
3342         int get_value0 = 0;
3343         int get_value1 = 0;
3344         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
3345         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3346         muse_camera_get_type_e get_type = MUSE_CAMERA_GET_TYPE_INT_PAIR;
3347         muse_camera_get_int_pair_e index = MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE;
3348
3349         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3350
3351         LOGD("handle : %p", muse_camera);
3352
3353         ret = legacy_camera_attr_get_zoom_range(muse_camera->camera_handle, &get_value0, &get_value1);
3354         if (ret == CAMERA_ERROR_NONE)
3355                 muse_camera_msg_return2(api, class, ret, module, get_type, index, get_value0, get_value1);
3356         else
3357                 muse_camera_msg_return(api, class, ret, module);
3358
3359         return MUSE_CAMERA_ERROR_NONE;
3360 }
3361
3362 int camera_dispatcher_attr_get_af_mode(muse_module_h module)
3363 {
3364         int ret = CAMERA_ERROR_NONE;
3365         muse_camera_handle_s *muse_camera = NULL;
3366         camera_attr_af_mode_e get_value = CAMERA_ATTR_AF_NONE;
3367         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_AF_MODE;
3368         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3369
3370         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3371
3372         LOGD("handle : %p", muse_camera);
3373
3374         ret = legacy_camera_attr_get_af_mode(muse_camera->camera_handle, &get_value);
3375         if (ret == CAMERA_ERROR_NONE) {
3376                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3377                         MUSE_CAMERA_GET_INT_AF_MODE, "get_value", get_value, NULL);
3378         } else {
3379                 muse_camera_msg_return(api, class, ret, module);
3380         }
3381
3382         return MUSE_CAMERA_ERROR_NONE;
3383 }
3384
3385 int camera_dispatcher_attr_get_exposure_mode(muse_module_h module)
3386 {
3387         int ret = CAMERA_ERROR_NONE;
3388         muse_camera_handle_s *muse_camera = NULL;
3389         camera_attr_exposure_mode_e get_value = CAMERA_ATTR_EXPOSURE_MODE_OFF;
3390         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE;
3391         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3392
3393         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3394
3395         LOGD("handle : %p", muse_camera);
3396
3397         ret = legacy_camera_attr_get_exposure_mode(muse_camera->camera_handle, &get_value);
3398         if (ret == CAMERA_ERROR_NONE) {
3399                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3400                         MUSE_CAMERA_GET_INT_EXPOSURE_MODE, "get_value", get_value, NULL);
3401         } else {
3402                 muse_camera_msg_return(api, class, ret, module);
3403         }
3404
3405         return MUSE_CAMERA_ERROR_NONE;
3406 }
3407
3408 int camera_dispatcher_attr_get_exposure(muse_module_h module)
3409 {
3410         int ret = CAMERA_ERROR_NONE;
3411         muse_camera_handle_s *muse_camera = NULL;
3412         int get_value = 0;
3413         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE;
3414         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3415
3416         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3417
3418         LOGD("handle : %p", muse_camera);
3419
3420         ret = legacy_camera_attr_get_exposure(muse_camera->camera_handle, &get_value);
3421         if (ret == CAMERA_ERROR_NONE) {
3422                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3423                         MUSE_CAMERA_GET_INT_EXPOSURE, "get_value", get_value, NULL);
3424         } else {
3425                 muse_camera_msg_return(api, class, ret, module);
3426         }
3427
3428         return MUSE_CAMERA_ERROR_NONE;
3429 }
3430
3431 int camera_dispatcher_attr_get_exposure_range(muse_module_h module)
3432 {
3433         int ret = CAMERA_ERROR_NONE;
3434         muse_camera_handle_s *muse_camera = NULL;
3435         int get_value0 = 0;
3436         int get_value1 = 0;
3437         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
3438         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3439         muse_camera_get_type_e get_type = MUSE_CAMERA_GET_TYPE_INT_PAIR;
3440         muse_camera_get_int_pair_e index = MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE;
3441
3442         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3443
3444         LOGD("handle : %p", muse_camera);
3445
3446         ret = legacy_camera_attr_get_exposure_range(muse_camera->camera_handle, &get_value0, &get_value1);
3447         if (ret == CAMERA_ERROR_NONE)
3448                 muse_camera_msg_return2(api, class, ret, module, get_type, index, get_value0, get_value1);
3449         else
3450                 muse_camera_msg_return(api, class, ret, module);
3451
3452         return MUSE_CAMERA_ERROR_NONE;
3453 }
3454
3455 int camera_dispatcher_attr_get_iso(muse_module_h module)
3456 {
3457         int ret = CAMERA_ERROR_NONE;
3458         muse_camera_handle_s *muse_camera = NULL;
3459         camera_attr_iso_e get_value = CAMERA_ATTR_ISO_AUTO;
3460         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ISO;
3461         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3462
3463         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3464
3465         LOGD("handle : %p", muse_camera);
3466
3467         ret = legacy_camera_attr_get_iso(muse_camera->camera_handle, &get_value);
3468         if (ret == CAMERA_ERROR_NONE) {
3469                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3470                         MUSE_CAMERA_GET_INT_ISO, "get_value", get_value, NULL);
3471         } else {
3472                 muse_camera_msg_return(api, class, ret, module);
3473         }
3474
3475         return MUSE_CAMERA_ERROR_NONE;
3476 }
3477
3478 int camera_dispatcher_attr_get_brightness(muse_module_h module)
3479 {
3480         int ret = CAMERA_ERROR_NONE;
3481         muse_camera_handle_s *muse_camera = NULL;
3482         int get_value = 0;
3483         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
3484         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3485
3486         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3487
3488         LOGD("handle : %p", muse_camera);
3489
3490         ret = legacy_camera_attr_get_brightness(muse_camera->camera_handle, &get_value);
3491         if (ret == CAMERA_ERROR_NONE) {
3492                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3493                         MUSE_CAMERA_GET_INT_BRIGHTNESS, "get_value", get_value, NULL);
3494         } else {
3495                 muse_camera_msg_return(api, class, ret, module);
3496         }
3497
3498         return MUSE_CAMERA_ERROR_NONE;
3499 }
3500
3501 int camera_dispatcher_attr_get_brightness_range(muse_module_h module)
3502 {
3503         int ret = CAMERA_ERROR_NONE;
3504         muse_camera_handle_s *muse_camera = NULL;
3505         int get_value0 = 0;
3506         int get_value1 = 0;
3507         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
3508         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3509         muse_camera_get_type_e get_type = MUSE_CAMERA_GET_TYPE_INT_PAIR;
3510         muse_camera_get_int_pair_e index = MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE;
3511
3512         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3513
3514         LOGD("handle : %p", muse_camera);
3515
3516         ret = legacy_camera_attr_get_brightness_range(muse_camera->camera_handle, &get_value0, &get_value1);
3517         if (ret == CAMERA_ERROR_NONE)
3518                 muse_camera_msg_return2(api, class, ret, module, get_type, index, get_value0, get_value1);
3519         else
3520                 muse_camera_msg_return(api, class, ret, module);
3521
3522         return MUSE_CAMERA_ERROR_NONE;
3523 }
3524
3525 int camera_dispatcher_attr_get_contrast(muse_module_h module)
3526 {
3527         int ret = CAMERA_ERROR_NONE;
3528         muse_camera_handle_s *muse_camera = NULL;
3529         int get_value = 0;
3530         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
3531         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3532
3533         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3534
3535         LOGD("handle : %p", muse_camera);
3536
3537         ret = legacy_camera_attr_get_contrast(muse_camera->camera_handle, &get_value);
3538         if (ret == CAMERA_ERROR_NONE) {
3539                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3540                         MUSE_CAMERA_GET_INT_CONTRAST, "get_value", get_value, NULL);
3541         } else {
3542                 muse_camera_msg_return(api, class, ret, module);
3543         }
3544
3545         return MUSE_CAMERA_ERROR_NONE;
3546 }
3547
3548 int camera_dispatcher_attr_get_contrast_range(muse_module_h module)
3549 {
3550         int ret = CAMERA_ERROR_NONE;
3551         muse_camera_handle_s *muse_camera = NULL;
3552         int get_value0 = 0;
3553         int get_value1 = 0;
3554         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
3555         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3556         muse_camera_get_type_e get_type = MUSE_CAMERA_GET_TYPE_INT_PAIR;
3557         muse_camera_get_int_pair_e index = MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE;
3558
3559         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3560
3561         LOGD("handle : %p", muse_camera);
3562
3563         ret = legacy_camera_attr_get_contrast_range(muse_camera->camera_handle, &get_value0, &get_value1);
3564         if (ret == CAMERA_ERROR_NONE)
3565                 muse_camera_msg_return2(api, class, ret, module, get_type, index, get_value0, get_value1);
3566         else
3567                 muse_camera_msg_return(api, class, ret, module);
3568
3569         return MUSE_CAMERA_ERROR_NONE;
3570 }
3571
3572 int camera_dispatcher_attr_get_whitebalance(muse_module_h module)
3573 {
3574         int ret = CAMERA_ERROR_NONE;
3575         muse_camera_handle_s *muse_camera = NULL;
3576         camera_attr_whitebalance_e get_value = CAMERA_ATTR_WHITE_BALANCE_NONE;
3577         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
3578         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3579
3580         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3581
3582         LOGD("handle : %p", muse_camera);
3583
3584         ret = legacy_camera_attr_get_whitebalance(muse_camera->camera_handle, &get_value);
3585         if (ret == CAMERA_ERROR_NONE) {
3586                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3587                         MUSE_CAMERA_GET_INT_WHITE_BALANCE, "get_value", get_value, NULL);
3588         } else {
3589                 muse_camera_msg_return(api, class, ret, module);
3590         }
3591
3592         return MUSE_CAMERA_ERROR_NONE;
3593 }
3594
3595 int camera_dispatcher_attr_get_effect(muse_module_h module)
3596 {
3597         int ret = CAMERA_ERROR_NONE;
3598         muse_camera_handle_s *muse_camera = NULL;
3599         camera_attr_effect_mode_e get_value = CAMERA_ATTR_EFFECT_NONE;
3600         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EFFECT;
3601         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3602
3603         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3604
3605         LOGD("handle : %p", muse_camera);
3606
3607         ret = legacy_camera_attr_get_effect(muse_camera->camera_handle, &get_value);
3608         if (ret == CAMERA_ERROR_NONE) {
3609                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3610                         MUSE_CAMERA_GET_INT_EFFECT, "get_value", get_value, NULL);
3611         } else {
3612                 muse_camera_msg_return(api, class, ret, module);
3613         }
3614
3615         return MUSE_CAMERA_ERROR_NONE;
3616 }
3617
3618 int camera_dispatcher_attr_get_scene_mode(muse_module_h module)
3619 {
3620         int ret = CAMERA_ERROR_NONE;
3621         muse_camera_handle_s *muse_camera = NULL;
3622         camera_attr_scene_mode_e get_value = CAMERA_ATTR_SCENE_MODE_NORMAL;
3623         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_SCENE_MODE;
3624         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3625
3626         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3627
3628         LOGD("handle : %p", muse_camera);
3629
3630         ret = legacy_camera_attr_get_scene_mode(muse_camera->camera_handle, &get_value);
3631         if (ret == CAMERA_ERROR_NONE) {
3632                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3633                         MUSE_CAMERA_GET_INT_SCENE_MODE, "get_value", get_value, NULL);
3634         } else {
3635                 muse_camera_msg_return(api, class, ret, module);
3636         }
3637
3638         return MUSE_CAMERA_ERROR_NONE;
3639 }
3640
3641 int camera_dispatcher_attr_is_enabled_tag(muse_module_h module)
3642 {
3643         int ret = CAMERA_ERROR_NONE;
3644         muse_camera_handle_s *muse_camera = NULL;
3645         bool get_value = false;
3646         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG;
3647         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3648
3649         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3650
3651         LOGD("handle : %p", muse_camera);
3652
3653         ret = legacy_camera_attr_is_enabled_tag(muse_camera->camera_handle, &get_value);
3654         if (ret == CAMERA_ERROR_NONE) {
3655                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3656                         MUSE_CAMERA_GET_INT_ENABLED_TAG, "get_value", get_value, NULL);
3657         } else {
3658                 muse_camera_msg_return(api, class, ret, module);
3659         }
3660
3661         return MUSE_CAMERA_ERROR_NONE;
3662 }
3663
3664 int camera_dispatcher_attr_get_tag_image_description(muse_module_h module)
3665 {
3666         int ret = CAMERA_ERROR_NONE;
3667         muse_camera_handle_s *muse_camera = NULL;
3668         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION;
3669         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3670         char *get_value = NULL;
3671
3672         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3673
3674         ret = legacy_camera_attr_get_tag_image_description(muse_camera->camera_handle, &get_value);
3675         if (ret == CAMERA_ERROR_NONE) {
3676                 LOGD("get_description : %s", muse_camera, get_value);
3677                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_STRING,
3678                         MUSE_CAMERA_GET_STRING_TAG_IMAGE_DESCRIPTION, "get_value", 0, get_value);
3679         } else {
3680                 muse_camera_msg_return(api, class, ret, module);
3681         }
3682
3683         if (get_value) {
3684                 free(get_value);
3685                 get_value = NULL;
3686         }
3687
3688         return MUSE_CAMERA_ERROR_NONE;
3689 }
3690
3691 int camera_dispatcher_attr_get_tag_orientation(muse_module_h module)
3692 {
3693         int ret = CAMERA_ERROR_NONE;
3694         muse_camera_handle_s *muse_camera = NULL;
3695         camera_attr_tag_orientation_e get_value = CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT;
3696         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION;
3697         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3698
3699         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3700
3701         LOGD("handle : %p", muse_camera);
3702
3703         ret = legacy_camera_attr_get_tag_orientation(muse_camera->camera_handle, &get_value);
3704         if (ret == CAMERA_ERROR_NONE) {
3705                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3706                         MUSE_CAMERA_GET_INT_TAG_ORIENTATION, "get_value", get_value, NULL);
3707         } else {
3708                 muse_camera_msg_return(api, class, ret, module);
3709         }
3710
3711         return MUSE_CAMERA_ERROR_NONE;
3712 }
3713
3714 int camera_dispatcher_attr_get_tag_software(muse_module_h module)
3715 {
3716         int ret = CAMERA_ERROR_NONE;
3717         muse_camera_handle_s *muse_camera = NULL;
3718         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE;
3719         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3720         char *get_value = NULL;
3721
3722         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3723
3724         ret = legacy_camera_attr_get_tag_software(muse_camera->camera_handle, &get_value);
3725         if (ret == CAMERA_ERROR_NONE) {
3726                 LOGD("get_software : %s", get_value);
3727                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_STRING,
3728                         MUSE_CAMERA_GET_STRING_TAG_SOFTWARE, "get_value", 0, get_value);
3729         } else {
3730                 muse_camera_msg_return(api, class, ret, module);
3731         }
3732
3733         if (get_value) {
3734                 free(get_value);
3735                 get_value = NULL;
3736         }
3737
3738         return MUSE_CAMERA_ERROR_NONE;
3739 }
3740
3741 int camera_dispatcher_attr_get_geotag(muse_module_h module)
3742 {
3743         int ret = CAMERA_ERROR_NONE;
3744         muse_camera_handle_s *muse_camera = NULL;
3745         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GEOTAG;
3746         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3747         double get_value[3] = {0.0, 0.0, 0.0};
3748         char *send_msg = NULL;
3749         int msg_array_size = 0;
3750
3751         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3752
3753         LOGD("handle : %p", muse_camera);
3754
3755         ret = legacy_camera_attr_get_geotag(muse_camera->camera_handle, &get_value[0], &get_value[1], &get_value[2]);
3756         if (ret == CAMERA_ERROR_NONE) {
3757                 msg_array_size = sizeof(get_value) / sizeof(int) + (sizeof(get_value) % sizeof(int) ? 1 : 0);
3758
3759                 send_msg = muse_core_msg_json_factory_new(api,
3760                         MUSE_TYPE_INT, PARAM_API_CLASS, class,
3761                         MUSE_TYPE_INT, PARAM_RET, ret,
3762                         MUSE_TYPE_INT, PARAM_GET_TYPE, MUSE_CAMERA_GET_TYPE_ARRAY,
3763                         MUSE_TYPE_ARRAY, "get_value", msg_array_size, get_value,
3764                         0);
3765
3766                 __camera_dispatcher_send_msg(module, send_msg);
3767         } else {
3768                 muse_camera_msg_return(api, class, ret, module);
3769         }
3770
3771         return MUSE_CAMERA_ERROR_NONE;
3772 }
3773
3774 int camera_dispatcher_attr_get_flash_mode(muse_module_h module)
3775 {
3776         int ret = CAMERA_ERROR_NONE;
3777         muse_camera_handle_s *muse_camera = NULL;
3778         camera_attr_flash_mode_e get_value = CAMERA_ATTR_FLASH_MODE_OFF;
3779         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_MODE;
3780         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
3781
3782         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3783
3784         LOGD("handle : %p", muse_camera);
3785
3786         ret = legacy_camera_attr_get_flash_mode(muse_camera->camera_handle, &get_value);
3787         if (ret == CAMERA_ERROR_NONE) {
3788                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
3789                         MUSE_CAMERA_GET_INT_FLASH_MODE, "get_value", get_value, NULL);
3790         } else {
3791                 muse_camera_msg_return(api, class, ret, module);
3792         }
3793
3794         return MUSE_CAMERA_ERROR_NONE;
3795 }
3796
3797 int camera_dispatcher_attr_foreach_supported_af_mode(muse_module_h module)
3798 {
3799         int ret = CAMERA_ERROR_NONE;
3800         muse_camera_handle_s *muse_camera = NULL;
3801         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE;
3802         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3803
3804         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3805
3806         LOGD("handle : %p", muse_camera);
3807
3808         ret = legacy_camera_attr_foreach_supported_af_mode(muse_camera->camera_handle,
3809                 (camera_attr_supported_af_mode_cb)_camera_dispatcher_callback_supported_af_mode,
3810                 (void *)module);
3811
3812         LOGD("ret : 0x%x", ret);
3813
3814         muse_camera_msg_return(api, class, ret, module);
3815
3816         return MUSE_CAMERA_ERROR_NONE;
3817 }
3818
3819 int camera_dispatcher_attr_foreach_supported_exposure_mode(muse_module_h module)
3820 {
3821         int ret = CAMERA_ERROR_NONE;
3822         muse_camera_handle_s *muse_camera = NULL;
3823         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE;
3824         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3825
3826         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3827
3828         LOGD("handle : 0x%x, api : %d", muse_camera, api);
3829
3830         ret = legacy_camera_attr_foreach_supported_exposure_mode(muse_camera->camera_handle,
3831                 (camera_attr_supported_exposure_mode_cb)_camera_dispatcher_callback_supported_exposure_mode,
3832                 (void *)module);
3833
3834         LOGD("ret : 0x%x", ret);
3835
3836         muse_camera_msg_return(api, class, ret, module);
3837
3838         return MUSE_CAMERA_ERROR_NONE;
3839 }
3840
3841 int camera_dispatcher_attr_foreach_supported_iso(muse_module_h module)
3842 {
3843         int ret = CAMERA_ERROR_NONE;
3844         muse_camera_handle_s *muse_camera = NULL;
3845         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO;
3846         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3847
3848         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3849
3850         LOGD("handle : %p", muse_camera);
3851
3852         ret = legacy_camera_attr_foreach_supported_iso(muse_camera->camera_handle,
3853                 (camera_attr_supported_iso_cb)_camera_dispatcher_callback_supported_iso_mode,
3854                 (void *)module);
3855
3856         LOGD("ret : 0x%x", ret);
3857
3858         muse_camera_msg_return(api, class, ret, module);
3859
3860         return MUSE_CAMERA_ERROR_NONE;
3861 }
3862
3863 int camera_dispatcher_attr_foreach_supported_whitebalance(muse_module_h module)
3864 {
3865         int ret = CAMERA_ERROR_NONE;
3866         muse_camera_handle_s *muse_camera = NULL;
3867         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE;
3868         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3869
3870         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3871
3872         LOGD("handle : %p", muse_camera);
3873
3874         ret = legacy_camera_attr_foreach_supported_whitebalance(muse_camera->camera_handle,
3875                 (camera_attr_supported_whitebalance_cb)_camera_dispatcher_callback_supported_whitebalance,
3876                 (void *)module);
3877
3878         LOGD("ret : 0x%x", ret);
3879
3880         muse_camera_msg_return(api, class, ret, module);
3881
3882         return MUSE_CAMERA_ERROR_NONE;
3883 }
3884
3885 int camera_dispatcher_attr_foreach_supported_effect(muse_module_h module)
3886 {
3887         int ret = CAMERA_ERROR_NONE;
3888         muse_camera_handle_s *muse_camera = NULL;
3889         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT;
3890         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3891
3892         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3893
3894         LOGD("handle : %p", muse_camera);
3895
3896         ret = legacy_camera_attr_foreach_supported_effect(muse_camera->camera_handle,
3897                 (camera_attr_supported_effect_cb)_camera_dispatcher_callback_supported_effect,
3898                 (void *)module);
3899
3900         LOGD("ret : 0x%x", ret);
3901
3902         muse_camera_msg_return(api, class, ret, module);
3903
3904         return MUSE_CAMERA_ERROR_NONE;
3905 }
3906
3907 int camera_dispatcher_attr_foreach_supported_scene_mode(muse_module_h module)
3908 {
3909         int ret = CAMERA_ERROR_NONE;
3910         muse_camera_handle_s *muse_camera = NULL;
3911         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE;
3912         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3913
3914         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3915
3916         LOGD("handle : %p", muse_camera);
3917
3918         ret = legacy_camera_attr_foreach_supported_scene_mode(muse_camera->camera_handle,
3919                 (camera_attr_supported_scene_mode_cb)_camera_dispatcher_callback_supported_scene_mode,
3920                 (void *)module);
3921
3922         LOGD("ret : 0x%x", ret);
3923
3924         muse_camera_msg_return(api, class, ret, module);
3925
3926         return MUSE_CAMERA_ERROR_NONE;
3927 }
3928
3929 int camera_dispatcher_attr_foreach_supported_flash_mode(muse_module_h module)
3930 {
3931         int ret = CAMERA_ERROR_NONE;
3932         muse_camera_handle_s *muse_camera = NULL;
3933         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE;
3934         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3935
3936         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3937
3938         LOGD("handle : %p", muse_camera);
3939
3940         ret = legacy_camera_attr_foreach_supported_flash_mode(muse_camera->camera_handle,
3941                 (camera_attr_supported_flash_mode_cb)_camera_dispatcher_callback_supported_flash_mode,
3942                 (void *)module);
3943
3944         LOGD("ret : 0x%x", ret);
3945
3946         muse_camera_msg_return(api, class, ret, module);
3947
3948         return MUSE_CAMERA_ERROR_NONE;
3949 }
3950
3951 int camera_dispatcher_attr_foreach_supported_fps(muse_module_h module)
3952 {
3953         int ret = CAMERA_ERROR_NONE;
3954         muse_camera_handle_s *muse_camera = NULL;
3955         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS;
3956         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3957
3958         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3959
3960         LOGD("handle : %p", muse_camera);
3961
3962         ret = legacy_camera_attr_foreach_supported_fps(muse_camera->camera_handle,
3963                 (camera_attr_supported_fps_cb)_camera_dispatcher_callback_supported_fps,
3964                 (void *)module);
3965
3966         LOGD("ret : 0x%x", ret);
3967
3968         muse_camera_msg_return(api, class, ret, module);
3969
3970         return MUSE_CAMERA_ERROR_NONE;
3971 }
3972
3973 int camera_dispatcher_attr_foreach_supported_fps_by_resolution(muse_module_h module)
3974 {
3975         int ret = CAMERA_ERROR_NONE;
3976         muse_camera_handle_s *muse_camera = NULL;
3977         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION;
3978         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
3979         int value = 0;
3980         int width = 0;
3981         int height = 0;
3982
3983         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
3984
3985         muse_camera_msg_get(value, muse_core_client_get_msg(module));
3986
3987         width = value >> 16;
3988         height = 0x0000ffff & value;
3989
3990         LOGD("handle : %p - %dx%d", muse_camera, width, height);
3991
3992         ret = legacy_camera_attr_foreach_supported_fps_by_resolution(muse_camera->camera_handle,
3993                 width, height,
3994                 (camera_attr_supported_fps_cb)_camera_dispatcher_callback_supported_fps_by_resolution,
3995                 (void *)module);
3996
3997         LOGD("ret : 0x%x", ret);
3998
3999         muse_camera_msg_return(api, class, ret, module);
4000
4001         return MUSE_CAMERA_ERROR_NONE;
4002 }
4003
4004 int camera_dispatcher_attr_foreach_supported_stream_flip(muse_module_h module)
4005 {
4006         int ret = CAMERA_ERROR_NONE;
4007         muse_camera_handle_s *muse_camera = NULL;
4008         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP;
4009         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
4010
4011         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4012
4013         LOGD("handle : %p", muse_camera);
4014
4015         ret = legacy_camera_attr_foreach_supported_stream_flip(muse_camera->camera_handle,
4016                 (camera_attr_supported_stream_flip_cb)_camera_dispatcher_callback_supported_stream_flip,
4017                 (void *)module);
4018
4019         LOGD("ret : 0x%x", ret);
4020
4021         muse_camera_msg_return(api, class, ret, module);
4022
4023         return MUSE_CAMERA_ERROR_NONE;
4024 }
4025
4026 int camera_dispatcher_attr_foreach_supported_stream_rotation(muse_module_h module)
4027 {
4028         int ret = CAMERA_ERROR_NONE;
4029         muse_camera_handle_s *muse_camera = NULL;
4030         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION;
4031         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
4032
4033         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4034
4035         LOGD("handle : %p", muse_camera);
4036
4037         ret = legacy_camera_attr_foreach_supported_stream_rotation(muse_camera->camera_handle,
4038                 (camera_attr_supported_stream_rotation_cb)_camera_dispatcher_callback_supported_stream_rotation,
4039                 (void *)module);
4040
4041         LOGD("ret : 0x%x", ret);
4042
4043         muse_camera_msg_return(api, class, ret, module);
4044
4045         return MUSE_CAMERA_ERROR_NONE;
4046 }
4047
4048 int camera_dispatcher_attr_set_stream_rotation(muse_module_h module)
4049 {
4050         int ret = CAMERA_ERROR_NONE;
4051         muse_camera_handle_s *muse_camera = NULL;
4052         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION;
4053         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4054         int set_rotation;
4055
4056         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4057
4058         muse_camera_msg_get(set_rotation, muse_core_client_get_msg(module));
4059
4060         LOGD("handle : %p", muse_camera);
4061
4062         ret = legacy_camera_attr_set_stream_rotation(muse_camera->camera_handle, (camera_rotation_e)set_rotation);
4063
4064         LOGD("ret : 0x%x", ret);
4065
4066         muse_camera_msg_return(api, class, ret, module);
4067
4068         return MUSE_CAMERA_ERROR_NONE;
4069 }
4070
4071 int camera_dispatcher_attr_get_stream_rotation(muse_module_h module)
4072 {
4073         int ret = CAMERA_ERROR_NONE;
4074         muse_camera_handle_s *muse_camera = NULL;
4075         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION;
4076         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4077         camera_rotation_e get_value = CAMERA_ROTATION_NONE;
4078
4079         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4080
4081         LOGD("handle : %p", muse_camera);
4082
4083         ret = legacy_camera_attr_get_stream_rotation(muse_camera->camera_handle, &get_value);
4084         if (ret == CAMERA_ERROR_NONE) {
4085                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4086                         MUSE_CAMERA_GET_INT_STREAM_ROTATION, "get_value", get_value, NULL);
4087         } else {
4088                 muse_camera_msg_return(api, class, ret, module);
4089         }
4090
4091         return MUSE_CAMERA_ERROR_NONE;
4092 }
4093
4094 int camera_dispatcher_attr_set_stream_flip(muse_module_h module)
4095 {
4096         int ret = CAMERA_ERROR_NONE;
4097         muse_camera_handle_s *muse_camera = NULL;
4098         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP;
4099         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4100         int set_flip;
4101
4102         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4103
4104         muse_camera_msg_get(set_flip, muse_core_client_get_msg(module));
4105
4106         LOGD("handle : %p", muse_camera);
4107
4108         ret = legacy_camera_attr_set_stream_flip(muse_camera->camera_handle, (camera_flip_e)set_flip);
4109
4110         LOGD("ret : 0x%x", ret);
4111
4112         muse_camera_msg_return(api, class, ret, module);
4113
4114         return MUSE_CAMERA_ERROR_NONE;
4115 }
4116
4117 int camera_dispatcher_attr_get_stream_flip(muse_module_h module)
4118 {
4119         int ret = CAMERA_ERROR_NONE;
4120         muse_camera_handle_s *muse_camera = NULL;
4121         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP;
4122         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4123         camera_flip_e get_value = CAMERA_FLIP_NONE;
4124
4125         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4126
4127         LOGD("handle : %p", muse_camera);
4128
4129         ret = legacy_camera_attr_get_stream_flip(muse_camera->camera_handle, &get_value);
4130         if (ret == CAMERA_ERROR_NONE) {
4131                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4132                         MUSE_CAMERA_GET_INT_STREAM_FLIP, "get_value", get_value, NULL);
4133         } else {
4134                 muse_camera_msg_return(api, class, ret, module);
4135         }
4136
4137         return MUSE_CAMERA_ERROR_NONE;
4138 }
4139
4140 int camera_dispatcher_attr_set_hdr_mode(muse_module_h module)
4141 {
4142         int set_mode = 0;
4143         muse_camera_handle_s *muse_camera = NULL;
4144
4145         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4146
4147         LOGD("handle : %p", muse_camera);
4148
4149         muse_camera_msg_get(set_mode, muse_core_client_get_msg(module));
4150
4151         _camera_task_add_job(muse_camera, MUSE_CAMERA_API_ATTR_SET_HDR_MODE,
4152                 MUSE_CAMERA_API_CLASS_IMMEDIATE, set_mode);
4153
4154         return MUSE_CAMERA_ERROR_NONE;
4155 }
4156
4157 int camera_dispatcher_attr_get_hdr_mode(muse_module_h module)
4158 {
4159         int ret = CAMERA_ERROR_NONE;
4160         muse_camera_handle_s *muse_camera = NULL;
4161         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HDR_MODE;
4162         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4163         camera_attr_hdr_mode_e get_value = CAMERA_ATTR_HDR_MODE_DISABLE;
4164
4165         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4166
4167         LOGD("handle : %p", muse_camera);
4168
4169         ret = legacy_camera_attr_get_hdr_mode(muse_camera->camera_handle, &get_value);
4170         if (ret == CAMERA_ERROR_NONE) {
4171                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4172                         MUSE_CAMERA_GET_INT_HDR_MODE, "get_value", get_value, NULL);
4173         } else {
4174                 muse_camera_msg_return(api, class, ret, module);
4175         }
4176
4177         return MUSE_CAMERA_ERROR_NONE;
4178 }
4179
4180 int camera_dispatcher_attr_is_supported_hdr_capture(muse_module_h module)
4181 {
4182         int ret = CAMERA_ERROR_NONE;
4183         muse_camera_handle_s *muse_camera = NULL;
4184         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE;
4185         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4186
4187         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4188
4189         LOGD("handle : %p", muse_camera);
4190
4191         ret = legacy_camera_attr_is_supported_hdr_capture(muse_camera->camera_handle);
4192
4193         LOGD("ret : 0x%x", ret);
4194
4195         muse_camera_msg_return(api, class, ret, module);
4196
4197         return MUSE_CAMERA_ERROR_NONE;
4198 }
4199
4200 int camera_dispatcher_attr_set_hdr_capture_progress_cb(muse_module_h module)
4201 {
4202         int ret = CAMERA_ERROR_NONE;
4203         muse_camera_handle_s *muse_camera = NULL;
4204         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
4205         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4206
4207         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4208
4209         LOGD("handle : %p", muse_camera);
4210
4211         ret = legacy_camera_attr_set_hdr_capture_progress_cb(muse_camera->camera_handle,
4212                 (camera_attr_hdr_progress_cb)_camera_dispatcher_hdr_progress_cb,
4213                 (void *)module);
4214
4215         LOGD("ret : 0x%x", ret);
4216
4217         muse_camera_msg_return(api, class, ret, module);
4218
4219         return MUSE_CAMERA_ERROR_NONE;
4220 }
4221
4222 int camera_dispatcher_attr_unset_hdr_capture_progress_cb(muse_module_h module)
4223 {
4224         int ret = CAMERA_ERROR_NONE;
4225         muse_camera_handle_s *muse_camera = NULL;
4226         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
4227         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4228
4229         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4230
4231         LOGD("handle : %p", muse_camera);
4232
4233         ret = legacy_camera_attr_unset_hdr_capture_progress_cb(muse_camera->camera_handle);
4234
4235         LOGD("ret : 0x%x", ret);
4236
4237         muse_camera_msg_return(api, class, ret, module);
4238
4239         return MUSE_CAMERA_ERROR_NONE;
4240 }
4241
4242 int camera_dispatcher_attr_enable_anti_shake(muse_module_h module)
4243 {
4244         int ret = CAMERA_ERROR_NONE;
4245         muse_camera_handle_s *muse_camera = NULL;
4246         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE;
4247         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4248         int set_enable;
4249
4250         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4251
4252         muse_camera_msg_get(set_enable, muse_core_client_get_msg(module));
4253
4254         LOGD("handle : %p", muse_camera);
4255
4256         ret = legacy_camera_attr_enable_anti_shake(muse_camera->camera_handle, (bool)set_enable);
4257
4258         LOGD("ret : 0x%x", ret);
4259
4260         muse_camera_msg_return(api, class, ret, module);
4261
4262         return MUSE_CAMERA_ERROR_NONE;
4263 }
4264
4265 int camera_dispatcher_attr_is_enabled_anti_shake(muse_module_h module)
4266 {
4267         int ret = CAMERA_ERROR_NONE;
4268         muse_camera_handle_s *muse_camera = NULL;
4269         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE;
4270         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4271         bool get_value = false;
4272
4273         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4274
4275         LOGD("handle : %p", muse_camera);
4276
4277         ret = legacy_camera_attr_is_enabled_anti_shake(muse_camera->camera_handle, &get_value);
4278         if (ret == CAMERA_ERROR_NONE) {
4279                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4280                         MUSE_CAMERA_GET_INT_ENABLED_ANTI_SHAKE, "get_value", get_value, NULL);
4281         } else {
4282                 muse_camera_msg_return(api, class, ret, module);
4283         }
4284
4285         return MUSE_CAMERA_ERROR_NONE;
4286 }
4287
4288 int camera_dispatcher_attr_is_supported_anti_shake(muse_module_h module)
4289 {
4290         int ret = CAMERA_ERROR_NONE;
4291         muse_camera_handle_s *muse_camera = NULL;
4292         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE;
4293         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4294
4295         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4296
4297         LOGD("handle : %p", muse_camera);
4298
4299         ret = legacy_camera_attr_is_supported_anti_shake(muse_camera->camera_handle);
4300
4301         LOGD("ret : 0x%x", ret);
4302
4303         muse_camera_msg_return(api, class, ret, module);
4304
4305         return MUSE_CAMERA_ERROR_NONE;
4306 }
4307
4308 int camera_dispatcher_attr_enable_video_stabilization(muse_module_h module)
4309 {
4310         int ret = CAMERA_ERROR_NONE;
4311         muse_camera_handle_s *muse_camera = NULL;
4312         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION;
4313         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4314         int set_enable;
4315
4316         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4317
4318         muse_camera_msg_get(set_enable, muse_core_client_get_msg(module));
4319
4320         LOGD("handle : %p", muse_camera);
4321
4322         ret = legacy_camera_attr_enable_video_stabilization(muse_camera->camera_handle, (bool)set_enable);
4323
4324         LOGD("ret : 0x%x", ret);
4325
4326         muse_camera_msg_return(api, class, ret, module);
4327
4328         return MUSE_CAMERA_ERROR_NONE;
4329 }
4330
4331 int camera_dispatcher_attr_is_enabled_video_stabilization(muse_module_h module)
4332 {
4333         int ret = CAMERA_ERROR_NONE;
4334         muse_camera_handle_s *muse_camera = NULL;
4335         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION;
4336         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4337         bool get_value = false;
4338
4339         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4340
4341         LOGD("handle : %p", muse_camera);
4342
4343         ret = legacy_camera_attr_is_enabled_video_stabilization(muse_camera->camera_handle, &get_value);
4344         if (ret == CAMERA_ERROR_NONE) {
4345                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4346                         MUSE_CAMERA_GET_INT_ENABLED_VIDEO_STABILIZATION, "get_value", get_value, NULL);
4347         } else {
4348                 muse_camera_msg_return(api, class, ret, module);
4349         }
4350
4351         return MUSE_CAMERA_ERROR_NONE;
4352 }
4353
4354 int camera_dispatcher_attr_is_supported_video_stabilization(muse_module_h module)
4355 {
4356         int ret = CAMERA_ERROR_NONE;
4357         muse_camera_handle_s *muse_camera = NULL;
4358         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION;
4359         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4360
4361         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4362
4363         LOGD("handle : %p", muse_camera);
4364
4365         ret = legacy_camera_attr_is_supported_video_stabilization(muse_camera->camera_handle);
4366
4367         LOGD("ret : 0x%x", ret);
4368
4369         muse_camera_msg_return(api, class, ret, module);
4370
4371         return MUSE_CAMERA_ERROR_NONE;
4372 }
4373
4374 int camera_dispatcher_attr_enable_auto_contrast(muse_module_h module)
4375 {
4376         int ret = CAMERA_ERROR_NONE;
4377         muse_camera_handle_s *muse_camera = NULL;
4378         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST;
4379         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4380         int set_enable;
4381
4382         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4383
4384         muse_camera_msg_get(set_enable, muse_core_client_get_msg(module));
4385
4386         LOGD("handle : %p", muse_camera);
4387
4388         ret = legacy_camera_attr_enable_auto_contrast(muse_camera->camera_handle, (bool)set_enable);
4389
4390         LOGD("ret : 0x%x", ret);
4391
4392         muse_camera_msg_return(api, class, ret, module);
4393
4394         return MUSE_CAMERA_ERROR_NONE;
4395 }
4396
4397 int camera_dispatcher_attr_is_enabled_auto_contrast(muse_module_h module)
4398 {
4399         int ret = CAMERA_ERROR_NONE;
4400         muse_camera_handle_s *muse_camera = NULL;
4401         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST;
4402         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4403         bool get_value = false;
4404
4405         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4406
4407         LOGD("handle : %p", muse_camera);
4408
4409         ret = legacy_camera_attr_is_enabled_auto_contrast(muse_camera->camera_handle, &get_value);
4410         if (ret == CAMERA_ERROR_NONE) {
4411                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4412                         MUSE_CAMERA_GET_INT_ENABLED_AUTO_CONTRAST, "get_value", get_value, NULL);
4413         } else {
4414                 muse_camera_msg_return(api, class, ret, module);
4415         }
4416
4417         return MUSE_CAMERA_ERROR_NONE;
4418 }
4419
4420 int camera_dispatcher_attr_is_supported_auto_contrast(muse_module_h module)
4421 {
4422         int ret = CAMERA_ERROR_NONE;
4423         muse_camera_handle_s *muse_camera = NULL;
4424         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST;
4425         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4426
4427         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4428
4429         LOGD("handle : %p", muse_camera);
4430
4431         ret = legacy_camera_attr_is_supported_auto_contrast(muse_camera->camera_handle);
4432
4433         LOGD("ret : 0x%x", ret);
4434
4435         muse_camera_msg_return(api, class, ret, module);
4436
4437         return MUSE_CAMERA_ERROR_NONE;
4438 }
4439
4440 int camera_dispatcher_attr_disable_shutter_sound(muse_module_h module)
4441 {
4442         int ret = CAMERA_ERROR_NONE;
4443         muse_camera_handle_s *muse_camera = NULL;
4444         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND;
4445         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4446         int set_disable;
4447
4448         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4449
4450         muse_camera_msg_get(set_disable, muse_core_client_get_msg(module));
4451
4452         LOGD("handle : %p", muse_camera);
4453
4454         ret = legacy_camera_attr_disable_shutter_sound(muse_camera->camera_handle, (bool)set_disable);
4455
4456         LOGD("ret : 0x%x", ret);
4457
4458         muse_camera_msg_return(api, class, ret, module);
4459
4460         return MUSE_CAMERA_ERROR_NONE;
4461 }
4462
4463 int camera_dispatcher_attr_get_encoded_preview_bitrate(muse_module_h module)
4464 {
4465         int ret = CAMERA_ERROR_NONE;
4466         muse_camera_handle_s *muse_camera = NULL;
4467         int get_value = 0;
4468         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE;
4469         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4470
4471         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4472
4473         LOGD("handle : %p", muse_camera);
4474
4475         ret = legacy_camera_attr_get_encoded_preview_bitrate(muse_camera->camera_handle, &get_value);
4476         if (ret == CAMERA_ERROR_NONE) {
4477                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4478                         MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_BITRATE, "get_value", get_value, NULL);
4479         } else {
4480                 muse_camera_msg_return(api, class, ret, module);
4481         }
4482
4483         return MUSE_CAMERA_ERROR_NONE;
4484 }
4485
4486 int camera_dispatcher_attr_set_encoded_preview_bitrate(muse_module_h module)
4487 {
4488         int ret = CAMERA_ERROR_NONE;
4489         muse_camera_handle_s *muse_camera = NULL;
4490         int set_bitrate;
4491         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE;
4492         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4493
4494         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4495
4496         muse_camera_msg_get(set_bitrate, muse_core_client_get_msg(module));
4497
4498         LOGD("handle : 0x%x, set_encoded_preview_bitrate : %d", muse_camera, set_bitrate);
4499
4500         ret = legacy_camera_attr_set_encoded_preview_bitrate(muse_camera->camera_handle, set_bitrate);
4501
4502         LOGD("ret : 0x%x", ret);
4503
4504         muse_camera_msg_return(api, class, ret, module);
4505
4506         return MUSE_CAMERA_ERROR_NONE;
4507 }
4508
4509 int camera_dispatcher_attr_get_encoded_preview_gop_interval(muse_module_h module)
4510 {
4511         int ret = CAMERA_ERROR_NONE;
4512         muse_camera_handle_s *muse_camera = NULL;
4513         int get_value;
4514         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL;
4515         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4516
4517         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4518
4519         LOGD("handle : %p", muse_camera);
4520
4521         ret = legacy_camera_attr_get_encoded_preview_gop_interval(muse_camera->camera_handle, &get_value);
4522         if (ret == CAMERA_ERROR_NONE) {
4523                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4524                         MUSE_CAMERA_GET_INT_ENCODED_PREVIEW_GOP_INTERVAL, "get_value", get_value, NULL);
4525         } else {
4526                 muse_camera_msg_return(api, class, ret, module);
4527         }
4528
4529         return MUSE_CAMERA_ERROR_NONE;
4530 }
4531
4532 int camera_dispatcher_attr_set_encoded_preview_gop_interval(muse_module_h module)
4533 {
4534         int ret = CAMERA_ERROR_NONE;
4535         muse_camera_handle_s *muse_camera = NULL;
4536         int set_gop_interval;
4537         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL;
4538         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4539
4540         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4541
4542         muse_camera_msg_get(set_gop_interval, muse_core_client_get_msg(module));
4543
4544         LOGD("handle : 0x%x, set_encoded_preview_gop_interval : %d", muse_camera, set_gop_interval);
4545
4546         ret = legacy_camera_attr_set_encoded_preview_gop_interval(muse_camera->camera_handle, set_gop_interval);
4547
4548         LOGD("ret : 0x%x", ret);
4549
4550         muse_camera_msg_return(api, class, ret, module);
4551
4552         return MUSE_CAMERA_ERROR_NONE;
4553 }
4554
4555 int camera_dispatcher_attr_set_pan(muse_module_h module)
4556 {
4557         int ret = CAMERA_ERROR_NONE;
4558         muse_camera_handle_s *muse_camera = NULL;
4559         int value = 0;
4560         int type = 0;
4561         int step = 0;
4562         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN;
4563         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4564
4565         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4566
4567         muse_camera_msg_get(value, muse_core_client_get_msg(module));
4568
4569         type = value >> 16;
4570         step = 0x0000ffff & value;
4571
4572         LOGD("handle : 0x%x - type %d, step %d", muse_camera, type, step);
4573
4574         ret = legacy_camera_attr_set_pan(muse_camera->camera_handle, type, step);
4575
4576         LOGD("ret : 0x%x", ret);
4577
4578         muse_camera_msg_return(api, class, ret, module);
4579
4580         return MUSE_CAMERA_ERROR_NONE;
4581 }
4582
4583 int camera_dispatcher_attr_get_pan(muse_module_h module)
4584 {
4585         int ret = CAMERA_ERROR_NONE;
4586         muse_camera_handle_s *muse_camera = NULL;
4587         int get_value = 0;
4588         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN;
4589         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4590
4591         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4592
4593         LOGD("handle : %p", muse_camera);
4594
4595         ret = legacy_camera_attr_get_pan(muse_camera->camera_handle, &get_value);
4596         if (ret == CAMERA_ERROR_NONE) {
4597                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4598                         MUSE_CAMERA_GET_INT_PAN, "get_value", get_value, NULL);
4599         } else {
4600                 muse_camera_msg_return(api, class, ret, module);
4601         }
4602
4603         return MUSE_CAMERA_ERROR_NONE;
4604 }
4605
4606 int camera_dispatcher_attr_get_pan_range(muse_module_h module)
4607 {
4608         int ret = CAMERA_ERROR_NONE;
4609         muse_camera_handle_s *muse_camera = NULL;
4610         int get_value0 = 0;
4611         int get_value1 = 0;
4612         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
4613         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4614         muse_camera_get_type_e get_type = MUSE_CAMERA_GET_TYPE_INT_PAIR;
4615         muse_camera_get_int_pair_e index = MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE;
4616
4617         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4618
4619         LOGD("handle : %p", muse_camera);
4620
4621         ret = legacy_camera_attr_get_pan_range(muse_camera->camera_handle, &get_value0, &get_value1);
4622         if (ret == CAMERA_ERROR_NONE)
4623                 muse_camera_msg_return2(api, class, ret, module, get_type, index, get_value0, get_value1);
4624         else
4625                 muse_camera_msg_return(api, class, ret, module);
4626
4627         return MUSE_CAMERA_ERROR_NONE;
4628 }
4629
4630 int camera_dispatcher_attr_set_tilt(muse_module_h module)
4631 {
4632         int ret = CAMERA_ERROR_NONE;
4633         muse_camera_handle_s *muse_camera = NULL;
4634         int value = 0;
4635         int type = 0;
4636         int step = 0;
4637         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT;
4638         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4639
4640         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4641
4642         muse_camera_msg_get(value, muse_core_client_get_msg(module));
4643
4644         type = value >> 16;
4645         step = 0x0000ffff & value;
4646
4647         LOGD("handle : 0x%x - type %d, step %d", muse_camera, type, step);
4648
4649         ret = legacy_camera_attr_set_tilt(muse_camera->camera_handle, type, step);
4650
4651         LOGD("ret : 0x%x", ret);
4652
4653         muse_camera_msg_return(api, class, ret, module);
4654
4655         return MUSE_CAMERA_ERROR_NONE;
4656 }
4657
4658 int camera_dispatcher_attr_get_tilt(muse_module_h module)
4659 {
4660         int ret = CAMERA_ERROR_NONE;
4661         muse_camera_handle_s *muse_camera = NULL;
4662         int get_value = 0;
4663         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT;
4664         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4665
4666         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4667
4668         LOGD("handle : %p", muse_camera);
4669
4670         ret = legacy_camera_attr_get_tilt(muse_camera->camera_handle, &get_value);
4671         if (ret == CAMERA_ERROR_NONE) {
4672                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4673                         MUSE_CAMERA_GET_INT_TILT, "get_value", get_value, NULL);
4674         } else {
4675                 muse_camera_msg_return(api, class, ret, module);
4676         }
4677
4678         return MUSE_CAMERA_ERROR_NONE;
4679 }
4680
4681 int camera_dispatcher_attr_get_tilt_range(muse_module_h module)
4682 {
4683         int ret = CAMERA_ERROR_NONE;
4684         muse_camera_handle_s *muse_camera = NULL;
4685         int get_value0 = 0;
4686         int get_value1 = 0;
4687         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
4688         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4689         muse_camera_get_type_e get_type = MUSE_CAMERA_GET_TYPE_INT_PAIR;
4690         muse_camera_get_int_pair_e index = MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE;
4691
4692         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4693
4694         LOGD("handle : %p", muse_camera);
4695
4696         ret = legacy_camera_attr_get_tilt_range(muse_camera->camera_handle, &get_value0, &get_value1);
4697         if (ret == CAMERA_ERROR_NONE)
4698                 muse_camera_msg_return2(api, class, ret, module, get_type, index, get_value0, get_value1);
4699         else
4700                 muse_camera_msg_return(api, class, ret, module);
4701
4702         return MUSE_CAMERA_ERROR_NONE;
4703 }
4704
4705 int camera_dispatcher_attr_set_ptz_type(muse_module_h module)
4706 {
4707         int ret = CAMERA_ERROR_NONE;
4708         muse_camera_handle_s *muse_camera = NULL;
4709         int set_ptz_type = 0;
4710         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE;
4711         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4712
4713         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4714
4715         muse_camera_msg_get(set_ptz_type, muse_core_client_get_msg(module));
4716
4717         LOGD("handle : 0x%x", muse_camera);
4718
4719         ret = legacy_camera_attr_set_ptz_type(muse_camera->camera_handle, set_ptz_type);
4720
4721         LOGD("ret : 0x%x", ret);
4722
4723         muse_camera_msg_return(api, class, ret, module);
4724
4725         return MUSE_CAMERA_ERROR_NONE;
4726 }
4727
4728 int camera_dispatcher_attr_foreach_supported_ptz_type(muse_module_h module)
4729 {
4730         int ret = CAMERA_ERROR_NONE;
4731         muse_camera_handle_s *muse_camera = NULL;
4732         muse_camera_api_e api = MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE;
4733         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_THREAD_SUB;
4734
4735         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4736
4737         LOGD("handle : %p", muse_camera);
4738
4739         ret = legacy_camera_attr_foreach_supported_ptz_type(muse_camera->camera_handle,
4740                 (camera_attr_supported_ptz_type_cb)_camera_dispatcher_callback_supported_ptz_type,
4741                 (void *)module);
4742
4743         LOGD("ret : 0x%x", ret);
4744
4745         muse_camera_msg_return(api, class, ret, module);
4746
4747         return MUSE_CAMERA_ERROR_NONE;
4748 }
4749
4750 int camera_dispatcher_attr_set_display_roi_area(muse_module_h module)
4751 {
4752         int ret = CAMERA_ERROR_NONE;
4753         muse_camera_handle_s *muse_camera = NULL;
4754         int set_display_roi_area[4] = {0,};
4755         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA;
4756         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4757
4758         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4759
4760         muse_camera_msg_get_array(set_display_roi_area, muse_core_client_get_msg(module));
4761
4762         LOGD("handle : 0x%x, x : %d, y : %d, width : %d, height : %d", muse_camera,
4763                 set_display_roi_area[0], set_display_roi_area[1], set_display_roi_area[2], set_display_roi_area[3]);
4764
4765         ret = legacy_camera_attr_set_display_roi_area(muse_camera->camera_handle, set_display_roi_area);
4766
4767         LOGD("ret : 0x%x", ret);
4768
4769         muse_camera_msg_return(api, class, ret, module);
4770
4771         return MUSE_CAMERA_ERROR_NONE;
4772 }
4773
4774 int camera_dispatcher_attr_get_display_roi_area(muse_module_h module)
4775 {
4776         int ret = CAMERA_ERROR_NONE;
4777         muse_camera_handle_s *muse_camera = NULL;
4778         int get_value[4] = {0,};
4779         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA;
4780         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4781         char *send_msg = NULL;
4782
4783         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4784
4785         LOGD("handle : %p", muse_camera);
4786
4787         ret = legacy_camera_attr_get_display_roi_area(muse_camera->camera_handle, get_value);
4788         if (ret == CAMERA_ERROR_NONE) {
4789                 send_msg = muse_core_msg_json_factory_new(api,
4790                         MUSE_TYPE_INT, PARAM_API_CLASS, class,
4791                         MUSE_TYPE_INT, PARAM_RET, ret,
4792                         MUSE_TYPE_INT, PARAM_GET_TYPE, MUSE_CAMERA_GET_TYPE_ARRAY,
4793                         MUSE_TYPE_ARRAY, "get_value", 4, get_value,
4794                         0);
4795
4796                 __camera_dispatcher_send_msg(module, send_msg);
4797         } else {
4798                 muse_camera_msg_return(api, class, ret, module);
4799         }
4800
4801         return MUSE_CAMERA_ERROR_NONE;
4802 }
4803
4804
4805 int camera_dispatcher_return_buffer(muse_module_h module)
4806 {
4807         int tbm_key = 0;
4808         muse_camera_handle_s *muse_camera = NULL;
4809
4810         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4811
4812         muse_camera_msg_get(tbm_key, muse_core_client_get_msg(module));
4813
4814         /*LOGD("handle : %p, key : %d", muse_camera, tbm_key);*/
4815
4816         if (!_camera_remove_export_data(module, tbm_key, FALSE))
4817                 LOGE("remove export data failed : key %d", tbm_key);
4818
4819         return MUSE_CAMERA_ERROR_NONE;
4820 }
4821
4822 int camera_dispatcher_preview_cb_return(muse_module_h module)
4823 {
4824         muse_camera_handle_s *muse_camera = NULL;
4825
4826         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4827
4828         if (muse_camera == NULL) {
4829                 LOGE("NULL handle");
4830                 return MUSE_CAMERA_ERROR_NONE;
4831         }
4832
4833         /*LOGD("ENTER");*/
4834
4835         g_mutex_lock(&muse_camera->preview_cb_lock);
4836         g_cond_signal(&muse_camera->preview_cb_cond);
4837         /*LOGD("send signal for preview callback");*/
4838         g_mutex_unlock(&muse_camera->preview_cb_lock);
4839
4840         /*LOGD("DONE");*/
4841
4842         return MUSE_CAMERA_ERROR_NONE;
4843 }
4844
4845 int camera_dispatcher_set_display_reuse_hint(muse_module_h module)
4846 {
4847         int ret = CAMERA_ERROR_NONE;
4848         int set_hint = 0;
4849         muse_camera_handle_s *muse_camera = NULL;
4850         muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT;
4851         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4852
4853         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4854
4855         muse_camera_msg_get(set_hint, muse_core_client_get_msg(module));
4856
4857         LOGD("set hint : %d", set_hint);
4858
4859         ret = legacy_camera_set_display_reuse_hint(muse_camera->camera_handle, (bool)set_hint);
4860
4861         muse_camera_msg_return(api, class, ret, module);
4862
4863         return MUSE_CAMERA_ERROR_NONE;
4864 }
4865
4866 int camera_dispatcher_get_display_reuse_hint(muse_module_h module)
4867 {
4868         int ret = CAMERA_ERROR_NONE;
4869         int get_value = 0;
4870         muse_camera_handle_s *muse_camera = NULL;
4871         muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
4872         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4873
4874         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
4875
4876         ret = legacy_camera_get_display_reuse_hint(muse_camera->camera_handle, &get_value);
4877         if (ret == CAMERA_ERROR_NONE) {
4878                 LOGD("hint : %d", get_value);
4879                 muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4880                         MUSE_CAMERA_GET_INT_DISPLAY_REUSE_HINT, "get_value", get_value, NULL);
4881         } else {
4882                 muse_camera_msg_return(api, class, ret, module);
4883         }
4884
4885         return MUSE_CAMERA_ERROR_NONE;
4886 }
4887
4888 int camera_dispatcher_get_device_state(muse_module_h module)
4889 {
4890         int ret = CAMERA_ERROR_NONE;
4891         bool is_called = false;
4892         char value_key[KEY_LENGTH] = {'\0',};
4893         camera_h camera = NULL;
4894         camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
4895         camera_device_state_e get_device_state = CAMERA_DEVICE_STATE_NULL;
4896         muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_STATE;
4897         muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
4898
4899         muse_camera_msg_get(device_type, muse_core_client_get_msg(module));
4900
4901         if (device_type < CAMERA_DEVICE_CAMERA0 || device_type > CAMERA_DEVICE_CAMERA1) {
4902                 LOGE("invalid device %d", device_type);
4903
4904                 ret = CAMERA_ERROR_INVALID_PARAMETER;
4905                 muse_camera_msg_return(api, class, ret, module);
4906
4907                 return MUSE_CAMERA_ERROR_NONE;
4908         }
4909
4910         muse_core_client_get_value(module, MUSED_KEY_DEVICE_STATE_CHECK, (int *)&is_called);
4911
4912         if (!is_called) {
4913                 ret = legacy_camera_create(device_type, &camera);
4914                 if (camera) {
4915                         legacy_camera_destroy(camera);
4916                         camera = NULL;
4917                 }
4918
4919                 muse_core_client_set_value(module, MUSED_KEY_DEVICE_STATE_RETURN, ret);
4920                 muse_core_client_set_value(module, MUSED_KEY_DEVICE_STATE_CHECK, (int)true);
4921         } else {
4922                 muse_core_client_get_value(module, MUSED_KEY_DEVICE_STATE_RETURN, &ret);
4923         }
4924
4925         LOGD("is_called %d, ret 0x%x", is_called, ret);
4926
4927         if (ret != CAMERA_ERROR_NONE) {
4928                 LOGE("failed to create camera handle 0x%x", ret);
4929
4930                 muse_camera_msg_return(api, class, ret, module);
4931
4932                 return MUSE_CAMERA_ERROR_NONE;
4933         }
4934
4935         snprintf(value_key, KEY_LENGTH, "device_state_camera%d", device_type);
4936         muse_core_client_get_value(module, value_key, (int *)&get_device_state);
4937
4938         LOGD("device[%d] state : %d", device_type, get_device_state);
4939
4940         muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_INT,
4941                 -1, "get_device_state", get_device_state, NULL);
4942
4943         return MUSE_CAMERA_ERROR_NONE;
4944 }
4945
4946 int (*dispatcher[MUSE_CAMERA_API_MAX]) (muse_module_h module) = {
4947         camera_dispatcher_create, /* MUSE_CAMERA_API_CREATE */
4948         camera_dispatcher_destroy, /* MUSE_CAMERA_API_DESTROY */
4949         camera_dispatcher_start_preview, /* MUSE_CAMERA_START_PREVIEW */
4950         camera_dispatcher_stop_preview, /* MUSE_CAMERA_API_START_PREVIEW */
4951         camera_dispatcher_start_capture, /* MUSE_CAMERA_START_CAPTURE */
4952         camera_dispatcher_is_supported_continuous_capture, /* MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE */
4953         camera_dispatcher_start_continuous_capture, /* MUSE_CAMERA_API_START_CONTINUOUS_CAPTURE, */
4954         camera_dispatcher_stop_continuous_capture, /* MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE, */
4955         camera_dispatcher_is_supported_face_detection, /* MUSE_CAMERA_API_SUPPORT_FACE_DETECTION, */
4956         camera_dispatcher_is_supported_zero_shutter_lag, /* MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG, */
4957         camera_dispatcher_is_supported_media_packet_preview_cb, /* MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB, */
4958         camera_dispatcher_get_device_count, /* MUSE_CAMERA_API_GET_DEVICE_COUNT, */
4959         camera_dispatcher_start_face_detection, /* MUSE_CAMERA_API_START_FACE_DETECTION, */
4960         camera_dispatcher_stop_face_detection, /* MUSE_CAMERA_API_STOP_FACE_DETECTION, */
4961         camera_dispatcher_get_state, /* MUSE_CAMERA_API_GET_STATE, */
4962         camera_dispatcher_start_focusing, /* MUSE_CAMERA_API_START_FOCUSING, */
4963         camera_dispatcher_stop_focusing, /* MUSE_CAMERA_API_CANCEL_FOCUSING, */
4964         camera_dispatcher_set_display, /* MUSE_CAMERA_API_SET_DISPLAY, */
4965         camera_dispatcher_set_preview_resolution, /* MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION, */
4966         camera_dispatcher_set_capture_resolution, /* MUSE_CAMERA_API_SET_CAPTURE_RESOLUTION, */
4967         camera_dispatcher_set_capture_format, /* MUSE_CAMERA_API_SET_CAPTURE_FORMAT, */
4968         camera_dispatcher_set_preview_format, /* MUSE_CAMERA_API_SET_PREVIEW_FORMAT, */
4969         camera_dispatcher_get_preview_resolution, /* MUSE_CAMERA_API_GET_PREVIEW_RESOLUTION, */
4970         camera_dispatcher_set_display_rotation, /* MUSE_CAMERA_API_SET_DISPLAY_ROTATION, */
4971         camera_dispatcher_get_display_rotation, /* MUSE_CAMERA_API_GET_DISPLAY_ROTATION, */
4972         camera_dispatcher_set_display_flip, /* MUSE_CAMERA_API_SET_DISPLAY_FLIP, */
4973         camera_dispatcher_get_display_flip, /* MUSE_CAMERA_API_GET_DISPLAY_FLIP, */
4974         camera_dispatcher_set_display_visible, /* MUSE_CAMERA_API_SET_DISPLAY_VISIBLE, */
4975         camera_dispatcher_is_display_visible, /* MUSE_CAMERA_API_IS_DISPLAY_VISIBLE, */
4976         camera_dispatcher_set_display_mode, /* MUSE_CAMERA_API_SET_DISPLAY_MODE, */
4977         camera_dispatcher_get_display_mode, /* MUSE_CAMERA_API_GET_DISPLAY_MODE, */
4978         camera_dispatcher_get_capture_resolution, /* MUSE_CAMERA_API_GET_CAPTURE_RESOLUTION, */
4979         camera_dispatcher_get_capture_format, /* MUSE_CAMERA_API_GET_CAPTURE_FORMAT, */
4980         camera_dispatcher_get_preview_format, /* MUSE_CAMERA_API_GET_PREVIEW_FORMAT, */
4981         camera_dispatcher_get_facing_direction, /* MUSE_CAMERA_API_GET_FACING_DIRECTION, */
4982         camera_dispatcher_get_flash_state, /* MUSE_CAMERA_API_GET_FLASH_STATE, */
4983         camera_dispatcher_set_preview_cb, /* MUSE_CAMERA_API_SET_PREVIEW_CB, */
4984         camera_dispatcher_unset_preview_cb, /* MUSE_CAMERA_API_UNSET_PREVIEW_CB, */
4985         camera_dispatcher_set_media_packet_preview_cb, /* MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB, */
4986         camera_dispatcher_unset_media_packet_preview_cb, /* MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB, */
4987         camera_dispatcher_set_state_changed_cb, /* MUSE_CAMERA_API_SET_STATE_CHANGED_CB, */
4988         camera_dispatcher_unset_state_changed_cb, /* MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB, */
4989         camera_dispatcher_set_interrupted_cb, /* MUSE_CAMERA_API_SET_INTERRUPTED_CB, */
4990         camera_dispatcher_unset_interrupted_cb, /* MUSE_CAMERA_API_UNSET_INTERRUPTED_CB, */
4991         camera_dispatcher_set_focus_changed_cb, /* MUSE_CAMERA_API_SET_FOCUS_CHANGED_CB, */
4992         camera_dispatcher_unset_focus_changed_cb, /* MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB, */
4993         camera_dispatcher_set_error_cb, /* MUSE_CAMERA_API_SET_ERROR_CB, */
4994         camera_dispatcher_unset_error_cb, /* MUSE_CAMERA_API_UNSET_ERROR_CB, */
4995         camera_dispatcher_foreach_supported_preview_resolution, /* MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_RESOLUTION, */
4996         camera_dispatcher_foreach_supported_capture_resolution, /* MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_RESOLUTION, */
4997         camera_dispatcher_foreach_supported_capture_format, /* MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_CAPTURE_FORMAT, */
4998         camera_dispatcher_foreach_supported_preview_format, /* MUSE_CAMERA_API_SET_FOREACH_SUPPORTED_PREVIEW_FORMAT, */
4999         camera_dispatcher_get_recommended_preview_resolution, /* MUSE_CAMERA_API_GET_RECOMMENDED_PREVIEW_RESOLUTION, */
5000         camera_dispatcher_attr_get_lens_orientation, /* MUSE_CAMERA_API_ATTR_GET_LENS_ORIENTATION, */
5001         camera_dispatcher_attr_set_theater_mode, /* MUSE_CAMERA_API_ATTR_SET_THEATER_MODE, */
5002         camera_dispatcher_attr_get_theater_mode, /* MUSE_CAMERA_API_ATTR_GET_THEATER_MODE, */
5003         camera_dispatcher_attr_foreach_supported_theater_mode, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_THEATER_MODE, */
5004         camera_dispatcher_attr_set_preview_fps, /* MUSE_CAMERA_API_ATTR_SET_PREVIEW_FPS, */
5005         camera_dispatcher_attr_set_image_quality, /* MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY, */
5006         camera_dispatcher_attr_get_preview_fps, /* MUSE_CAMERA_API_ATTR_GET_PREVIEW_FPS, */
5007         camera_dispatcher_attr_get_image_quality, /* MUSE_CAMERA_API_ATTR_GET_IMAGE_QUALITY, */
5008         camera_dispatcher_attr_set_zoom, /* MUSE_CAMERA_API_ATTR_SET_ZOOM, */
5009         camera_dispatcher_attr_set_af_mode, /* MUSE_CAMERA_API_ATTR_SET_AF_MODE, */
5010         camera_dispatcher_attr_set_af_area, /* MUSE_CAMERA_API_ATTR_SET_AF_AREA, */
5011         camera_dispatcher_attr_clear_af_area, /* MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA, */
5012         camera_dispatcher_attr_set_exposure_mode, /* MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE, */
5013         camera_dispatcher_attr_set_exposure, /* MUSE_CAMERA_API_ATTR_SET_EXPOSURE, */
5014         camera_dispatcher_attr_set_iso, /* MUSE_CAMERA_API_ATTR_SET_ISO, */
5015         camera_dispatcher_attr_set_brightness, /* MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS, */
5016         camera_dispatcher_attr_set_contrast, /* MUSE_CAMERA_API_ATTR_SET_CONTRAST, */
5017         camera_dispatcher_attr_set_whitebalance, /* MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE, */
5018         camera_dispatcher_attr_set_effect, /* MUSE_CAMERA_API_ATTR_SET_EFFECT, */
5019         camera_dispatcher_attr_set_scene_mode, /* MUSE_CAMERA_API_ATTR_SET_SCENE_MODE, */
5020         camera_dispatcher_attr_enable_tag, /* MUSE_CAMERA_API_ATTR_ENABLE_TAG, */
5021         camera_dispatcher_attr_set_tag_image_description, /* MUSE_CAMERA_API_ATTR_SET_TAG_IMAGE_DESCRIPTION, */
5022         camera_dispatcher_attr_set_tag_orientation, /* MUSE_CAMERA_API_ATTR_SET_TAG_ORIENTATION, */
5023         camera_dispatcher_attr_set_tag_software, /* MUSE_CAMERA_API_ATTR_SET_TAG_SOFTWARE, */
5024         camera_dispatcher_attr_set_geotag, /* MUSE_CAMERA_API_ATTR_SET_GEOTAG, */
5025         camera_dispatcher_attr_remove_geotag, /* MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG, */
5026         camera_dispatcher_attr_set_flash_mode, /* MUSE_CAMERA_API_ATTR_SET_FLASH_MODE, */
5027         camera_dispatcher_attr_get_zoom, /* MUSE_CAMERA_API_ATTR_GET_ZOOM, */
5028         camera_dispatcher_attr_get_zoom_range, /* MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE, */
5029         camera_dispatcher_attr_get_af_mode, /* MUSE_CAMERA_API_ATTR_GET_AF_MODE, */
5030         camera_dispatcher_attr_get_exposure_mode, /* MUSE_CAMERA_API_ATTR_GET_EXPOSURE_MODE, */
5031         camera_dispatcher_attr_get_exposure, /* MUSE_CAMERA_API_ATTR_GET_EXPOSURE, */
5032         camera_dispatcher_attr_get_exposure_range, /* MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE, */
5033         camera_dispatcher_attr_get_iso, /* MUSE_CAMERA_API_ATTR_GET_ISO, */
5034         camera_dispatcher_attr_get_brightness, /* MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS, */
5035         camera_dispatcher_attr_get_brightness_range, /* MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE, */
5036         camera_dispatcher_attr_get_contrast, /* MUSE_CAMERA_API_ATTR_GET_CONTRAST, */
5037         camera_dispatcher_attr_get_contrast_range, /* MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE, */
5038         camera_dispatcher_attr_get_whitebalance, /* MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE, */
5039         camera_dispatcher_attr_get_effect, /* MUSE_CAMERA_API_ATTR_GET_EFFECT, */
5040         camera_dispatcher_attr_get_scene_mode, /* MUSE_CAMERA_API_ATTR_GET_SCENE_MODE, */
5041         camera_dispatcher_attr_is_enabled_tag, /* MUSE_CAMERA_API_ATTR_IS_ENABLED_TAG, */
5042         camera_dispatcher_attr_get_tag_image_description, /* MUSE_CAMERA_API_ATTR_GET_TAG_IMAGE_DESCRIPTION, */
5043         camera_dispatcher_attr_get_tag_orientation, /* MUSE_CAMERA_API_ATTR_GET_TAG_ORIENTATION, */
5044         camera_dispatcher_attr_get_tag_software, /* MUSE_CAMERA_API_ATTR_GET_TAG_SOFTWARE, */
5045         camera_dispatcher_attr_get_geotag, /* MUSE_CAMERA_API_ATTR_GET_GEOTAG, */
5046         camera_dispatcher_attr_get_flash_mode, /* MUSE_CAMERA_API_ATTR_GET_FLASH_MODE, */
5047         camera_dispatcher_attr_foreach_supported_af_mode, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_AF_MODE, */
5048         camera_dispatcher_attr_foreach_supported_exposure_mode, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EXPOSURE_MODE, */
5049         camera_dispatcher_attr_foreach_supported_iso, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_ISO, */
5050         camera_dispatcher_attr_foreach_supported_whitebalance, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_WHITEBALANCE, */
5051         camera_dispatcher_attr_foreach_supported_effect, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_EFFECT, */
5052         camera_dispatcher_attr_foreach_supported_scene_mode, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_SCENE_MODE, */
5053         camera_dispatcher_attr_foreach_supported_flash_mode, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FLASH_MODE, */
5054         camera_dispatcher_attr_foreach_supported_fps, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS, */
5055         camera_dispatcher_attr_foreach_supported_fps_by_resolution, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_FPS_BY_RESOLUTION, */
5056         camera_dispatcher_attr_foreach_supported_stream_flip, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_FLIP, */
5057         camera_dispatcher_attr_foreach_supported_stream_rotation, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_STREAM_ROTATION, */
5058         camera_dispatcher_attr_set_stream_rotation, /* MUSE_CAMERA_API_ATTR_SET_STREAM_ROTATION, */
5059         camera_dispatcher_attr_get_stream_rotation, /* MUSE_CAMERA_API_ATTR_GET_STREAM_ROTATION, */
5060         camera_dispatcher_attr_set_stream_flip, /* MUSE_CAMERA_API_ATTR_SET_STREAM_FLIP, */
5061         camera_dispatcher_attr_get_stream_flip, /* MUSE_CAMERA_API_ATTR_GET_STREAM_FLIP, */
5062         camera_dispatcher_attr_set_hdr_mode, /* MUSE_CAMERA_API_ATTR_SET_HDR_MODE, */
5063         camera_dispatcher_attr_get_hdr_mode, /* MUSE_CAMERA_API_ATTR_GET_HDR_MODE, */
5064         camera_dispatcher_attr_is_supported_hdr_capture, /* MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE, */
5065         camera_dispatcher_attr_set_hdr_capture_progress_cb, /* MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB, */
5066         camera_dispatcher_attr_unset_hdr_capture_progress_cb, /* MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB, */
5067         camera_dispatcher_attr_enable_anti_shake, /* MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE, */
5068         camera_dispatcher_attr_is_enabled_anti_shake, /* MUSE_CAMERA_API_ATTR_IS_ENABLED_ANTI_SHAKE, */
5069         camera_dispatcher_attr_is_supported_anti_shake, /* MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE, */
5070         camera_dispatcher_attr_enable_video_stabilization, /* MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION, */
5071         camera_dispatcher_attr_is_enabled_video_stabilization, /* MUSE_CAMERA_API_ATTR_IS_ENABLED_VIDEO_STABILIZATION, */
5072         camera_dispatcher_attr_is_supported_video_stabilization, /* MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION, */
5073         camera_dispatcher_attr_enable_auto_contrast, /* MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST, */
5074         camera_dispatcher_attr_is_enabled_auto_contrast, /* MUSE_CAMERA_API_ATTR_IS_ENABLED_AUTO_CONTRAST, */
5075         camera_dispatcher_attr_is_supported_auto_contrast, /* MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST, */
5076         camera_dispatcher_attr_disable_shutter_sound, /* MUSE_CAMERA_API_ATTR_DISABLE_SHUTTER_SOUND, */
5077         camera_dispatcher_attr_get_encoded_preview_bitrate, /* MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_BITRATE, */
5078         camera_dispatcher_attr_set_encoded_preview_bitrate, /* MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_BITRATE, */
5079         camera_dispatcher_attr_get_encoded_preview_gop_interval, /* MUSE_CAMERA_API_ATTR_GET_ENCODED_PREVIEW_GOP_INTERVAL, */
5080         camera_dispatcher_attr_set_encoded_preview_gop_interval, /* MUSE_CAMERA_API_ATTR_SET_ENCODED_PREVIEW_GOP_INTERVAL, */
5081         camera_dispatcher_attr_set_pan, /* MUSE_CAMERA_API_ATTR_SET_PAN */
5082         camera_dispatcher_attr_get_pan, /* MUSE_CAMERA_API_ATTR_GET_PAN */
5083         camera_dispatcher_attr_get_pan_range, /* MUSE_CAMERA_API_ATTR_GET_PAN_RANGE */
5084         camera_dispatcher_attr_set_tilt, /* MUSE_CAMERA_API_ATTR_SET_TILT */
5085         camera_dispatcher_attr_get_tilt, /* MUSE_CAMERA_API_ATTR_GET_TILT */
5086         camera_dispatcher_attr_get_tilt_range, /* MUSE_CAMERA_API_ATTR_GET_TILT_RANGE */
5087         camera_dispatcher_attr_set_ptz_type, /* MUSE_CAMERA_API_ATTR_SET_PTZ_TYPE */
5088         camera_dispatcher_attr_foreach_supported_ptz_type, /* MUSE_CAMERA_API_ATTR_FOREACH_SUPPORTED_PTZ_TYPE */
5089         camera_dispatcher_attr_set_display_roi_area, /* MUSE_CAMERA_API_SET_DISPLAY_ROI_AREA */
5090         camera_dispatcher_attr_get_display_roi_area, /* MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA */
5091         camera_dispatcher_return_buffer, /* MUSE_CAMERA_API_RETURN_BUFFER */
5092         camera_dispatcher_preview_cb_return, /* MUSE_CAMERA_API_PREVIEW_CB_RETURN */
5093         camera_dispatcher_set_display_reuse_hint, /* MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT */
5094         camera_dispatcher_get_display_reuse_hint, /* MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT */
5095         camera_dispatcher_change_device, /* MUSE_CAMERA_API_CHANGE_DEVICE */
5096         camera_dispatcher_get_device_state /* MUSE_CAMERA_API_GET_DEVICE_STATE */
5097 };
5098
5099
5100 /******************/
5101 /* cmd dispatcher */
5102 /******************/
5103 static int camera_cmd_dispatcher_initialize(muse_module_h module)
5104 {
5105         int item_count = 0;
5106         int i = 0;
5107         GstPlugin *plugin = NULL;
5108
5109         const char *load_list[] = {
5110                 LIBDIR"/gstreamer-1.0/libgstcoreelements.so",
5111                 LIBDIR"/gstreamer-1.0/libgstcamerasrc.so",
5112                 LIBDIR"/gstreamer-1.0/libgstwaylandsink.so",
5113         };
5114
5115         item_count = sizeof(load_list) / sizeof(load_list[0]);
5116
5117         LOGD("item count %d", item_count);
5118
5119         for (i = 0 ; i < item_count ; i++) {
5120                 plugin = gst_plugin_load_file(load_list[i], NULL);
5121                 if (plugin) {
5122                         LOGD("%s loaded", load_list[i]);
5123                         gst_object_unref(plugin);
5124                         plugin = NULL;
5125                 } else {
5126                         LOGW("failed to load %s", load_list[i]);
5127                 }
5128         }
5129
5130         LOGD("done");
5131
5132         return MUSE_CAMERA_ERROR_NONE;
5133 }
5134
5135
5136 static int camera_cmd_dispatcher_shutdown(muse_module_h module)
5137 {
5138         muse_camera_handle_s *muse_camera = NULL;
5139         camera_state_e state = CAMERA_STATE_NONE;
5140         int capture_try_count = 0;
5141         int ret = 0;
5142
5143         muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
5144         if (muse_camera == NULL) {
5145                 LOGE("NULL handle");
5146                 return MUSE_CAMERA_ERROR_INVALID;
5147         }
5148
5149         legacy_camera_lock(muse_camera->camera_handle, true);
5150
5151         if (legacy_camera_is_used(muse_camera->camera_handle)) {
5152                 LOGW("camera is used in recorder.. wait...");
5153                 if (legacy_camera_wait(muse_camera->camera_handle, 3000)) {
5154                         LOGD("recorder is released");
5155                 } else {
5156                         legacy_camera_lock(muse_camera->camera_handle, false);
5157                         LOGE("wait timeout, could not release camera handle %p", muse_camera->camera_handle);
5158                         return MUSE_CAMERA_ERROR_INVALID;
5159                 }
5160         }
5161
5162         legacy_camera_lock(muse_camera->camera_handle, false);
5163
5164         muse_camera->is_shutting_down = true;
5165
5166 again:
5167         legacy_camera_get_state(muse_camera->camera_handle, &state);
5168
5169         LOGW("current state : %d", state);
5170
5171         switch (state) {
5172         case CAMERA_STATE_CAPTURING:
5173                 if (capture_try_count < 30) {
5174                         LOGW("now capturing.. wait for capture data...");
5175                         usleep(100 * 1000);
5176                         capture_try_count++;
5177                         goto again;
5178                 } else {
5179                         LOGE("wait capture data timeout! keep going...");
5180                 }
5181                 /* fall through */
5182         case CAMERA_STATE_CAPTURED:
5183                 legacy_camera_start_preview(muse_camera->camera_handle);
5184                 /* fall through */
5185         case CAMERA_STATE_PREVIEW:
5186                 _camera_remove_export_data(module, 0, TRUE); /* force return buffer before stop preview */
5187                 legacy_camera_stop_preview(muse_camera->camera_handle);
5188                 /* fall through */
5189         case CAMERA_STATE_CREATED:
5190                 ret = legacy_camera_destroy(muse_camera->camera_handle);
5191                 if (ret == CAMERA_ERROR_NONE)
5192                         _camera_dispatcher_release_resource(module);
5193                 else
5194                         LOGE("failed to destroy camera handle");
5195
5196                 break;
5197         default:
5198                 break;
5199         }
5200
5201         LOGW("done");
5202
5203         return MUSE_CAMERA_ERROR_NONE;
5204 }
5205
5206
5207 int (*cmd_dispatcher[MUSE_MODULE_COMMAND_MAX])(muse_module_h module) = {
5208         camera_cmd_dispatcher_initialize, /* MUSE_MODULE_COMMAND_INITIALIZE */
5209         camera_cmd_dispatcher_shutdown, /* MUSE_MODULE_COMMAND_SHUTDOWN */
5210         NULL, /* MUSE_MODULE_COMMAND_DEBUG_INFO_DUMP */
5211         NULL, /* MUSE_MODULE_COMMAND_CREATE_SERVER_ACK */
5212         NULL  /* MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE */
5213 };