995c8c113337767c73b4e839847067a3c239ee76
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Camera / CameraFeature.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using Tizen.Internals.Errors;
20 using System.Xml.Schema;
21
22 namespace Tizen.Multimedia
23 {
24     /// <summary>
25     /// The CameraFeature class provides properties
26     /// to get various capability information of the camera device.
27     /// </summary>
28     public class CameraFeature
29     {
30         internal readonly IntPtr _cameraHandle;
31         private readonly List<CameraResolution> _previewResolution;
32         private readonly List<CameraResolution> _cameraResolution;
33         private readonly List<CameraPixelFormat> _captureFormat;
34         private readonly List<CameraPixelFormat> _previewFormat;
35         private readonly List<CameraFps> _fps;
36         private readonly List<CameraFps> _fpsResolution;
37         private readonly List<CameraAutoFocusMode> _afMode;
38         private readonly List<CameraExposureMode> _exposureMode;
39         private readonly List<CameraTheaterMode> _theater;
40         private readonly List<CameraWhitebalance> _whitebalance;
41         private readonly List<CameraIsoLevel> _iso;
42         private readonly List<CameraEffectMode> _effect;
43         private readonly List<CameraSceneMode> _sceneMode;
44         private readonly List<CameraFlashMode> _flashMode;
45         private readonly List<CameraRotation> _streamRotation;
46         private readonly List<CameraFlip> _streamFlip;
47         private readonly List<CameraPtzType> _ptzType;
48
49         internal CameraFeature(IntPtr _handle)
50         {
51             _cameraHandle = _handle;
52             _previewResolution = new List<CameraResolution>();
53             _cameraResolution = new List<CameraResolution>();
54             _captureFormat = new List<CameraPixelFormat>();
55             _previewFormat = new List<CameraPixelFormat>();
56             _fps = new List<CameraFps>();
57             _fpsResolution = new List<CameraFps>();
58             _afMode = new List<CameraAutoFocusMode>();
59             _exposureMode = new List<CameraExposureMode>();
60             _theater = new List<CameraTheaterMode>();
61             _whitebalance = new List<CameraWhitebalance>();
62             _iso = new List<CameraIsoLevel>();
63             _effect = new List<CameraEffectMode>();
64             _sceneMode = new List<CameraSceneMode>();
65             _flashMode = new List<CameraFlashMode>();
66             _streamRotation = new List<CameraRotation>();
67             _streamFlip = new List<CameraFlip>();
68             _ptzType = new List<CameraPtzType>();
69         }
70
71         /// <summary>
72         /// Gets continuous capture feature's supported state.
73         /// true if supported, otherwise false.
74         /// </summary>
75         public bool ContinuousCapture
76         {
77             get
78             {
79                 bool val = false;
80
81                 val = Interop.CameraFeature.ContinuousCaptureSupport(_cameraHandle);
82                 int ret = ErrorFacts.GetLastResult();
83                 if ((CameraError)ret != CameraError.None)
84                 {
85                     CameraError err = (CameraError)ret;
86                     Log.Error(CameraLog.Tag, "Failed to get continuous feature support, " + err.ToString());
87                 }
88
89                 return val;
90             }
91         }
92
93         /// <summary>
94         /// Gets the face detection feature's supported state.
95         /// true if supported, otherwise false.
96         /// </summary>
97         public bool FaceDetectionSupported
98         {
99             get
100             {
101                 bool val = false;
102
103                 val = Interop.CameraFeature.FaceDetectionSupport(_cameraHandle);
104                 int ret = ErrorFacts.GetLastResult();
105                 if ((CameraError)ret != CameraError.None)
106                 {
107                     CameraError err = (CameraError)ret;
108                     Log.Error(CameraLog.Tag, "Failed to get face detection support, " + err.ToString());
109                 }
110
111                 return val;
112             }
113         }
114
115         /// <summary>
116         /// Gets the zero shutter lag feature's supported state.
117         /// true if supported, otherwise false.
118         /// </summary>
119         public bool ZeroShutterLag
120         {
121             get
122             {
123                 bool val = false;
124
125                 val = Interop.CameraFeature.ZeroShutterLagSupport(_cameraHandle);
126                 int ret = ErrorFacts.GetLastResult();
127                 if ((CameraError)ret != CameraError.None)
128                 {
129                     CameraError err = (CameraError)ret;
130                     Log.Error(CameraLog.Tag, "Failed to get zero shutter lag support, " + err.ToString());
131                 }
132
133                 return val;
134             }
135         }
136
137         /// <summary>
138         /// Gets the media packet preview callback feature's supported state.
139         /// true if supported, otherwise false.
140         /// </summary>
141         public bool MediaPacketPreviewCallback
142         {
143             get
144             {
145                 bool val = false;
146
147                 val = Interop.CameraFeature.MediaPacketPreviewCallbackSupport(_cameraHandle);
148                 int ret = ErrorFacts.GetLastResult();
149                 if ((CameraError)ret != CameraError.None)
150                 {
151                     CameraError err = (CameraError)ret;
152                     Log.Error(CameraLog.Tag, "Failed to get media packet preview callback support, " + err.ToString());
153                 }
154
155                 return val;
156             }
157         }
158
159         /// <summary>
160         /// Gets the support state of HDR capture.
161         /// true if supported, otherwise false.
162         /// </summary>
163         public bool HdrCapture
164         {
165             get
166             {
167                 bool val = false;
168
169                 val = Interop.CameraFeature.HdrCaptureSupport(_cameraHandle);
170                 int ret = ErrorFacts.GetLastResult();
171                 if ((CameraError)ret != CameraError.None)
172                 {
173                     CameraError err = (CameraError)ret;
174                     Log.Error(CameraLog.Tag, "Failed to get hdr capture feature support, " + err.ToString());
175                 }
176
177                 return val;
178             }
179         }
180
181         /// <summary>
182         /// Gets the support state of the anti-shake feature.
183         /// true if supported, otherwise false.
184         /// </summary>
185         public bool AntiShake
186         {
187             get
188             {
189                 bool val = false;
190
191                 val = Interop.CameraFeature.AntiShakeSupport(_cameraHandle);
192                 int ret = ErrorFacts.GetLastResult();
193                 if ((CameraError)ret != CameraError.None)
194                 {
195                     CameraError err = (CameraError)ret;
196                     Log.Error(CameraLog.Tag, "Failed to get anti shake feature support, " + err.ToString());
197                 }
198
199                 return val;
200             }
201         }
202
203         /// <summary>
204         /// Gets the support state of the video stabilization feature.
205         /// true if supported, otherwise false.
206         /// </summary>
207         public bool VideoStabilization
208         {
209             get
210             {
211                 bool val = false;
212
213                 val = Interop.CameraFeature.VideoStabilizationSupport(_cameraHandle);
214                 int ret = ErrorFacts.GetLastResult();
215                 if ((CameraError)ret != CameraError.None)
216                 {
217                     CameraError err = (CameraError)ret;
218                     Log.Error(CameraLog.Tag, "Failed to get video stabilization feature support, " + err.ToString());
219                 }
220
221                 return val;
222             }
223         }
224
225         /// <summary>
226         /// Gets state of support of auto contrast feature.
227         /// true if supported, otherwise false.
228         /// </summary>
229         public bool AutoContrast
230         {
231             get
232             {
233                 bool val = false;
234
235                 val = Interop.CameraFeature.AutoContrastSupport(_cameraHandle);
236                 int ret = ErrorFacts.GetLastResult();
237                 if ((CameraError)ret != CameraError.None)
238                 {
239                     CameraError err = (CameraError)ret;
240                     Log.Error(CameraLog.Tag, "Failed to get auto contrast feature support, " + err.ToString());
241                 }
242
243                 return val;
244             }
245         }
246
247         /// <summary>
248         /// Retrieves all the preview resolutions supported by the camera.
249         /// </summary>
250         /// <returns>
251         /// It returns a list containing all the supported preview resolutions.
252         /// by recorder.
253         /// </returns>
254         public IEnumerable<CameraResolution> PreviewResolutions
255         {
256             get
257             {
258                 if (_previewResolution.Count == 0)
259                 {
260                     Interop.CameraFeature.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
261                     {
262                         CameraResolution temp = new CameraResolution(width, height);
263                         _previewResolution.Add(temp);
264                         return true;
265                     };
266
267                     int ret = Interop.CameraFeature.SupportedPreviewResolutions(_cameraHandle, callback, IntPtr.Zero);
268                     if (ret != (int)CameraError.None)
269                     {
270                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported preview resolutions");
271                     }
272                 }
273
274                 return _previewResolution;
275             }
276         }
277
278         /// <summary>
279         /// Retrieves all the capture resolutions supported by the camera.
280         /// </summary>
281         /// <returns>
282         /// It returns a list containing all the supported capture resolutions.
283         /// </returns>
284         public IEnumerable<CameraResolution> CaptureResolutions
285         {
286             get
287             {
288                 if (_cameraResolution.Count == 0)
289                 {
290                     Interop.CameraFeature.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
291                     {
292                         CameraResolution temp = new CameraResolution(width, height);
293                         _cameraResolution.Add(temp);
294                         return true;
295                     };
296
297                     int ret = Interop.CameraFeature.SupportedCaptureResolutions(_cameraHandle, callback, IntPtr.Zero);
298                     if (ret != (int)CameraError.None)
299                     {
300                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported capture resolutions");
301                     }
302                 }
303
304                 return _cameraResolution;
305             }
306         }
307
308         /// <summary>
309         /// Retrieves all the capture formats supported by the camera.
310         /// </summary>
311         /// <returns>
312         /// It returns a list containing all the supported capture formats.
313         /// </returns>
314         public IEnumerable<CameraPixelFormat> CaptureFormats
315         {
316             get
317             {
318                 if (_captureFormat.Count == 0)
319                 {
320                     Interop.CameraFeature.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
321                     {
322                         _captureFormat.Add(format);
323                         return true;
324                     };
325
326                     int ret = Interop.CameraFeature.SupportedCaptureFormats(_cameraHandle, callback, IntPtr.Zero);
327                     if (ret != (int)CameraError.None)
328                     {
329                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported capture formats.");
330                     }
331                 }
332
333                 return _captureFormat;
334             }
335         }
336
337         /// <summary>
338         /// Retrieves all the preview formats supported by the camera.
339         /// </summary>
340         /// <returns>
341         /// It returns a list containing all the supported preview formats.
342         /// </returns>
343         public IEnumerable<CameraPixelFormat> PreviewFormats
344         {
345             get
346             {
347                 if (_previewFormat.Count == 0)
348                 {
349                     Interop.CameraFeature.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
350                     {
351                         _previewFormat.Add(format);
352                         return true;
353                     };
354
355                     int ret = Interop.CameraFeature.SupportedPreviewFormats(_cameraHandle, callback, IntPtr.Zero);
356                     if (ret != (int)CameraError.None)
357                     {
358                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported preview formats.");
359                     }
360                 }
361
362                 return _previewFormat;
363             }
364         }
365
366         /// <summary>
367         /// Retrieves all the fps supported by the camera.
368         /// </summary>
369         /// <returns>
370         /// It returns a list containing all the supported fps.
371         /// </returns>
372         public IEnumerable<CameraFps> Fps
373         {
374             get
375             {
376                 if (_fps.Count == 0)
377                 {
378                     Interop.CameraFeature.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
379                     {
380                         _fps.Add(fps);
381                         return true;
382                     };
383
384                     int ret = Interop.CameraFeature.SupportedFps(_cameraHandle, callback, IntPtr.Zero);
385                     if (ret != (int)CameraError.None)
386                     {
387                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera fps");
388                     }
389                 }
390
391                 return _fps;
392             }
393         }
394
395         private bool resolutionCallback(CameraFps fps, IntPtr userData)
396         {
397             _fpsResolution.Add(fps);
398             return true;
399         }
400
401         /// <summary>
402         /// Retrieves all the fps by resolution supported by the camera.
403         /// </summary>
404         /// <returns>
405         /// It returns a list containing all the supported fps by resolution.
406         /// </returns>
407         public IEnumerable<CameraFps> FpsByResolution(int width, int height)
408         {
409             if (_fpsResolution.Count == 0)
410             {
411                 int ret = Interop.CameraFeature.SupportedFpsByResolution(_cameraHandle, width, height, resolutionCallback, IntPtr.Zero);
412                 if (ret != (int)CameraError.None)
413                 {
414                     CameraErrorFactory.ThrowException(ret, "Failed to get the supported fps by resolutions.");
415                 }
416             }
417
418             return _fpsResolution;
419         }
420
421         /// <summary>
422         /// Retrieves all the fps by resolution supported by the camera.
423         /// </summary>
424         /// <returns>
425         /// It returns a list containing all the supported fps by resolution.
426         /// </returns>
427         public IEnumerable<CameraAutoFocusMode> AfMode
428         {
429             get
430             {
431                 if (_afMode.Count == 0)
432                 {
433                     Interop.CameraFeature.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
434                     {
435                         _afMode.Add(mode);
436                         return true;
437                     };
438
439                     int ret = Interop.CameraFeature.SupportedAfModes(_cameraHandle, callback, IntPtr.Zero);
440                     if (ret != (int)CameraError.None)
441                     {
442                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported Auto focus modes.");
443                     }
444                 }
445
446                 return _afMode;
447             }
448         }
449
450         /// <summary>
451         /// Retrieves all the exposure modes supported by the camera.
452         /// </summary>
453         /// <returns>
454         /// It returns a list containing all the supported camera exposure modes.
455         /// </returns>
456         public IEnumerable<CameraExposureMode> ExposureModes
457         {
458             get
459             {
460                 if (_exposureMode.Count == 0)
461                 {
462                     Interop.CameraFeature.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
463                     {
464                         _exposureMode.Add(mode);
465                         return true;
466                     };
467
468                     int ret = Interop.CameraFeature.SupportedExposureModes(_cameraHandle, callback, IntPtr.Zero);
469                     if (ret != (int)CameraError.None)
470                     {
471                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported Exposure modes.");
472                     }
473                 }
474
475                 return _exposureMode;
476             }
477         }
478
479         /// <summary>
480         /// Retrieves all the Iso level supported by the camera.
481         /// </summary>
482         /// <returns>
483         /// It returns a list containing all the supported camera Iso levels.
484         /// </returns>
485         public IEnumerable<CameraIsoLevel> IsoLevel
486         {
487             get
488             {
489                 if (_iso.Count == 0)
490                 {
491                     Interop.CameraFeature.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
492                     {
493                         _iso.Add(iso);
494                         return true;
495                     };
496
497                     int ret = Interop.CameraFeature.SupportedIso(_cameraHandle, callback, IntPtr.Zero);
498                     if (ret != (int)CameraError.None)
499                     {
500                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported Iso levels.");
501                     }
502                 }
503
504                 return _iso;
505             }
506         }
507
508         /// <summary>
509         /// Retrieves all the theater modes supported by the camera.
510         /// </summary>
511         /// <returns>
512         /// It returns a list containing all the supported camera theater modes.
513         /// </returns>
514         public IEnumerable<CameraTheaterMode> TheaterMode
515         {
516             get
517             {
518                 if (_theater.Count == 0)
519                 {
520                     Interop.CameraFeature.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
521                     {
522                         _theater.Add(theaterMode);
523                         return true;
524                     };
525
526                     int ret = Interop.CameraFeature.SupportedTheaterModes(_cameraHandle, callback, IntPtr.Zero);
527                     if (ret != (int)CameraError.None)
528                     {
529                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported theater modes.");
530                     }
531                 }
532
533                 return _theater;
534             }
535         }
536
537         /// <summary>
538         /// Retrieves all the whitebalance mode supported by the camera.
539         /// </summary>
540         /// <returns>
541         /// It returns a list containing all the supported camera white balance modes.
542         /// </returns>
543         public IEnumerable<CameraWhitebalance> Whitebalance
544         {
545             get
546             {
547                 if (_whitebalance.Count == 0)
548                 {
549                     Interop.CameraFeature.WhitebalanceCallback callback = (CameraWhitebalance whitebalance, IntPtr userData) =>
550                     {
551                         _whitebalance.Add(whitebalance);
552                         return true;
553                     };
554                     int ret = Interop.CameraFeature.SupportedWhitebalance(_cameraHandle, callback, IntPtr.Zero);
555                     if (ret != (int)CameraError.None)
556                     {
557                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported white balance.");
558                     }
559                 }
560
561                 return _whitebalance;
562             }
563         }
564
565         /// <summary>
566         /// Retrieves all the flash modes supported by the camera.
567         /// </summary>
568         /// <returns>
569         /// It returns a list containing all the supported camera flash modes.
570         /// </returns>
571         public IEnumerable<CameraFlashMode> FlashMode
572         {
573             get
574             {
575                 if (_flashMode.Count == 0)
576                 {
577                     Interop.CameraFeature.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
578                     {
579                         _flashMode.Add(flashMode);
580                         return true;
581                     };
582                     int ret = Interop.CameraFeature.SupportedFlashModes(_cameraHandle, callback, IntPtr.Zero);
583                     if (ret != (int)CameraError.None)
584                     {
585                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported flash modes.");
586                     }
587                 }
588
589                 return _flashMode;
590             }
591         }
592
593         /// <summary>
594         /// Retrieves all the scene modes supported by the camera.
595         /// </summary>
596         /// <returns>
597         /// It returns a list containing all the supported camera scene modes.
598         /// </returns>
599         public IEnumerable<CameraSceneMode> SceneMode
600         {
601             get
602             {
603                 if (_sceneMode.Count == 0)
604                 {
605                     Interop.CameraFeature.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
606                     {
607                         _sceneMode.Add(sceneMode);
608                         return true;
609                     };
610                     int ret = Interop.CameraFeature.SupportedSceneModes(_cameraHandle, callback, IntPtr.Zero);
611                     if (ret != (int)CameraError.None)
612                     {
613                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported scene modes.");
614                     }
615                 }
616
617                 return _sceneMode;
618             }
619         }
620
621         /// <summary>
622         /// Retrieves all the effects supported by the camera.
623         /// </summary>
624         /// <returns>
625         /// It returns a list containing all the supported camera effects.
626         /// </returns>
627         public IEnumerable<CameraEffectMode> Effect
628         {
629             get
630             {
631                 if (_effect.Count == 0)
632                 {
633                     Interop.CameraFeature.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
634                     {
635                         _effect.Add(effect);
636                         return true;
637                     };
638                     int ret = Interop.CameraFeature.SupportedEffects(_cameraHandle, callback, IntPtr.Zero);
639                     if (ret != (int)CameraError.None)
640                     {
641                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera effects.");
642                     }
643                 }
644
645                 return _effect;
646             }
647         }
648
649         /// <summary>
650         /// Retrieves all the stream rotation supported by the camera.
651         /// </summary>
652         /// <returns>
653         /// It returns a list containing all the supported camera stream rotations.
654         /// </returns>
655         public IEnumerable<CameraRotation> StreamRotation
656         {
657             get
658             {
659                 if (_streamRotation.Count == 0)
660                 {
661                     Interop.CameraFeature.StreamRotationCallback callback = (CameraRotation streamRotation, IntPtr userData) =>
662                     {
663                         _streamRotation.Add(streamRotation);
664                         return true;
665                     };
666                     int ret = Interop.CameraFeature.SupportedStreamRotations(_cameraHandle, callback, IntPtr.Zero);
667                     if (ret != (int)CameraError.None)
668                     {
669                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera rotations.");
670                     }
671                 }
672
673                 return _streamRotation;
674             }
675         }
676
677         /// <summary>
678         /// Retrieves all the flips supported by the camera.
679         /// </summary>
680         /// <returns>
681         /// It returns a list containing all the supported camera flip.
682         /// </returns>
683         public IEnumerable<CameraFlip> StreamFlip
684         {
685             get
686             {
687                 if (_streamFlip.Count == 0)
688                 {
689                     Interop.CameraFeature.StreamFlipCallback callback = (CameraFlip streamFlip, IntPtr userData) =>
690                     {
691                         _streamFlip.Add(streamFlip);
692                         return true;
693                     };
694                     int ret = Interop.CameraFeature.SupportedStreamFlips(_cameraHandle, callback, IntPtr.Zero);
695                     if (ret != (int)CameraError.None)
696                     {
697                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera flips.");
698                     }
699                 }
700
701                 return _streamFlip;
702             }
703         }
704
705         /// <summary>
706         /// Retrieves all the ptz types by the camera.
707         /// </summary>
708         /// <returns>
709         /// It returns a list containing all the supported ptz types.
710         /// </returns>
711         public IEnumerable<CameraPtzType> PtzType
712         {
713             get
714             {
715                 if (_ptzType.Count == 0)
716                 {
717                     Interop.CameraFeature.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
718                     {
719                         _ptzType.Add(ptzType);
720                         return true;
721                     };
722                     int ret = Interop.CameraFeature.SupportedPtzTypes(_cameraHandle, callback, IntPtr.Zero);
723                     if (ret != (int)CameraError.None)
724                     {
725                         CameraErrorFactory.ThrowException(ret, "Failed to get the supported Ptz types.");
726                     }
727                 }
728
729                 return _ptzType;
730             }
731         }
732     }
733 }