7db795ff82f139f9a65da0a70ca98bfa9db4b635
[apps/core/preloaded/ug-camera-efl.git] / src / cam_mm.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <string.h>
19 #include "cam_mm.h"
20 #include "cam_debug.h"
21 #include "cam_ta.h"
22 #include "cam_property.h"
23 #include "cam_typeconverter.h"
24
25 typedef struct _CamMMHandle {
26         camera_h hcam;
27         recorder_h hrec;
28         camera_device_e hdev;
29 } CamMMHandle;
30
31 static unsigned int g_caps = 0;
32 static int g_caps_cb_cnt = 0;
33
34
35 static void __get_iso_cb(camera_attr_iso_e iso, void *user_data);
36 static void __get_effect_cb(camera_attr_effect_mode_e effect, void *user_data);
37 static void __get_fps_cb(camera_attr_fps_e fps, void *user_data);
38 static void __get_wb_cb(camera_attr_whitebalance_e wb, void *user_data);
39 static void __get_focus_cb(camera_attr_af_mode_e focus, void *user_data);
40 static void __get_metering_cb(camera_attr_exposure_mode_e metering, void *user_data);
41 static void __get_scene_cb(camera_attr_scene_mode_e scene, void *user_data);
42 static void __get_flash_cb(camera_attr_flash_mode_e flash, void *user_data);
43 static void __get_capture_res_cb(int width, int height, void *user_data);
44 static void __get_recording_res_cb(int width, int height, void *user_data);
45
46
47
48 void rec_detail_error_get(int err_no)
49 {
50         switch(err_no) {
51         case RECORDER_ERROR_INVALID_PARAMETER:
52                 DEBUG_TRACE("RECORDER_ERROR_INVALID_PARAMETER");
53                 break;
54         case RECORDER_ERROR_INVALID_STATE:
55                 DEBUG_TRACE("RECORDER_ERROR_INVALID_STATE");
56                 break;
57         case RECORDER_ERROR_OUT_OF_MEMORY:
58                 DEBUG_TRACE("RECORDER_ERROR_OUT_OF_MEMORY");
59                 break;
60         case RECORDER_ERROR_DEVICE:
61                 DEBUG_TRACE("RECORDER_ERROR_DEVICE");
62                 break;
63         case RECORDER_ERROR_INVALID_OPERATION:
64                 DEBUG_TRACE("RECORDER_ERROR_INVALID_OPERATION");
65                 break;
66         case RECORDER_ERROR_SOUND_POLICY:
67                 DEBUG_TRACE("RECORDER_ERROR_SOUND_POLICY");
68                 break;
69         case RECORDER_ERROR_NONE:
70                 DEBUG_TRACE("NO ERROR");
71                 break;
72         default:
73                 DEBUG_TRACE("unknown error,err_no = %d", err_no);
74
75         }
76
77 }
78 void cam_detail_error_get(int err_no)
79 {
80         switch(err_no) {
81         case CAMERA_ERROR_INVALID_PARAMETER:
82                 DEBUG_TRACE("CAMERA_ERROR_INVALID_PARAMETER");
83                 break;
84         case CAMERA_ERROR_INVALID_STATE:
85                 DEBUG_TRACE("CAMERA_ERROR_INVALID_STATE");
86                 break;
87         case CAMERA_ERROR_OUT_OF_MEMORY:
88                 DEBUG_TRACE("CAMERA_ERROR_OUT_OF_MEMORY");
89                 break;
90         case CAMERA_ERROR_DEVICE:
91                 DEBUG_TRACE("CAMERA_ERROR_DEVICE");
92                 break;
93         case CAMERA_ERROR_INVALID_OPERATION:
94                 DEBUG_TRACE("CAMERA_ERROR_INVALID_OPERATION");
95                 break;
96         case CAMERA_ERROR_SOUND_POLICY:
97                 DEBUG_TRACE("CAMERA_ERROR_SOUND_POLICY");
98                 break;
99         case CAMERA_ERROR_NONE:
100                 DEBUG_TRACE("NO ERROR");
101                 break;
102         default:
103                 DEBUG_TRACE("unknown error,err_no = %d", err_no);
104
105         }
106 }
107
108
109 static CamMMHandle *g_mm_handle = NULL;
110
111 int cam_mm_get_cam_state(void)
112 {
113         g_return_val_if_fail(g_mm_handle, FALSE);
114         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
115         int ret = 0;
116         camera_state_e state = 0;
117         ret = camera_get_state(g_mm_handle->hcam, &state);
118         if (ret == CAMERA_ERROR_NONE)
119                 return (int)state;
120         else
121                 return -1;
122 }
123
124 int cam_mm_get_state(void)
125 {
126         g_return_val_if_fail(g_mm_handle, FALSE);
127         int ret = 0;
128         camera_state_e state = 0;
129         struct appdata *ad =  (struct appdata *)cam_appdata_get();
130         g_return_val_if_fail(ad, FALSE);
131         CamAppData *camapp = ad->camapp_handle;
132         g_return_val_if_fail(camapp, FALSE);
133         if (camapp->camera_mode == CAM_CAMERA_MODE) {
134                 g_return_val_if_fail(g_mm_handle->hcam, FALSE);
135                 ret = camera_get_state(g_mm_handle->hcam, (camera_state_e *)&state);
136                 if (ret == CAMERA_ERROR_NONE)
137                         return (int)state;
138                 else
139                         return -1;
140         }
141         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
142                 g_return_val_if_fail(g_mm_handle->hrec, FALSE);
143                 ret = recorder_get_state(g_mm_handle->hrec, (recorder_state_e *)&state);
144                 if (ret == RECORDER_ERROR_NONE)
145                         return (int)state;
146                 else
147                         return -1;
148         }
149         return -1;
150 }
151
152 int cam_mm_get_rec_state(void)
153 {
154         g_return_val_if_fail(g_mm_handle, FALSE);
155         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
156         int ret = 0;
157         recorder_state_e state = 0;
158         ret = recorder_get_state(g_mm_handle->hrec, (recorder_state_e *)&state);
159         if (ret == RECORDER_ERROR_NONE)
160                 return (int)state;
161         else
162                 return -1;
163 }
164
165 gboolean cam_mm_get_video_device(int *device)
166 {
167         g_return_val_if_fail(g_mm_handle, FALSE);
168
169         if (g_mm_handle->hdev > CAMERA_DEVICE_CAMERA1)
170                 return FALSE;
171
172         *device = g_mm_handle->hdev;
173         DEBUG_TRACE("%d,%d",g_mm_handle->hdev,*device);
174         return TRUE;
175 }
176
177 gboolean cam_mm_get_video_size(int *width, int *height)
178 {
179         int ret = 0;
180         g_return_val_if_fail(g_mm_handle, FALSE);
181         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
182         ret = camera_get_preview_resolution(g_mm_handle->hcam,  width, height);
183
184         if (ret != CAMERA_ERROR_NONE) {
185                 DEBUG_TRACE("camera_get_preview_resolution error code = %d" , ret);
186                 return FALSE;
187         }
188
189         return TRUE;
190 }
191
192 gboolean cam_mm_set_video_size(int width, int height)
193 {
194         int ret = 0;
195         g_return_val_if_fail(g_mm_handle, FALSE);
196         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
197
198         ret = camera_set_preview_resolution(g_mm_handle->hcam, width, height);
199
200         if (ret != CAMERA_ERROR_NONE) {
201                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
202                 return FALSE;
203         }
204         return TRUE;
205 }
206
207 gboolean cam_mm_get_zoom(int *value)
208 {
209         int ret = 0;
210         g_return_val_if_fail(g_mm_handle, FALSE);
211         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
212         ret = camera_attr_get_zoom(g_mm_handle->hcam, value);
213         if (ret) {
214
215                 return FALSE;
216         }
217         return TRUE;
218 }
219
220 gboolean cam_mm_set_zoom(int value)
221 {
222         int ret = 0;
223         g_return_val_if_fail(g_mm_handle, FALSE);
224         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
225
226         ret = camera_attr_set_zoom(g_mm_handle->hcam, value);
227         if (ret) {
228
229                 return FALSE;
230         }
231         return TRUE;
232 }
233
234 gboolean cam_mm_get_wdr(int *value)
235 {
236 /*TODO:we do not need set this attribute now*/
237 #ifdef TODO_SURRPORT
238         return TRUE;
239 #endif
240 }
241
242 gboolean cam_mm_set_wdr(int value)
243 {
244 /*TODO:we do not need set this attribute now*/
245 #ifdef TODO_SURRPORT
246         return TRUE;
247 #endif
248 }
249
250 gboolean cam_mm_is_support_anti_hand_shake()
251 {
252         bool ret = 0;
253         g_return_val_if_fail(g_mm_handle, FALSE);
254         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
255
256         ret = camera_attr_is_supported_anti_shake(g_mm_handle->hcam);
257
258         return ret;
259
260 }
261
262 gboolean cam_mm_get_anti_hand_shake(gboolean *value)
263 {
264         int ret = 0;
265         g_return_val_if_fail(g_mm_handle, FALSE);
266         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
267
268         ret = camera_attr_is_enabled_anti_shake(g_mm_handle->hcam, (bool *)value);
269         if (ret != CAMERA_ERROR_NONE) {
270                 return FALSE;
271         }
272         return TRUE;
273
274 }
275
276 gboolean cam_mm_set_anti_hand_shake(gboolean value)
277 {
278         int ret = 0;
279         g_return_val_if_fail(g_mm_handle, FALSE);
280         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
281
282         ret = camera_attr_enable_anti_shake(g_mm_handle->hcam, value);
283         if (ret != CAMERA_ERROR_NONE) {
284                 return FALSE;
285         }
286         return  TRUE;
287
288 }
289
290 gboolean cam_mm_get_auto_exposure(int *value)
291 {
292         int ret = 0;
293         g_return_val_if_fail(g_mm_handle, FALSE);
294         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
295
296         ret = camera_attr_get_exposure_mode(g_mm_handle->hcam, (camera_attr_exposure_mode_e *)value);
297         if (ret != CAMERA_ERROR_NONE) {
298                 return FALSE;
299         }
300         return TRUE;
301 }
302
303 gboolean cam_mm_set_auto_exposure(int value)
304 {
305         int ret = 0;
306         g_return_val_if_fail(g_mm_handle, FALSE);
307         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
308
309         ret = camera_attr_set_exposure_mode(g_mm_handle->hcam, (camera_attr_exposure_mode_e)value);
310         if (ret != CAMERA_ERROR_NONE) {
311                 return FALSE;
312         }
313         return TRUE;
314 }
315
316 gboolean cam_mm_set_fps(camera_attr_fps_e value)
317 {
318         int ret = 0;
319         g_return_val_if_fail(g_mm_handle, FALSE);
320         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
321
322         ret = camera_attr_set_preview_fps(g_mm_handle->hcam, value);
323         if (ret != CAMERA_ERROR_NONE) {
324                 cam_detail_error_get(ret);
325                 return FALSE;
326         }
327         return TRUE;
328 }
329
330 gboolean cam_mm_get_iso(int *value)
331 {
332         int ret = 0;
333         g_return_val_if_fail(g_mm_handle, FALSE);
334         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
335
336         ret = camera_attr_get_iso(g_mm_handle->hcam, (camera_attr_iso_e *)value);
337         if (ret != CAMERA_ERROR_NONE) {
338                 return FALSE;
339         }
340         return TRUE;
341 }
342
343 gboolean cam_mm_set_iso(int value)
344 {
345         int ret = 0;
346         g_return_val_if_fail(g_mm_handle, FALSE);
347         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
348
349         ret = camera_attr_set_iso(g_mm_handle->hcam, (camera_attr_iso_e)value);
350         if (ret != CAMERA_ERROR_NONE) {
351                 return FALSE;
352         }
353         return TRUE;
354 }
355
356 gboolean cam_mm_get_focus_mode(int *value)
357 {
358         int ret = 0;
359         g_return_val_if_fail(g_mm_handle, FALSE);
360         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
361
362         ret = camera_attr_get_af_mode(g_mm_handle->hcam, (camera_attr_af_mode_e *)value);
363         if (ret != CAMERA_ERROR_NONE) {
364
365                 return FALSE;
366         }
367         return TRUE;
368
369 }
370
371 gboolean cam_mm_set_focus_mode(int value)
372 {
373         int ret = 0;
374         ret = camera_attr_set_af_mode(g_mm_handle->hcam, (camera_attr_af_mode_e)value);
375         if (ret != CAMERA_ERROR_NONE) {
376
377                 return FALSE;
378         }
379         return TRUE;
380 }
381
382 gboolean cam_mm_get_zoom_valid_intrange(int *min, int *max)
383 {
384         int ret = 0;
385         g_return_val_if_fail(g_mm_handle, FALSE);
386         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
387
388         ret = camera_attr_get_zoom_range(g_mm_handle->hcam, min, max);
389         if (ret != CAMERA_ERROR_NONE) {
390
391                 return FALSE;
392         }
393
394         return TRUE;
395
396 }
397
398 gboolean cam_mm_get_brightless_valid_intrange(int *min, int *max)
399 {
400         int ret = 0;
401         g_return_val_if_fail(g_mm_handle, FALSE);
402         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
403
404         ret = camera_attr_get_brightness_range(g_mm_handle->hcam, min, max);
405         if (ret != CAMERA_ERROR_NONE) {
406
407                 return FALSE;
408         }
409
410         return TRUE;
411
412 }
413
414 gboolean cam_mm_get_exposure_valid_intrange(int *min, int *max)
415 {
416         int ret = 0;
417         g_return_val_if_fail(g_mm_handle, FALSE);
418         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
419
420         ret = camera_attr_get_exposure_range(g_mm_handle->hcam, min, max);
421         if (ret != CAMERA_ERROR_NONE) {
422
423                 return FALSE;
424         }
425
426         return TRUE;
427
428 }
429
430 gboolean cam_mm_set_af_area(int x, int y, int w, int h)
431 {
432         int ret = 0;
433         g_return_val_if_fail(g_mm_handle, FALSE);
434         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
435
436         DEBUG_TRACE("\n Touch AF area ![ x,y,width,height: %d,%d,%d,%d ]\n", x, y, w, h);
437
438         ret = camera_attr_set_af_area(g_mm_handle->hcam, x, y);
439         if (ret != CAMERA_ERROR_NONE) {
440                 DEBUG_TRACE("camera_attr_set_af_area failed [%d]\n", ret);
441                 return FALSE;
442         }
443         return TRUE;
444
445 }
446
447 gboolean cam_mm_get_detect_mode(int *value)
448 {
449 #ifndef TODO_SURRPORT
450 /*TODO:framework not surrport it*/
451 #endif
452         return TRUE;
453 }
454
455 gboolean cam_mm_set_detect_mode(int value)
456 {
457 /*TODO:libmm-camcorder not surrport it*/
458 #ifdef TODO_SURRPORT
459         return TRUE;
460 #endif
461 }
462
463 gboolean cam_mm_get_image_enc_quality(int *value)
464 {
465         int ret = 0;
466         g_return_val_if_fail(g_mm_handle, FALSE);
467         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
468
469         ret = camera_attr_get_image_quality(g_mm_handle->hcam, value);
470         if (ret != CAMERA_ERROR_NONE) {
471
472                 return FALSE;
473         }
474         return TRUE;
475
476 }
477
478 gboolean cam_mm_set_image_enc_quality(int value)
479 {
480         int ret = 0;
481         g_return_val_if_fail(g_mm_handle, FALSE);
482         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
483
484         ret = camera_attr_set_image_quality(g_mm_handle->hcam, value);
485         if (ret != CAMERA_ERROR_NONE) {
486
487                 return FALSE;
488         }
489         return TRUE;
490
491 }
492
493 gboolean cam_mm_get_flash(int *value)
494 {
495         int ret = 0;
496         g_return_val_if_fail(g_mm_handle, FALSE);
497         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
498
499         ret = camera_attr_get_flash_mode(g_mm_handle->hcam, (camera_attr_flash_mode_e *)value);
500         if (ret != CAMERA_ERROR_NONE) {
501
502                 return FALSE;
503         }
504         return TRUE;
505 }
506
507 gboolean cam_mm_set_flash(int value)
508 {
509         int ret = 0;
510         g_return_val_if_fail(g_mm_handle, FALSE);
511         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
512
513         ret = camera_attr_set_flash_mode(g_mm_handle->hcam, (camera_attr_flash_mode_e)value);
514         if (ret != CAMERA_ERROR_NONE) {
515
516                 return FALSE;
517         }
518         return TRUE;
519 }
520
521 gboolean cam_mm_enable_auto_contrast(gboolean enable)
522 {
523         int ret = 0;
524         g_return_val_if_fail(g_mm_handle, FALSE);
525         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
526
527         ret = camera_attr_enable_auto_contrast(g_mm_handle->hcam, enable);
528         if (ret != CAMERA_ERROR_NONE) {
529
530                 return FALSE;
531         }
532         return TRUE;
533 }
534
535 gboolean cam_mm_is_enabled_auto_contrast(gboolean *enable)
536 {
537         int ret = 0;
538         g_return_val_if_fail(g_mm_handle, FALSE);
539         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
540
541         ret = camera_attr_is_enabled_auto_contrast(g_mm_handle->hcam, (bool *)enable);
542         if (ret != CAMERA_ERROR_NONE) {
543
544                 return FALSE;
545         }
546         return TRUE;
547 }
548
549 gboolean cam_mm_get_brightness(int *value)
550 {
551         int ret = 0;
552         g_return_val_if_fail(g_mm_handle, FALSE);
553         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
554
555         ret = camera_attr_get_brightness(g_mm_handle->hcam, value);
556         if (ret != CAMERA_ERROR_NONE) {
557
558                 return FALSE;
559         }
560         return TRUE;
561
562 }
563
564 gboolean cam_mm_set_brightness(int value)
565 {
566         int ret = 0;
567         g_return_val_if_fail(g_mm_handle, FALSE);
568         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
569
570         ret = camera_attr_set_brightness(g_mm_handle->hcam, value);
571         if (ret != CAMERA_ERROR_NONE) {
572
573                 return FALSE;
574         }
575         return TRUE;
576 }
577
578 gboolean cam_mm_get_white_balance(int *value)
579 {
580         int ret = 0;
581         g_return_val_if_fail(g_mm_handle, FALSE);
582         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
583
584         ret = camera_attr_get_whitebalance(g_mm_handle->hcam, (camera_attr_whitebalance_e *)value);
585         if (ret != CAMERA_ERROR_NONE) {
586
587                 return FALSE;
588         }
589         return TRUE;
590 }
591
592 gboolean cam_mm_set_white_balance(int value)
593 {
594         int ret = 0;
595         g_return_val_if_fail(g_mm_handle, FALSE);
596         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
597
598         ret = camera_attr_set_whitebalance(g_mm_handle->hcam, (camera_attr_whitebalance_e)value);
599         if (ret != CAMERA_ERROR_NONE) {
600
601                 return FALSE;
602         }
603         return TRUE;
604 }
605
606 gboolean cam_mm_get_effect(int *value)
607 {
608         int ret = 0;
609         g_return_val_if_fail(g_mm_handle, FALSE);
610         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
611
612         ret = camera_attr_get_effect(g_mm_handle->hcam, (camera_attr_effect_mode_e *)value);
613         if (ret != CAMERA_ERROR_NONE) {
614
615                 return FALSE;
616         }
617         return TRUE;
618
619 }
620
621 gboolean cam_mm_set_effect(int value)
622 {
623         int ret = 0;
624         g_return_val_if_fail(g_mm_handle, FALSE);
625         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
626
627         ret = camera_attr_set_effect(g_mm_handle->hcam, (camera_attr_effect_mode_e)value);
628         if (ret != CAMERA_ERROR_NONE) {
629
630                 return FALSE;
631         }
632         return TRUE;
633
634 }
635
636 gboolean cam_mm_get_program_mode(int *value)
637 {
638         int ret = 0;
639         g_return_val_if_fail(g_mm_handle, FALSE);
640         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
641
642         ret = camera_attr_get_scene_mode(g_mm_handle->hcam, (camera_attr_scene_mode_e *)value);
643         if (ret != CAMERA_ERROR_NONE) {
644
645                 return FALSE;
646         }
647         return TRUE;
648
649 }
650
651 gboolean cam_mm_set_program_mode(int value)
652 {
653         int ret = 0;
654         g_return_val_if_fail(g_mm_handle, FALSE);
655         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
656
657         ret = camera_attr_set_scene_mode(g_mm_handle->hcam, value);
658         if (ret != CAMERA_ERROR_NONE) {
659
660                 return FALSE;
661         }
662         return TRUE;
663
664 }
665
666 gboolean cam_mm_set_outdoor_visibility(gboolean on)
667 {
668         int scenario = -1;
669
670         if (cam_mm_get_mdnie_mode(&scenario) == FALSE || scenario != SCENARIO_CAMERA) {
671                 if (cam_mm_set_mdnie_mode(TRUE) == FALSE) {
672                         cam_critical(LOG_MM, "device_set_image_enhance_scenario() fail");
673                         return FALSE;
674                 }
675         }
676
677         if (on) {
678                 if (device_set_image_enhance_outdoor(OUTDOOR_ON) < 0) {
679                         cam_critical(LOG_MM, "device_set_image_enhance_outdoor(on) fail");
680                         return FALSE;
681                 }
682         } else {
683                 if (device_set_image_enhance_outdoor(OUTDOOR_OFF) < 0) {
684                         cam_critical(LOG_MM, "device_set_image_enhance_outdoor(off) fail");
685                         return FALSE;
686                 }
687         }
688
689         return TRUE;
690 }
691
692 gboolean cam_mm_get_outdoor_visibility(gboolean *on)
693 {
694         int val = -1;
695         if ((val = device_get_image_enhance_outdoor()) < 0)
696                 return FALSE;
697         if (val == OUTDOOR_OFF)
698                 *on = FALSE;
699         else
700                 *on = TRUE;
701         return TRUE;
702 }
703
704
705 gboolean cam_mm_is_supported_outdoor_visibility(void)
706 {
707         if (device_get_image_enhance_info() < 0)
708                 return FALSE;
709
710         return TRUE;
711 }
712
713 gboolean cam_mm_set_mdnie_mode(gboolean on)
714 {
715         DEBUG_TRACE("mode :%d", on);
716         if (cam_mm_is_supported_outdoor_visibility()) {
717
718                 if (on) {
719                         if (device_set_image_enhance_scenario(SCENARIO_CAMERA) < 0) {
720                                 cam_critical(LOG_MM, "device_set_image_enhance_scenario(SCENARIO_CAMERA) fail");
721                                 return FALSE;
722                         }
723                 } else {
724                         if (device_set_image_enhance_scenario(SCENARIO_UI) < 0) {
725                                 cam_critical(LOG_MM, "device_set_image_enhance_scenario(SCENARIO_UI) fail");
726                                 return FALSE;
727                         }
728                 }
729         } else {
730                 cam_critical(LOG_MM, "cam_mm_is_supported_outdoor_visibility() false");
731                 return FALSE;
732         }
733
734         return TRUE;
735 }
736
737 gboolean cam_mm_get_mdnie_mode(int *val)
738 {
739         int ret = -1;
740         if ((ret = device_get_image_enhance_scenario()) < 0) {
741                 cam_critical(LOG_MM, "device_get_image_enhance_scenario() fail");
742                 return FALSE;
743         }
744
745         *val = ret;
746         return TRUE;
747 }
748
749
750
751 gboolean cam_mm_set_audio_recording(gboolean b_on)
752 {
753         int ret = 0;
754
755         g_return_val_if_fail(g_mm_handle, FALSE);
756         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
757         if (b_on)
758                 ret = recorder_attr_set_mute(g_mm_handle->hrec, FALSE);
759         else
760                 ret = recorder_attr_set_mute(g_mm_handle->hrec, TRUE);
761
762         if (ret != RECORDER_ERROR_NONE) {
763                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
764                 return FALSE;
765         }
766         return TRUE;
767
768 }
769
770 gboolean cam_mm_set_image_count(int value)
771 {
772         return TRUE;
773 }
774
775 gboolean cam_mm_get_recommanded_preview_size(int *width, int *height)
776 {
777         int ret = 0;
778         g_return_val_if_fail(g_mm_handle, FALSE);
779         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
780
781         ret = camera_get_recommended_preview_resolution(g_mm_handle->hcam,      width, height);
782
783         if (ret != CAMERA_ERROR_NONE) {
784                 DEBUG_TRACE("camera_get_recommended_preview_resolution failed - code[%x] name[%s]\n", ret);
785                 return FALSE;
786         }
787         return TRUE;
788 }
789
790
791 gboolean cam_mm_get_image_size(int *width, int *height)
792 {
793         int ret = 0;
794         g_return_val_if_fail(g_mm_handle, FALSE);
795         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
796
797         ret = camera_get_capture_resolution(g_mm_handle->hcam, width, height);
798
799         if (ret != CAMERA_ERROR_NONE) {
800                 DEBUG_TRACE("set attr failed - code[%x] name[%s]\n", ret);
801                 return FALSE;
802         }
803         return TRUE;
804 }
805
806 gboolean cam_mm_set_image_size(int width, int height)
807 {
808         int ret = 0;
809         g_return_val_if_fail(g_mm_handle, FALSE);
810         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
811
812         g_return_val_if_fail(g_mm_handle, FALSE);
813         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
814
815         ret = camera_set_capture_resolution(g_mm_handle->hcam, width, height);
816
817         if (ret != CAMERA_ERROR_NONE) {
818                 DEBUG_TRACE("cam_mm_set_image_size failed");
819                 return FALSE;
820         }
821         return TRUE;
822 }
823
824 gboolean cam_mm_set_video_encoder_bitrate(int bitrate)
825 {
826         recorder_error_e ret;
827         g_return_val_if_fail(g_mm_handle, FALSE);
828         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
829
830         ret = recorder_attr_set_video_encoder_bitrate(g_mm_handle->hrec, bitrate);
831         if (ret != RECORDER_ERROR_NONE) {
832                 return FALSE;
833         }
834         return TRUE;
835 }
836
837 gboolean cam_mm_set_audio_encoder_bitrate(int bitrate)
838 {
839         recorder_error_e ret;
840         g_return_val_if_fail(g_mm_handle, FALSE);
841         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
842
843         ret = recorder_attr_set_audio_encoder_bitrate(g_mm_handle->hrec, bitrate);
844         if (ret != RECORDER_ERROR_NONE) {
845                 return FALSE;
846         }
847         return TRUE;
848 }
849
850 gboolean cam_mm_set_display_device(int display_device, void *xid)
851 {
852         int ret;
853         g_return_val_if_fail(g_mm_handle, FALSE);
854         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
855
856         ret = camera_set_display(g_mm_handle->hcam, display_device, xid);
857         if (ret != CAMERA_ERROR_NONE) {
858
859                 return FALSE;
860         }
861         return TRUE;
862 }
863
864 gboolean cam_mm_set_display_rotate(int rotate)
865 {
866         int ret;
867         g_return_val_if_fail(g_mm_handle, FALSE);
868         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
869
870         ret = camera_set_x11_display_rotation(g_mm_handle->hcam, rotate);
871         if (ret != CAMERA_ERROR_NONE) {
872
873                 return FALSE;
874         }
875         return TRUE;
876 }
877
878 gboolean cam_mm_set_camera_rotate(int camera_rotate)
879 {
880         int ret;
881         g_return_val_if_fail(g_mm_handle, FALSE);
882         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
883
884         #ifdef CAMERA_MACHINE_I686
885         ret = camera_attr_set_stream_rotation(g_mm_handle->hcam, 0);
886         #else
887         ret = camera_attr_set_stream_rotation(g_mm_handle->hcam, camera_rotate);
888         #endif
889         if (ret != CAMERA_ERROR_NONE) {
890                 cam_detail_error_get(ret);
891                 return FALSE;
892         }
893         return TRUE;
894
895 }
896
897 gboolean cam_mm_get_display_geometry_method(int *value)
898 {
899         int ret;
900         g_return_val_if_fail(g_mm_handle, FALSE);
901         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
902
903         ret = camera_get_x11_display_mode(g_mm_handle->hcam, (camera_display_mode_e *)value);
904         if (ret != CAMERA_ERROR_NONE) {
905                 return FALSE;
906         }
907         return TRUE;
908
909 }
910
911 gboolean cam_mm_set_display_geometry_method(int value)
912 {
913         int ret;
914         g_return_val_if_fail(g_mm_handle, FALSE);
915         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
916
917         ret = camera_set_x11_display_mode(g_mm_handle->hcam, (camera_display_mode_e)value);
918         if (ret != CAMERA_ERROR_NONE) {
919                 return FALSE;
920         }
921         return TRUE;
922 }
923
924 gboolean cam_mm_set_display_visible(gboolean visible)
925 {
926         int ret = 0;
927
928         g_return_val_if_fail(g_mm_handle, FALSE);
929         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
930
931         ret = camera_set_x11_display_visible(g_mm_handle->hcam, visible);
932         if (ret != RECORDER_ERROR_NONE) {
933                 return FALSE;
934         }
935         return TRUE;
936
937 }
938
939 gboolean cam_mm_set_filename(const gchar *filename)
940 {
941         int ret = 0;
942         /*char *err_name = NULL;*/
943
944         g_return_val_if_fail(g_mm_handle, FALSE);
945         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
946
947         if (filename) {
948                 ret = recorder_set_filename(g_mm_handle->hrec, filename);
949                 if (ret != RECORDER_ERROR_NONE) {
950                         return FALSE;
951                 }
952                 return TRUE;
953
954         } else {
955                 return FALSE;
956         }
957         return TRUE;
958 }
959
960 gboolean cam_mm_get_filename(char **filename, gint *size)
961 {
962         int ret = 0;
963
964         g_return_val_if_fail(g_mm_handle, FALSE);
965         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
966
967         ret = recorder_get_filename(g_mm_handle->hrec, filename);
968         if (ret != RECORDER_ERROR_NONE) {
969                 return FALSE;
970         }
971         return TRUE;
972
973 }
974
975 gboolean cam_mm_get_max_size(int *value)
976 {
977         recorder_error_e ret;
978         g_return_val_if_fail(g_mm_handle, FALSE);
979         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
980         ret = recorder_attr_get_time_limit(g_mm_handle->hrec, value);
981         if (ret != RECORDER_ERROR_NONE) {
982                 return  FALSE;
983
984         }
985         return TRUE;
986 }
987
988 gboolean cam_mm_get_max_time(int *value)
989 {
990         recorder_error_e ret;
991         g_return_val_if_fail(g_mm_handle, FALSE);
992         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
993
994         ret = recorder_attr_get_time_limit(g_mm_handle->hrec, value);
995         if (ret != RECORDER_ERROR_NONE) {
996                 return  FALSE;
997
998         }
999         return TRUE;
1000
1001 }
1002
1003 gboolean cam_mm_set_max_size(int max_val)
1004 {
1005
1006         recorder_error_e ret;
1007         g_return_val_if_fail(g_mm_handle, FALSE);
1008         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1009
1010         ret = recorder_attr_set_size_limit(g_mm_handle->hrec, max_val);
1011         if (ret != RECORDER_ERROR_NONE) {
1012                 return  FALSE;
1013
1014         }
1015         return TRUE;
1016 }
1017
1018 gboolean cam_mm_set_max_time(int max_val)
1019 {
1020         recorder_error_e ret;
1021         g_return_val_if_fail(g_mm_handle, FALSE);
1022         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1023         ret = recorder_attr_set_time_limit(g_mm_handle->hrec, max_val);
1024         if (ret != RECORDER_ERROR_NONE) {
1025                 return  FALSE;
1026
1027         }
1028         return TRUE;
1029 }
1030
1031 gboolean cam_mm_get_tag_enable(int *value)
1032 {
1033         int ret;
1034         g_return_val_if_fail(g_mm_handle, FALSE);
1035         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1036
1037         ret = camera_attr_is_enabled_tag(g_mm_handle->hcam, (bool *)value);
1038         if (ret != CAMERA_ERROR_NONE) {
1039                 return FALSE;
1040         }
1041
1042         return TRUE;
1043
1044 }
1045
1046 gboolean cam_mm_set_tag_enable(gboolean bvalue)
1047 {
1048         int ret;
1049         g_return_val_if_fail(g_mm_handle, FALSE);
1050         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1051
1052         ret = camera_attr_enable_tag(g_mm_handle->hcam, (bool)bvalue);
1053         if (ret != CAMERA_ERROR_NONE) {
1054                 return FALSE;
1055         }
1056
1057         return TRUE;
1058 }
1059
1060 gboolean cam_mm_set_tag_img_orient(int orient)
1061 {
1062         g_return_val_if_fail(g_mm_handle, FALSE);
1063         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1064         camera_error_e ret;
1065         ret = camera_attr_set_tag_orientation(g_mm_handle->hcam, (camera_attr_tag_orientation_e)orient);
1066         if (ret != CAMERA_ERROR_NONE) {
1067                 cam_detail_error_get(ret);
1068                 return  FALSE;
1069
1070         }
1071         return TRUE;
1072
1073 }
1074
1075 gboolean cam_mm_set_file_format(int format)
1076 {
1077         recorder_error_e ret;
1078         g_return_val_if_fail(g_mm_handle, FALSE);
1079         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1080         ret = recorder_set_file_format(g_mm_handle->hrec, format);
1081         if (ret != RECORDER_ERROR_NONE) {
1082                 DEBUG_TRACE("recorder_set_file_format failed - [%d]", ret);
1083                 return  FALSE;
1084
1085         }
1086         return TRUE;
1087 }
1088
1089 gboolean cam_mm_set_video_profile(void)
1090 {
1091         recorder_error_e e;
1092
1093         g_return_val_if_fail(g_mm_handle, FALSE);
1094         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1095
1096         e = recorder_attr_set_audio_device(g_mm_handle->hrec, RECORDER_AUDIO_DEVICE_MIC);
1097         if (e != RECORDER_ERROR_NONE) {
1098                 DEBUG_TRACE("set attr failed - code[%x]\n", e);
1099                 rec_detail_error_get(e);
1100                 return FALSE;
1101         }
1102
1103         return TRUE;
1104 }
1105
1106 gboolean cam_mm_set_codec(int audio_codec, int video_codec)
1107 {
1108         int ret = 0;
1109         recorder_error_e e;
1110         g_return_val_if_fail(g_mm_handle, FALSE);
1111         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1112
1113         e = recorder_set_audio_encoder(g_mm_handle->hrec, audio_codec);
1114         if (e != RECORDER_ERROR_NONE) {
1115                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
1116                 rec_detail_error_get(ret);
1117                 return FALSE;
1118         }
1119         e = recorder_set_video_encoder(g_mm_handle->hrec, video_codec);
1120         if (e != RECORDER_ERROR_NONE) {
1121                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
1122                 return FALSE;
1123         }
1124         return TRUE;
1125 }
1126
1127 gboolean cam_mm_set_audio_source(int sample_rate, int channel)
1128 {
1129         int ret = 0;
1130         recorder_error_e e;
1131         g_return_val_if_fail(g_mm_handle, FALSE);
1132         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1133         e = recorder_attr_set_audio_samplerate(g_mm_handle->hrec, sample_rate);
1134         if (e != RECORDER_ERROR_NONE) {
1135                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
1136                 return FALSE;
1137         }
1138         e = recorder_attr_set_audio_channel(g_mm_handle->hrec, channel);
1139         if (e != RECORDER_ERROR_NONE) {
1140                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
1141                 return FALSE;
1142         }
1143         return TRUE;
1144 }
1145
1146 gboolean cam_mm_set_video_source_format(int format)
1147 {
1148         if (format <= CAMERA_PIXEL_FORMAT_INVALID || format > CAMERA_PIXEL_FORMAT_JPEG)
1149                 return FALSE;
1150
1151         int err;
1152         g_return_val_if_fail(g_mm_handle, FALSE);
1153         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1154         err = camera_set_preview_format(g_mm_handle->hcam, format);
1155
1156         DEBUG_TRACE("!!!!!!!!!!!!!!!! format:%d !!!!!!!!!!!!!!!!!!!", format);
1157         if (err != CAMERA_ERROR_NONE) {
1158
1159                 return FALSE;
1160         }
1161         return TRUE;
1162 }
1163
1164 gboolean cam_mm_get_video_source_format(const char *attribute_name, int *format)
1165 {
1166         DEBUG_TRACE("attribute_name = %s", attribute_name);
1167         int err;
1168         g_return_val_if_fail(g_mm_handle, FALSE);
1169         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1170         err = camera_get_preview_format(g_mm_handle->hcam, format);
1171         if (err != CAMERA_ERROR_NONE) {
1172
1173                 return FALSE;
1174         }
1175         return TRUE;
1176 }
1177
1178 gboolean  cam_mm_get_front_cam_display_rotate_value(int *value, int *rotate)
1179 {
1180         int err;
1181         g_return_val_if_fail(g_mm_handle, FALSE);
1182         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1183         err = camera_attr_get_lens_orientation(g_mm_handle->hcam, value);
1184         switch (*value) {
1185         case 0:
1186                 *rotate = CAMERA_ROTATION_NONE;
1187                 break;
1188         case 90:
1189                 *rotate = CAMERA_ROTATION_90;
1190                 break;
1191         case 180:
1192                 *rotate = CAMERA_ROTATION_180;
1193                 break;
1194         case 270:
1195                 *rotate = CAMERA_ROTATION_270;
1196                 break;
1197         default:
1198                 *rotate = CAMERA_ROTATION_NONE;
1199
1200         }
1201         if (err != CAMERA_ERROR_NONE) {
1202
1203                 return FALSE;
1204         }
1205
1206         return TRUE;
1207
1208 }
1209
1210 gboolean cam_mm_get_scene_mode(camera_attr_scene_mode_e *mode)
1211 {
1212         int err;
1213         g_return_val_if_fail(g_mm_handle, FALSE);
1214         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1215         err = camera_attr_get_scene_mode(g_mm_handle->hcam, mode);
1216         if (err != CAMERA_ERROR_NONE) {
1217                 return FALSE;
1218         }
1219
1220         return TRUE;
1221 }
1222
1223 gboolean cam_mm_set_scene_mode(camera_attr_scene_mode_e mode)
1224 {
1225         int err;
1226         g_return_val_if_fail(g_mm_handle, FALSE);
1227         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1228         err = camera_attr_set_scene_mode(g_mm_handle->hcam, mode);
1229         if (err != CAMERA_ERROR_NONE) {
1230                 return FALSE;
1231         }
1232         return TRUE;
1233 }
1234
1235 gboolean cam_mm_set_conti_shot_break(gboolean bvalue)
1236 {
1237         int err;
1238         g_return_val_if_fail(g_mm_handle, FALSE);
1239         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1240         if (bvalue) {
1241                 err = camera_stop_continuous_capture(g_mm_handle->hcam);
1242                 if (err != CAMERA_ERROR_NONE) {
1243
1244                         return FALSE;
1245                 }
1246         }
1247         return TRUE;
1248 }
1249
1250 gboolean cam_mm_set_capture_format(int value)
1251 {
1252         int err;
1253         g_return_val_if_fail(g_mm_handle, FALSE);
1254         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1255
1256         err = camera_set_capture_format(g_mm_handle->hcam, value);
1257         if (err != CAMERA_ERROR_NONE) {
1258
1259                 return FALSE;
1260         }
1261
1262         return TRUE;
1263 }
1264
1265 gboolean cam_mm_get_shutter_sound(int *value)
1266 {
1267 /*todo:for lawer policy, capi could not surport it*/
1268 #ifndef TODO_SURRPORT
1269         return cam_mm_get_attr_int(MMCAM_SHUTTER_SOUND, value);
1270 #else
1271         return TRUE;
1272 #endif
1273
1274 }
1275 gboolean cam_mm_set_shutter_sound(int value)
1276 {
1277 /*todo:for lawer policy, capi could not surport it*/
1278 #ifndef TODO_SURRPORT
1279         return cam_mm_set_attr_int(MMCAM_SHUTTER_SOUND, value);
1280 #else
1281         return TRUE;
1282 #endif
1283
1284 }
1285
1286 gboolean cam_mm_remove_geo_tag(void)
1287 {
1288         g_return_val_if_fail(g_mm_handle, FALSE);
1289         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1290 #ifdef TODO_SURRPORT
1291         int ret = 0;
1292         ret = camera_attr_remove_geotag(g_mm_handle->hcam);
1293         if (ret != CAMERA_ERROR_NONE) {
1294                 return FALSE;
1295         }
1296 #endif /*TODO:capi has issue.if it fix, I will open it*/
1297         return TRUE;
1298 }
1299
1300 gboolean cam_mm_enable_geo_tag(gboolean value)
1301 {
1302         int ret = 0;
1303         g_return_val_if_fail(g_mm_handle, FALSE);
1304         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1305         if (value) {
1306                 ret = camera_attr_set_geotag(g_mm_handle->hcam, -1.0, -1.0, -1.0);
1307         } else {
1308                 ret = camera_attr_remove_geotag(g_mm_handle->hcam);
1309         }
1310         if (ret != CAMERA_ERROR_NONE) {
1311                 return FALSE;
1312         }
1313         return TRUE;
1314 }
1315
1316 gboolean cam_mm_reset_recording_motion_fps()
1317 {
1318         int ret = 0;
1319         g_return_val_if_fail(g_mm_handle, FALSE);
1320         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1321
1322         ret = recorder_attr_set_recording_motion_rate(g_mm_handle->hrec, DEFAULT_REC_FPS);
1323         if (ret != RECORDER_ERROR_NONE) {
1324
1325                 return FALSE;
1326         }
1327         return TRUE;
1328 }
1329
1330 gboolean cam_mm_set_gps_data(double lat, double lon, double alt)
1331 {
1332         camera_error_e e;
1333         g_return_val_if_fail(g_mm_handle, FALSE);
1334         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1335         e = camera_attr_set_geotag(g_mm_handle->hcam, lat, lon, alt);
1336         if (e != CAMERA_ERROR_NONE) {
1337                 return FALSE;
1338         }
1339         return TRUE;
1340 }
1341
1342 gboolean cam_mm_is_preview_started(int mode)
1343 {
1344         g_return_val_if_fail(g_mm_handle, FALSE);
1345         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1346
1347         int mm_state = 0;
1348         mm_state = cam_mm_get_state();
1349
1350         if ((CAM_CAMERA_MODE == mode && mm_state < CAMERA_STATE_PREVIEW)
1351                 || (mode == CAM_CAMCORDER_MODE && mm_state < RECORDER_STATE_READY) ) {
1352                 cam_critical(LOG_MM, "cur_state:%d", mm_state);
1353                 return FALSE;
1354         } else
1355                 return TRUE;
1356 }
1357
1358 gboolean cam_mm_preview_start(int mode)
1359 {
1360         g_return_val_if_fail(g_mm_handle, FALSE);
1361         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1362
1363         struct appdata *ad = (struct appdata *)cam_appdata_get();
1364         g_return_val_if_fail(ad, FALSE);
1365
1366         int ret = (mode == CAM_CAMERA_MODE) ? CAMERA_ERROR_NONE : RECORDER_ERROR_NONE;
1367         if (CAM_CAMERA_MODE == mode) {
1368
1369                 ret = camera_start_preview(g_mm_handle->hcam);
1370                 if (ret != CAMERA_ERROR_NONE) {
1371                         if (ret == CAMERA_ERROR_SOUND_POLICY) {
1372                                 ad->fw_error_type = CAMERA_ERROR_SOUND_POLICY;
1373                         } else if (ret == CAMERA_ERROR_SECURITY_RESTRICTED) {
1374                                 cam_app_mdm_syspopup(ad);
1375                                 return FALSE;
1376                         } else {
1377                                 cam_critical(LOG_MM, "camera_start_preview failed");
1378                                 return FALSE;
1379                         }
1380                 }
1381                 cam_debug(LOG_MM, " ret : %d", ret);
1382
1383         }else if (CAM_CAMCORDER_MODE == mode) {
1384
1385                 g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1386
1387                 ret = recorder_prepare(g_mm_handle->hrec);
1388                 if (ret != RECORDER_ERROR_NONE) {
1389                         if (ret == RECORDER_ERROR_SOUND_POLICY) {
1390                                 ad->fw_error_type = RECORDER_ERROR_SOUND_POLICY;
1391                         } else if (ret == RECORDER_ERROR_SECURITY_RESTRICTED) {
1392                                 cam_app_mdm_syspopup(ad);
1393                                 return FALSE;
1394                         } else {
1395                                 cam_critical(LOG_MM, "camera_start_preview failed");
1396                                 return FALSE;
1397                         }
1398                 }
1399                 cam_debug(LOG_MM, " ret : %d", ret);
1400         }
1401
1402         return TRUE;
1403
1404 }
1405
1406 gboolean cam_mm_preview_stop(int mode)
1407 {
1408         int state = 0;
1409         g_return_val_if_fail(g_mm_handle, FALSE);
1410         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1411
1412         if (CAM_CAMERA_MODE == mode) {
1413                 state = cam_mm_get_cam_state();
1414                 cam_critical(LOG_MM, " camera state : %d", state);
1415                 /*todo:please consider recorder and camera*/
1416                 if (state < 0)
1417                         return FALSE;
1418
1419                 switch (state) {
1420                 case CAMERA_STATE_NONE:
1421                 case CAMERA_STATE_CAPTURING:
1422                 case CAMERA_STATE_CREATED:
1423                         return FALSE;
1424                 case CAMERA_STATE_PREVIEW:
1425                         CHECK_MM_ERROR(camera_stop_preview(g_mm_handle->hcam));
1426                         break;
1427                 case CAMERA_STATE_CAPTURED:
1428                         break;
1429                 }
1430                 return TRUE;
1431         }else if (CAM_CAMCORDER_MODE == mode) {
1432
1433                 state = cam_mm_get_rec_state();
1434                 g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1435                 cam_debug(LOG_MM, " camera state : %d", state);
1436                 /*todo:please consider recorder and camera*/
1437                 if (state < 0)
1438                         return FALSE;
1439
1440                 switch (state) {
1441                 case RECORDER_STATE_NONE:
1442                 case RECORDER_STATE_RECORDING:
1443                 case RECORDER_STATE_PAUSED:
1444                         return FALSE;
1445
1446                 case RECORDER_STATE_READY:
1447                         CHECK_MM_ERROR(recorder_unprepare(g_mm_handle->hrec));
1448                         break;
1449
1450                 case RECORDER_STATE_CREATED:
1451                         break;
1452
1453                 }
1454                 return TRUE;
1455
1456         }
1457         return TRUE;
1458 }
1459
1460 gboolean cam_mm_is_created(void)
1461 {
1462         debug_fenter(LOG_MM);
1463         if (g_mm_handle) {
1464                 return TRUE;
1465         }
1466         return FALSE;
1467 }
1468
1469 gboolean cam_mm_create(int camera_type, int mode)
1470 {
1471                 CAM_TA_ACUM_ITEM_BEGIN("----cam_mm_create", 0);
1472         DEBUG_TRACE
1473                 ("--------------------------------START----------------------------");
1474         DEBUG_TRACE("camera_type = %d" ,camera_type);
1475         if (g_mm_handle) {
1476                 cam_critical(LOG_MM, "The mm handle is already created");
1477                 return FALSE;
1478         }
1479         g_return_val_if_fail(g_mm_handle == NULL, FALSE);
1480         camera_h hcam;
1481         camera_error_e e;
1482         e = camera_create(camera_type, &hcam);
1483         if (e != CAMERA_ERROR_NONE) {
1484                 DEBUG_TRACE("[ERROR] camera_create - error(%d)", e);
1485                 return FALSE;
1486         }
1487         g_return_val_if_fail(hcam, FALSE);
1488         recorder_h hrec = NULL;
1489         recorder_error_e re;
1490         re = recorder_create_videorecorder(hcam, &hrec);
1491         if (re != RECORDER_ERROR_NONE) {
1492                 DEBUG_TRACE("[ERROR] camera_create - error(%d)", e);
1493                 recorder_destroy(hrec);
1494                 CHECK_MM_ERROR(camera_destroy(hcam));
1495                 return FALSE;
1496         }
1497         g_return_val_if_fail(hrec, FALSE);
1498         g_mm_handle = g_new0(CamMMHandle, 1);
1499         if (g_mm_handle) {
1500                 g_mm_handle->hcam = hcam;
1501                 g_mm_handle->hdev = camera_type;
1502                 g_mm_handle->hrec = hrec;
1503         } else {
1504                 DEBUG_TRACE("[ERROR] memory allocation failed", e);
1505                 recorder_destroy(hrec);
1506                 CHECK_MM_ERROR(camera_destroy(hcam));
1507                 return FALSE;
1508         }
1509
1510         DEBUG_TRACE("camera_type = %d" , g_mm_handle->hdev);
1511
1512         DEBUG_TRACE("--------------END---------------");
1513         CAM_TA_ACUM_ITEM_BEGIN("----cam_mm_create", 0);
1514
1515         return TRUE;
1516 }
1517
1518 gboolean cam_mm_destory(void)
1519 {
1520         g_return_val_if_fail(g_mm_handle, FALSE);
1521
1522         if( g_mm_handle->hrec != 0){
1523                 recorder_destroy(g_mm_handle->hrec);
1524                 g_mm_handle->hrec = 0;
1525         }
1526
1527         if(g_mm_handle->hcam != 0){
1528                 camera_destroy(g_mm_handle->hcam);
1529                 g_mm_handle->hcam = 0;
1530         }
1531
1532         g_mm_handle->hdev = -1;
1533
1534         g_free(g_mm_handle);
1535         g_mm_handle = NULL;
1536
1537         return TRUE;
1538 }
1539
1540 gboolean cam_mm_continuous_capture_start(int count, int interval, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb , void *user_data)
1541 {
1542         g_return_val_if_fail(g_mm_handle, FALSE);
1543         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1544
1545         cam_debug(LOG_MM, "");
1546         CAM_TA_ACUM_ITEM_END("        camera key to capture start", 0);
1547
1548         if (cam_mm_get_state() == CAMERA_STATE_PREVIEW) {
1549                 CAM_TA_ACUM_ITEM_BEGIN("camera_start_continuous_capture", 0);
1550                 CHECK_MM_ERROR(camera_start_continuous_capture(g_mm_handle->hcam, count, interval, capturing_cb, completed_cb, user_data));
1551                 CAM_TA_ACUM_ITEM_END("camera_start_continuous_capture", 0);
1552         } else {
1553                 printf("[%s:%d] operation failed - state:%d \n", __func__, __LINE__, cam_mm_get_state());
1554                 return FALSE;
1555         }
1556         return TRUE;
1557 }
1558
1559
1560 gboolean cam_mm_capture_start(camera_capturing_cb capturing_cb , camera_capture_completed_cb completed_cb , void *user_data)
1561 {
1562         g_return_val_if_fail(g_mm_handle, FALSE);
1563         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1564
1565         struct appdata *ad =  (struct appdata *)user_data;
1566         g_return_val_if_fail(ad, FALSE);
1567         CamAppData *camapp = ad->camapp_handle;
1568         g_return_val_if_fail(camapp, FALSE);
1569
1570         cam_debug(LOG_MM, "");
1571         CAM_TA_ACUM_ITEM_END("        camera key to capture start", 0);
1572
1573         gboolean do_capture = FALSE;
1574         if (camapp->camera_mode == CAM_CAMERA_MODE) {
1575                 if (cam_mm_get_state() == CAMERA_STATE_PREVIEW)
1576                         do_capture = TRUE;
1577         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
1578                 if (cam_mm_get_state() == RECORDER_STATE_RECORDING
1579                         || cam_mm_get_state() == RECORDER_STATE_PAUSED)
1580                         do_capture = TRUE;
1581         }
1582
1583         if (do_capture){
1584                 CAM_TA_ACUM_ITEM_BEGIN("camera_start_capture", 0);
1585                 CHECK_MM_ERROR(camera_start_capture(g_mm_handle->hcam, capturing_cb, completed_cb, user_data));
1586                 CAM_TA_ACUM_ITEM_END("camera_start_capture", 0);
1587         } else {
1588                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1589                        __LINE__, cam_mm_get_state());
1590                 return FALSE;
1591         }
1592         return TRUE;
1593 }
1594
1595 gboolean cam_mm_capture_stop(gboolean skip_preview, CamMode mode)
1596 {
1597         int state = CAMERA_STATE_NONE;/*TODO:now the value is same to record*/
1598
1599         g_return_val_if_fail(g_mm_handle, FALSE);
1600         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1601
1602         cam_debug(LOG_MM, " start");
1603
1604         state = cam_mm_get_state();
1605         if (state == RECORDER_STATE_READY && skip_preview == FALSE && mode == CAM_CAMCORDER_MODE) {
1606                 CHECK_MM_ERROR(recorder_prepare(g_mm_handle->hrec));
1607         } else {
1608                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1609                        __LINE__, cam_mm_get_state());
1610                 return FALSE;
1611         }
1612
1613         cam_debug(LOG_MM, " done");
1614
1615         return TRUE;
1616 }
1617
1618 gboolean cam_mm_rec_start()
1619 {
1620         int state = 0;
1621         g_return_val_if_fail(g_mm_handle, FALSE);
1622         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1623
1624         state = cam_mm_get_state();
1625         if ((state == RECORDER_STATE_READY)
1626             || (state == RECORDER_STATE_PAUSED)) {
1627                 CHECK_MM_ERROR(recorder_start(g_mm_handle->hrec));
1628         } else {
1629                 DEBUG_TRACE("operation failed - state:%d \n", state);
1630                 return FALSE;
1631         }
1632         return TRUE;
1633 }
1634
1635 gboolean cam_mm_rec_stop(gboolean to_stop)
1636 {
1637         int state = 0;
1638         g_return_val_if_fail(g_mm_handle, FALSE);
1639         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1640
1641         state = cam_mm_get_state();
1642         if ((state == RECORDER_STATE_RECORDING)
1643             || (state == RECORDER_STATE_PAUSED)) {
1644                 if (!to_stop) {
1645                         CHECK_MM_ERROR(recorder_commit(g_mm_handle->hrec));
1646                 } else {
1647                         CHECK_MM_ERROR(recorder_commit(g_mm_handle->hrec));
1648                         CHECK_MM_ERROR(recorder_unprepare(g_mm_handle->hrec));
1649                 }
1650         } else {
1651                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1652                        __LINE__, state);
1653                 return FALSE;
1654         }
1655         return TRUE;
1656 }
1657
1658 gboolean cam_mm_rec_pause()
1659 {
1660         int state = 0;
1661         g_return_val_if_fail(g_mm_handle, FALSE);
1662         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1663
1664         state = cam_mm_get_state();
1665         if ((state == RECORDER_STATE_RECORDING)) {
1666                 CHECK_MM_ERROR(recorder_pause(g_mm_handle->hrec));
1667         } else {
1668                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1669                        __LINE__, state);
1670                 return FALSE;
1671         }
1672         return TRUE;
1673 }
1674
1675 gboolean cam_mm_rec_cancel()
1676 {
1677         int state = 0;
1678         g_return_val_if_fail(g_mm_handle, FALSE);
1679         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1680
1681         state = cam_mm_get_state();
1682         if ((state == RECORDER_STATE_RECORDING)
1683             || (state == RECORDER_STATE_PAUSED)) {
1684                 CHECK_MM_ERROR(recorder_cancel(g_mm_handle->hrec));
1685         } else {
1686                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1687                        __LINE__, state);
1688                 return FALSE;
1689         }
1690         return TRUE;
1691 }
1692
1693 gboolean cam_mm_session_init(sound_session_type_e session_type)
1694 {
1695         int ret = SOUND_MANAGER_ERROR_NONE;
1696         if (ret != sound_manager_set_session_type(session_type)) {
1697                 DEBUG_TRACE("[%s:%d] operation failed - session_type:%d \n",
1698                        __func__, __LINE__, session_type);
1699                 return FALSE;
1700         }
1701         return TRUE;
1702
1703 }
1704 gboolean cam_mm_start_focusing(gint af_mode)
1705 {
1706         g_return_val_if_fail(g_mm_handle, FALSE);
1707         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1708
1709         struct appdata *ad =  (struct appdata *)cam_appdata_get();
1710         g_return_val_if_fail(ad, FALSE);
1711         CamAppData *camapp = ad->camapp_handle;
1712         g_return_val_if_fail(camapp, FALSE);
1713
1714         cam_debug(LOG_UI, "");
1715
1716         int state = 0;
1717         state = cam_mm_get_state();
1718
1719         if (camapp->camera_mode == CAM_CAMERA_MODE) {
1720                 if (state == CAMERA_STATE_PREVIEW
1721                         || state == CAMERA_STATE_CREATED
1722                         || state == CAMERA_STATE_CAPTURED) {
1723                         if ((CamAppFocusMode)af_mode == CAM_FOCUS_MODE_CONTINUOUS) {
1724                                 cam_debug(LOG_UI, "continuous");
1725                                 CHECK_MM_ERROR(camera_start_focusing(g_mm_handle->hcam, TRUE));
1726                         } else {
1727                                 cam_debug(LOG_UI, "touchAF");
1728                                 CHECK_MM_ERROR(camera_start_focusing(g_mm_handle->hcam, FALSE));
1729                         }
1730                 } else {
1731                         DEBUG_TRACE("Start focus operation failed in camera mode - invalid state:%d \n", state);
1732                         return FALSE;
1733                 }
1734         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
1735                 if (state == RECORDER_STATE_CREATED
1736                         || state == RECORDER_STATE_READY
1737                         || state == RECORDER_STATE_RECORDING
1738                         || state == RECORDER_STATE_PAUSED) {
1739                         if ((CamAppFocusMode)af_mode == CAM_FOCUS_MODE_CONTINUOUS) {
1740                                 CHECK_MM_ERROR(camera_start_focusing(g_mm_handle->hcam, TRUE));
1741                         } else {
1742                                 CHECK_MM_ERROR(camera_start_focusing(g_mm_handle->hcam, FALSE));
1743                         }
1744                 } else {
1745                         DEBUG_TRACE("Start focus operation failed in camcorder mode- invalid state:%d \n", state);
1746                         return FALSE;
1747                 }
1748         }
1749
1750         return TRUE;
1751 }
1752
1753 gboolean cam_mm_stop_focusing()
1754 {
1755         int state = 0;
1756
1757         g_return_val_if_fail(g_mm_handle, FALSE);
1758         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1759
1760         cam_debug(LOG_UI, "");
1761
1762         state = cam_mm_get_state();
1763         if (state == CAMERA_STATE_PREVIEW
1764                 || state == CAMERA_STATE_CREATED
1765                 || state == RECORDER_STATE_RECORDING) {
1766                 /*TODO:please think rec mod, but now the rec and cam mode state value is same*/
1767                 CHECK_MM_ERROR(camera_cancel_focusing(g_mm_handle->hcam));
1768         } else {
1769                 printf
1770                     ("[%s:%d] Stop focus operation failed - invalid state:%d \n",
1771                      __func__, __LINE__, state);
1772                 return FALSE;
1773         }
1774
1775         return TRUE;
1776 }
1777
1778 gboolean cam_mm_set_error_cb(camera_error_cb error_cb, void *data)
1779 {
1780         camera_error_e e;
1781         g_return_val_if_fail(g_mm_handle, FALSE);
1782         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1783         e = camera_set_error_cb(g_mm_handle->hcam, error_cb, data);
1784                 if (e != CAMERA_ERROR_NONE) {
1785                         DEBUG_TRACE("[ERROR] camera_set_error_cb - error(%d)", e);
1786                         return FALSE;
1787                 }
1788                 return TRUE;
1789
1790 }
1791
1792 gboolean cam_mm_unset_error_cb(void)
1793 {
1794         camera_error_e e;
1795         g_return_val_if_fail(g_mm_handle, FALSE);
1796         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1797         e = camera_unset_error_cb(g_mm_handle->hcam);
1798         if (e != CAMERA_ERROR_NONE) {
1799                 DEBUG_TRACE("[ERROR] camera_unset_error_cb - error(%d)", e);
1800                 return FALSE;
1801         }
1802         return TRUE;
1803
1804 }
1805
1806 gboolean cam_mm_set_state_changed_cb(camera_state_changed_cb state_cb, void *data)
1807 {
1808         camera_error_e e;
1809         g_return_val_if_fail(g_mm_handle, FALSE);
1810         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1811
1812         e = camera_set_state_changed_cb(g_mm_handle->hcam, state_cb, data);
1813         if (e != CAMERA_ERROR_NONE) {
1814                 DEBUG_TRACE("[ERROR] camera_set_state_changed_cb - error(%d)", e);
1815                 return FALSE;
1816         }
1817         return TRUE;
1818 }
1819
1820 gboolean cam_mm_unset_state_changed_cb(void)
1821 {
1822         camera_error_e e;
1823         g_return_val_if_fail(g_mm_handle, FALSE);
1824         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1825
1826         e = camera_unset_state_changed_cb(g_mm_handle->hcam);
1827         if (e != CAMERA_ERROR_NONE) {
1828                 DEBUG_TRACE("[ERROR] camera_unset_state_changed_cb - error(%d)", e);
1829                 return FALSE;
1830         }
1831         return TRUE;
1832 }
1833
1834
1835 gboolean cam_mm_set_focus_changed_cb(camera_focus_changed_cb focus_cb, void *data)
1836 {
1837         camera_error_e e;
1838         g_return_val_if_fail(g_mm_handle, FALSE);
1839         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1840
1841         e = camera_set_focus_changed_cb(g_mm_handle->hcam, focus_cb, data);
1842         if (e != CAMERA_ERROR_NONE) {
1843                 DEBUG_TRACE("[ERROR] camera_set_focus_changed_cb - error(%d)", e);
1844                 return FALSE;
1845         }
1846         return TRUE;
1847 }
1848
1849 gboolean cam_mm_unset_focus_changed_cb(void)
1850 {
1851         camera_error_e e;
1852         g_return_val_if_fail(g_mm_handle, FALSE);
1853         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1854
1855         e = camera_unset_focus_changed_cb(g_mm_handle->hcam);
1856         if (e != CAMERA_ERROR_NONE) {
1857                 DEBUG_TRACE("[ERROR] camera_unset_focus_changed_cb - error(%d)", e);
1858                 return FALSE;
1859         }
1860         return TRUE;
1861 }
1862
1863 gboolean cam_mm_set_preview_cb(camera_preview_cb preview_cb, void *data)
1864 {
1865         camera_error_e e;
1866         g_return_val_if_fail(g_mm_handle, FALSE);
1867         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1868
1869         e = camera_set_preview_cb(g_mm_handle->hcam, preview_cb, data);
1870         if (e != CAMERA_ERROR_NONE) {
1871                 DEBUG_TRACE("[ERROR] camera_set_preview_cb - error(%d)", e);
1872                 return FALSE;
1873         }
1874         return TRUE;
1875
1876 }
1877
1878 gboolean cam_mm_unset_preview_cb(void)
1879 {
1880         camera_error_e e;
1881         g_return_val_if_fail(g_mm_handle, FALSE);
1882         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1883
1884         e = camera_unset_preview_cb(g_mm_handle->hcam);
1885         if (e != CAMERA_ERROR_NONE) {
1886                 DEBUG_TRACE("[ERROR] camera_unset_preview_cb - error(%d)", e);
1887                 return FALSE;
1888         }
1889         return TRUE;
1890
1891 }
1892
1893 gboolean cam_mm_set_camera_interrupted_cb(camera_interrupted_cb callback, void *data){
1894
1895         camera_error_e e;
1896         g_return_val_if_fail(g_mm_handle, FALSE);
1897         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1898
1899         e = camera_set_interrupted_cb(g_mm_handle->hcam, callback, data);
1900         if (e != CAMERA_ERROR_NONE) {
1901                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1902                 return FALSE;
1903         }
1904         return TRUE;
1905 }
1906 gboolean cam_mm_set_recorder_interrupted_cb(recorder_interrupted_cb callback, void *data){
1907
1908         recorder_error_e e;
1909         g_return_val_if_fail(g_mm_handle, FALSE);
1910         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1911
1912         e = recorder_set_interrupted_cb(g_mm_handle->hrec, callback, data);
1913         if (e != RECORDER_ERROR_NONE) {
1914                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1915                 return FALSE;
1916         }
1917         return TRUE;
1918 }
1919
1920 gboolean cam_mm_recorder_set_state_changed_cb(recorder_state_changed_cb callback, void* user_data)
1921 {
1922         recorder_error_e e;
1923         g_return_val_if_fail(g_mm_handle, FALSE);
1924         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1925
1926         e = recorder_set_state_changed_cb(g_mm_handle->hrec, callback, user_data);
1927         if (e != RECORDER_ERROR_NONE) {
1928                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1929                 rec_detail_error_get(e);
1930                 return FALSE;
1931         }
1932         return TRUE;
1933
1934 }
1935
1936 gboolean cam_mm_recorder_unset_state_changed_cb(void)
1937 {
1938         recorder_error_e e;
1939         g_return_val_if_fail(g_mm_handle, FALSE);
1940         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1941
1942         e = recorder_unset_state_changed_cb(g_mm_handle->hrec);
1943         if (e != RECORDER_ERROR_NONE) {
1944                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1945                 rec_detail_error_get(e);
1946                 return FALSE;
1947         }
1948         return TRUE;
1949
1950 }
1951
1952 gboolean cam_mm_recorder_set_recording_status_cb(recorder_recording_status_cb callback, void* user_data)
1953 {
1954         recorder_error_e e;
1955         g_return_val_if_fail(g_mm_handle, FALSE);
1956         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1957
1958         e = recorder_set_recording_status_cb(g_mm_handle->hrec, callback, user_data);
1959         if (e != RECORDER_ERROR_NONE) {
1960                 DEBUG_TRACE("[ERROR] recorder_set_recording_status_cb - error(%d)", e);
1961                 rec_detail_error_get(e);
1962                 return FALSE;
1963         }
1964         return TRUE;
1965
1966 }
1967
1968 gboolean cam_mm_recorder_unset_recording_status_cb(void)
1969 {
1970         recorder_error_e e;
1971         g_return_val_if_fail(g_mm_handle, FALSE);
1972         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1973
1974         e = recorder_unset_recording_status_cb(g_mm_handle->hrec);
1975         if (e != RECORDER_ERROR_NONE) {
1976                 DEBUG_TRACE("[ERROR] recorder_unset_recording_status_cb - error(%d)", e);
1977                 rec_detail_error_get(e);
1978                 return FALSE;
1979         }
1980         return TRUE;
1981
1982 }
1983
1984 gboolean cam_mm_recorder_set_recording_limit_reached_cb(recorder_recording_limit_reached_cb callback, void* user_data)
1985 {
1986         recorder_error_e e;
1987         g_return_val_if_fail(g_mm_handle, FALSE);
1988         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1989
1990         e = recorder_set_recording_limit_reached_cb(g_mm_handle->hrec, callback, user_data);
1991         if (e != RECORDER_ERROR_NONE) {
1992                 DEBUG_TRACE("[ERROR] recorder_set_recording_status_cb - error(%d)", e);
1993                 rec_detail_error_get(e);
1994                 return FALSE;
1995         }
1996         return TRUE;
1997
1998 }
1999
2000 gboolean cam_mm_recorder_unset_recording_limit_reached_cb(void)
2001 {
2002         recorder_error_e e;
2003         g_return_val_if_fail(g_mm_handle, FALSE);
2004         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
2005
2006         e = recorder_unset_recording_limit_reached_cb(g_mm_handle->hrec);
2007         if (e != RECORDER_ERROR_NONE) {
2008                 DEBUG_TRACE("[ERROR] recorder_unset_recording_status_cb - error(%d)", e);
2009                 rec_detail_error_get(e);
2010                 return FALSE;
2011         }
2012         return TRUE;
2013
2014 }
2015
2016 gboolean cam_mm_set_recording_motion(double rate)
2017 {
2018         g_return_val_if_fail(g_mm_handle, FALSE);
2019         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
2020
2021         int err;
2022         err = recorder_attr_set_recording_motion_rate(g_mm_handle->hrec, rate);
2023         if (err != RECORDER_ERROR_NONE) {
2024                 DEBUG_TRACE("recorder_attr_set_recording_motion_rate failed");
2025                 return FALSE;
2026         }
2027
2028         return TRUE;
2029 }
2030
2031 gboolean cam_mm_start_camera_face_detection(camera_face_detected_cb callback, void *data)
2032 {
2033         camera_error_e e;
2034         g_return_val_if_fail(g_mm_handle, FALSE);
2035         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2036
2037         e = camera_start_face_detection(g_mm_handle->hcam, callback, data);
2038         if (e != CAMERA_ERROR_NONE) {
2039                 DEBUG_TRACE("[ERROR] camera_start_face_detection - error(%d)", e);
2040                 return FALSE;
2041         }
2042         return TRUE;
2043 }
2044
2045 gboolean cam_mm_stop_camera_face_detection(void)
2046 {
2047         camera_error_e e;
2048         g_return_val_if_fail(g_mm_handle, FALSE);
2049         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2050
2051         e = camera_stop_face_detection(g_mm_handle->hcam);
2052         if (e != CAMERA_ERROR_NONE) {
2053                 DEBUG_TRACE("[ERROR] camera_stop_face_detection - error(%d)", e);
2054                 return FALSE;
2055         }
2056         return TRUE;
2057 }
2058
2059 gboolean cam_mm_is_supported_face_detection(void)
2060 {
2061         g_return_val_if_fail(g_mm_handle, FALSE);
2062         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2063
2064         return camera_is_supported_face_detection(g_mm_handle->hcam);
2065
2066 }
2067
2068 gboolean cam_mm_set_camera_face_zoom(int face_id)
2069 {
2070         camera_error_e e;
2071         g_return_val_if_fail(g_mm_handle, FALSE);
2072         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2073
2074         e = camera_face_zoom(g_mm_handle->hcam, face_id);
2075         if (e != CAMERA_ERROR_NONE) {
2076                 DEBUG_TRACE("[ERROR] camera_face_zoom - error(%d)", e);
2077                 return FALSE;
2078         }
2079         return TRUE;
2080 }
2081
2082 gboolean cam_mm_camera_cancel_face_zoom(void)
2083 {
2084         camera_error_e e;
2085         g_return_val_if_fail(g_mm_handle, FALSE);
2086         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2087
2088         e = camera_cancel_face_zoom(g_mm_handle->hcam);
2089         if (e != CAMERA_ERROR_NONE) {
2090                 DEBUG_TRACE("[ERROR] camera_cancel_face_zoom - error(%d)", e);
2091                 return FALSE;
2092         }
2093         return TRUE;
2094
2095 }
2096
2097 gboolean cam_mm_set_image_flip(gboolean value)
2098 {
2099         camera_error_e e;
2100         g_return_val_if_fail(g_mm_handle, FALSE);
2101         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2102
2103         if (value) {
2104                 e = camera_attr_set_stream_flip(g_mm_handle->hcam, CAMERA_FLIP_HORIZONTAL);
2105
2106                 if (g_mm_handle->hdev == 0) {
2107                         e = camera_set_x11_display_flip(g_mm_handle->hcam, CAMERA_FLIP_VERTICAL);
2108                 } else {
2109                         e = camera_set_x11_display_flip(g_mm_handle->hcam, CAMERA_FLIP_NONE);
2110                 }
2111         } else {
2112                 e = camera_attr_set_stream_flip(g_mm_handle->hcam, CAMERA_FLIP_NONE);
2113
2114                 if (g_mm_handle->hdev == 0) {
2115                         e = camera_set_x11_display_flip(g_mm_handle->hcam, CAMERA_FLIP_NONE);
2116                 } else {
2117                         e = camera_set_x11_display_flip(g_mm_handle->hcam, CAMERA_FLIP_VERTICAL);
2118                 }
2119         }
2120
2121         if (e != CAMERA_ERROR_NONE) {
2122                 DEBUG_TRACE("recorder_attr_set_recording_flip() error(%d)", e);
2123                 return FALSE;
2124         }
2125         return TRUE;
2126 }
2127
2128 gboolean cam_mm_get_caps_minmax(unsigned int type, int *min, int *max)
2129 {
2130         if (!cam_mm_is_created()) {
2131                 cam_debug(LOG_CAM, "cam_mm_is_created() false");
2132                 return FALSE;
2133         }
2134
2135         gboolean ret = TRUE;
2136         int tempmin, tempmax = 0;
2137
2138         switch(type) {
2139         case CAM_CP_FUNC_EXPOSURE:
2140                 {
2141                          if (camera_attr_get_exposure_range(g_mm_handle->hcam, &tempmin, &tempmax) != CAMERA_ERROR_NONE) {
2142                                 cam_debug(LOG_CAM, "camera_attr_get_exposure_range() is false");
2143                                 ret = FALSE;
2144                          }
2145                 }
2146                 break;
2147         case CAM_CP_FUNC_BRIGHTNESS:
2148                 {
2149                          if (camera_attr_get_brightness_range(g_mm_handle->hcam, &tempmin, &tempmax) != CAMERA_ERROR_NONE) {
2150                                 cam_debug(LOG_CAM, "camera_attr_get_brightness_range() is false");
2151                                 ret = FALSE;
2152                          }
2153                 }
2154                 break;
2155         case CAM_CP_FUNC_ZOOM:
2156                 {
2157                         if (camera_attr_get_zoom_range(g_mm_handle->hcam, &tempmin, &tempmax) != CAMERA_ERROR_NONE) {
2158                                 cam_debug(LOG_CAM, "camera_attr_get_zoom_range() is false");
2159                                 ret = FALSE;
2160                         }
2161
2162                         if (tempmin == tempmax) {
2163                                 cam_debug(LOG_CAM, "zoom is not supported");
2164                                 ret = FALSE;
2165                         }
2166                 }
2167                 break;
2168         default:
2169                 {
2170                         cam_debug(LOG_CAM, "not support get_minmax() about this type[%d]", type);
2171                         ret = FALSE;
2172                 }
2173                 break;
2174         }
2175
2176         if (!ret) {
2177                 tempmin = 0;
2178                 tempmax = 0;
2179         }
2180
2181         *min = tempmin;
2182         *max = tempmax;
2183
2184         return ret;
2185 }
2186
2187 gboolean cam_mm_get_caps_range(unsigned int type, unsigned int *caps, void *user_data)
2188 {
2189         if (!cam_mm_is_created()) {
2190                 cam_debug(LOG_CAM, "cam_mm_is_created() false");
2191                 return FALSE;
2192         }
2193
2194         g_caps = 0;
2195         g_caps_cb_cnt = 0;
2196         gboolean ret = TRUE;
2197
2198         switch(type) {
2199         case CAM_CP_FUNC_FLASH_MODE:
2200                 {
2201                         if (camera_attr_foreach_supported_flash_mode(g_mm_handle->hcam,
2202                                 (camera_attr_supported_flash_mode_cb)__get_flash_cb, user_data) != CAMERA_ERROR_NONE ) {
2203                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_flash_mode() is fail");
2204                                 ret = FALSE;
2205                         }
2206                 }
2207                 break;
2208         case CAM_CP_FUNC_ISO:
2209                 {
2210                         if (camera_attr_foreach_supported_iso(g_mm_handle->hcam,
2211                                 (camera_attr_supported_iso_cb)__get_iso_cb, user_data) != CAMERA_ERROR_NONE ) {
2212                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_iso() is fail");
2213                                 ret = FALSE;
2214                         }
2215                 }
2216                 break;
2217         case CAM_CP_FUNC_SCENE_MODE:
2218                 {
2219                         if (camera_attr_foreach_supported_scene_mode(g_mm_handle->hcam,
2220                                 (camera_attr_supported_scene_mode_cb)__get_scene_cb, user_data) != CAMERA_ERROR_NONE ) {
2221                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_scene_mode() is fail");
2222                                 ret = FALSE;
2223                         }
2224                 }
2225                 break;
2226         case CAM_CP_FUNC_METERING:
2227                 {
2228                         if (camera_attr_foreach_supported_exposure_mode(g_mm_handle->hcam,
2229                                 (camera_attr_supported_exposure_mode_cb)__get_metering_cb, user_data) != CAMERA_ERROR_NONE ) {
2230                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_exposure_mode() is fail");
2231                                 ret = FALSE;
2232                         }
2233                 }
2234                 break;
2235         case CAM_CP_FUNC_EFFECT_MODE:
2236                 {
2237                         if (camera_attr_foreach_supported_effect(g_mm_handle->hcam,
2238                                 (camera_attr_supported_effect_cb)__get_effect_cb, user_data) != CAMERA_ERROR_NONE ) {
2239                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_effect() is fail");
2240                                 ret = FALSE;
2241                         }
2242                 }
2243                 break;
2244         case CAM_CP_FUNC_WHITE_BALANCE:
2245                 {
2246                         if (camera_attr_foreach_supported_whitebalance(g_mm_handle->hcam,
2247                                 (camera_attr_supported_whitebalance_cb)__get_wb_cb, user_data) != CAMERA_ERROR_NONE) {
2248                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_whitebalance() is fail");
2249                                 ret = FALSE;
2250                         }
2251                 }
2252                 break;
2253         case CAM_CP_FUNC_FOCUS_MODE:
2254                 {
2255                         if (camera_attr_foreach_supported_af_mode(g_mm_handle->hcam,
2256                                 (camera_attr_supported_af_mode_cb)__get_focus_cb, user_data) != CAMERA_ERROR_NONE) {
2257                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_exposure_mode() is fail");
2258                                 ret = FALSE;
2259                         }
2260                 }
2261                 break;
2262         case CAM_CP_FUNC_FPS:
2263                 {
2264                         if (camera_attr_foreach_supported_fps(g_mm_handle->hcam,
2265                                 (camera_attr_supported_fps_cb)__get_fps_cb, user_data) != CAMERA_ERROR_NONE) {
2266                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_fps() is fail");
2267                                 ret = FALSE;
2268                         }
2269                 }
2270                 break;
2271         case CAM_CP_FUNC_CAM_RESOLUTION:
2272                 {
2273                         if(camera_foreach_supported_capture_resolution(g_mm_handle->hcam,
2274                                 (camera_supported_capture_resolution_cb)__get_capture_res_cb, user_data) != CAMERA_ERROR_NONE) {
2275                                 cam_debug(LOG_CAM, "camera_foreach_supported_capture_resolution() is fail");
2276                                 ret = FALSE;
2277                         }
2278                 }
2279                 break;
2280         case CAM_CP_FUNC_REC_RESOLUTION:
2281                 {
2282                         if(camera_foreach_supported_preview_resolution(g_mm_handle->hcam,
2283                                 (camera_supported_preview_resolution_cb)__get_recording_res_cb, user_data) != CAMERA_ERROR_NONE) {
2284                                 cam_debug(LOG_CAM, "camera_foreach_supported_capture_resolution() is fail");
2285                                 ret = FALSE;
2286                         }
2287                 }
2288                 break;
2289         default:
2290                 {
2291                         cam_debug(LOG_CAM, "not support get_range() about this type[%d]", type);
2292                         ret = FALSE;
2293                 }
2294                 break;
2295         }
2296
2297         *caps = g_caps;
2298         return ret;
2299 }
2300
2301 const int cam_mm_get_caps_cb_cnt()
2302 {
2303         return g_caps_cb_cnt;
2304 }
2305
2306 static void __get_iso_cb(camera_attr_iso_e iso, void *user_data)
2307 {
2308         cam_retm_if(iso > CAMERA_ATTR_ISO_3200, "input is invalid");
2309
2310         unsigned int uRet = cam_iso_dev_convert_caps(iso);
2311         if (uRet != 0) {
2312                 g_caps |= uRet;
2313                 g_caps_cb_cnt++;
2314         }
2315 }
2316
2317 static void __get_effect_cb(camera_attr_effect_mode_e effect, void *user_data)
2318 {
2319         cam_retm_if(effect > CAMERA_ATTR_EFFECT_SKETCH, "input is invalid");
2320
2321         unsigned int uRet = cam_effect_dev_convert_caps(effect);
2322         if (uRet != 0 ) {
2323                 g_caps |= uRet;
2324                 g_caps_cb_cnt++;
2325         }
2326 }
2327
2328 static void __get_fps_cb(camera_attr_fps_e fps, void *user_data)
2329 {
2330         cam_retm_if(fps > CAMERA_ATTR_FPS_120, "input is invalid");
2331
2332         unsigned int uRet = cam_fps_dev_convert_caps(fps);
2333         if (uRet != 0) {
2334                 g_caps |= uRet;
2335                 g_caps_cb_cnt++;
2336         }
2337 }
2338
2339 static void __get_wb_cb(camera_attr_whitebalance_e wb, void *user_data)
2340 {
2341         cam_retm_if(wb > CAMERA_ATTR_WHITE_BALANCE_CUSTOM, "input is invalid");
2342
2343         unsigned int uRet = cam_wb_dev_convert_caps(wb);
2344         if (uRet != 0) {
2345                 g_caps |= uRet;
2346                 g_caps_cb_cnt++;
2347         }
2348 }
2349
2350 static void __get_focus_cb(camera_attr_af_mode_e focus, void *user_data)
2351 {
2352         cam_retm_if(focus > CAMERA_ATTR_AF_FULL, "input is invalid");
2353
2354         unsigned int uRet = cam_focus_dev_convert_caps(focus);
2355         if (uRet != 0) {
2356                 g_caps |= uRet;
2357                 g_caps_cb_cnt++;
2358         }
2359 }
2360
2361 static void __get_metering_cb(camera_attr_exposure_mode_e metering, void *user_data)
2362 {
2363         cam_retm_if(metering > CAMERA_ATTR_EXPOSURE_MODE_CUSTOM, "input is invalid");
2364
2365         unsigned int uRet = cam_metering_dev_convert_caps(metering);
2366         if (uRet != 0) {
2367                 g_caps |= uRet;
2368                 g_caps_cb_cnt++;
2369         }
2370 }
2371
2372 static void __get_scene_cb(camera_attr_scene_mode_e scene, void *user_data)
2373 {
2374         cam_retm_if(scene > CAMERA_ATTR_SCENE_MODE_BACKLIGHT, "input is invalid");
2375
2376         unsigned int uRet = cam_scene_dev_convert_caps(scene);
2377         if (uRet != 0) {
2378                 g_caps |= uRet;
2379                 g_caps_cb_cnt++;
2380         }
2381 }
2382
2383 static void __get_flash_cb(camera_attr_flash_mode_e flash, void *user_data)
2384 {
2385         cam_retm_if(flash > CAMERA_ATTR_FLASH_MODE_PERMANENT, "input is invalid");
2386
2387         unsigned int uRet = cam_flash_dev_convert_caps(flash);
2388         if (uRet != 0 ) {
2389                 g_caps |= uRet;
2390                 g_caps_cb_cnt++;
2391         }
2392 }
2393
2394 static void __get_capture_res_cb(int width, int height, void *user_data)
2395 {
2396         unsigned int uRet = cam_resolution_cam_convert_caps((unsigned int)CAM_RESOLUTION(width, height));
2397         if (uRet != 0) {
2398                 g_caps |= uRet;
2399                 g_caps_cb_cnt++;
2400         }
2401 }
2402
2403 static void __get_recording_res_cb(int width, int height, void *user_data)
2404 {
2405         unsigned int uRet = cam_resolution_cam_convert_caps((unsigned int)CAM_RESOLUTION(width, height));
2406         if (uRet != 0) {
2407                 g_caps |= uRet;
2408                 g_caps_cb_cnt++;
2409         }
2410 }
2411
2412 gboolean cam_mm_is_support_front_camera(void)
2413 {
2414         g_return_val_if_fail(g_mm_handle, FALSE);
2415         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
2416
2417         bool ret = 0;
2418         int device_count = 0;
2419
2420         camera_get_device_count(g_mm_handle->hcam, &device_count);
2421         cam_debug(LOG_MM, "device count is [%d]", device_count);
2422
2423         if (device_count == 2) {
2424                 ret = TRUE;
2425         } else {
2426                 ret = FALSE;
2427         }
2428
2429         return ret;
2430 }
2431 //end of file