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.
85 /// true if supported, otherwise false.
87 /// <since_tizen> 3 </since_tizen>
88 public bool IsFaceDetectionSupported { get; }
91 /// Gets the media packet preview callback feature's supported state.
92 /// true if supported, otherwise false.
94 /// <since_tizen> 3 </since_tizen>
95 public bool IsMediaPacketPreviewCallbackSupported { get; }
98 /// Gets the zero shutter lag feature's supported state.
99 /// true if supported, otherwise false.
101 /// <since_tizen> 3 </since_tizen>
102 public bool IsZeroShutterLagSupported { get; }
105 /// Gets continuous capture feature's supported state.
106 /// true if supported, otherwise false.
108 /// <since_tizen> 3 </since_tizen>
109 public bool IsContinuousCaptureSupported { get; }
112 /// Gets the support state of HDR capture.
113 /// true if supported, otherwise false.
115 /// <since_tizen> 3 </since_tizen>
116 public bool IsHdrCaptureSupported { get; }
119 /// Gets the support state of the anti-shake feature.
120 /// true if supported, otherwise false.
122 /// <since_tizen> 3 </since_tizen>
123 public bool IsAntiShakeSupported { get; }
126 /// Gets the support state of the video stabilization feature.
127 /// true if supported, otherwise false.
129 /// <since_tizen> 3 </since_tizen>
130 public bool IsVideoStabilizationSupported { get; }
133 /// Gets the support state of auto contrast feature.
134 /// true if supported, otherwise false.
136 /// <since_tizen> 3 </since_tizen>
137 public bool IsAutoContrastSupported { get; }
140 /// Gets the support state of brightness feature.
141 /// true if supported, otherwise false.
143 /// <since_tizen> 3 </since_tizen>
144 public bool IsBrigtnessSupported { get; }
147 /// Gets the support state of exposure feature.
148 /// true if supported, otherwise false.
150 /// <since_tizen> 3 </since_tizen>
151 public bool IsExposureSupported { get; }
154 /// Gets the support state of zoom feature.
155 /// true if supported, otherwise false.
157 /// <since_tizen> 3 </since_tizen>
158 public bool IsZoomSupported { get; }
161 /// Gets the support state of pan feature.
162 /// true if supported, otherwise false.
164 /// <since_tizen> 3 </since_tizen>
165 public bool IsPanSupported { get; }
168 /// Gets the support state of tilt feature.
169 /// true if supported, otherwise false.
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.
182 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
183 public IEnumerable<Size> SupportedPreviewResolutions
187 if (_previewResolutions == null)
189 _previewResolutions = GetSupportedPreviewResolutions();
192 return _previewResolutions;
197 /// Retrieves all the capture resolutions supported by the camera.
199 /// <since_tizen> 3 </since_tizen>
201 /// It returns a list containing all the supported capture resolutions.
203 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
204 public IEnumerable<Size> SupportedCaptureResolutions
208 if (_cameraResolutions == null)
210 _cameraResolutions = GetSupportedCaptureResolutions();
213 return _cameraResolutions;
218 /// Retrieves all the capture formats supported by the camera.
220 /// <since_tizen> 3 </since_tizen>
222 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
224 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
225 public IEnumerable<CameraPixelFormat> SupportedCapturePixelFormats
229 if (_captureFormats == null)
231 _captureFormats = GetSupportedCapturePixelFormats();
234 return _captureFormats;
239 /// Retrieves all the preview formats supported by the camera.
241 /// <since_tizen> 3 </since_tizen>
243 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
245 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
246 public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
250 if (_previewFormats == null)
252 _previewFormats = GetSupportedPreviewPixelFormats();
255 return _previewFormats;
260 /// Retrieves all the fps supported by the camera.
262 /// <since_tizen> 3 </since_tizen>
264 /// It returns a list containing all the supported <see cref="CameraFps"/>.
266 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
267 public IEnumerable<CameraFps> SupportedPreviewFps
273 _fps = GetSupportedPreviewFps();
281 /// Retrieves all the fps by resolution supported by the camera.
283 /// <since_tizen> 3 </since_tizen>
284 /// <param name="width">The width of required preview resolution.</param>
285 /// <param name="height">The height of required preview resolution.</param>
287 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
289 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
290 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
292 return GetSupportedPreviewFpsByResolutions(width, height);
296 /// Retrieves all the fps by resolution supported by the camera.
298 /// <since_tizen> 3 </since_tizen>
299 /// <param name="size">The size of required preview resolution.</param>
301 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
303 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
304 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
306 return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
310 /// Retrieves all the auto focus modes supported by the camera.
312 /// <since_tizen> 3 </since_tizen>
314 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
316 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
317 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
321 if (_autoFocusModes == null)
323 _autoFocusModes = GetSupportedAutoFocusModes();
326 return _autoFocusModes;
331 /// Retrieves all the exposure modes supported by the camera.
333 /// <since_tizen> 3 </since_tizen>
335 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
337 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
338 public IEnumerable<CameraExposureMode> SupportedExposureModes
342 if (_exposureModes == null)
344 _exposureModes = GetSupportedExposureModes();
347 return _exposureModes;
352 /// Retrieves all the Iso level supported by the camera.
354 /// <since_tizen> 3 </since_tizen>
356 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
358 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
359 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
363 if (_isoLevels == null)
365 _isoLevels = GetSupportedIsoLevels();
373 /// Retrieves all the theater modes supported by the camera.
375 /// <since_tizen> 3 </since_tizen>
377 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
379 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
380 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
384 if (_theaterModes == null)
386 _theaterModes = GetSupportedTheaterModes();
389 return _theaterModes;
394 /// Retrieves all the whitebalance modes supported by the camera.
396 /// <since_tizen> 3 </since_tizen>
398 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
400 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
401 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
405 if (_whitebalances == null)
407 _whitebalances = GetSupportedWhitebalances();
410 return _whitebalances;
415 /// Retrieves all the flash modes supported by the camera.
417 /// <since_tizen> 3 </since_tizen>
419 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
421 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
422 public IEnumerable<CameraFlashMode> SupportedFlashModes
426 if (_flashModes == null)
428 _flashModes = GetSupportedFlashModes();
436 /// Retrieves all the scene modes supported by the camera.
438 /// <since_tizen> 3 </since_tizen>
440 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
442 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
443 public IEnumerable<CameraSceneMode> SupportedSceneModes
447 if (_sceneModes == null)
449 _sceneModes = GetSupportedSceneModes();
457 /// Retrieves all the effect modes supported by the camera.
459 /// <since_tizen> 3 </since_tizen>
461 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
463 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
464 public IEnumerable<CameraEffectMode> SupportedEffects
468 if (_effectModes == null)
470 _effectModes = GetSupportedEffects();
478 /// Retrieves all the stream rotation supported by the camera.
480 /// <since_tizen> 3 </since_tizen>
482 /// An IEnumerable containing all the supported <see cref="Rotation"/>.
484 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
485 public IEnumerable<Rotation> SupportedStreamRotations
489 if (_streamRotations == null)
491 _streamRotations = GetSupportedStreamRotations();
494 return _streamRotations;
499 /// Retrieves all the flips supported by the camera.
501 /// <since_tizen> 3 </since_tizen>
503 /// It returns a list containing all the supported <see cref="Flips"/>.
505 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
506 public IEnumerable<Flips> SupportedStreamFlips
510 if (_streamFlips == null)
512 _streamFlips = GetSupportedStreamFlips();
520 /// Retrieves all the ptz types by the camera.
522 /// <since_tizen> 3 </since_tizen>
524 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
526 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
527 public IEnumerable<CameraPtzType> SupportedPtzTypes
531 if (_ptzTypes.Count == 0)
533 _ptzTypes = GetSupportedPtzTypes();
540 #region Methods for getting supported values
541 private IList<Size> GetSupportedPreviewResolutions()
543 List<Size> previewResolutions = new List<Size>();
545 NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
547 previewResolutions.Add(new Size(width, height));
550 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
551 "Failed to get the supported preview resolutions");
553 return previewResolutions.AsReadOnly();
556 private IList<Size> GetSupportedCaptureResolutions()
558 List<Size> cameraResolutions = new List<Size>();
560 NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
562 cameraResolutions.Add(new Size(width, height));
565 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
566 "Failed to get the supported capture resolutions");
568 return cameraResolutions.AsReadOnly();
571 private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
573 List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
575 NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
577 captureFormats.Add(format);
580 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
581 "Failed to get the supported capture formats.");
583 return captureFormats.AsReadOnly();
586 private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
588 List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
590 NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
592 previewFormats.Add(format);
595 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
596 "Failed to get the supported preview formats.");
598 return previewFormats.AsReadOnly();
601 private IList<CameraFps> GetSupportedPreviewFps()
603 List<CameraFps> previewFps = new List<CameraFps>();
605 NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
610 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
611 "Failed to get the supported camera fps");
613 return previewFps.AsReadOnly();
616 private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
618 List<CameraFps> fpsByResolution = new List<CameraFps>();
620 NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
622 fpsByResolution.Add(fps);
625 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(),
626 width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");
628 return fpsByResolution.AsReadOnly();
631 private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
633 List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
635 NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
637 autoFocusModes.Add(mode);
640 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero),
641 "Failed to get the supported Auto focus modes.");
643 return autoFocusModes.AsReadOnly();
646 private IList<CameraExposureMode> GetSupportedExposureModes()
648 List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
650 NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
652 exposureModes.Add(mode);
655 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero),
656 "Failed to get the supported Exposure modes.");
658 return exposureModes.AsReadOnly();
661 private IList<CameraIsoLevel> GetSupportedIsoLevels()
663 List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
665 NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
670 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
671 "Failed to get the supported Iso levels.");
673 return isoLevels.AsReadOnly();
676 private IList<CameraTheaterMode> GetSupportedTheaterModes()
678 List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
680 NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
682 theaterModes.Add(theaterMode);
685 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero),
686 "Failed to get the supported theater modes.");
688 return theaterModes.AsReadOnly();
691 private IList<CameraWhiteBalance> GetSupportedWhitebalances()
693 List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
695 NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
697 whitebalances.Add(whiteBalance);
700 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
701 "Failed to get the supported white balance.");
703 return whitebalances.AsReadOnly();
706 private IList<CameraFlashMode> GetSupportedFlashModes()
708 List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
710 NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
712 flashModes.Add(flashMode);
715 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero),
716 "Failed to get the supported flash modes.");
718 return flashModes.AsReadOnly();
721 private IList<CameraSceneMode> GetSupportedSceneModes()
723 List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
725 NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
727 sceneModes.Add(sceneMode);
730 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
731 "Failed to get the supported scene modes.");
733 return sceneModes.AsReadOnly();
736 private IList<CameraEffectMode> GetSupportedEffects()
738 List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
740 NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
742 effectModes.Add(effect);
745 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
746 "Failed to get the supported camera effects.");
748 return effectModes.AsReadOnly();
751 private IList<Rotation> GetSupportedStreamRotations()
753 List<Rotation> streamRotations = new List<Rotation>();
755 NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
757 streamRotations.Add(streamRotation);
760 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
761 "Failed to get the supported camera rotations.");
763 return streamRotations.AsReadOnly();
766 private IList<Flips> GetSupportedStreamFlips()
768 List<Flips> streamFlips = new List<Flips>();
770 NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
772 streamFlips.Add(streamFlip);
775 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
776 "Failed to get the supported camera flips.");
778 return streamFlips.AsReadOnly();
781 private IList<CameraPtzType> GetSupportedPtzTypes()
783 List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
785 NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
787 ptzTypes.Add(ptzType);
790 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
791 "Failed to get the supported Ptz types.");
793 return ptzTypes.AsReadOnly();
795 #endregion Methods for getting supported values