2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using NativeCapabilities = Interop.CameraCapabilities;
20 using NativeSettings = Interop.CameraSettings;
22 namespace Tizen.Multimedia
25 /// The CameraCapabilities class provides properties
26 /// to get various capability information of the camera device.
28 /// <since_tizen> 4 </since_tizen>
29 public class CameraCapabilities
31 internal readonly Camera _camera;
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);
52 internal CameraCapabilities(Camera camera)
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);
72 private bool IsFeatureSupported(IsSupportedDelegate func)
74 return func(_camera.GetHandle());
77 private bool CheckRangeValid(GetRangeDelegate func)
79 func(_camera.GetHandle(), out int min, out int max).
80 ThrowIfFailed("Failed to check feature is suported or not.");
86 /// Gets the face detection feature's supported state.
88 /// <value>true if supported, otherwise false.</value>
89 /// <since_tizen> 4 </since_tizen>
90 public bool IsFaceDetectionSupported { get; }
93 /// Gets the media packet preview callback feature's supported state.
95 /// <value>true if supported, otherwise false.</value>
96 /// <since_tizen> 4 </since_tizen>
97 public bool IsMediaPacketPreviewCallbackSupported { get; }
100 /// Gets the zero shutter lag feature's supported state.
102 /// <value>true if supported, otherwise false.</value>
103 /// <since_tizen> 4 </since_tizen>
104 public bool IsZeroShutterLagSupported { get; }
107 /// Gets the continuous capture feature's supported state.
109 /// <value>true if supported, otherwise false.</value>
110 /// <since_tizen> 4 </since_tizen>
111 public bool IsContinuousCaptureSupported { get; }
114 /// Gets the support state of the HDR capture.
116 /// <value>true if supported, otherwise false.</value>
117 /// <since_tizen> 4 </since_tizen>
118 public bool IsHdrCaptureSupported { get; }
121 /// Gets the support state of the anti-shake feature.
123 /// <value>true if supported, otherwise false.</value>
124 /// <since_tizen> 4 </since_tizen>
125 public bool IsAntiShakeSupported { get; }
128 /// Gets the support state of the video stabilization feature.
130 /// <value>true if supported, otherwise false.</value>
131 /// <since_tizen> 4 </since_tizen>
132 public bool IsVideoStabilizationSupported { get; }
135 /// Gets the support state of auto contrast feature.
137 /// <value>true if supported, otherwise false.</value>
138 /// <since_tizen> 4 </since_tizen>
139 public bool IsAutoContrastSupported { get; }
142 /// Gets the support state of the brightness feature.
144 /// <value>true if supported, otherwise false.</value>
145 /// <since_tizen> 4 </since_tizen>
146 public bool IsBrigtnessSupported { get; }
149 /// Gets the support state of the exposure feature.
151 /// <value>true if supported, otherwise false.</value>
152 /// <since_tizen> 4 </since_tizen>
153 public bool IsExposureSupported { get; }
156 /// Gets the support state of the zoom feature.
158 /// <value>true if supported, otherwise false.</value>
159 /// <since_tizen> 4 </since_tizen>
160 public bool IsZoomSupported { get; }
163 /// Gets the support state of the pan feature.
165 /// <value>true if supported, otherwise false.</value>
166 /// <since_tizen> 4 </since_tizen>
167 public bool IsPanSupported { get; }
170 /// Gets the support state of the tilt feature.
172 /// <value>true if supported, otherwise false.</value>
173 /// <since_tizen> 4 </since_tizen>
174 public bool IsTiltSupported { get; }
177 /// Gets the support state of the hue feature.
179 /// <value>true if supported, otherwise false.</value>
180 /// <since_tizen> 5 </since_tizen>
181 public bool IsHueSupported { get; }
184 /// Retrieves all the preview resolutions supported by the camera.
186 /// <since_tizen> 4 </since_tizen>
188 /// It returns a list containing all the supported preview resolutions.
190 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
191 public IEnumerable<Size> SupportedPreviewResolutions
195 _camera.ValidateNotDisposed();
197 if (_previewResolutions == null)
199 _previewResolutions = GetSupportedPreviewResolutions();
202 return _previewResolutions;
207 /// Retrieves all the capture resolutions supported by the camera.
209 /// <since_tizen> 4 </since_tizen>
211 /// It returns a list containing all the supported capture resolutions.
213 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
214 public IEnumerable<Size> SupportedCaptureResolutions
218 _camera.ValidateNotDisposed();
220 if (_cameraResolutions == null)
222 _cameraResolutions = GetSupportedCaptureResolutions();
225 return _cameraResolutions;
230 /// Retrieves all the capture formats supported by the camera.
232 /// <since_tizen> 4 </since_tizen>
234 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
236 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
237 public IEnumerable<CameraPixelFormat> SupportedCapturePixelFormats
241 _camera.ValidateNotDisposed();
243 if (_captureFormats == null)
245 _captureFormats = GetSupportedCapturePixelFormats();
248 return _captureFormats;
253 /// Retrieves all the preview formats supported by the camera.
255 /// <since_tizen> 4 </since_tizen>
257 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
259 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
260 public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
264 _camera.ValidateNotDisposed();
266 if (_previewFormats == null)
268 _previewFormats = GetSupportedPreviewPixelFormats();
271 return _previewFormats;
276 /// Retrieves all the fps supported by the camera.
278 /// <since_tizen> 4 </since_tizen>
280 /// It returns a list containing all the supported <see cref="CameraFps"/>.
282 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
283 public IEnumerable<CameraFps> SupportedPreviewFps
287 _camera.ValidateNotDisposed();
291 _fps = GetSupportedPreviewFps();
299 /// Retrieves all the fps by resolution supported by the camera.
301 /// <param name="width">The width of required preview resolution.</param>
302 /// <param name="height">The height of required preview resolution.</param>
304 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
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)
311 return GetSupportedPreviewFpsByResolutions(width, height);
315 /// Retrieves all the fps by resolution supported by the camera.
317 /// <param name="size">The size of required preview resolution.</param>
319 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
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)
326 return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
330 /// Retrieves all the auto focus modes supported by the camera.
333 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
335 /// <since_tizen> 4 </since_tizen>
336 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
337 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
341 _camera.ValidateNotDisposed();
343 if (_autoFocusModes == null)
345 _autoFocusModes = GetSupportedAutoFocusModes();
348 return _autoFocusModes;
353 /// Retrieves all the exposure modes supported by the camera.
356 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
358 /// <since_tizen> 4 </since_tizen>
359 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
360 public IEnumerable<CameraExposureMode> SupportedExposureModes
364 _camera.ValidateNotDisposed();
366 if (_exposureModes == null)
368 _exposureModes = GetSupportedExposureModes();
371 return _exposureModes;
376 /// Retrieves all the ISO levels supported by the camera.
378 /// <since_tizen> 4 </since_tizen>
380 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
382 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
383 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
387 _camera.ValidateNotDisposed();
389 if (_isoLevels == null)
391 _isoLevels = GetSupportedIsoLevels();
399 /// Retrieves all the theater modes supported by the camera.
401 /// <since_tizen> 4 </since_tizen>
403 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
405 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
406 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
410 _camera.ValidateNotDisposed();
412 if (_theaterModes == null)
414 _theaterModes = GetSupportedTheaterModes();
417 return _theaterModes;
422 /// Retrieves all the white balance modes supported by the camera.
424 /// <since_tizen> 4 </since_tizen>
426 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
428 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
429 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
433 _camera.ValidateNotDisposed();
435 if (_whitebalances == null)
437 _whitebalances = GetSupportedWhitebalances();
440 return _whitebalances;
445 /// Retrieves all the flash modes supported by the camera.
447 /// <since_tizen> 4 </since_tizen>
449 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
451 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
452 public IEnumerable<CameraFlashMode> SupportedFlashModes
456 _camera.ValidateNotDisposed();
458 if (_flashModes == null)
460 _flashModes = GetSupportedFlashModes();
468 /// Retrieves all the scene modes supported by the camera.
470 /// <since_tizen> 4 </since_tizen>
472 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
474 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
475 public IEnumerable<CameraSceneMode> SupportedSceneModes
479 _camera.ValidateNotDisposed();
481 if (_sceneModes == null)
483 _sceneModes = GetSupportedSceneModes();
491 /// Retrieves all the effect modes supported by the camera.
493 /// <since_tizen> 4 </since_tizen>
495 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
497 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
498 public IEnumerable<CameraEffectMode> SupportedEffects
502 _camera.ValidateNotDisposed();
504 if (_effectModes == null)
506 _effectModes = GetSupportedEffects();
514 /// Retrieves all the stream rotations supported by the camera.
516 /// <since_tizen> 4 </since_tizen>
518 /// An IEnumerable containing all the supported <see cref="Rotation"/>.
520 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
521 public IEnumerable<Rotation> SupportedStreamRotations
525 _camera.ValidateNotDisposed();
527 if (_streamRotations == null)
529 _streamRotations = GetSupportedStreamRotations();
532 return _streamRotations;
537 /// Retrieves all the flips supported by the camera.
539 /// <since_tizen> 4 </since_tizen>
541 /// It returns a list containing all the supported <see cref="Flips"/>.
543 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
544 public IEnumerable<Flips> SupportedStreamFlips
548 _camera.ValidateNotDisposed();
550 if (_streamFlips == null)
552 _streamFlips = GetSupportedStreamFlips();
560 /// Retrieves all the PTZ types by the camera.
562 /// <since_tizen> 4 </since_tizen>
564 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
566 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
567 public IEnumerable<CameraPtzType> SupportedPtzTypes
571 _camera.ValidateNotDisposed();
573 if (_ptzTypes == null)
575 _ptzTypes = GetSupportedPtzTypes();
582 #region Methods for getting supported values
583 private IList<Size> GetSupportedPreviewResolutions()
585 List<Size> previewResolutions = new List<Size>();
587 NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
589 previewResolutions.Add(new Size(width, height));
593 NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
594 ThrowIfFailed("Failed to get the supported preview resolutions");
596 return previewResolutions.AsReadOnly();
599 private IList<Size> GetSupportedCaptureResolutions()
601 List<Size> cameraResolutions = new List<Size>();
603 NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
605 cameraResolutions.Add(new Size(width, height));
609 NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
610 ThrowIfFailed("Failed to get the supported capture resolutions");
612 return cameraResolutions.AsReadOnly();
615 private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
617 List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
619 NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
621 captureFormats.Add(format);
625 NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
626 ThrowIfFailed("Failed to get the supported capture formats.");
628 return captureFormats.AsReadOnly();
631 private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
633 List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
635 NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
637 previewFormats.Add(format);
641 NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
642 ThrowIfFailed("Failed to get the supported preview formats.");
644 return previewFormats.AsReadOnly();
647 private IList<CameraFps> GetSupportedPreviewFps()
649 List<CameraFps> previewFps = new List<CameraFps>();
651 NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
657 NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero).
658 ThrowIfFailed("Failed to get the supported camera fps");
660 return previewFps.AsReadOnly();
663 private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
665 List<CameraFps> fpsByResolution = new List<CameraFps>();
667 NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
669 fpsByResolution.Add(fps);
673 NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback, IntPtr.Zero).
674 ThrowIfFailed("Failed to get the supported fps by resolutions.");
676 return fpsByResolution.AsReadOnly();
679 private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
681 List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
683 NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
685 autoFocusModes.Add(mode);
689 NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero).
690 ThrowIfFailed("Failed to get the supported Auto focus modes.");
692 return autoFocusModes.AsReadOnly();
695 private IList<CameraExposureMode> GetSupportedExposureModes()
697 List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
699 NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
701 exposureModes.Add(mode);
705 NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero).
706 ThrowIfFailed("Failed to get the supported Exposure modes.");
708 return exposureModes.AsReadOnly();
711 private IList<CameraIsoLevel> GetSupportedIsoLevels()
713 List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
715 NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
721 NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero).
722 ThrowIfFailed("Failed to get the supported Iso levels.");
724 return isoLevels.AsReadOnly();
727 private IList<CameraTheaterMode> GetSupportedTheaterModes()
729 List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
731 NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
733 theaterModes.Add(theaterMode);
737 NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero).
738 ThrowIfFailed("Failed to get the supported theater modes.");
740 return theaterModes.AsReadOnly();
743 private IList<CameraWhiteBalance> GetSupportedWhitebalances()
745 List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
747 NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
749 whitebalances.Add(whiteBalance);
753 NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero).
754 ThrowIfFailed("Failed to get the supported white balance.");
756 return whitebalances.AsReadOnly();
759 private IList<CameraFlashMode> GetSupportedFlashModes()
761 List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
763 NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
765 flashModes.Add(flashMode);
769 NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero).
770 ThrowIfFailed("Failed to get the supported flash modes.");
772 return flashModes.AsReadOnly();
775 private IList<CameraSceneMode> GetSupportedSceneModes()
777 List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
779 NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
781 sceneModes.Add(sceneMode);
785 NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero).
786 ThrowIfFailed("Failed to get the supported scene modes.");
788 return sceneModes.AsReadOnly();
791 private IList<CameraEffectMode> GetSupportedEffects()
793 List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
795 NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
797 effectModes.Add(effect);
801 NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero).
802 ThrowIfFailed("Failed to get the supported camera effects.");
804 return effectModes.AsReadOnly();
807 private IList<Rotation> GetSupportedStreamRotations()
809 List<Rotation> streamRotations = new List<Rotation>();
811 NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
813 streamRotations.Add(streamRotation);
817 NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero).
818 ThrowIfFailed("Failed to get the supported camera rotations.");
820 return streamRotations.AsReadOnly();
823 private IList<Flips> GetSupportedStreamFlips()
825 List<Flips> streamFlips = new List<Flips>();
827 NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
829 streamFlips.Add(streamFlip);
833 NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero).
834 ThrowIfFailed("Failed to get the supported camera flips.");
836 return streamFlips.AsReadOnly();
839 private IList<CameraPtzType> GetSupportedPtzTypes()
841 List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
843 NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
845 ptzTypes.Add(ptzType);
849 NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero).
850 ThrowIfFailed("Failed to get the supported Ptz types.");
852 return ptzTypes.AsReadOnly();
854 #endregion Methods for getting supported values