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);
71 private bool IsFeatureSupported(IsSupportedDelegate func)
73 return func(_camera.GetHandle());
76 private bool CheckRangeValid(GetRangeDelegate func)
78 CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out int min, out int max),
79 "Failed to check feature is suported or not.");
85 /// Gets the face detection feature's supported state.
87 /// <value>true if supported, otherwise false.</value>
88 /// <since_tizen> 4 </since_tizen>
89 public bool IsFaceDetectionSupported { get; }
92 /// Gets the media packet preview callback feature's supported state.
94 /// <value>true if supported, otherwise false.</value>
95 /// <since_tizen> 4 </since_tizen>
96 public bool IsMediaPacketPreviewCallbackSupported { get; }
99 /// Gets the zero shutter lag feature's supported state.
101 /// <value>true if supported, otherwise false.</value>
102 /// <since_tizen> 4 </since_tizen>
103 public bool IsZeroShutterLagSupported { get; }
106 /// Gets the continuous capture feature's supported state.
108 /// <value>true if supported, otherwise false.</value>
109 /// <since_tizen> 4 </since_tizen>
110 public bool IsContinuousCaptureSupported { get; }
113 /// Gets the support state of the HDR capture.
115 /// <value>true if supported, otherwise false.</value>
116 /// <since_tizen> 4 </since_tizen>
117 public bool IsHdrCaptureSupported { get; }
120 /// Gets the support state of the anti-shake feature.
122 /// <value>true if supported, otherwise false.</value>
123 /// <since_tizen> 4 </since_tizen>
124 public bool IsAntiShakeSupported { get; }
127 /// Gets the support state of the video stabilization feature.
129 /// <value>true if supported, otherwise false.</value>
130 /// <since_tizen> 4 </since_tizen>
131 public bool IsVideoStabilizationSupported { get; }
134 /// Gets the support state of auto contrast feature.
136 /// <value>true if supported, otherwise false.</value>
137 /// <since_tizen> 4 </since_tizen>
138 public bool IsAutoContrastSupported { get; }
141 /// Gets the support state of the brightness feature.
143 /// <value>true if supported, otherwise false.</value>
144 /// <since_tizen> 4 </since_tizen>
145 public bool IsBrigtnessSupported { get; }
148 /// Gets the support state of the exposure feature.
150 /// <value>true if supported, otherwise false.</value>
151 /// <since_tizen> 4 </since_tizen>
152 public bool IsExposureSupported { get; }
155 /// Gets the support state of the zoom feature.
157 /// <value>true if supported, otherwise false.</value>
158 /// <since_tizen> 4 </since_tizen>
159 public bool IsZoomSupported { get; }
162 /// Gets the support state of the pan feature.
164 /// <value>true if supported, otherwise false.</value>
165 /// <since_tizen> 4 </since_tizen>
166 public bool IsPanSupported { get; }
169 /// Gets the support state of the tilt feature.
171 /// <value>true if supported, otherwise false.</value>
172 /// <since_tizen> 4 </since_tizen>
173 public bool IsTiltSupported { get; }
176 /// Retrieves all the preview resolutions supported by the camera.
178 /// <since_tizen> 4 </since_tizen>
180 /// It returns a list containing all the supported preview resolutions.
182 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
201 /// It returns a list containing all the supported capture resolutions.
203 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
222 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
224 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
243 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
245 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
264 /// It returns a list containing all the supported <see cref="CameraFps"/>.
266 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
267 public IEnumerable<CameraFps> SupportedPreviewFps
273 _fps = GetSupportedPreviewFps();
281 /// Retrieves all the fps by resolution supported by the camera.
283 /// <since_tizen> 4 </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 of.</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> 4 </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 of.</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> 4 </since_tizen>
314 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
316 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
335 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
337 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
338 public IEnumerable<CameraExposureMode> SupportedExposureModes
342 if (_exposureModes == null)
344 _exposureModes = GetSupportedExposureModes();
347 return _exposureModes;
352 /// Retrieves all the ISO levels supported by the camera.
354 /// <since_tizen> 4 </since_tizen>
356 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
358 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
377 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
379 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
380 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
384 if (_theaterModes == null)
386 _theaterModes = GetSupportedTheaterModes();
389 return _theaterModes;
394 /// Retrieves all the white balance modes supported by the camera.
396 /// <since_tizen> 4 </since_tizen>
398 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
400 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
419 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
421 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
440 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
442 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
461 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
463 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
464 public IEnumerable<CameraEffectMode> SupportedEffects
468 if (_effectModes == null)
470 _effectModes = GetSupportedEffects();
478 /// Retrieves all the stream rotations supported by the camera.
480 /// <since_tizen> 4 </since_tizen>
482 /// An IEnumerable containing all the supported <see cref="Rotation"/>.
484 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
503 /// It returns a list containing all the supported <see cref="Flips"/>.
505 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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> 4 </since_tizen>
524 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
526 /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</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