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 if (_previewResolutions == null)
197 _previewResolutions = GetSupportedPreviewResolutions();
200 return _previewResolutions;
205 /// Retrieves all the capture resolutions supported by the camera.
207 /// <since_tizen> 4 </since_tizen>
209 /// It returns a list containing all the supported capture resolutions.
211 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
212 public IEnumerable<Size> SupportedCaptureResolutions
216 if (_cameraResolutions == null)
218 _cameraResolutions = GetSupportedCaptureResolutions();
221 return _cameraResolutions;
226 /// Retrieves all the capture formats supported by the camera.
228 /// <since_tizen> 4 </since_tizen>
230 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
232 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
233 public IEnumerable<CameraPixelFormat> SupportedCapturePixelFormats
237 if (_captureFormats == null)
239 _captureFormats = GetSupportedCapturePixelFormats();
242 return _captureFormats;
247 /// Retrieves all the preview formats supported by the camera.
249 /// <since_tizen> 4 </since_tizen>
251 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
253 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
254 public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
258 if (_previewFormats == null)
260 _previewFormats = GetSupportedPreviewPixelFormats();
263 return _previewFormats;
268 /// Retrieves all the fps supported by the camera.
270 /// <since_tizen> 4 </since_tizen>
272 /// It returns a list containing all the supported <see cref="CameraFps"/>.
274 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
275 public IEnumerable<CameraFps> SupportedPreviewFps
281 _fps = GetSupportedPreviewFps();
289 /// Retrieves all the fps by resolution supported by the camera.
291 /// <param name="width">The width of required preview resolution.</param>
292 /// <param name="height">The height of required preview resolution.</param>
294 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
296 /// <since_tizen> 4 </since_tizen>
297 /// <feature> http://tizen.org/feature/camera </feature>
298 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
299 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
301 return GetSupportedPreviewFpsByResolutions(width, height);
305 /// Retrieves all the fps by resolution supported by the camera.
307 /// <param name="size">The size of required preview resolution.</param>
309 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
311 /// <since_tizen> 4 </since_tizen>
312 /// <feature> http://tizen.org/feature/camera </feature>
313 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
314 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
316 return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
320 /// Retrieves all the auto focus modes supported by the camera.
323 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
325 /// <since_tizen> 4 </since_tizen>
326 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
327 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
331 if (_autoFocusModes == null)
333 _autoFocusModes = GetSupportedAutoFocusModes();
336 return _autoFocusModes;
341 /// Retrieves all the exposure modes supported by the camera.
344 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
346 /// <since_tizen> 4 </since_tizen>
347 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
348 public IEnumerable<CameraExposureMode> SupportedExposureModes
352 if (_exposureModes == null)
354 _exposureModes = GetSupportedExposureModes();
357 return _exposureModes;
362 /// Retrieves all the ISO levels supported by the camera.
364 /// <since_tizen> 4 </since_tizen>
366 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
368 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
369 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
373 if (_isoLevels == null)
375 _isoLevels = GetSupportedIsoLevels();
383 /// Retrieves all the theater modes supported by the camera.
385 /// <since_tizen> 4 </since_tizen>
387 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
389 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
390 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
394 if (_theaterModes == null)
396 _theaterModes = GetSupportedTheaterModes();
399 return _theaterModes;
404 /// Retrieves all the white balance modes supported by the camera.
406 /// <since_tizen> 4 </since_tizen>
408 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
410 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
411 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
415 if (_whitebalances == null)
417 _whitebalances = GetSupportedWhitebalances();
420 return _whitebalances;
425 /// Retrieves all the flash modes supported by the camera.
427 /// <since_tizen> 4 </since_tizen>
429 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
431 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
432 public IEnumerable<CameraFlashMode> SupportedFlashModes
436 if (_flashModes == null)
438 _flashModes = GetSupportedFlashModes();
446 /// Retrieves all the scene modes supported by the camera.
448 /// <since_tizen> 4 </since_tizen>
450 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
452 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
453 public IEnumerable<CameraSceneMode> SupportedSceneModes
457 if (_sceneModes == null)
459 _sceneModes = GetSupportedSceneModes();
467 /// Retrieves all the effect modes supported by the camera.
469 /// <since_tizen> 4 </since_tizen>
471 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
473 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
474 public IEnumerable<CameraEffectMode> SupportedEffects
478 if (_effectModes == null)
480 _effectModes = GetSupportedEffects();
488 /// Retrieves all the stream rotations supported by the camera.
490 /// <since_tizen> 4 </since_tizen>
492 /// An IEnumerable containing all the supported <see cref="Rotation"/>.
494 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
495 public IEnumerable<Rotation> SupportedStreamRotations
499 if (_streamRotations == null)
501 _streamRotations = GetSupportedStreamRotations();
504 return _streamRotations;
509 /// Retrieves all the flips supported by the camera.
511 /// <since_tizen> 4 </since_tizen>
513 /// It returns a list containing all the supported <see cref="Flips"/>.
515 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
516 public IEnumerable<Flips> SupportedStreamFlips
520 if (_streamFlips == null)
522 _streamFlips = GetSupportedStreamFlips();
530 /// Retrieves all the PTZ types by the camera.
532 /// <since_tizen> 4 </since_tizen>
534 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
536 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
537 public IEnumerable<CameraPtzType> SupportedPtzTypes
541 if (_ptzTypes.Count == 0)
543 _ptzTypes = GetSupportedPtzTypes();
550 #region Methods for getting supported values
551 private IList<Size> GetSupportedPreviewResolutions()
553 List<Size> previewResolutions = new List<Size>();
555 NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
557 previewResolutions.Add(new Size(width, height));
561 NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
562 ThrowIfFailed("Failed to get the supported preview resolutions");
564 return previewResolutions.AsReadOnly();
567 private IList<Size> GetSupportedCaptureResolutions()
569 List<Size> cameraResolutions = new List<Size>();
571 NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
573 cameraResolutions.Add(new Size(width, height));
577 NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
578 ThrowIfFailed("Failed to get the supported capture resolutions");
580 return cameraResolutions.AsReadOnly();
583 private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
585 List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
587 NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
589 captureFormats.Add(format);
593 NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
594 ThrowIfFailed("Failed to get the supported capture formats.");
596 return captureFormats.AsReadOnly();
599 private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
601 List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
603 NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
605 previewFormats.Add(format);
609 NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
610 ThrowIfFailed("Failed to get the supported preview formats.");
612 return previewFormats.AsReadOnly();
615 private IList<CameraFps> GetSupportedPreviewFps()
617 List<CameraFps> previewFps = new List<CameraFps>();
619 NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
625 NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero).
626 ThrowIfFailed("Failed to get the supported camera fps");
628 return previewFps.AsReadOnly();
631 private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
633 List<CameraFps> fpsByResolution = new List<CameraFps>();
635 NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
637 fpsByResolution.Add(fps);
641 NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback, IntPtr.Zero).
642 ThrowIfFailed("Failed to get the supported fps by resolutions.");
644 return fpsByResolution.AsReadOnly();
647 private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
649 List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
651 NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
653 autoFocusModes.Add(mode);
657 NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero).
658 ThrowIfFailed("Failed to get the supported Auto focus modes.");
660 return autoFocusModes.AsReadOnly();
663 private IList<CameraExposureMode> GetSupportedExposureModes()
665 List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
667 NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
669 exposureModes.Add(mode);
673 NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero).
674 ThrowIfFailed("Failed to get the supported Exposure modes.");
676 return exposureModes.AsReadOnly();
679 private IList<CameraIsoLevel> GetSupportedIsoLevels()
681 List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
683 NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
689 NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero).
690 ThrowIfFailed("Failed to get the supported Iso levels.");
692 return isoLevels.AsReadOnly();
695 private IList<CameraTheaterMode> GetSupportedTheaterModes()
697 List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
699 NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
701 theaterModes.Add(theaterMode);
705 NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero).
706 ThrowIfFailed("Failed to get the supported theater modes.");
708 return theaterModes.AsReadOnly();
711 private IList<CameraWhiteBalance> GetSupportedWhitebalances()
713 List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
715 NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
717 whitebalances.Add(whiteBalance);
721 NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero).
722 ThrowIfFailed("Failed to get the supported white balance.");
724 return whitebalances.AsReadOnly();
727 private IList<CameraFlashMode> GetSupportedFlashModes()
729 List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
731 NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
733 flashModes.Add(flashMode);
737 NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero).
738 ThrowIfFailed("Failed to get the supported flash modes.");
740 return flashModes.AsReadOnly();
743 private IList<CameraSceneMode> GetSupportedSceneModes()
745 List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
747 NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
749 sceneModes.Add(sceneMode);
753 NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero).
754 ThrowIfFailed("Failed to get the supported scene modes.");
756 return sceneModes.AsReadOnly();
759 private IList<CameraEffectMode> GetSupportedEffects()
761 List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
763 NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
765 effectModes.Add(effect);
769 NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero).
770 ThrowIfFailed("Failed to get the supported camera effects.");
772 return effectModes.AsReadOnly();
775 private IList<Rotation> GetSupportedStreamRotations()
777 List<Rotation> streamRotations = new List<Rotation>();
779 NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
781 streamRotations.Add(streamRotation);
785 NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero).
786 ThrowIfFailed("Failed to get the supported camera rotations.");
788 return streamRotations.AsReadOnly();
791 private IList<Flips> GetSupportedStreamFlips()
793 List<Flips> streamFlips = new List<Flips>();
795 NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
797 streamFlips.Add(streamFlip);
801 NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero).
802 ThrowIfFailed("Failed to get the supported camera flips.");
804 return streamFlips.AsReadOnly();
807 private IList<CameraPtzType> GetSupportedPtzTypes()
809 List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
811 NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
813 ptzTypes.Add(ptzType);
817 NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero).
818 ThrowIfFailed("Failed to get the supported Ptz types.");
820 return ptzTypes.AsReadOnly();
822 #endregion Methods for getting supported values