[Camera] Fix ObjectDisposedException bug (#1991)
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Camera / Camera / CameraCapabilities.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 NativeCapabilities = Interop.CameraCapabilities;
20 using NativeSettings = Interop.CameraSettings;
21
22 namespace Tizen.Multimedia
23 {
24     /// <summary>
25     /// The CameraCapabilities class provides properties
26     /// to get various capability information of the camera device.
27     /// </summary>
28     /// <since_tizen> 4 </since_tizen>
29     public class CameraCapabilities
30     {
31         internal readonly Camera _camera;
32
33         private IList<Size> _previewResolutions;
34         private IList<Size> _cameraResolutions;
35         private IList<CameraPixelFormat> _captureFormats;
36         private IList<CameraPixelFormat> _previewFormats;
37         private IList<CameraFps> _fps;
38         private IList<CameraAutoFocusMode> _autoFocusModes;
39         private IList<CameraExposureMode> _exposureModes;
40         private IList<CameraIsoLevel> _isoLevels;
41         private IList<CameraTheaterMode> _theaterModes;
42         private IList<CameraWhiteBalance> _whitebalances;
43         private IList<CameraFlashMode> _flashModes;
44         private IList<CameraSceneMode> _sceneModes;
45         private IList<CameraEffectMode> _effectModes;
46         private IList<Rotation> _streamRotations;
47         private IList<Flips> _streamFlips;
48         private IList<CameraPtzType> _ptzTypes;
49         private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max);
50         private delegate bool IsSupportedDelegate(IntPtr handle);
51
52         internal CameraCapabilities(Camera camera)
53         {
54             _camera = camera;
55
56             IsFaceDetectionSupported = IsFeatureSupported(NativeCapabilities.IsFaceDetectionSupported);
57             IsMediaPacketPreviewCallbackSupported = IsFeatureSupported(NativeCapabilities.IsMediaPacketPreviewCallbackSupported);
58             IsZeroShutterLagSupported = IsFeatureSupported(NativeCapabilities.IsZeroShutterLagSupported);
59             IsContinuousCaptureSupported = IsFeatureSupported(NativeCapabilities.IsContinuousCaptureSupported);
60             IsHdrCaptureSupported = IsFeatureSupported(NativeCapabilities.IsHdrCaptureSupported);
61             IsAntiShakeSupported = IsFeatureSupported(NativeCapabilities.IsAntiShakeSupported);
62             IsVideoStabilizationSupported = IsFeatureSupported(NativeCapabilities.IsVideoStabilizationSupported);
63             IsAutoContrastSupported = IsFeatureSupported(NativeCapabilities.IsAutoContrastSupported);
64             IsBrigtnessSupported = CheckRangeValid(NativeSettings.GetBrightnessRange);
65             IsExposureSupported = CheckRangeValid(NativeSettings.GetExposureRange);
66             IsZoomSupported = CheckRangeValid(NativeSettings.GetZoomRange);
67             IsPanSupported = CheckRangeValid(NativeSettings.GetPanRange);
68             IsTiltSupported = CheckRangeValid(NativeSettings.GetTiltRange);
69             IsHueSupported = CheckRangeValid(NativeSettings.GetHueRange);
70         }
71
72         private bool IsFeatureSupported(IsSupportedDelegate func)
73         {
74             return func(_camera.GetHandle());
75         }
76
77         private bool CheckRangeValid(GetRangeDelegate func)
78         {
79             func(_camera.GetHandle(), out int min, out int max).
80                 ThrowIfFailed("Failed to check feature is suported or not.");
81
82             return min < max;
83         }
84
85         /// <summary>
86         /// Gets the face detection feature's supported state.
87         /// </summary>
88         /// <value>true if supported, otherwise false.</value>
89         /// <since_tizen> 4 </since_tizen>
90         public bool IsFaceDetectionSupported { get; }
91
92         /// <summary>
93         /// Gets the media packet preview callback feature's supported state.
94         /// </summary>
95         /// <value>true if supported, otherwise false.</value>
96         /// <since_tizen> 4 </since_tizen>
97         public bool IsMediaPacketPreviewCallbackSupported { get; }
98
99         /// <summary>
100         /// Gets the zero shutter lag feature's supported state.
101         /// </summary>
102         /// <value>true if supported, otherwise false.</value>
103         /// <since_tizen> 4 </since_tizen>
104         public bool IsZeroShutterLagSupported { get; }
105
106         /// <summary>
107         /// Gets the continuous capture feature's supported state.
108         /// </summary>
109         /// <value>true if supported, otherwise false.</value>
110         /// <since_tizen> 4 </since_tizen>
111         public bool IsContinuousCaptureSupported { get; }
112
113         /// <summary>
114         /// Gets the support state of the HDR capture.
115         /// </summary>
116         /// <value>true if supported, otherwise false.</value>
117         /// <since_tizen> 4 </since_tizen>
118         public bool IsHdrCaptureSupported { get; }
119
120         /// <summary>
121         /// Gets the support state of the anti-shake feature.
122         /// </summary>
123         /// <value>true if supported, otherwise false.</value>
124         /// <since_tizen> 4 </since_tizen>
125         public bool IsAntiShakeSupported { get; }
126
127         /// <summary>
128         /// Gets the support state of the video stabilization feature.
129         /// </summary>
130         /// <value>true if supported, otherwise false.</value>
131         /// <since_tizen> 4 </since_tizen>
132         public bool IsVideoStabilizationSupported { get; }
133
134         /// <summary>
135         /// Gets the support state of auto contrast feature.
136         /// </summary>
137         /// <value>true if supported, otherwise false.</value>
138         /// <since_tizen> 4 </since_tizen>
139         public bool IsAutoContrastSupported { get; }
140
141         /// <summary>
142         /// Gets the support state of the brightness feature.
143         /// </summary>
144         /// <value>true if supported, otherwise false.</value>
145         /// <since_tizen> 4 </since_tizen>
146         public bool IsBrigtnessSupported { get; }
147
148         /// <summary>
149         /// Gets the support state of the exposure feature.
150         /// </summary>
151         /// <value>true if supported, otherwise false.</value>
152         /// <since_tizen> 4 </since_tizen>
153         public bool IsExposureSupported { get; }
154
155         /// <summary>
156         /// Gets the support state of the zoom feature.
157         /// </summary>
158         /// <value>true if supported, otherwise false.</value>
159         /// <since_tizen> 4 </since_tizen>
160         public bool IsZoomSupported { get; }
161
162         /// <summary>
163         /// Gets the support state of the pan feature.
164         /// </summary>
165         /// <value>true if supported, otherwise false.</value>
166         /// <since_tizen> 4 </since_tizen>
167         public bool IsPanSupported { get; }
168
169         /// <summary>
170         /// Gets the support state of the tilt feature.
171         /// </summary>
172         /// <value>true if supported, otherwise false.</value>
173         /// <since_tizen> 4 </since_tizen>
174         public bool IsTiltSupported { get; }
175
176         /// <summary>
177         /// Gets the support state of the hue feature.
178         /// </summary>
179         /// <value>true if supported, otherwise false.</value>
180         /// <since_tizen> 5 </since_tizen>
181         public bool IsHueSupported { get; }
182
183         /// <summary>
184         /// Retrieves all the preview resolutions supported by the camera.
185         /// </summary>
186         /// <since_tizen> 4 </since_tizen>
187         /// <returns>
188         /// It returns a list containing all the supported preview resolutions.
189         /// </returns>
190         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
191         public IEnumerable<Size> SupportedPreviewResolutions
192         {
193             get
194             {
195                 _camera.ValidateNotDisposed();
196
197                 if (_previewResolutions == null)
198                 {
199                     _previewResolutions = GetSupportedPreviewResolutions();
200                 }
201
202                 return _previewResolutions;
203             }
204         }
205
206         /// <summary>
207         /// Retrieves all the capture resolutions supported by the camera.
208         /// </summary>
209         /// <since_tizen> 4 </since_tizen>
210         /// <returns>
211         /// It returns a list containing all the supported capture resolutions.
212         /// </returns>
213         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
214         public IEnumerable<Size> SupportedCaptureResolutions
215         {
216             get
217             {
218                 _camera.ValidateNotDisposed();
219
220                 if (_cameraResolutions == null)
221                 {
222                     _cameraResolutions = GetSupportedCaptureResolutions();
223                 }
224
225                 return _cameraResolutions;
226             }
227         }
228
229         /// <summary>
230         /// Retrieves all the capture formats supported by the camera.
231         /// </summary>
232         /// <since_tizen> 4 </since_tizen>
233         /// <returns>
234         /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
235         /// </returns>
236         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
237         public IEnumerable<CameraPixelFormat> SupportedCapturePixelFormats
238         {
239             get
240             {
241                 _camera.ValidateNotDisposed();
242
243                 if (_captureFormats == null)
244                 {
245                     _captureFormats = GetSupportedCapturePixelFormats();
246                 }
247
248                 return _captureFormats;
249             }
250         }
251
252         /// <summary>
253         /// Retrieves all the preview formats supported by the camera.
254         /// </summary>
255         /// <since_tizen> 4 </since_tizen>
256         /// <returns>
257         /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
258         /// </returns>
259         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
260         public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
261         {
262             get
263             {
264                 _camera.ValidateNotDisposed();
265
266                 if (_previewFormats == null)
267                 {
268                     _previewFormats = GetSupportedPreviewPixelFormats();
269                 }
270
271                 return _previewFormats;
272             }
273         }
274
275         /// <summary>
276         /// Retrieves all the fps supported by the camera.
277         /// </summary>
278         /// <since_tizen> 4 </since_tizen>
279         /// <returns>
280         /// It returns a list containing all the supported <see cref="CameraFps"/>.
281         /// </returns>
282         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
283         public IEnumerable<CameraFps> SupportedPreviewFps
284         {
285             get
286             {
287                 _camera.ValidateNotDisposed();
288
289                 if (_fps == null)
290                 {
291                     _fps = GetSupportedPreviewFps();
292                 }
293
294                 return _fps;
295             }
296         }
297
298         /// <summary>
299         /// Retrieves all the fps by resolution supported by the camera.
300         /// </summary>
301         /// <param name="width">The width of required preview resolution.</param>
302         /// <param name="height">The height of required preview resolution.</param>
303         /// <returns>
304         /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
305         /// </returns>
306         /// <since_tizen> 4 </since_tizen>
307         /// <feature> http://tizen.org/feature/camera </feature>
308         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
309         public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
310         {
311             return GetSupportedPreviewFpsByResolutions(width, height);
312         }
313
314         /// <summary>
315         /// Retrieves all the fps by resolution supported by the camera.
316         /// </summary>
317         /// <param name="size">The size of required preview resolution.</param>
318         /// <returns>
319         /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
320         /// </returns>
321         /// <since_tizen> 4 </since_tizen>
322         /// <feature> http://tizen.org/feature/camera </feature>
323         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
324         public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
325         {
326             return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
327         }
328
329         /// <summary>
330         /// Retrieves all the auto focus modes supported by the camera.
331         /// </summary>
332         /// <returns>
333         /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
334         /// </returns>
335         /// <since_tizen> 4 </since_tizen>
336         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
337         public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
338         {
339             get
340             {
341                 _camera.ValidateNotDisposed();
342
343                 if (_autoFocusModes == null)
344                 {
345                     _autoFocusModes = GetSupportedAutoFocusModes();
346                 }
347
348                 return _autoFocusModes;
349             }
350         }
351
352         /// <summary>
353         /// Retrieves all the exposure modes supported by the camera.
354         /// </summary>
355         /// <returns>
356         /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
357         /// </returns>
358         /// <since_tizen> 4 </since_tizen>
359         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
360         public IEnumerable<CameraExposureMode> SupportedExposureModes
361         {
362             get
363             {
364                 _camera.ValidateNotDisposed();
365
366                 if (_exposureModes == null)
367                 {
368                     _exposureModes = GetSupportedExposureModes();
369                 }
370
371                 return _exposureModes;
372             }
373         }
374
375         /// <summary>
376         /// Retrieves all the ISO levels supported by the camera.
377         /// </summary>
378         /// <since_tizen> 4 </since_tizen>
379         /// <returns>
380         /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
381         /// </returns>
382         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
383         public IEnumerable<CameraIsoLevel> SupportedIsoLevels
384         {
385             get
386             {
387                 _camera.ValidateNotDisposed();
388
389                 if (_isoLevels == null)
390                 {
391                     _isoLevels = GetSupportedIsoLevels();
392                 }
393
394                 return _isoLevels;
395             }
396         }
397
398         /// <summary>
399         /// Retrieves all the theater modes supported by the camera.
400         /// </summary>
401         /// <since_tizen> 4 </since_tizen>
402         /// <returns>
403         /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
404         /// </returns>
405         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
406         public IEnumerable<CameraTheaterMode> SupportedTheaterModes
407         {
408             get
409             {
410                 _camera.ValidateNotDisposed();
411
412                 if (_theaterModes == null)
413                 {
414                     _theaterModes = GetSupportedTheaterModes();
415                 }
416
417                 return _theaterModes;
418             }
419         }
420
421         /// <summary>
422         /// Retrieves all the white balance modes supported by the camera.
423         /// </summary>
424         /// <since_tizen> 4 </since_tizen>
425         /// <returns>
426         /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
427         /// </returns>
428         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
429         public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
430         {
431             get
432             {
433                 _camera.ValidateNotDisposed();
434
435                 if (_whitebalances == null)
436                 {
437                     _whitebalances = GetSupportedWhitebalances();
438                 }
439
440                 return _whitebalances;
441             }
442         }
443
444         /// <summary>
445         /// Retrieves all the flash modes supported by the camera.
446         /// </summary>
447         /// <since_tizen> 4 </since_tizen>
448         /// <returns>
449         /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
450         /// </returns>
451         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
452         public IEnumerable<CameraFlashMode> SupportedFlashModes
453         {
454             get
455             {
456                 _camera.ValidateNotDisposed();
457
458                 if (_flashModes == null)
459                 {
460                     _flashModes = GetSupportedFlashModes();
461                 }
462
463                 return _flashModes;
464             }
465         }
466
467         /// <summary>
468         /// Retrieves all the scene modes supported by the camera.
469         /// </summary>
470         /// <since_tizen> 4 </since_tizen>
471         /// <returns>
472         /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
473         /// </returns>
474         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
475         public IEnumerable<CameraSceneMode> SupportedSceneModes
476         {
477             get
478             {
479                 _camera.ValidateNotDisposed();
480
481                 if (_sceneModes == null)
482                 {
483                     _sceneModes = GetSupportedSceneModes();
484                 }
485
486                 return _sceneModes;
487             }
488         }
489
490         /// <summary>
491         /// Retrieves all the effect modes supported by the camera.
492         /// </summary>
493         /// <since_tizen> 4 </since_tizen>
494         /// <returns>
495         /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
496         /// </returns>
497         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
498         public IEnumerable<CameraEffectMode> SupportedEffects
499         {
500             get
501             {
502                 _camera.ValidateNotDisposed();
503
504                 if (_effectModes == null)
505                 {
506                     _effectModes = GetSupportedEffects();
507                 }
508
509                 return _effectModes;
510             }
511         }
512
513         /// <summary>
514         /// Retrieves all the stream rotations supported by the camera.
515         /// </summary>
516         /// <since_tizen> 4 </since_tizen>
517         /// <returns>
518         /// An IEnumerable containing all the supported <see cref="Rotation"/>.
519         /// </returns>
520         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
521         public IEnumerable<Rotation> SupportedStreamRotations
522         {
523             get
524             {
525                 _camera.ValidateNotDisposed();
526
527                 if (_streamRotations == null)
528                 {
529                     _streamRotations = GetSupportedStreamRotations();
530                 }
531
532                 return _streamRotations;
533             }
534         }
535
536         /// <summary>
537         /// Retrieves all the flips supported by the camera.
538         /// </summary>
539         /// <since_tizen> 4 </since_tizen>
540         /// <returns>
541         /// It returns a list containing all the supported <see cref="Flips"/>.
542         /// </returns>
543         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
544         public IEnumerable<Flips> SupportedStreamFlips
545         {
546             get
547             {
548                 _camera.ValidateNotDisposed();
549
550                 if (_streamFlips == null)
551                 {
552                     _streamFlips = GetSupportedStreamFlips();
553                 }
554
555                 return _streamFlips;
556             }
557         }
558
559         /// <summary>
560         /// Retrieves all the PTZ types by the camera.
561         /// </summary>
562         /// <since_tizen> 4 </since_tizen>
563         /// <returns>
564         /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
565         /// </returns>
566         /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
567         public IEnumerable<CameraPtzType> SupportedPtzTypes
568         {
569             get
570             {
571                 _camera.ValidateNotDisposed();
572
573                 if (_ptzTypes == null)
574                 {
575                     _ptzTypes = GetSupportedPtzTypes();
576                 }
577
578                 return _ptzTypes;
579             }
580         }
581
582         #region Methods for getting supported values
583         private IList<Size> GetSupportedPreviewResolutions()
584         {
585             List<Size> previewResolutions = new List<Size>();
586
587             NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
588             {
589                 previewResolutions.Add(new Size(width, height));
590                 return true;
591             };
592
593             NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
594                 ThrowIfFailed("Failed to get the supported preview resolutions");
595
596             return previewResolutions.AsReadOnly();
597         }
598
599         private IList<Size> GetSupportedCaptureResolutions()
600         {
601             List<Size> cameraResolutions = new List<Size>();
602
603             NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
604             {
605                 cameraResolutions.Add(new Size(width, height));
606                 return true;
607             };
608
609             NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
610                 ThrowIfFailed("Failed to get the supported capture resolutions");
611
612             return cameraResolutions.AsReadOnly();
613         }
614
615         private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
616         {
617             List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
618
619             NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
620             {
621                 captureFormats.Add(format);
622                 return true;
623             };
624
625             NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
626                 ThrowIfFailed("Failed to get the supported capture formats.");
627
628             return captureFormats.AsReadOnly();
629         }
630
631         private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
632         {
633             List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
634
635             NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
636             {
637                 previewFormats.Add(format);
638                 return true;
639             };
640
641             NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
642                 ThrowIfFailed("Failed to get the supported preview formats.");
643
644             return previewFormats.AsReadOnly();
645         }
646
647         private IList<CameraFps> GetSupportedPreviewFps()
648         {
649             List<CameraFps> previewFps = new List<CameraFps>();
650
651             NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
652             {
653                 previewFps.Add(fps);
654                 return true;
655             };
656
657             NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero).
658                 ThrowIfFailed("Failed to get the supported camera fps");
659
660             return previewFps.AsReadOnly();
661         }
662
663         private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
664         {
665             List<CameraFps> fpsByResolution = new List<CameraFps>();
666
667             NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
668             {
669                 fpsByResolution.Add(fps);
670                 return true;
671             };
672
673             NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback, IntPtr.Zero).
674                 ThrowIfFailed("Failed to get the supported fps by resolutions.");
675
676             return fpsByResolution.AsReadOnly();
677         }
678
679         private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
680         {
681             List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
682
683             NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
684             {
685                 autoFocusModes.Add(mode);
686                 return true;
687             };
688
689             NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero).
690                 ThrowIfFailed("Failed to get the supported Auto focus modes.");
691
692             return autoFocusModes.AsReadOnly();
693         }
694
695         private IList<CameraExposureMode> GetSupportedExposureModes()
696         {
697             List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
698
699             NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
700             {
701                 exposureModes.Add(mode);
702                 return true;
703             };
704
705             NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero).
706                 ThrowIfFailed("Failed to get the supported Exposure modes.");
707
708             return exposureModes.AsReadOnly();
709         }
710
711         private IList<CameraIsoLevel> GetSupportedIsoLevels()
712         {
713             List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
714
715             NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
716             {
717                 isoLevels.Add(iso);
718                 return true;
719             };
720
721             NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero).
722                 ThrowIfFailed("Failed to get the supported Iso levels.");
723
724             return isoLevels.AsReadOnly();
725         }
726
727         private IList<CameraTheaterMode> GetSupportedTheaterModes()
728         {
729             List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
730
731             NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
732             {
733                 theaterModes.Add(theaterMode);
734                 return true;
735             };
736
737             NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero).
738                 ThrowIfFailed("Failed to get the supported theater modes.");
739
740             return theaterModes.AsReadOnly();
741         }
742
743         private IList<CameraWhiteBalance> GetSupportedWhitebalances()
744         {
745             List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
746
747             NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
748             {
749                 whitebalances.Add(whiteBalance);
750                 return true;
751             };
752
753             NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero).
754                 ThrowIfFailed("Failed to get the supported white balance.");
755
756             return whitebalances.AsReadOnly();
757         }
758
759         private IList<CameraFlashMode> GetSupportedFlashModes()
760         {
761             List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
762
763             NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
764             {
765                 flashModes.Add(flashMode);
766                 return true;
767             };
768
769             NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero).
770                 ThrowIfFailed("Failed to get the supported flash modes.");
771
772             return flashModes.AsReadOnly();
773         }
774
775         private IList<CameraSceneMode> GetSupportedSceneModes()
776         {
777             List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
778
779             NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
780             {
781                 sceneModes.Add(sceneMode);
782                 return true;
783             };
784
785             NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero).
786                 ThrowIfFailed("Failed to get the supported scene modes.");
787
788             return sceneModes.AsReadOnly();
789         }
790
791         private IList<CameraEffectMode> GetSupportedEffects()
792         {
793             List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
794
795             NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
796             {
797                 effectModes.Add(effect);
798                 return true;
799             };
800
801             NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero).
802                 ThrowIfFailed("Failed to get the supported camera effects.");
803
804             return effectModes.AsReadOnly();
805         }
806
807         private IList<Rotation> GetSupportedStreamRotations()
808         {
809             List<Rotation> streamRotations = new List<Rotation>();
810
811             NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
812             {
813                 streamRotations.Add(streamRotation);
814                 return true;
815             };
816
817             NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero).
818                 ThrowIfFailed("Failed to get the supported camera rotations.");
819
820             return streamRotations.AsReadOnly();
821         }
822
823         private IList<Flips> GetSupportedStreamFlips()
824         {
825             List<Flips> streamFlips = new List<Flips>();
826
827             NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
828             {
829                 streamFlips.Add(streamFlip);
830                 return true;
831             };
832
833             NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero).
834                 ThrowIfFailed("Failed to get the supported camera flips.");
835
836             return streamFlips.AsReadOnly();
837         }
838
839         private IList<CameraPtzType> GetSupportedPtzTypes()
840         {
841             List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
842
843             NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
844             {
845                 ptzTypes.Add(ptzType);
846                 return true;
847             };
848
849             NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero).
850                 ThrowIfFailed("Failed to get the supported Ptz types.");
851
852             return ptzTypes.AsReadOnly();
853         }
854         #endregion Methods for getting supported values
855     }
856 }