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>
285 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
287 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
288 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
290 return GetSupportedPreviewFpsByResolutions(width, height);
294 /// Retrieves all the fps by resolution supported by the camera.
296 /// <since_tizen> 3 </since_tizen>
298 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
300 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
301 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
303 return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
307 /// Retrieves all the auto focus modes supported by the camera.
309 /// <since_tizen> 3 </since_tizen>
311 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
313 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
314 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
318 if (_autoFocusModes == null)
320 _autoFocusModes = GetSupportedAutoFocusModes();
323 return _autoFocusModes;
328 /// Retrieves all the exposure modes supported by the camera.
330 /// <since_tizen> 3 </since_tizen>
332 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
334 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
335 public IEnumerable<CameraExposureMode> SupportedExposureModes
339 if (_exposureModes == null)
341 _exposureModes = GetSupportedExposureModes();
344 return _exposureModes;
349 /// Retrieves all the Iso level supported by the camera.
351 /// <since_tizen> 3 </since_tizen>
353 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
355 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
356 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
360 if (_isoLevels == null)
362 _isoLevels = GetSupportedIsoLevels();
370 /// Retrieves all the theater modes supported by the camera.
372 /// <since_tizen> 3 </since_tizen>
374 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
376 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
377 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
381 if (_theaterModes == null)
383 _theaterModes = GetSupportedTheaterModes();
386 return _theaterModes;
391 /// Retrieves all the whitebalance modes supported by the camera.
393 /// <since_tizen> 3 </since_tizen>
395 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
397 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
398 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
402 if (_whitebalances == null)
404 _whitebalances = GetSupportedWhitebalances();
407 return _whitebalances;
412 /// Retrieves all the flash modes supported by the camera.
414 /// <since_tizen> 3 </since_tizen>
416 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
418 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
419 public IEnumerable<CameraFlashMode> SupportedFlashModes
423 if (_flashModes == null)
425 _flashModes = GetSupportedFlashModes();
433 /// Retrieves all the scene modes supported by the camera.
435 /// <since_tizen> 3 </since_tizen>
437 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
439 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
440 public IEnumerable<CameraSceneMode> SupportedSceneModes
444 if (_sceneModes == null)
446 _sceneModes = GetSupportedSceneModes();
454 /// Retrieves all the effect modes supported by the camera.
456 /// <since_tizen> 3 </since_tizen>
458 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
460 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
461 public IEnumerable<CameraEffectMode> SupportedEffects
465 if (_effectModes == null)
467 _effectModes = GetSupportedEffects();
475 /// Retrieves all the stream rotation supported by the camera.
477 /// <since_tizen> 3 </since_tizen>
479 /// An IEnumerable containing all the supported <see cref="Rotation"/>.
481 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
482 public IEnumerable<Rotation> SupportedStreamRotations
486 if (_streamRotations == null)
488 _streamRotations = GetSupportedStreamRotations();
491 return _streamRotations;
496 /// Retrieves all the flips supported by the camera.
498 /// <since_tizen> 3 </since_tizen>
500 /// It returns a list containing all the supported <see cref="CameraFlip"/>.
502 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
503 public IEnumerable<Flips> SupportedStreamFlips
507 if (_streamFlips == null)
509 _streamFlips = GetSupportedStreamFlips();
517 /// Retrieves all the ptz types by the camera.
519 /// <since_tizen> 3 </since_tizen>
521 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
523 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
524 public IEnumerable<CameraPtzType> SupportedPtzTypes
528 if (_ptzTypes.Count == 0)
530 _ptzTypes = GetSupportedPtzTypes();
537 #region Methods for getting supported values
538 private IList<Size> GetSupportedPreviewResolutions()
540 List<Size> previewResolutions = new List<Size>();
542 NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
544 previewResolutions.Add(new Size(width, height));
547 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
548 "Failed to get the supported preview resolutions");
550 return previewResolutions.AsReadOnly();
553 private IList<Size> GetSupportedCaptureResolutions()
555 List<Size> cameraResolutions = new List<Size>();
557 NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
559 cameraResolutions.Add(new Size(width, height));
562 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
563 "Failed to get the supported capture resolutions");
565 return cameraResolutions.AsReadOnly();
568 private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
570 List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
572 NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
574 captureFormats.Add(format);
577 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
578 "Failed to get the supported capture formats.");
580 return captureFormats.AsReadOnly();
583 private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
585 List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
587 NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
589 previewFormats.Add(format);
592 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
593 "Failed to get the supported preview formats.");
595 return previewFormats.AsReadOnly();
598 private IList<CameraFps> GetSupportedPreviewFps()
600 List<CameraFps> previewFps = new List<CameraFps>();
602 NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
607 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
608 "Failed to get the supported camera fps");
610 return previewFps.AsReadOnly();
613 private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
615 List<CameraFps> fpsByResolution = new List<CameraFps>();
617 NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
619 fpsByResolution.Add(fps);
622 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(),
623 width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");
625 return fpsByResolution.AsReadOnly();
628 private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
630 List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
632 NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
634 autoFocusModes.Add(mode);
637 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero),
638 "Failed to get the supported Auto focus modes.");
640 return autoFocusModes.AsReadOnly();
643 private IList<CameraExposureMode> GetSupportedExposureModes()
645 List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
647 NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
649 exposureModes.Add(mode);
652 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero),
653 "Failed to get the supported Exposure modes.");
655 return exposureModes.AsReadOnly();
658 private IList<CameraIsoLevel> GetSupportedIsoLevels()
660 List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
662 NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
667 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
668 "Failed to get the supported Iso levels.");
670 return isoLevels.AsReadOnly();
673 private IList<CameraTheaterMode> GetSupportedTheaterModes()
675 List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
677 NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
679 theaterModes.Add(theaterMode);
682 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero),
683 "Failed to get the supported theater modes.");
685 return theaterModes.AsReadOnly();
688 private IList<CameraWhiteBalance> GetSupportedWhitebalances()
690 List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
692 NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
694 whitebalances.Add(whiteBalance);
697 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
698 "Failed to get the supported white balance.");
700 return whitebalances.AsReadOnly();
703 private IList<CameraFlashMode> GetSupportedFlashModes()
705 List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
707 NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
709 flashModes.Add(flashMode);
712 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero),
713 "Failed to get the supported flash modes.");
715 return flashModes.AsReadOnly();
718 private IList<CameraSceneMode> GetSupportedSceneModes()
720 List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
722 NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
724 sceneModes.Add(sceneMode);
727 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
728 "Failed to get the supported scene modes.");
730 return sceneModes.AsReadOnly();
733 private IList<CameraEffectMode> GetSupportedEffects()
735 List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
737 NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
739 effectModes.Add(effect);
742 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
743 "Failed to get the supported camera effects.");
745 return effectModes.AsReadOnly();
748 private IList<Rotation> GetSupportedStreamRotations()
750 List<Rotation> streamRotations = new List<Rotation>();
752 NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
754 streamRotations.Add(streamRotation);
757 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
758 "Failed to get the supported camera rotations.");
760 return streamRotations.AsReadOnly();
763 private IList<Flips> GetSupportedStreamFlips()
765 List<Flips> streamFlips = new List<Flips>();
767 NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
769 streamFlips.Add(streamFlip);
772 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
773 "Failed to get the supported camera flips.");
775 return streamFlips.AsReadOnly();
778 private IList<CameraPtzType> GetSupportedPtzTypes()
780 List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
782 NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
784 ptzTypes.Add(ptzType);
787 CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
788 "Failed to get the supported Ptz types.");
790 return ptzTypes.AsReadOnly();
792 #endregion Methods for getting supported values