Updating INI configuration file to work with most cameras.
[profile/ivi/camera.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://www.tizenopensource.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_effect_cb(camera_attr_effect_mode_e effect, void *user_data);
36
37
38 void rec_detail_error_get(int err_no)
39 {
40         switch(err_no) {
41         case RECORDER_ERROR_INVALID_PARAMETER:
42                 DEBUG_TRACE("RECORDER_ERROR_INVALID_PARAMETER");
43                 break;
44         case RECORDER_ERROR_INVALID_STATE:
45                 DEBUG_TRACE("RECORDER_ERROR_INVALID_STATE");
46                 break;
47         case RECORDER_ERROR_OUT_OF_MEMORY:
48                 DEBUG_TRACE("RECORDER_ERROR_OUT_OF_MEMORY");
49                 break;
50         case RECORDER_ERROR_DEVICE:
51                 DEBUG_TRACE("RECORDER_ERROR_DEVICE");
52                 break;
53         case RECORDER_ERROR_INVALID_OPERATION:
54                 DEBUG_TRACE("RECORDER_ERROR_INVALID_OPERATION");
55                 break;
56         case RECORDER_ERROR_SOUND_POLICY:
57                 DEBUG_TRACE("RECORDER_ERROR_SOUND_POLICY");
58                 break;
59         case RECORDER_ERROR_NONE:
60                 DEBUG_TRACE("NO ERROR");
61                 break;
62         default:
63                 DEBUG_TRACE("unknown error,err_no = %d", err_no);
64
65         }
66
67 }
68 void cam_detail_error_get(int err_no)
69 {
70         switch(err_no) {
71         case CAMERA_ERROR_INVALID_PARAMETER:
72                 DEBUG_TRACE("CAMERA_ERROR_INVALID_PARAMETER");
73                 break;
74         case CAMERA_ERROR_INVALID_STATE:
75                 DEBUG_TRACE("CAMERA_ERROR_INVALID_STATE");
76                 break;
77         case CAMERA_ERROR_OUT_OF_MEMORY:
78                 DEBUG_TRACE("CAMERA_ERROR_OUT_OF_MEMORY");
79                 break;
80         case CAMERA_ERROR_DEVICE:
81                 DEBUG_TRACE("CAMERA_ERROR_DEVICE");
82                 break;
83         case CAMERA_ERROR_INVALID_OPERATION:
84                 DEBUG_TRACE("CAMERA_ERROR_INVALID_OPERATION");
85                 break;
86         case CAMERA_ERROR_SOUND_POLICY:
87                 DEBUG_TRACE("CAMERA_ERROR_SOUND_POLICY");
88                 break;
89         case CAMERA_ERROR_NONE:
90                 DEBUG_TRACE("NO ERROR");
91                 break;
92         default:
93                 DEBUG_TRACE("unknown error,err_no = %d", err_no);
94
95         }
96 }
97
98
99 static CamMMHandle *g_mm_handle = NULL;
100
101 int cam_mm_get_cam_state(void)
102 {
103         g_return_val_if_fail(g_mm_handle, FALSE);
104         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
105         int ret = 0;
106         camera_state_e state = 0;
107         ret = camera_get_state(g_mm_handle->hcam, &state);
108         if (ret == CAMERA_ERROR_NONE)
109                 return (int)state;
110         else
111                 return -1;
112 }
113
114 int cam_mm_get_state(void)
115 {
116         g_return_val_if_fail(g_mm_handle, FALSE);
117         int ret = 0;
118         camera_state_e state = 0;
119         struct appdata *ad =  (struct appdata *)cam_appdata_get();
120         CamAppData *camapp = ad->camapp_handle;
121         if (camapp->camera_mode == CAM_CAMERA_MODE) {
122                 g_return_val_if_fail(g_mm_handle->hcam, FALSE);
123                 ret = camera_get_state(g_mm_handle->hcam, (camera_state_e *)&state);
124                 if (ret == CAMERA_ERROR_NONE)
125                         return (int)state;
126                 else
127                         return -1;
128         }
129         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
130                 g_return_val_if_fail(g_mm_handle->hrec, FALSE);
131                 ret = recorder_get_state(g_mm_handle->hrec, (recorder_state_e *)&state);
132                 if (ret == RECORDER_ERROR_NONE)
133                         return (int)state;
134                 else
135                         return -1;
136         }
137         return -1;
138 }
139
140
141 int cam_mm_get_rec_state(void)
142 {
143         g_return_val_if_fail(g_mm_handle, FALSE);
144         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
145         int ret = 0;
146         recorder_state_e state = 0;
147         ret = recorder_get_state(g_mm_handle->hrec, (recorder_state_e *)&state);
148         if (ret == RECORDER_ERROR_NONE)
149                 return (int)state;
150         else
151                 return -1;
152 }
153
154 gboolean cam_mm_get_video_device(int *device)
155 {
156         g_return_val_if_fail(g_mm_handle, FALSE);
157
158         if (g_mm_handle->hdev < CAMERA_DEVICE_CAMERA0 || g_mm_handle->hdev > CAMERA_DEVICE_CAMERA1)
159                 return FALSE;
160
161         *device = g_mm_handle->hdev;
162         DEBUG_TRACE("%d,%d",g_mm_handle->hdev,*device);
163         return TRUE;
164 }
165
166 gboolean cam_mm_get_video_size(int *width, int *height)
167 {
168         int ret = 0;
169         g_return_val_if_fail(g_mm_handle, FALSE);
170         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
171         ret = camera_get_preview_resolution(g_mm_handle->hcam,  width, height);
172
173         if (ret != CAMERA_ERROR_NONE) {
174                 DEBUG_TRACE("camera_get_preview_resolution error code = %d" , ret);
175                 return FALSE;
176         }
177
178         return TRUE;
179 }
180
181 gboolean cam_mm_set_video_size(int width, int height)
182 {
183         int ret = 0;
184         g_return_val_if_fail(g_mm_handle, FALSE);
185         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
186
187         ret = camera_set_preview_resolution(g_mm_handle->hcam, width, height);
188
189         if (ret != CAMERA_ERROR_NONE) {
190                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
191                 return FALSE;
192         }
193         return TRUE;
194 }
195
196 gboolean cam_mm_get_zoom(int *value)
197 {
198         int ret = 0;
199         g_return_val_if_fail(g_mm_handle, FALSE);
200         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
201         ret = camera_attr_get_zoom(g_mm_handle->hcam, value);
202         if (ret) {
203
204                 return FALSE;
205         }
206         return TRUE;
207 }
208
209 gboolean cam_mm_set_zoom(int value)
210 {
211         int ret = 0;
212         g_return_val_if_fail(g_mm_handle, FALSE);
213         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
214
215         ret = camera_attr_set_zoom(g_mm_handle->hcam, value);
216         if (ret) {
217
218                 return FALSE;
219         }
220         return TRUE;
221 }
222
223 gboolean cam_mm_set_fps(camera_attr_fps_e value)
224 {
225         int ret = 0;
226         g_return_val_if_fail(g_mm_handle, FALSE);
227         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
228
229         ret = camera_attr_set_preview_fps(g_mm_handle->hcam, value);
230         if (ret != CAMERA_ERROR_NONE) {
231                 cam_detail_error_get(ret);
232                 return FALSE;
233         }
234         return TRUE;
235 }
236
237 gboolean cam_mm_get_focus_mode(int *value)
238 {
239         int ret = 0;
240         g_return_val_if_fail(g_mm_handle, FALSE);
241         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
242
243         ret = camera_attr_get_af_mode(g_mm_handle->hcam, (camera_attr_af_mode_e *)value);
244         if (ret != CAMERA_ERROR_NONE) {
245
246                 return FALSE;
247         }
248         return TRUE;
249
250 }
251
252 gboolean cam_mm_set_focus_mode(int value)
253 {
254         int ret = 0;
255         ret = camera_attr_set_af_mode(g_mm_handle->hcam, (camera_attr_af_mode_e)value);
256         if (ret != CAMERA_ERROR_NONE) {
257
258                 return FALSE;
259         }
260         return TRUE;
261 }
262
263 gboolean cam_mm_get_zoom_valid_intrange(int *min, int *max)
264 {
265         int ret = 0;
266         g_return_val_if_fail(g_mm_handle, FALSE);
267         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
268
269         ret = camera_attr_get_zoom_range(g_mm_handle->hcam, min, max);
270         if (ret != CAMERA_ERROR_NONE) {
271
272                 return FALSE;
273         }
274
275         return TRUE;
276
277 }
278
279 gboolean cam_mm_set_af_area(int x, int y, int w, int h)
280 {
281         int ret = 0;
282         g_return_val_if_fail(g_mm_handle, FALSE);
283         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
284
285         DEBUG_TRACE("\n Touch AF area ![ x,y,width,height: %d,%d,%d,%d ]\n", x, y, w, h);
286
287         ret = camera_attr_set_af_area(g_mm_handle->hcam, x, y);
288         if (ret != CAMERA_ERROR_NONE) {
289                 DEBUG_TRACE("camera_attr_set_af_area failed [%d]\n", ret);
290                 return FALSE;
291         }
292         return TRUE;
293
294 }
295
296 gboolean cam_mm_get_detect_mode(int *value)
297 {
298 #ifndef TODO_SURRPORT
299 /*TODO:framework not surrport it*/
300 #endif
301         return TRUE;
302 }
303
304 gboolean cam_mm_set_detect_mode(int value)
305 {
306 /*TODO:libmm-camcorder not surrport it*/
307 #ifdef TODO_SURRPORT
308         return TRUE;
309 #endif
310 }
311
312 gboolean cam_mm_get_image_enc_quality(int *value)
313 {
314         int ret = 0;
315         g_return_val_if_fail(g_mm_handle, FALSE);
316         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
317
318         ret = camera_attr_get_image_quality(g_mm_handle->hcam, value);
319         if (ret != CAMERA_ERROR_NONE) {
320
321                 return FALSE;
322         }
323         return TRUE;
324
325 }
326
327 gboolean cam_mm_set_image_enc_quality(int value)
328 {
329         int ret = 0;
330         g_return_val_if_fail(g_mm_handle, FALSE);
331         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
332
333         ret = camera_attr_set_image_quality(g_mm_handle->hcam, value);
334         if (ret != CAMERA_ERROR_NONE) {
335
336                 return FALSE;
337         }
338         return TRUE;
339
340 }
341
342 gboolean cam_mm_get_flash(int *value)
343 {
344         int ret = 0;
345         g_return_val_if_fail(g_mm_handle, FALSE);
346         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
347
348         ret = camera_attr_get_flash_mode(g_mm_handle->hcam, (camera_attr_flash_mode_e *)value);
349         if (ret != CAMERA_ERROR_NONE) {
350
351                 return FALSE;
352         }
353         return TRUE;
354 }
355
356 gboolean cam_mm_set_flash(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_set_flash_mode(g_mm_handle->hcam, (camera_attr_flash_mode_e)value);
363         if (ret != CAMERA_ERROR_NONE) {
364
365                 return FALSE;
366         }
367         return TRUE;
368 }
369
370 gboolean cam_mm_get_effect(int *value)
371 {
372         int ret = 0;
373         g_return_val_if_fail(g_mm_handle, FALSE);
374         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
375
376         ret = camera_attr_get_effect(g_mm_handle->hcam, (camera_attr_effect_mode_e *)value);
377         if (ret != CAMERA_ERROR_NONE) {
378
379                 return FALSE;
380         }
381         return TRUE;
382
383 }
384
385 gboolean cam_mm_set_effect(int value)
386 {
387         int ret = 0;
388         g_return_val_if_fail(g_mm_handle, FALSE);
389         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
390
391         ret = camera_attr_set_effect(g_mm_handle->hcam, (camera_attr_effect_mode_e)value);
392         if (ret != CAMERA_ERROR_NONE) {
393
394                 return FALSE;
395         }
396         return TRUE;
397
398 }
399
400 gboolean cam_mm_set_audio_recording(gboolean b_on)
401 {
402         int ret = 0;
403
404         g_return_val_if_fail(g_mm_handle, FALSE);
405         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
406         if (b_on)
407                 ret = recorder_attr_set_mute(g_mm_handle->hrec, FALSE);
408         else
409                 ret = recorder_attr_set_mute(g_mm_handle->hrec, TRUE);
410
411         if (ret != RECORDER_ERROR_NONE) {
412                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
413                 return FALSE;
414         }
415         return TRUE;
416
417 }
418
419 gboolean cam_mm_set_image_count(int value)
420 {
421         return TRUE;
422 }
423
424
425 gboolean cam_mm_get_image_size(int *width, int *height)
426 {
427         int ret = 0;
428         g_return_val_if_fail(g_mm_handle, FALSE);
429         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
430
431         ret = camera_get_capture_resolution(g_mm_handle->hcam, width, height);
432
433         if (ret != CAMERA_ERROR_NONE) {
434                 DEBUG_TRACE("set attr failed - code[%x] name[%s]\n", ret);
435                 return FALSE;
436         }
437         return TRUE;
438 }
439
440 gboolean cam_mm_set_image_size(int width, int height)
441 {
442         int ret = 0;
443         g_return_val_if_fail(g_mm_handle, FALSE);
444         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
445
446         g_return_val_if_fail(g_mm_handle, FALSE);
447         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
448
449         ret = camera_set_capture_resolution(g_mm_handle->hcam, width, height);
450
451         if (ret != CAMERA_ERROR_NONE) {
452                 DEBUG_TRACE("cam_mm_set_image_size failed");
453                 return FALSE;
454         }
455         return TRUE;
456 }
457
458 gboolean cam_mm_set_video_encoder_bitrate(int bitrate)
459 {
460         recorder_error_e ret;
461         g_return_val_if_fail(g_mm_handle, FALSE);
462         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
463
464         ret = recorder_attr_set_video_encoder_bitrate(g_mm_handle->hrec, bitrate);
465         if (ret != RECORDER_ERROR_NONE) {
466                 return FALSE;
467         }
468         return TRUE;
469 }
470
471 gboolean cam_mm_set_audio_encoder_bitrate(int bitrate)
472 {
473         recorder_error_e ret;
474         g_return_val_if_fail(g_mm_handle, FALSE);
475         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
476
477         ret = recorder_attr_set_audio_encoder_bitrate(g_mm_handle->hrec, bitrate);
478         if (ret != RECORDER_ERROR_NONE) {
479                 return FALSE;
480         }
481         return TRUE;
482 }
483
484 gboolean cam_mm_set_display_device(int display_device, void *xid)
485 {
486         int ret;
487         g_return_val_if_fail(g_mm_handle, FALSE);
488         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
489
490         ret = camera_set_display(g_mm_handle->hcam, display_device, xid);
491         if (ret != CAMERA_ERROR_NONE) {
492
493                 return FALSE;
494         }
495         return TRUE;
496 }
497
498 gboolean cam_mm_set_display_rotate(int rotate)
499 {
500         int ret;
501         g_return_val_if_fail(g_mm_handle, FALSE);
502         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
503
504         ret = camera_set_x11_display_rotation(g_mm_handle->hcam, rotate);
505         if (ret != CAMERA_ERROR_NONE) {
506
507                 return FALSE;
508         }
509         return TRUE;
510 }
511
512 gboolean cam_mm_set_camera_rotate(int camera_rotate)
513 {
514         int ret;
515         g_return_val_if_fail(g_mm_handle, FALSE);
516         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
517
518         #ifdef CAMERA_MACHINE_I686
519         ret = camera_attr_set_stream_rotation(g_mm_handle->hcam, 0);
520         #else
521         ret = camera_attr_set_stream_rotation(g_mm_handle->hcam, camera_rotate);
522         #endif
523         if (ret != CAMERA_ERROR_NONE) {
524                 cam_detail_error_get(ret);
525                 return FALSE;
526         }
527         return TRUE;
528
529 }
530
531 gboolean cam_mm_get_display_geometry_method(int *value)
532 {
533         int ret;
534         g_return_val_if_fail(g_mm_handle, FALSE);
535         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
536
537         ret = camera_get_x11_display_mode(g_mm_handle->hcam, (camera_display_mode_e *)value);
538         if (ret != CAMERA_ERROR_NONE) {
539                 return FALSE;
540         }
541         return TRUE;
542
543 }
544
545 gboolean cam_mm_set_display_geometry_method(int value)
546 {
547         int ret;
548         g_return_val_if_fail(g_mm_handle, FALSE);
549         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
550
551         ret = camera_set_x11_display_mode(g_mm_handle->hcam, (camera_display_mode_e)value);
552         if (ret != CAMERA_ERROR_NONE) {
553                 return FALSE;
554         }
555         return TRUE;
556 }
557
558 gboolean cam_mm_set_display_visible(gboolean visible)
559 {
560         int ret = 0;
561
562         g_return_val_if_fail(g_mm_handle, FALSE);
563         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
564
565         ret = camera_set_x11_display_visible(g_mm_handle->hcam, visible);
566         if (ret != RECORDER_ERROR_NONE) {
567                 return FALSE;
568         }
569         return TRUE;
570
571 }
572
573 gboolean cam_mm_set_filename(const gchar *filename)
574 {
575         int ret = 0;
576         /*char *err_name = NULL;*/
577
578         g_return_val_if_fail(g_mm_handle, FALSE);
579         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
580
581         if (filename) {
582                 ret = recorder_set_filename(g_mm_handle->hrec, filename);
583                 if (ret != RECORDER_ERROR_NONE) {
584                         return FALSE;
585                 }
586                 return TRUE;
587
588         } else {
589                 return FALSE;
590         }
591         return TRUE;
592 }
593
594 gboolean cam_mm_get_filename(char **filename, gint *size)
595 {
596         int ret = 0;
597
598         g_return_val_if_fail(g_mm_handle, FALSE);
599         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
600
601         ret = recorder_get_filename(g_mm_handle->hrec, filename);
602         if (ret != RECORDER_ERROR_NONE) {
603                 return FALSE;
604         }
605         return TRUE;
606
607 }
608
609 #ifdef ENABLE_CAPTURE_ANIMATION
610 gboolean cam_mm_get_screennail(MMCamcorderCaptureDataType **scrnl)
611 {
612         int ret = 0;
613         char *err_name = NULL;
614
615         MMCamcorderCaptureDataType *capture_struct = NULL;
616         int size = 0;
617         /* This is not the size of screennail buffer, this is a size of MMCamcorderCaptureDataType struct */
618         g_return_val_if_fail(g_mm_handle, FALSE);
619         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
620
621         ret = mm_camcorder_get_attributes(g_mm_handle->hmm, &err_name,
622                                           "captured-screennail",
623                                           &capture_struct, &size, NULL);
624
625         if (ret != CAMERA_ERROR_NONE) {
626                 printf("set attr failed - code[%x] name[%s]\n", ret, err_name);
627                 free(err_name);
628                 err_name = NULL;
629                 *scrnl = NULL;
630                 return FALSE;
631         }
632
633         *scrnl = capture_struct;
634
635         return TRUE;
636
637 }
638 #endif
639
640 gboolean cam_mm_get_max_size(int *value)
641 {
642         recorder_error_e ret;
643         g_return_val_if_fail(g_mm_handle, FALSE);
644         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
645         ret = recorder_attr_get_time_limit(g_mm_handle->hrec, value);
646         if (ret != RECORDER_ERROR_NONE) {
647                 return  FALSE;
648
649         }
650         return TRUE;
651
652 }
653
654 gboolean cam_mm_get_max_time(int *value)
655 {
656         recorder_error_e ret;
657         g_return_val_if_fail(g_mm_handle, FALSE);
658         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
659
660         ret = recorder_attr_get_time_limit(g_mm_handle->hrec, value);
661         if (ret != RECORDER_ERROR_NONE) {
662                 return  FALSE;
663
664         }
665         return TRUE;
666
667 }
668
669 gboolean cam_mm_set_max_size(int max_val)
670 {
671         recorder_error_e ret;
672         g_return_val_if_fail(g_mm_handle, FALSE);
673         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
674
675         ret = recorder_attr_set_size_limit(g_mm_handle->hrec, max_val);
676         if (ret != RECORDER_ERROR_NONE) {
677                 return  FALSE;
678
679         }
680         return TRUE;
681 }
682 gboolean cam_mm_get_tag_enable(int *value)
683 {
684         int ret;
685         g_return_val_if_fail(g_mm_handle, FALSE);
686         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
687
688         ret = camera_attr_is_enabled_tag(g_mm_handle->hcam, (bool *)value);
689         if (ret != CAMERA_ERROR_NONE) {
690                 return FALSE;
691         }
692
693         return TRUE;
694
695 }
696
697 gboolean cam_mm_set_tag_enable(gboolean bvalue)
698 {
699         int ret;
700         g_return_val_if_fail(g_mm_handle, FALSE);
701         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
702
703         ret = camera_attr_enable_tag(g_mm_handle->hcam, (bool)bvalue);
704         if (ret != CAMERA_ERROR_NONE) {
705                 return FALSE;
706         }
707
708         return TRUE;
709 }
710
711 gboolean cam_mm_set_tag_img_orient(int orient)
712 {
713         g_return_val_if_fail(g_mm_handle, FALSE);
714         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
715         camera_error_e ret;
716         ret = camera_attr_set_tag_orientation(g_mm_handle->hcam, (camera_attr_tag_orientation_e)orient);
717         if (ret != CAMERA_ERROR_NONE) {
718                 cam_detail_error_get(ret);
719                 return  FALSE;
720
721         }
722         return TRUE;
723
724 }
725
726 gboolean cam_mm_set_file_format(int format)
727 {
728         recorder_error_e ret;
729         g_return_val_if_fail(g_mm_handle, FALSE);
730         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
731         ret = recorder_set_file_format(g_mm_handle->hrec, format);
732         if (ret != RECORDER_ERROR_NONE) {
733                 return  FALSE;
734
735         }
736         return TRUE;
737 }
738
739 gboolean cam_mm_set_video_profile(void)
740 {
741         recorder_error_e e;
742
743         g_return_val_if_fail(g_mm_handle, FALSE);
744         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
745
746         e = recorder_attr_set_audio_device(g_mm_handle->hrec, RECORDER_AUDIO_DEVICE_MIC);
747         if (e != RECORDER_ERROR_NONE) {
748                 DEBUG_TRACE("set attr failed - code[%x]\n", e);
749                 rec_detail_error_get(e);
750                 return FALSE;
751         }
752
753         e = recorder_set_file_format(g_mm_handle->hrec, RECORDER_FILE_FORMAT_3GP);
754         if (e != RECORDER_ERROR_NONE) {
755                 DEBUG_TRACE("set attr failed - code[%x]\n", e);
756                 rec_detail_error_get(e);
757                 return FALSE;
758         }
759         return TRUE;
760 }
761
762 gboolean cam_mm_set_codec(int audio_codec, int video_codec)
763 {
764         int ret = 0;
765         recorder_error_e e;
766         g_return_val_if_fail(g_mm_handle, FALSE);
767         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
768
769         e = recorder_set_audio_encoder(g_mm_handle->hrec, audio_codec);
770         if (e != RECORDER_ERROR_NONE) {
771                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
772                 rec_detail_error_get(ret);
773                 return FALSE;
774         }
775         e = recorder_set_video_encoder(g_mm_handle->hrec, video_codec);
776         if (e != RECORDER_ERROR_NONE) {
777                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
778                 return FALSE;
779         }
780         return TRUE;
781 }
782
783 gboolean cam_mm_set_audio_source(int sample_rate, int format, int channel)
784 {
785         int ret = 0;
786         recorder_error_e e;
787         g_return_val_if_fail(g_mm_handle, FALSE);
788         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
789         e = recorder_attr_set_audio_samplerate(g_mm_handle->hrec, sample_rate);
790         if (e != RECORDER_ERROR_NONE) {
791                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
792                 return FALSE;
793         }
794         e = recorder_attr_set_audio_channel(g_mm_handle->hrec, channel);
795         if (e != RECORDER_ERROR_NONE) {
796                 DEBUG_TRACE("set attr failed - code[%x]\n", ret);
797                 return FALSE;
798         }
799         return TRUE;
800 }
801
802 gboolean cam_mm_set_video_source_format(int format)
803 {
804         if (format <= CAMERA_PIXEL_FORMAT_INVALID || format > CAMERA_PIXEL_FORMAT_JPEG)
805                 return FALSE;
806
807         int err;
808         g_return_val_if_fail(g_mm_handle, FALSE);
809         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
810         err = camera_set_preview_format(g_mm_handle->hcam, format);
811         if (err != CAMERA_ERROR_NONE) {
812
813                 return FALSE;
814         }
815         return TRUE;
816 }
817
818 gboolean cam_mm_get_video_source_format(const char *attribute_name, int *format)
819 {
820         DEBUG_TRACE("attribute_name = %s", attribute_name);
821         int err;
822         g_return_val_if_fail(g_mm_handle, FALSE);
823         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
824         err = camera_get_preview_format(g_mm_handle->hcam, format);
825         if (err != CAMERA_ERROR_NONE) {
826
827                 return FALSE;
828         }
829         return TRUE;
830 }
831
832 gboolean  cam_mm_get_front_cam_display_rotate_value(int *value, int *rotate)
833 {
834         int err;
835         g_return_val_if_fail(g_mm_handle, FALSE);
836         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
837         err = camera_attr_get_lens_orientation(g_mm_handle->hcam, value);
838         switch (*value) {
839         case 0:
840                 *rotate = CAMERA_ROTATION_NONE;
841                 break;
842         case 90:
843                 *rotate = CAMERA_ROTATION_90;
844                 break;
845         case 180:
846                 *rotate = CAMERA_ROTATION_180;
847                 break;
848         case 270:
849                 *rotate = CAMERA_ROTATION_270;
850                 break;
851         default:
852                 *rotate = CAMERA_ROTATION_NONE;
853
854         }
855         if (err != CAMERA_ERROR_NONE) {
856
857                 return FALSE;
858         }
859
860         return TRUE;
861
862 }
863
864 gboolean cam_mm_set_capture_format(int value)
865 {
866         int err;
867         g_return_val_if_fail(g_mm_handle, FALSE);
868         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
869
870         err = camera_set_capture_format(g_mm_handle->hcam, value);
871         if (err != CAMERA_ERROR_NONE) {
872
873                 return FALSE;
874         }
875
876         return TRUE;
877 }
878
879 gboolean cam_mm_get_shutter_sound(int *value)
880 {
881 /*todo:for lawer policy, capi could not surport it*/
882 #ifndef TODO_SURRPORT
883         return cam_mm_get_attr_int(MMCAM_SHUTTER_SOUND, value);
884 #else
885         return TRUE;
886 #endif
887
888 }
889 gboolean cam_mm_set_shutter_sound(int value)
890 {
891 /*todo:for lawer policy, capi could not surport it*/
892 #ifndef TODO_SURRPORT
893         return cam_mm_set_attr_int(MMCAM_SHUTTER_SOUND, value);
894 #else
895         return TRUE;
896 #endif
897
898 }
899
900 gboolean cam_mm_reset_recording_motion_fps()
901 {
902         int ret = 0;
903         g_return_val_if_fail(g_mm_handle, FALSE);
904         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
905
906         ret = recorder_attr_set_recording_motion_rate(g_mm_handle->hrec, DEFAULT_REC_FPS);
907         if (ret != RECORDER_ERROR_NONE) {
908
909                 return FALSE;
910         }
911         return TRUE;
912 }
913
914 gboolean cam_mm_preview_start(int mode)
915 {
916         g_return_val_if_fail(g_mm_handle, FALSE);
917         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
918
919         struct appdata *ad = (struct appdata *)cam_appdata_get();
920         g_return_val_if_fail(ad, FALSE);
921
922         int ret = (mode == CAM_CAMERA_MODE) ? CAMERA_ERROR_NONE : RECORDER_ERROR_NONE;
923         if (CAM_CAMERA_MODE == mode) {
924
925                 ret = camera_start_preview(g_mm_handle->hcam);
926                 if (ret != CAMERA_ERROR_NONE) {
927                         if (ret == CAMERA_ERROR_SOUND_POLICY) {
928                                 ad->is_calling = CAMERA_ERROR_SOUND_POLICY;
929                         } else if (ret == CAMERA_ERROR_SECURITY_RESTRICTED) {
930                                 cam_app_mdm_syspopup(ad);
931                                 return FALSE;
932                         } else {
933                                 cam_critical(LOG_MM, "camera_start_preview failed");
934                                 return FALSE;
935                         }
936                 }
937                 cam_debug(LOG_MM, " ret : %d", ret);
938
939         }else if (CAM_CAMCORDER_MODE == mode) {
940
941                 g_return_val_if_fail(g_mm_handle->hrec, FALSE);
942
943                 ret = recorder_prepare(g_mm_handle->hrec);
944                 if (ret != RECORDER_ERROR_NONE) {
945                         if (ret == RECORDER_ERROR_SOUND_POLICY) {
946                                 ad->is_calling = RECORDER_ERROR_SOUND_POLICY;
947                         } else if (ret == RECORDER_ERROR_SECURITY_RESTRICTED) {
948                                 cam_app_mdm_syspopup(ad);
949                                 return FALSE;
950                         } else {
951                                 cam_critical(LOG_MM, "camera_start_preview failed");
952                                 return FALSE;
953                         }
954                 }
955                 cam_debug(LOG_MM, " ret : %d", ret);
956         }
957
958         return TRUE;
959
960 }
961
962 gboolean cam_mm_preview_stop(int mode)
963 {
964         int state = 0;
965         g_return_val_if_fail(g_mm_handle, FALSE);
966         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
967
968         if (CAM_CAMERA_MODE == mode) {
969                 state = cam_mm_get_cam_state();
970                 cam_debug(LOG_MM, " camera state : %d", state);
971                 /*todo:please consider recorder and camera*/
972                 if (state < 0)
973                         return FALSE;
974
975                 switch (state) {
976                 case CAMERA_STATE_NONE:
977                         return FALSE;
978                         break;
979                 case CAMERA_STATE_CREATED:
980                         /* stop state return TRUE; */
981                         break;
982                 case CAMERA_STATE_PREVIEW:
983                         CHECK_MM_ERROR(camera_stop_preview(g_mm_handle->hcam));
984                         break;
985                 case CAMERA_STATE_CAPTURING:
986                         return FALSE;
987                         break;
988                 default:
989                         break;
990
991                 }
992                 return TRUE;
993         }else if (CAM_CAMCORDER_MODE == mode) {
994
995                 state = cam_mm_get_rec_state();
996                 g_return_val_if_fail(g_mm_handle->hrec, FALSE);
997                 cam_debug(LOG_MM, " camera state : %d", state);
998                 /*todo:please consider recorder and camera*/
999                 if (state < 0)
1000                         return FALSE;
1001
1002                 switch (state) {
1003                 case RECORDER_STATE_NONE:
1004                         return FALSE;
1005                         break;
1006                 case RECORDER_STATE_CREATED:
1007                         /* stop state return TRUE; */
1008                         break;
1009                 case RECORDER_STATE_READY:
1010                         CHECK_MM_ERROR(recorder_unprepare(g_mm_handle->hrec));
1011                         break;
1012                 case RECORDER_STATE_RECORDING:
1013                         return FALSE;
1014                         break;
1015                 case RECORDER_STATE_PAUSED:
1016                         return FALSE;
1017                         break;
1018                 default:
1019                         break;
1020
1021                 }
1022                 return TRUE;
1023
1024         }
1025         return TRUE;
1026 }
1027
1028 gboolean cam_mm_is_created(void)
1029 {
1030         debug_fenter(LOG_MM);
1031         if (g_mm_handle) {
1032                 return TRUE;
1033         }
1034         return FALSE;
1035 }
1036
1037 gboolean cam_mm_create(int camera_type, int mode)
1038 {
1039                 CAM_TA_ACUM_ITEM_BEGIN("----cam_mm_create", 0);
1040                 DEBUG_TRACE
1041                         ("--------------------------------START----------------------------");
1042                 DEBUG_TRACE("camera_type = %d" ,camera_type);
1043                 if (g_mm_handle) {
1044                         cam_critical(LOG_MM, "The mm handle is already created");
1045                         return false;
1046                 }
1047                 g_return_val_if_fail(g_mm_handle == NULL, FALSE);
1048                 camera_h hcam;
1049                 camera_error_e e;
1050                 e = camera_create(camera_type, &hcam);
1051                 if (e != CAMERA_ERROR_NONE) {
1052                         DEBUG_TRACE("[ERROR] camera_create - error(%d)", e);
1053                         return FALSE;
1054                 }
1055                 g_return_val_if_fail(hcam, FALSE);
1056                 recorder_h hrec = NULL;
1057                 if (mode == CAM_CAMCORDER_MODE) {
1058                         recorder_error_e re;
1059                         re = recorder_create_videorecorder(hcam, &hrec);
1060                         if (re != RECORDER_ERROR_NONE) {
1061                                 DEBUG_TRACE("[ERROR] camera_create - error(%d)", e);
1062                                 recorder_destroy(hrec);
1063                                 camera_destroy(hcam);
1064                                 return FALSE;
1065                         }
1066                         g_return_val_if_fail(hcam, FALSE);
1067                 }
1068                 g_mm_handle = g_new0(CamMMHandle, 1);
1069                 if (g_mm_handle) {
1070                         g_mm_handle->hcam = hcam;
1071                         g_mm_handle->hdev = camera_type;
1072                         g_mm_handle->hrec = hrec;
1073                 }
1074                 DEBUG_TRACE("camera_type = %d" , g_mm_handle->hdev);
1075
1076                 DEBUG_TRACE("--------------END---------------");
1077                 CAM_TA_ACUM_ITEM_BEGIN("----cam_mm_create", 0);
1078
1079                 return g_mm_handle ? TRUE : FALSE;
1080
1081 }
1082
1083 gboolean cam_mm_destory(void)
1084 {
1085         int state = 0;
1086         g_return_val_if_fail(g_mm_handle, FALSE);
1087         struct appdata *ad = (struct appdata *)cam_appdata_get();
1088         g_return_val_if_fail(ad, FALSE);
1089         CamAppData *camapp = ad->camapp_handle;
1090         g_return_val_if_fail(camapp, FALSE);
1091         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
1092                 if (g_mm_handle->hrec) {
1093                         state = cam_mm_get_state();
1094                         DEBUG_TRACE("camera state : %d\n",
1095                                state);
1096                         if (state != RECORDER_STATE_CREATED) { /*no need delete*/
1097                         /*TODO:now capi, have to change with camera and rec handle*/
1098                                 printf
1099                                     ("[cam_mm_destory] Camera state is not match : %d\n",
1100                                      state);
1101                                 return FALSE;
1102                         }
1103                         CHECK_MM_ERROR(recorder_destroy(g_mm_handle->hrec));/*TODO:there is issue about in rec,to delete rec and cam handle*/
1104                         CHECK_MM_ERROR(camera_destroy(g_mm_handle->hcam));
1105                         g_mm_handle->hcam = 0;
1106                         g_mm_handle->hrec = 0;
1107                         g_mm_handle->hdev = -1;
1108
1109                 }
1110         } else if (camapp->camera_mode == CAM_CAMERA_MODE) {
1111                 state = cam_mm_get_state();
1112                                 DEBUG_TRACE("camera state : %d\n",
1113                        state);
1114                 if (state != CAMERA_STATE_CREATED) {
1115                         printf
1116                             ("[cam_mm_destory] Camera state is not match : %d\n",
1117                              state);
1118                         return FALSE;
1119                 }
1120                 CHECK_MM_ERROR(camera_destroy(g_mm_handle->hcam));
1121
1122                 g_mm_handle->hcam = 0;
1123                 g_mm_handle->hrec = 0;
1124                 g_mm_handle->hdev = -1;
1125         }
1126
1127         g_free(g_mm_handle);
1128         g_mm_handle = NULL;
1129
1130         return TRUE;
1131 }
1132
1133 gboolean cam_mm_continuous_capture_start(int count, int interval, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb , void *user_data)
1134 {
1135         g_return_val_if_fail(g_mm_handle, FALSE);
1136         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1137
1138         cam_debug(LOG_MM, "");
1139         CAM_TA_ACUM_ITEM_END("        camera key to capture start", 0);
1140
1141         if (cam_mm_get_state() == CAMERA_STATE_PREVIEW) {
1142                 CAM_TA_ACUM_ITEM_BEGIN("camera_start_continuous_capture", 0);
1143                 CHECK_MM_ERROR(camera_start_continuous_capture(g_mm_handle->hcam, count, interval, capturing_cb, completed_cb, user_data));
1144                 CAM_TA_ACUM_ITEM_END("camera_start_continuous_capture", 0);
1145         } else {
1146                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1147                        __LINE__, cam_mm_get_state());
1148                 return FALSE;
1149         }
1150         return TRUE;
1151 }
1152
1153
1154 gboolean cam_mm_capture_start(camera_capturing_cb capturing_cb , camera_capture_completed_cb completed_cb , void *user_data)
1155 {
1156         g_return_val_if_fail(g_mm_handle, FALSE);
1157         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1158
1159         cam_debug(LOG_MM, "");
1160         CAM_TA_ACUM_ITEM_END("        camera key to capture start", 0);
1161
1162         if (cam_mm_get_state() == CAMERA_STATE_PREVIEW
1163                 || cam_mm_get_state() == RECORDER_STATE_RECORDING) {
1164                 CAM_TA_ACUM_ITEM_BEGIN("camera_start_capture", 0);
1165                 CHECK_MM_ERROR(camera_start_capture(g_mm_handle->hcam, capturing_cb, completed_cb, user_data));
1166                 CAM_TA_ACUM_ITEM_END("mm_camcorder_capture_start", 0);
1167         } else {
1168                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1169                        __LINE__, cam_mm_get_state());
1170                 return FALSE;
1171         }
1172         return TRUE;
1173 }
1174
1175 gboolean cam_mm_capture_stop(gboolean skip_preview, CamMode mode)
1176 {
1177         int state = CAMERA_STATE_NONE;/*TODO:now the value is same to record*/
1178
1179         g_return_val_if_fail(g_mm_handle, FALSE);
1180         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1181
1182         cam_debug(LOG_MM, " start");
1183
1184         state = cam_mm_get_state();
1185         if (state == RECORDER_STATE_READY && skip_preview == FALSE && mode == CAM_CAMCORDER_MODE) {
1186                 CHECK_MM_ERROR(recorder_prepare(g_mm_handle->hrec));
1187         } else {
1188                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1189                        __LINE__, cam_mm_get_state());
1190                 return FALSE;
1191         }
1192
1193         cam_debug(LOG_MM, " done");
1194
1195         return TRUE;
1196 }
1197
1198 gboolean cam_mm_rec_start()
1199 {
1200         int state = 0;
1201         g_return_val_if_fail(g_mm_handle, FALSE);
1202         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1203
1204         state = cam_mm_get_state();
1205         if ((state == RECORDER_STATE_READY)
1206             || (state == RECORDER_STATE_PAUSED)) {
1207                 CHECK_MM_ERROR(recorder_start(g_mm_handle->hrec));
1208         } else {
1209                 DEBUG_TRACE("operation failed - state:%d \n", state);
1210                 return FALSE;
1211         }
1212         return TRUE;
1213 }
1214
1215 gboolean cam_mm_rec_stop(gboolean to_stop)
1216 {
1217         int state = 0;
1218         g_return_val_if_fail(g_mm_handle, FALSE);
1219         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1220
1221         state = cam_mm_get_state();
1222         if ((state == RECORDER_STATE_RECORDING)
1223             || (state == RECORDER_STATE_PAUSED)) {
1224                 if (!to_stop) {
1225                         CHECK_MM_ERROR(recorder_commit(g_mm_handle->hrec));
1226                 } else {
1227                         CHECK_MM_ERROR(recorder_commit(g_mm_handle->hrec));
1228                         CHECK_MM_ERROR(recorder_unprepare(g_mm_handle->hrec));
1229                 }
1230         } else {
1231                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1232                        __LINE__, state);
1233                 return FALSE;
1234         }
1235         return TRUE;
1236 }
1237
1238 gboolean cam_mm_rec_pause()
1239 {
1240         int state = 0;
1241         g_return_val_if_fail(g_mm_handle, FALSE);
1242         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1243
1244         state = cam_mm_get_state();
1245         if ((state == RECORDER_STATE_RECORDING)) {
1246                 CHECK_MM_ERROR(recorder_pause(g_mm_handle->hrec));
1247         } else {
1248                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1249                        __LINE__, state);
1250                 return FALSE;
1251         }
1252         return TRUE;
1253 }
1254
1255 gboolean cam_mm_rec_cancel()
1256 {
1257         int state = 0;
1258         g_return_val_if_fail(g_mm_handle, FALSE);
1259         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1260
1261         state = cam_mm_get_state();
1262         if ((state == RECORDER_STATE_RECORDING)
1263             || (state == RECORDER_STATE_PAUSED)) {
1264                 CHECK_MM_ERROR(recorder_cancel(g_mm_handle->hrec));
1265         } else {
1266                 printf("[%s:%d] operation failed - state:%d \n", __func__,
1267                        __LINE__, state);
1268                 return FALSE;
1269         }
1270         return TRUE;
1271 }
1272
1273 gboolean cam_mm_session_init(sound_session_type_e session_type)
1274 {
1275         int ret = SOUND_MANAGER_ERROR_NONE;
1276         if (ret != sound_manager_set_session_type(session_type)) {
1277                 DEBUG_TRACE("[%s:%d] operation failed - session_type:%d \n",
1278                        __func__, __LINE__, session_type);
1279                 return FALSE;
1280         }
1281         return TRUE;
1282
1283 }
1284 gboolean cam_mm_start_focusing(gint af_mode)
1285 {
1286         int state = 0;
1287
1288         g_return_val_if_fail(g_mm_handle, FALSE);
1289         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1290
1291         cam_debug(LOG_UI, "");
1292         state = cam_mm_get_state();
1293         if (state == CAMERA_STATE_PREVIEW
1294                 || state == CAMERA_STATE_CREATED) {
1295                 if (af_mode) {
1296                         /*continuous AF*/
1297                         CHECK_MM_ERROR(camera_start_focusing(g_mm_handle->hcam, TRUE));
1298                 } else {
1299                         /*Touch Auto AF*/
1300                         CHECK_MM_ERROR(camera_start_focusing(g_mm_handle->hcam, FALSE));
1301                 }
1302         } else {
1303                 DEBUG_TRACE("Start focus operation failed - invalid state:%d \n", state);
1304                 return FALSE;
1305         }
1306
1307         return TRUE;
1308 }
1309
1310 gboolean cam_mm_stop_focusing()
1311 {
1312         int state = 0;
1313
1314         g_return_val_if_fail(g_mm_handle, FALSE);
1315         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1316
1317         cam_debug(LOG_UI, "");
1318
1319         state = cam_mm_get_state();
1320         if (state == CAMERA_STATE_PREVIEW
1321                 || state == CAMERA_STATE_CREATED
1322                 || state == RECORDER_STATE_RECORDING) {
1323                 /*TODO:please think rec mod, but now the rec and cam mode state value is same*/
1324                 CHECK_MM_ERROR(camera_cancel_focusing(g_mm_handle->hcam));
1325         } else {
1326                 printf
1327                     ("[%s:%d] Stop focus operation failed - invalid state:%d \n",
1328                      __func__, __LINE__, state);
1329                 return FALSE;
1330         }
1331
1332         return TRUE;
1333 }
1334
1335 gboolean cam_mm_set_error_cb(camera_error_cb error_cb, void *data)
1336 {
1337         camera_error_e e;
1338         g_return_val_if_fail(g_mm_handle, FALSE);
1339         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1340         e = camera_set_error_cb(g_mm_handle->hcam, error_cb, data);
1341                 if (e != CAMERA_ERROR_NONE) {
1342                         DEBUG_TRACE("[ERROR] camera_set_error_cb - error(%d)", e);
1343                         return FALSE;
1344                 }
1345                 return TRUE;
1346
1347 }
1348
1349 gboolean cam_mm_unset_error_cb(void)
1350 {
1351         camera_error_e e;
1352         g_return_val_if_fail(g_mm_handle, FALSE);
1353         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1354         e = camera_unset_error_cb(g_mm_handle->hcam);
1355         if (e != CAMERA_ERROR_NONE) {
1356                 DEBUG_TRACE("[ERROR] camera_unset_error_cb - error(%d)", e);
1357                 return FALSE;
1358         }
1359         return TRUE;
1360
1361 }
1362
1363 gboolean cam_mm_set_state_changed_cb(camera_state_changed_cb state_cb, void *data)
1364 {
1365         camera_error_e e;
1366         g_return_val_if_fail(g_mm_handle, FALSE);
1367         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1368
1369         e = camera_set_state_changed_cb(g_mm_handle->hcam, state_cb, data);
1370         if (e != CAMERA_ERROR_NONE) {
1371                 DEBUG_TRACE("[ERROR] camera_set_state_changed_cb - error(%d)", e);
1372                 return FALSE;
1373         }
1374         return TRUE;
1375 }
1376
1377 gboolean cam_mm_unset_state_changed_cb(void)
1378 {
1379         camera_error_e e;
1380         g_return_val_if_fail(g_mm_handle, FALSE);
1381         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1382
1383         e = camera_unset_state_changed_cb(g_mm_handle->hcam);
1384         if (e != CAMERA_ERROR_NONE) {
1385                 DEBUG_TRACE("[ERROR] camera_unset_state_changed_cb - error(%d)", e);
1386                 return FALSE;
1387         }
1388         return TRUE;
1389 }
1390
1391
1392 gboolean cam_mm_set_focus_changed_cb(camera_focus_changed_cb focus_cb, void *data)
1393 {
1394         camera_error_e e;
1395         g_return_val_if_fail(g_mm_handle, FALSE);
1396         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1397
1398         e = camera_set_focus_changed_cb(g_mm_handle->hcam, focus_cb, data);
1399         if (e != CAMERA_ERROR_NONE) {
1400                 DEBUG_TRACE("[ERROR] camera_set_focus_changed_cb - error(%d)", e);
1401                 return FALSE;
1402         }
1403         return TRUE;
1404 }
1405
1406 gboolean cam_mm_unset_focus_changed_cb(void)
1407 {
1408         camera_error_e e;
1409         g_return_val_if_fail(g_mm_handle, FALSE);
1410         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1411
1412         e = camera_unset_focus_changed_cb(g_mm_handle->hcam);
1413         if (e != CAMERA_ERROR_NONE) {
1414                 DEBUG_TRACE("[ERROR] camera_unset_focus_changed_cb - error(%d)", e);
1415                 return FALSE;
1416         }
1417         return TRUE;
1418 }
1419
1420 gboolean cam_mm_set_preview_cb(camera_preview_cb preview_cb, void *data)
1421 {
1422         camera_error_e e;
1423         g_return_val_if_fail(g_mm_handle, FALSE);
1424         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1425
1426         e = camera_set_preview_cb(g_mm_handle->hcam, preview_cb, data);
1427         if (e != CAMERA_ERROR_NONE) {
1428                 DEBUG_TRACE("[ERROR] camera_set_preview_cb - error(%d)", e);
1429                 return FALSE;
1430         }
1431         return TRUE;
1432
1433 }
1434
1435 gboolean cam_mm_unset_preview_cb(void)
1436 {
1437         camera_error_e e;
1438         g_return_val_if_fail(g_mm_handle, FALSE);
1439         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1440
1441         e = camera_unset_preview_cb(g_mm_handle->hcam);
1442         if (e != CAMERA_ERROR_NONE) {
1443                 DEBUG_TRACE("[ERROR] camera_unset_preview_cb - error(%d)", e);
1444                 return FALSE;
1445         }
1446         return TRUE;
1447
1448 }
1449
1450 #ifndef CAPI_CAMERA_NEW/*TODO:the capi have changed, but they have not upload pkg,if uploaded, delete these*/
1451 gboolean cam_mm_set_capturing_cb(camera_capturing_cb capture_cb, void *data)
1452 {
1453         camera_error_e e;
1454         g_return_val_if_fail(g_mm_handle, FALSE);
1455         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1456
1457         e = camera_set_capturing_cb(g_mm_handle->hcam, capture_cb, data);
1458         if (e != CAMERA_ERROR_NONE) {
1459                 DEBUG_TRACE("[ERROR] cam_mm_set_capturing_cb - error(%d)", e);
1460                 return FALSE;
1461         }
1462         return TRUE;
1463 }
1464
1465 gboolean cam_mm_unset_capturing_cb(void)
1466 {
1467         camera_error_e e;
1468         g_return_val_if_fail(g_mm_handle, FALSE);
1469         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1470
1471         e = camera_unset_capturing_cb(g_mm_handle->hcam);
1472         if (e != CAMERA_ERROR_NONE) {
1473                 DEBUG_TRACE("[ERROR] camera_unset_capturing_cb - error(%d)", e);
1474                 return FALSE;
1475         }
1476         return TRUE;
1477 }
1478
1479 gboolean cam_mm_set_capture_completed_cb(camera_capture_completed_cb capture_completed_cb, void *data)
1480 {
1481         camera_error_e e;
1482         g_return_val_if_fail(g_mm_handle, FALSE);
1483         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1484
1485         e = camera_set_capture_completed_cb(g_mm_handle->hcam, capture_completed_cb, data);
1486         if (e != CAMERA_ERROR_NONE) {
1487                 DEBUG_TRACE("[ERROR] cam_mm_set_capture_completed_cb - error(%d)", e);
1488                 return FALSE;
1489         }
1490         return TRUE;
1491 }
1492
1493 gboolean cam_mm_unset_capture_completed_cb(void)
1494 {
1495         camera_error_e e;
1496         g_return_val_if_fail(g_mm_handle, FALSE);
1497         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1498
1499         e = camera_unset_capture_completed_cb(g_mm_handle->hcam);
1500         if (e != CAMERA_ERROR_NONE) {
1501                 DEBUG_TRACE("[ERROR] camera_unset_capture_completed_cb - error(%d)", e);
1502                 return FALSE;
1503         }
1504         return TRUE;
1505 }
1506
1507 #endif
1508
1509 gboolean cam_mm_set_camera_interrupted_cb(camera_interrupted_cb callback, void *data){
1510
1511         camera_error_e e;
1512         g_return_val_if_fail(g_mm_handle, FALSE);
1513         g_return_val_if_fail(g_mm_handle->hcam, FALSE);
1514
1515         e = camera_set_interrupted_cb(g_mm_handle->hcam, callback, data);
1516         if (e != CAMERA_ERROR_NONE) {
1517                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1518                 return FALSE;
1519         }
1520         return TRUE;
1521 }
1522 gboolean cam_mm_set_recorder_interrupted_cb(recorder_interrupted_cb callback, void *data){
1523
1524         recorder_error_e e;
1525         g_return_val_if_fail(g_mm_handle, FALSE);
1526         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1527
1528         e = recorder_set_interrupted_cb(g_mm_handle->hrec, callback, data);
1529         if (e != RECORDER_ERROR_NONE) {
1530                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1531                 return FALSE;
1532         }
1533         return TRUE;
1534 }
1535
1536 gboolean cam_mm_recorder_set_state_changed_cb(recorder_state_changed_cb callback, void* user_data)
1537 {
1538         recorder_error_e e;
1539         g_return_val_if_fail(g_mm_handle, FALSE);
1540         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1541
1542         e = recorder_set_state_changed_cb(g_mm_handle->hrec, callback, user_data);
1543         if (e != RECORDER_ERROR_NONE) {
1544                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1545                 rec_detail_error_get(e);
1546                 return FALSE;
1547         }
1548         return TRUE;
1549
1550 }
1551
1552 gboolean cam_mm_recorder_unset_state_changed_cb(void)
1553 {
1554         recorder_error_e e;
1555         g_return_val_if_fail(g_mm_handle, FALSE);
1556         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1557
1558         e = recorder_unset_state_changed_cb(g_mm_handle->hrec);
1559         if (e != RECORDER_ERROR_NONE) {
1560                 DEBUG_TRACE("[ERROR] recorder_set_state_changed_cb - error(%d)", e);
1561                 rec_detail_error_get(e);
1562                 return FALSE;
1563         }
1564         return TRUE;
1565
1566 }
1567
1568 gboolean cam_mm_recorder_set_recording_status_cb(recorder_recording_status_cb callback, void* user_data)
1569 {
1570         recorder_error_e e;
1571         g_return_val_if_fail(g_mm_handle, FALSE);
1572         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1573
1574         e = recorder_set_recording_status_cb(g_mm_handle->hrec, callback, user_data);
1575         if (e != RECORDER_ERROR_NONE) {
1576                 DEBUG_TRACE("[ERROR] recorder_set_recording_status_cb - error(%d)", e);
1577                 rec_detail_error_get(e);
1578                 return FALSE;
1579         }
1580         return TRUE;
1581
1582 }
1583
1584 gboolean cam_mm_recorder_unset_recording_status_cb(void)
1585 {
1586         recorder_error_e e;
1587         g_return_val_if_fail(g_mm_handle, FALSE);
1588         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1589
1590         e = recorder_unset_recording_status_cb(g_mm_handle->hrec);
1591         if (e != RECORDER_ERROR_NONE) {
1592                 DEBUG_TRACE("[ERROR] recorder_unset_recording_status_cb - error(%d)", e);
1593                 rec_detail_error_get(e);
1594                 return FALSE;
1595         }
1596         return TRUE;
1597
1598 }
1599
1600 gboolean cam_mm_recorder_set_recording_limit_reached_cb(recorder_recording_limit_reached_cb callback, void* user_data)
1601 {
1602         recorder_error_e e;
1603         g_return_val_if_fail(g_mm_handle, FALSE);
1604         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1605
1606         e = recorder_set_recording_limit_reached_cb(g_mm_handle->hrec, callback, user_data);
1607         if (e != RECORDER_ERROR_NONE) {
1608                 DEBUG_TRACE("[ERROR] recorder_set_recording_status_cb - error(%d)", e);
1609                 rec_detail_error_get(e);
1610                 return FALSE;
1611         }
1612         return TRUE;
1613
1614 }
1615
1616 gboolean cam_mm_recorder_unset_recording_limit_reached_cb(void)
1617 {
1618         recorder_error_e e;
1619         g_return_val_if_fail(g_mm_handle, FALSE);
1620         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1621
1622         e = recorder_unset_recording_limit_reached_cb(g_mm_handle->hrec);
1623         if (e != RECORDER_ERROR_NONE) {
1624                 DEBUG_TRACE("[ERROR] recorder_unset_recording_status_cb - error(%d)", e);
1625                 rec_detail_error_get(e);
1626                 return FALSE;
1627         }
1628         return TRUE;
1629
1630 }
1631
1632 gboolean cam_mm_set_recording_motion(double rate)
1633 {
1634         g_return_val_if_fail(g_mm_handle, FALSE);
1635         g_return_val_if_fail(g_mm_handle->hrec, FALSE);
1636
1637         int err;
1638         err = recorder_attr_set_recording_motion_rate(g_mm_handle->hrec, rate);
1639         if (err != RECORDER_ERROR_NONE) {
1640                 DEBUG_TRACE("recorder_attr_set_recording_motion_rate failed");
1641                 return FALSE;
1642         }
1643
1644         err = recorder_set_video_encoder(g_mm_handle->hrec, RECORDER_VIDEO_CODEC_H264);
1645         if (err != RECORDER_ERROR_NONE) {
1646                 DEBUG_TRACE("recorder_set_video_encoder failed");
1647                 return FALSE;
1648         }
1649
1650         err = recorder_attr_set_video_encoder_bitrate(g_mm_handle->hrec, 10000000);
1651         if (err != RECORDER_ERROR_NONE) {
1652                 DEBUG_TRACE("recorder_attr_set_video_encoder_bitrate failed");
1653                 return FALSE;
1654         }
1655
1656         err = recorder_set_file_format(g_mm_handle->hrec, RECORDER_FILE_FORMAT_3GP);
1657         if (err < 0) {
1658                 cam_debug(LOG_MM,
1659                           "High speed recording. mm_camcorder_set_attributes fail. %d)", err);
1660                 return FALSE;
1661         }
1662         return TRUE;
1663
1664 }
1665 gboolean cam_mm_get_caps_minmax(unsigned int type, int *min, int *max)
1666 {
1667         if (!cam_mm_is_created()) {
1668                 cam_debug(LOG_CAM, "cam_mm_is_created() false");
1669                 return FALSE;
1670         }
1671
1672         gboolean ret = TRUE;
1673         int tempmin, tempmax = 0;
1674
1675         switch(type) {
1676         case CAM_CP_FUNC_ZOOM:
1677                 {
1678                         if (camera_attr_get_zoom_range(g_mm_handle->hcam, &tempmin, &tempmax)
1679                                 != CAMERA_ERROR_NONE) {
1680                                 cam_debug(LOG_CAM, "camera_attr_get_zoom_range() is false");
1681                                 ret = FALSE;
1682                          }
1683                 }
1684                 break;
1685         default:
1686                 {
1687                         cam_debug(LOG_CAM, "not support get_minmax() about this type[%d]", type);
1688                         ret = FALSE;
1689                 }
1690                 break;
1691         }
1692
1693         if (!ret) {
1694                 tempmin = 0;
1695                 tempmax = 0;
1696         }
1697
1698         *min = tempmin;
1699         *max = tempmax;
1700         return ret;
1701
1702 }
1703
1704 gboolean cam_mm_get_caps_range(unsigned int type, unsigned int *caps, void *user_data)
1705 {
1706         if (!cam_mm_is_created()) {
1707                 cam_debug(LOG_CAM, "cam_mm_is_created() false");
1708                 return FALSE;
1709         }
1710
1711         g_caps = 0;
1712         g_caps_cb_cnt = 0;
1713         gboolean ret = TRUE;
1714
1715         switch(type) {
1716         case CAM_CP_FUNC_EFFECT_MODE:
1717                 {
1718                         if (camera_attr_foreach_supported_effect(g_mm_handle->hcam,
1719                                 (camera_attr_supported_effect_cb)__get_effect_cb, user_data) != CAMERA_ERROR_NONE ) {
1720                                 cam_debug(LOG_CAM, "camera_attr_foreach_supported_effect() is fail");
1721                                 ret = FALSE;
1722                         }
1723                 }
1724                 break;
1725         default:
1726                 {
1727                         cam_debug(LOG_CAM, "not support get_range() about this type[%d]", type);
1728                         ret = FALSE;
1729                 }
1730                 break;
1731         }
1732
1733         *caps = g_caps;
1734         return ret;
1735 }
1736
1737 const int cam_mm_get_caps_cb_cnt()
1738 {
1739         return g_caps_cb_cnt;
1740 }
1741
1742 static void __get_effect_cb(camera_attr_effect_mode_e effect, void *user_data)
1743 {
1744         cam_retm_if(effect < CAMERA_ATTR_EFFECT_NONE|| effect > CAMERA_ATTR_EFFECT_SKETCH, "input is invalid");
1745
1746         unsigned int uRet = cam_effect_dev_convert_caps(effect);
1747         if (uRet != 0 ) {
1748                 g_caps |= uRet;
1749                 g_caps_cb_cnt++;
1750         }
1751 }
1752
1753 //end of file