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 public class CameraCapabilities
30 internal readonly Camera _camera;
32 private IList<Size> _previewResolutions;
33 private IList<Size> _cameraResolutions;
34 private IList<CameraPixelFormat> _captureFormats;
35 private IList<CameraPixelFormat> _previewFormats;
36 private IList<CameraFps> _fps;
37 private IList<CameraAutoFocusMode> _autoFocusModes;
38 private IList<CameraExposureMode> _exposureModes;
39 private IList<CameraIsoLevel> _isoLevels;
40 private IList<CameraTheaterMode> _theaterModes;
41 private IList<CameraWhiteBalance> _whitebalances;
42 private IList<CameraFlashMode> _flashModes;
43 private IList<CameraSceneMode> _sceneModes;
44 private IList<CameraEffectMode> _effectModes;
45 private IList<Rotation> _streamRotations;
46 private IList<Flips> _streamFlips;
47 private IList<CameraPtzType> _ptzTypes;
48 private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max);
49 private delegate bool IsSupportedDelegate(IntPtr handle);
51 internal CameraCapabilities(Camera camera)
55 IsFaceDetectionSupported = IsFeatureSupported(NativeCapabilities.IsFaceDetectionSupported);
56 IsMediaPacketPreviewCallbackSupported = IsFeatureSupported(NativeCapabilities.IsMediaPacketPreviewCallbackSupported);
57 IsZeroShutterLagSupported = IsFeatureSupported(NativeCapabilities.IsZeroShutterLagSupported);
58 IsContinuousCaptureSupported = IsFeatureSupported(NativeCapabilities.IsContinuousCaptureSupported);
59 IsHdrCaptureSupported = IsFeatureSupported(NativeCapabilities.IsHdrCaptureSupported);
60 IsAntiShakeSupported = IsFeatureSupported(NativeCapabilities.IsAntiShakeSupported);
61 IsVideoStabilizationSupported = IsFeatureSupported(NativeCapabilities.IsVideoStabilizationSupported);
62 IsAutoContrastSupported = IsFeatureSupported(NativeCapabilities.IsAutoContrastSupported);
63 IsBrigtnessSupported = CheckRangeValid(NativeSettings.GetBrightnessRange);
64 IsExposureSupported = CheckRangeValid(NativeSettings.GetExposureRange);
65 IsZoomSupported = CheckRangeValid(NativeSettings.GetZoomRange);
66 IsPanSupported = CheckRangeValid(NativeSettings.GetPanRange);
67 IsTiltSupported = CheckRangeValid(NativeSettings.GetTiltRange);
70 private bool IsFeatureSupported(IsSupportedDelegate func)
72 return func(_camera.GetHandle());
75 private bool CheckRangeValid(GetRangeDelegate func)
77 CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out int min, out int max),
78 "Failed to check feature is suported or not.");
84 /// Gets the face detection feature's supported state.
86 /// <value>true if supported, otherwise false.</value>
87 /// <since_tizen> 3 </since_tizen>
88 public bool IsFaceDetectionSupported { get; }
91 /// Gets the media packet preview callback feature's supported state.
93 /// <value>true if supported, otherwise false.</value>
94 /// <since_tizen> 3 </since_tizen>
95 public bool IsMediaPacketPreviewCallbackSupported { get; }
98 /// Gets the zero shutter lag feature's supported state.
100 /// <value>true if supported, otherwise false.</value>
101 /// <since_tizen> 3 </since_tizen>
102 public bool IsZeroShutterLagSupported { get; }
105 /// Gets the continuous capture feature's supported state.
107 /// <value>true if supported, otherwise false.</value>
108 /// <since_tizen> 3 </since_tizen>
109 public bool IsContinuousCaptureSupported { get; }
112 /// Gets the support state of the HDR capture.
114 /// <value>true if supported, otherwise false.</value>
115 /// <since_tizen> 3 </since_tizen>
116 public bool IsHdrCaptureSupported { get; }
119 /// Gets the support state of the anti-shake feature.
121 /// <value>true if supported, otherwise false.</value>
122 /// <since_tizen> 3 </since_tizen>
123 public bool IsAntiShakeSupported { get; }
126 /// Gets the support state of the video stabilization feature.
128 /// <value>true if supported, otherwise false.</value>
129 /// <since_tizen> 3 </since_tizen>
130 public bool IsVideoStabilizationSupported { get; }
133 /// Gets the support state of auto contrast feature.
135 /// <value>true if supported, otherwise false.</value>
136 /// <since_tizen> 3 </since_tizen>
137 public bool IsAutoContrastSupported { get; }
140 /// Gets the support state of the brightness feature.
142 /// <value>true if supported, otherwise false.</value>
143 /// <since_tizen> 3 </since_tizen>
144 public bool IsBrigtnessSupported { get; }
147 /// Gets the support state of the exposure feature.
149 /// <value>true if supported, otherwise false.</value>
150 /// <since_tizen> 3 </since_tizen>
151 public bool IsExposureSupported { get; }
154 /// Gets the support state of the zoom feature.
156 /// <value>true if supported, otherwise false.</value>
157 /// <since_tizen> 3 </since_tizen>
158 public bool IsZoomSupported { get; }
161 /// Gets the support state of the pan feature.
163 /// <value>true if supported, otherwise false.</value>
164 /// <since_tizen> 3 </since_tizen>
165 public bool IsPanSupported { get; }
168 /// Gets the support state of the tilt feature.
170 /// <value>true if supported, otherwise false.</value>
171 /// <since_tizen> 3 </since_tizen>
172 public bool IsTiltSupported { get; }
175 /// Retrieves all the preview resolutions supported by the camera.
177 /// <since_tizen> 3 </since_tizen>
179 /// It returns a list containing all the supported preview resolutions.
181 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
182 public IEnumerable<Size> SupportedPreviewResolutions
186 if (_previewResolutions == null)
188 _previewResolutions = GetSupportedPreviewResolutions();
191 return _previewResolutions;
196 /// Retrieves all the capture resolutions supported by the camera.
198 /// <since_tizen> 3 </since_tizen>
200 /// It returns a list containing all the supported capture resolutions.
202 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
203 public IEnumerable<Size> SupportedCaptureResolutions
207 if (_cameraResolutions == null)
209 _cameraResolutions = GetSupportedCaptureResolutions();
212 return _cameraResolutions;
217 /// Retrieves all the capture formats supported by the camera.
219 /// <since_tizen> 3 </since_tizen>
221 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
223 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
224 public IEnumerable<CameraPixelFormat> SupportedCapturePixelFormats
228 if (_captureFormats == null)
230 _captureFormats = GetSupportedCapturePixelFormats();
233 return _captureFormats;
238 /// Retrieves all the preview formats supported by the camera.
240 /// <since_tizen> 3 </since_tizen>
242 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
244 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
245 public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
249 if (_previewFormats == null)
251 _previewFormats = GetSupportedPreviewPixelFormats();
254 return _previewFormats;
259 /// Retrieves all the fps supported by the camera.
261 /// <since_tizen> 3 </since_tizen>
263 /// It returns a list containing all the supported <see cref="CameraFps"/>.
265 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
266 public IEnumerable<CameraFps> SupportedPreviewFps
272 _fps = GetSupportedPreviewFps();
280 /// Retrieves all the fps by resolution supported by the camera.
282 /// <since_tizen> 3 </since_tizen>
283 /// <param name="width">The width of required preview resolution.</param>
284 /// <param name="height">The height of required preview resolution.</param>
286 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
288 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
289 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
291 return GetSupportedPreviewFpsByResolutions(width, height);
295 /// Retrieves all the fps by resolution supported by the camera.
297 /// <since_tizen> 3 </since_tizen>
298 /// <param name="size">The size of required preview resolution.</param>
300 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
302 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
303 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
305 return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
309 /// Retrieves all the auto focus modes supported by the camera.
311 /// <since_tizen> 3 </since_tizen>
313 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
315 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
316 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
320 if (_autoFocusModes == null)
322 _autoFocusModes = GetSupportedAutoFocusModes();
325 return _autoFocusModes;
330 /// Retrieves all the exposure modes supported by the camera.
332 /// <since_tizen> 3 </since_tizen>
334 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
336 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
337 public IEnumerable<CameraExposureMode> SupportedExposureModes
341 if (_exposureModes == null)
343 _exposureModes = GetSupportedExposureModes();
346 return _exposureModes;
351 /// Retrieves all the ISO levels supported by the camera.
353 /// <since_tizen> 3 </since_tizen>
355 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
357 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
358 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
362 if (_isoLevels == null)
364 _isoLevels = GetSupportedIsoLevels();
372 /// Retrieves all the theater modes supported by the camera.
374 /// <since_tizen> 3 </since_tizen>
376 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
378 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
379 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
383 if (_theaterModes == null)
385 _theaterModes = GetSupportedTheaterModes();
388 return _theaterModes;
393 /// Retrieves all the white balance modes supported by the camera.
395 /// <since_tizen> 3 </since_tizen>
397 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
399 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
400 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
404 if (_whitebalances == null)
406 _whitebalances = GetSupportedWhitebalances();
409 return _whitebalances;
414 /// Retrieves all the flash modes supported by the camera.
416 /// <since_tizen> 3 </since_tizen>
418 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
420 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
421 public IEnumerable<CameraFlashMode> SupportedFlashModes
425 if (_flashModes == null)
427 _flashModes = GetSupportedFlashModes();
435 /// Retrieves all the scene modes supported by the camera.
437 /// <since_tizen> 3 </since_tizen>
439 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
441 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
442 public IEnumerable<CameraSceneMode> SupportedSceneModes
446 if (_sceneModes == null)
448 _sceneModes = GetSupportedSceneModes();
456 /// Retrieves all the effect modes supported by the camera.
458 /// <since_tizen> 3 </since_tizen>
460 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
462 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
463 public IEnumerable<CameraEffectMode> SupportedEffects
467 if (_effectModes == null)
469 _effectModes = GetSupportedEffects();
477 /// Retrieves all the stream rotations supported by the camera.
479 /// <since_tizen> 3 </since_tizen>
481 /// An IEnumerable containing all the supported <see cref="Rotation"/>.
483 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
484 public IEnumerable<Rotation> SupportedStreamRotations
488 if (_streamRotations == null)
490 _streamRotations = GetSupportedStreamRotations();
493 return _streamRotations;
498 /// Retrieves all the flips supported by the camera.
500 /// <since_tizen> 3 </since_tizen>
502 /// It returns a list containing all the supported <see cref="Flips"/>.
504 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
505 public IEnumerable<Flips> SupportedStreamFlips
509 if (_streamFlips == null)
511 _streamFlips = GetSupportedStreamFlips();
519 /// Retrieves all the PTZ types by the camera.
521 /// <since_tizen> 3 </since_tizen>
523 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
525 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
526 public IEnumerable<CameraPtzType> SupportedPtzTypes
530 if (_ptzTypes.Count == 0)
532 _ptzTypes = GetSupportedPtzTypes();
539 #region Methods for getting supported values
540 private IList<Size> GetSupportedPreviewResolutions()
542 List<Size> previewResolutions = new List<Size>();
544 NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
546 previewResolutions.Add(new Size(width, height));
549 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
550 "Failed to get the supported preview resolutions");
552 return previewResolutions.AsReadOnly();
555 private IList<Size> GetSupportedCaptureResolutions()
557 List<Size> cameraResolutions = new List<Size>();
559 NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
561 cameraResolutions.Add(new Size(width, height));
564 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
565 "Failed to get the supported capture resolutions");
567 return cameraResolutions.AsReadOnly();
570 private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
572 List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
574 NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
576 captureFormats.Add(format);
579 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
580 "Failed to get the supported capture formats.");
582 return captureFormats.AsReadOnly();
585 private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
587 List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
589 NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
591 previewFormats.Add(format);
594 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
595 "Failed to get the supported preview formats.");
597 return previewFormats.AsReadOnly();
600 private IList<CameraFps> GetSupportedPreviewFps()
602 List<CameraFps> previewFps = new List<CameraFps>();
604 NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
609 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
610 "Failed to get the supported camera fps");
612 return previewFps.AsReadOnly();
615 private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
617 List<CameraFps> fpsByResolution = new List<CameraFps>();
619 NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
621 fpsByResolution.Add(fps);
624 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(),
625 width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");
627 return fpsByResolution.AsReadOnly();
630 private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
632 List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
634 NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
636 autoFocusModes.Add(mode);
639 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero),
640 "Failed to get the supported Auto focus modes.");
642 return autoFocusModes.AsReadOnly();
645 private IList<CameraExposureMode> GetSupportedExposureModes()
647 List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
649 NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
651 exposureModes.Add(mode);
654 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero),
655 "Failed to get the supported Exposure modes.");
657 return exposureModes.AsReadOnly();
660 private IList<CameraIsoLevel> GetSupportedIsoLevels()
662 List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
664 NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
669 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
670 "Failed to get the supported Iso levels.");
672 return isoLevels.AsReadOnly();
675 private IList<CameraTheaterMode> GetSupportedTheaterModes()
677 List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
679 NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
681 theaterModes.Add(theaterMode);
684 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero),
685 "Failed to get the supported theater modes.");
687 return theaterModes.AsReadOnly();
690 private IList<CameraWhiteBalance> GetSupportedWhitebalances()
692 List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
694 NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
696 whitebalances.Add(whiteBalance);
699 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
700 "Failed to get the supported white balance.");
702 return whitebalances.AsReadOnly();
705 private IList<CameraFlashMode> GetSupportedFlashModes()
707 List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
709 NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
711 flashModes.Add(flashMode);
714 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero),
715 "Failed to get the supported flash modes.");
717 return flashModes.AsReadOnly();
720 private IList<CameraSceneMode> GetSupportedSceneModes()
722 List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
724 NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
726 sceneModes.Add(sceneMode);
729 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
730 "Failed to get the supported scene modes.");
732 return sceneModes.AsReadOnly();
735 private IList<CameraEffectMode> GetSupportedEffects()
737 List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
739 NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
741 effectModes.Add(effect);
744 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
745 "Failed to get the supported camera effects.");
747 return effectModes.AsReadOnly();
750 private IList<Rotation> GetSupportedStreamRotations()
752 List<Rotation> streamRotations = new List<Rotation>();
754 NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
756 streamRotations.Add(streamRotation);
759 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
760 "Failed to get the supported camera rotations.");
762 return streamRotations.AsReadOnly();
765 private IList<Flips> GetSupportedStreamFlips()
767 List<Flips> streamFlips = new List<Flips>();
769 NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
771 streamFlips.Add(streamFlip);
774 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
775 "Failed to get the supported camera flips.");
777 return streamFlips.AsReadOnly();
780 private IList<CameraPtzType> GetSupportedPtzTypes()
782 List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
784 NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
786 ptzTypes.Add(ptzType);
789 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
790 "Failed to get the supported Ptz types.");
792 return ptzTypes.AsReadOnly();
794 #endregion Methods for getting supported values