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 NativeFeatures = Interop.CameraFeatures;
20 using NativeSettings = Interop.CameraSettings;
22 namespace Tizen.Multimedia
25 /// The CameraFeatures class provides properties
26 /// to get various capability information of the camera device.
28 public class CameraFeatures
30 internal readonly Camera _camera;
32 private List<Size> _previewResolutions;
33 private List<Size> _cameraResolutions;
34 private List<CameraPixelFormat> _captureFormats;
35 private List<CameraPixelFormat> _previewFormats;
36 private List<CameraFps> _fps;
37 private List<CameraFps> _fpsByResolution;
38 private List<CameraAutoFocusMode> _autoFocusModes;
39 private List<CameraExposureMode> _exposureModes;
40 private List<CameraIsoLevel> _isoLevels;
41 private List<CameraTheaterMode> _theaterModes;
42 private List<CameraWhiteBalance> _whitebalances;
43 private List<CameraFlashMode> _flashModes;
44 private List<CameraSceneMode> _sceneModes;
45 private List<CameraEffectMode> _effectModes;
46 private List<CameraRotation> _streamRotations;
47 private List<CameraFlip> _streamFlips;
48 private List<CameraPtzType> _ptzTypes;
50 private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max);
51 private delegate bool IsSupportedDelegate(IntPtr handle);
53 internal CameraFeatures(Camera camera)
57 IsFaceDetectionSupported = IsFeatureSupported(NativeFeatures.IsFaceDetectionSupported);
58 IsMediaPacketPreviewCallbackSupported = IsFeatureSupported(NativeFeatures.IsMediaPacketPreviewCallbackSupported);
59 IsZeroShutterLagSupported = IsFeatureSupported(NativeFeatures.IsZeroShutterLagSupported);
60 IsContinuousCaptureSupported = IsFeatureSupported(NativeFeatures.IsContinuousCaptureSupported);
61 IsHdrCaptureSupported = IsFeatureSupported(NativeFeatures.IsHdrCaptureSupported);
62 IsAntiShakeSupported = IsFeatureSupported(NativeFeatures.IsAntiShakeSupported);
63 IsVideoStabilizationSupported = IsFeatureSupported(NativeFeatures.IsVideoStabilizationSupported);
64 IsAutoContrastSupported = IsFeatureSupported(NativeFeatures.IsAutoContrastSupported);
65 IsBrigtnessSupported = CheckRangeValid(NativeSettings.GetBrightnessRange);
66 IsExposureSupported = CheckRangeValid(NativeSettings.GetExposureRange);
67 IsZoomSupported = CheckRangeValid(NativeSettings.GetZoomRange);
68 IsPanSupported = CheckRangeValid(NativeSettings.GetPanRange);
69 IsTiltSupported = CheckRangeValid(NativeSettings.GetTiltRange);
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.
87 /// true if supported, otherwise false.
89 /// <since_tizen> 3 </since_tizen>
90 public bool IsFaceDetectionSupported { get; }
93 /// Gets the media packet preview callback feature's supported state.
94 /// true if supported, otherwise false.
96 /// <since_tizen> 3 </since_tizen>
97 public bool IsMediaPacketPreviewCallbackSupported { get; }
100 /// Gets the zero shutter lag feature's supported state.
101 /// true if supported, otherwise false.
103 /// <since_tizen> 3 </since_tizen>
104 public bool IsZeroShutterLagSupported { get; }
107 /// Gets continuous capture feature's supported state.
108 /// true if supported, otherwise false.
110 /// <since_tizen> 3 </since_tizen>
111 public bool IsContinuousCaptureSupported { get; }
114 /// Gets the support state of HDR capture.
115 /// true if supported, otherwise false.
117 /// <since_tizen> 3 </since_tizen>
118 public bool IsHdrCaptureSupported { get; }
121 /// Gets the support state of the anti-shake feature.
122 /// true if supported, otherwise false.
124 /// <since_tizen> 3 </since_tizen>
125 public bool IsAntiShakeSupported { get; }
128 /// Gets the support state of the video stabilization feature.
129 /// true if supported, otherwise false.
131 /// <since_tizen> 3 </since_tizen>
132 public bool IsVideoStabilizationSupported { get; }
135 /// Gets the support state of auto contrast feature.
136 /// true if supported, otherwise false.
138 /// <since_tizen> 3 </since_tizen>
139 public bool IsAutoContrastSupported { get; }
142 /// Gets the support state of brightness feature.
143 /// true if supported, otherwise false.
145 /// <since_tizen> 3 </since_tizen>
146 public bool IsBrigtnessSupported { get; }
149 /// Gets the support state of exposure feature.
150 /// true if supported, otherwise false.
152 /// <since_tizen> 3 </since_tizen>
153 public bool IsExposureSupported { get; }
156 /// Gets the support state of zoom feature.
157 /// true if supported, otherwise false.
159 /// <since_tizen> 3 </since_tizen>
160 public bool IsZoomSupported { get; }
163 /// Gets the support state of pan feature.
164 /// true if supported, otherwise false.
166 /// <since_tizen> 3 </since_tizen>
167 public bool IsPanSupported { get; }
170 /// Gets the support state of tilt feature.
171 /// true if supported, otherwise false.
173 /// <since_tizen> 3 </since_tizen>
174 public bool IsTiltSupported { get; }
177 /// Retrieves all the preview resolutions supported by the camera.
179 /// <since_tizen> 3 </since_tizen>
181 /// It returns a list containing all the supported preview resolutions.
184 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
185 public IEnumerable<Size> SupportedPreviewResolutions
189 if (_previewResolutions == null)
193 _previewResolutions = new List<Size>();
195 NativeFeatures.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
197 _previewResolutions.Add(new Size(width, height));
200 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
201 "Failed to get the supported preview resolutions");
205 _previewResolutions = null;
210 return _previewResolutions;
215 /// Retrieves all the capture resolutions supported by the camera.
217 /// <since_tizen> 3 </since_tizen>
219 /// It returns a list containing all the supported capture resolutions.
221 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
222 public IEnumerable<Size> SupportedCaptureResolutions
226 if (_cameraResolutions == null)
230 _cameraResolutions = new List<Size>();
232 NativeFeatures.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
234 _cameraResolutions.Add(new Size(width, height));
237 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
238 "Failed to get the supported capture resolutions");
242 _cameraResolutions = null;
247 return _cameraResolutions;
252 /// Retrieves all the capture formats supported by the camera.
254 /// <since_tizen> 3 </since_tizen>
256 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
258 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
259 public IEnumerable<CameraPixelFormat> SupportedCapturePixelFormats
263 if (_captureFormats == null)
267 _captureFormats = new List<CameraPixelFormat>();
269 NativeFeatures.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
271 _captureFormats.Add(format);
274 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
275 "Failed to get the supported capture formats.");
279 _captureFormats = null;
284 return _captureFormats;
289 /// Retrieves all the preview formats supported by the camera.
291 /// <since_tizen> 3 </since_tizen>
293 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
295 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
296 public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
300 if (_previewFormats == null)
304 _previewFormats = new List<CameraPixelFormat>();
306 NativeFeatures.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
308 _previewFormats.Add(format);
311 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
312 "Failed to get the supported preview formats.");
316 _previewFormats = null;
321 return _previewFormats;
326 /// Retrieves all the fps supported by the camera.
328 /// <since_tizen> 3 </since_tizen>
330 /// It returns a list containing all the supported <see cref="CameraFps"/>.
332 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
333 public IEnumerable<CameraFps> SupportedPreviewFps
341 _fps = new List<CameraFps>();
343 NativeFeatures.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
348 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
349 "Failed to get the supported camera fps");
363 /// Retrieves all the fps by resolution supported by the camera.
365 /// <since_tizen> 3 </since_tizen>
367 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
369 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
370 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
372 if (_fpsByResolution == null)
376 _fpsByResolution = new List<CameraFps>();
378 NativeFeatures.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
380 _fpsByResolution.Add(fps);
383 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedPreviewFpsByResolution(_camera.GetHandle(),
384 width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");
388 _fpsByResolution = null;
393 return _fpsByResolution;
397 /// Retrieves all the fps by resolution supported by the camera.
399 /// <since_tizen> 3 </since_tizen>
401 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
403 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
404 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
406 return GetSupportedPreviewFpsByResolution(size.Width, size.Height);
410 /// Retrieves all the auto focus modes supported by the camera.
412 /// <since_tizen> 3 </since_tizen>
414 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
416 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
417 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
421 if (_autoFocusModes == null)
425 _autoFocusModes = new List<CameraAutoFocusMode>();
427 NativeFeatures.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
429 _autoFocusModes.Add(mode);
432 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedAfModes(_camera.GetHandle(), callback, IntPtr.Zero),
433 "Failed to get the supported Auto focus modes.");
437 _autoFocusModes = null;
442 return _autoFocusModes;
447 /// Retrieves all the exposure modes supported by the camera.
449 /// <since_tizen> 3 </since_tizen>
451 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
453 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
454 public IEnumerable<CameraExposureMode> SupportedExposureModes
458 if (_exposureModes == null)
462 _exposureModes = new List<CameraExposureMode>();
464 NativeFeatures.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
466 _exposureModes.Add(mode);
469 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero),
470 "Failed to get the supported Exposure modes.");
474 _exposureModes = null;
479 return _exposureModes;
484 /// Retrieves all the Iso level supported by the camera.
486 /// <since_tizen> 3 </since_tizen>
488 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
490 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
491 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
495 if (_isoLevels == null)
499 _isoLevels = new List<CameraIsoLevel>();
501 NativeFeatures.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
506 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
507 "Failed to get the supported Iso levels.");
521 /// Retrieves all the theater modes supported by the camera.
523 /// <since_tizen> 3 </since_tizen>
525 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
527 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
528 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
532 if (_theaterModes == null)
536 _theaterModes = new List<CameraTheaterMode>();
538 NativeFeatures.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
540 _theaterModes.Add(theaterMode);
543 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero),
544 "Failed to get the supported theater modes.");
548 _theaterModes = null;
553 return _theaterModes;
558 /// Retrieves all the whitebalance modes supported by the camera.
560 /// <since_tizen> 3 </since_tizen>
562 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
564 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
565 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
569 if (_whitebalances == null)
573 _whitebalances = new List<CameraWhiteBalance>();
575 NativeFeatures.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
577 _whitebalances.Add(whiteBalance);
580 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
581 "Failed to get the supported white balance.");
585 _whitebalances = null;
590 return _whitebalances;
595 /// Retrieves all the flash modes supported by the camera.
597 /// <since_tizen> 3 </since_tizen>
599 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
601 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
602 public IEnumerable<CameraFlashMode> SupportedFlashModes
606 if (_flashModes == null)
610 _flashModes = new List<CameraFlashMode>();
612 NativeFeatures.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
614 _flashModes.Add(flashMode);
617 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero),
618 "Failed to get the supported flash modes.");
632 /// Retrieves all the scene modes supported by the camera.
634 /// <since_tizen> 3 </since_tizen>
636 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
638 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
639 public IEnumerable<CameraSceneMode> SupportedSceneModes
643 if (_sceneModes == null)
647 _sceneModes = new List<CameraSceneMode>();
649 NativeFeatures.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
651 _sceneModes.Add(sceneMode);
654 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
655 "Failed to get the supported scene modes.");
669 /// Retrieves all the effect modes supported by the camera.
671 /// <since_tizen> 3 </since_tizen>
673 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
675 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
676 public IEnumerable<CameraEffectMode> SupportedEffects
680 if (_effectModes == null)
684 _effectModes = new List<CameraEffectMode>();
686 NativeFeatures.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
688 _effectModes.Add(effect);
691 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
692 "Failed to get the supported camera effects.");
706 /// Retrieves all the stream rotation supported by the camera.
708 /// <since_tizen> 3 </since_tizen>
710 /// It returns a list containing all the supported <see cref="CameraRotation"/>.
712 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
713 public IEnumerable<CameraRotation> SupportedStreamRotations
717 if (_streamRotations == null)
721 _streamRotations = new List<CameraRotation>();
723 NativeFeatures.StreamRotationCallback callback = (CameraRotation streamRotation, IntPtr userData) =>
725 _streamRotations.Add(streamRotation);
728 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
729 "Failed to get the supported camera rotations.");
733 _streamRotations = null;
738 return _streamRotations;
743 /// Retrieves all the flips supported by the camera.
745 /// <since_tizen> 3 </since_tizen>
747 /// It returns a list containing all the supported <see cref="CameraFlip"/>.
749 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
750 public IEnumerable<CameraFlip> SupportedStreamFlips
754 if (_streamFlips == null)
758 _streamFlips = new List<CameraFlip>();
760 NativeFeatures.StreamFlipCallback callback = (CameraFlip streamFlip, IntPtr userData) =>
762 _streamFlips.Add(streamFlip);
765 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
766 "Failed to get the supported camera flips.");
780 /// Retrieves all the ptz types by the camera.
782 /// <since_tizen> 3 </since_tizen>
784 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
786 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
787 public IEnumerable<CameraPtzType> SupportedPtzTypes
791 if (_ptzTypes.Count == 0)
795 _ptzTypes = new List<CameraPtzType>();
797 NativeFeatures.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
799 _ptzTypes.Add(ptzType);
802 CameraErrorFactory.ThrowIfError(NativeFeatures.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
803 "Failed to get the supported Ptz types.");