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 CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out int min, out int max),
80 "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));
560 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
561 "Failed to get the supported preview resolutions");
563 return previewResolutions.AsReadOnly();
566 private IList<Size> GetSupportedCaptureResolutions()
568 List<Size> cameraResolutions = new List<Size>();
570 NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
572 cameraResolutions.Add(new Size(width, height));
575 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
576 "Failed to get the supported capture resolutions");
578 return cameraResolutions.AsReadOnly();
581 private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
583 List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
585 NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
587 captureFormats.Add(format);
590 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
591 "Failed to get the supported capture formats.");
593 return captureFormats.AsReadOnly();
596 private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
598 List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
600 NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
602 previewFormats.Add(format);
605 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
606 "Failed to get the supported preview formats.");
608 return previewFormats.AsReadOnly();
611 private IList<CameraFps> GetSupportedPreviewFps()
613 List<CameraFps> previewFps = new List<CameraFps>();
615 NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
620 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
621 "Failed to get the supported camera fps");
623 return previewFps.AsReadOnly();
626 private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
628 List<CameraFps> fpsByResolution = new List<CameraFps>();
630 NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
632 fpsByResolution.Add(fps);
635 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(),
636 width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");
638 return fpsByResolution.AsReadOnly();
641 private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
643 List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
645 NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
647 autoFocusModes.Add(mode);
650 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero),
651 "Failed to get the supported Auto focus modes.");
653 return autoFocusModes.AsReadOnly();
656 private IList<CameraExposureMode> GetSupportedExposureModes()
658 List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
660 NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
662 exposureModes.Add(mode);
665 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero),
666 "Failed to get the supported Exposure modes.");
668 return exposureModes.AsReadOnly();
671 private IList<CameraIsoLevel> GetSupportedIsoLevels()
673 List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
675 NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
680 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
681 "Failed to get the supported Iso levels.");
683 return isoLevels.AsReadOnly();
686 private IList<CameraTheaterMode> GetSupportedTheaterModes()
688 List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
690 NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
692 theaterModes.Add(theaterMode);
695 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero),
696 "Failed to get the supported theater modes.");
698 return theaterModes.AsReadOnly();
701 private IList<CameraWhiteBalance> GetSupportedWhitebalances()
703 List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
705 NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
707 whitebalances.Add(whiteBalance);
710 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
711 "Failed to get the supported white balance.");
713 return whitebalances.AsReadOnly();
716 private IList<CameraFlashMode> GetSupportedFlashModes()
718 List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
720 NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
722 flashModes.Add(flashMode);
725 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero),
726 "Failed to get the supported flash modes.");
728 return flashModes.AsReadOnly();
731 private IList<CameraSceneMode> GetSupportedSceneModes()
733 List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
735 NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
737 sceneModes.Add(sceneMode);
740 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
741 "Failed to get the supported scene modes.");
743 return sceneModes.AsReadOnly();
746 private IList<CameraEffectMode> GetSupportedEffects()
748 List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
750 NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
752 effectModes.Add(effect);
755 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
756 "Failed to get the supported camera effects.");
758 return effectModes.AsReadOnly();
761 private IList<Rotation> GetSupportedStreamRotations()
763 List<Rotation> streamRotations = new List<Rotation>();
765 NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
767 streamRotations.Add(streamRotation);
770 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
771 "Failed to get the supported camera rotations.");
773 return streamRotations.AsReadOnly();
776 private IList<Flips> GetSupportedStreamFlips()
778 List<Flips> streamFlips = new List<Flips>();
780 NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
782 streamFlips.Add(streamFlip);
785 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
786 "Failed to get the supported camera flips.");
788 return streamFlips.AsReadOnly();
791 private IList<CameraPtzType> GetSupportedPtzTypes()
793 List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
795 NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
797 ptzTypes.Add(ptzType);
800 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
801 "Failed to get the supported Ptz types.");
803 return ptzTypes.AsReadOnly();
805 #endregion Methods for getting supported values