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 Tizen.Internals.Errors;
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(Interop.CameraFeatures.IsFaceDetectionSupported);
58 IsMediaPacketPreviewCallbackSupported = IsFeatureSupported(Interop.CameraFeatures.IsMediaPacketPreviewCallbackSupported);
59 IsZeroShutterLagSupported = IsFeatureSupported(Interop.CameraFeatures.IsZeroShutterLagSupported);
60 IsContinuousCaptureSupported = IsFeatureSupported(Interop.CameraFeatures.IsContinuousCaptureSupported);
61 IsHdrCaptureSupported = IsFeatureSupported(Interop.CameraFeatures.IsHdrCaptureSupported);
62 IsAntiShakeSupported = IsFeatureSupported(Interop.CameraFeatures.IsAntiShakeSupported);
63 IsVideoStabilizationSupported = IsFeatureSupported(Interop.CameraFeatures.IsVideoStabilizationSupported);
64 IsAutoContrastSupported = IsFeatureSupported(Interop.CameraFeatures.IsAutoContrastSupported);
65 IsBrigtnessSupported = CheckRangeValid(Interop.CameraSettings.GetBrightnessRange);
66 IsExposureSupported = CheckRangeValid(Interop.CameraSettings.GetExposureRange);
67 IsZoomSupported = CheckRangeValid(Interop.CameraSettings.GetZoomRange);
68 IsPanSupported = CheckRangeValid(Interop.CameraSettings.GetPanRange);
69 IsTiltSupported = CheckRangeValid(Interop.CameraSettings.GetTiltRange);
72 private bool IsFeatureSupported(IsSupportedDelegate func)
74 return func(_camera.GetHandle());
77 private bool CheckRangeValid(GetRangeDelegate func)
82 CameraErrorFactory.ThrowIfError(func(_camera.GetHandle(), out min, out max),
83 "Failed to check feature is suported or not.");
89 /// Gets the face detection feature's supported state.
90 /// true if supported, otherwise false.
92 public bool IsFaceDetectionSupported { get; }
95 /// Gets the media packet preview callback feature's supported state.
96 /// true if supported, otherwise false.
98 public bool IsMediaPacketPreviewCallbackSupported { get; }
101 /// Gets the zero shutter lag feature's supported state.
102 /// true if supported, otherwise false.
104 public bool IsZeroShutterLagSupported { get; }
107 /// Gets continuous capture feature's supported state.
108 /// true if supported, otherwise false.
110 public bool IsContinuousCaptureSupported { get; }
113 /// Gets the support state of HDR capture.
114 /// true if supported, otherwise false.
116 public bool IsHdrCaptureSupported { get; }
119 /// Gets the support state of the anti-shake feature.
120 /// true if supported, otherwise false.
122 public bool IsAntiShakeSupported { get; }
125 /// Gets the support state of the video stabilization feature.
126 /// true if supported, otherwise false.
128 public bool IsVideoStabilizationSupported { get; }
131 /// Gets the support state of auto contrast feature.
132 /// true if supported, otherwise false.
134 public bool IsAutoContrastSupported { get; }
137 /// Gets the support state of brightness feature.
138 /// true if supported, otherwise false.
140 public bool IsBrigtnessSupported { get; }
143 /// Gets the support state of exposure feature.
144 /// true if supported, otherwise false.
146 public bool IsExposureSupported { get; }
149 /// Gets the support state of zoom feature.
150 /// true if supported, otherwise false.
152 public bool IsZoomSupported { get; }
155 /// Gets the support state of pan feature.
156 /// true if supported, otherwise false.
158 public bool IsPanSupported { get; }
161 /// Gets the support state of tilt feature.
162 /// true if supported, otherwise false.
164 public bool IsTiltSupported { get; }
167 /// Retrieves all the preview resolutions supported by the camera.
170 /// It returns a list containing all the supported preview resolutions.
173 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
174 public IEnumerable<Size> SupportedPreviewResolutions
178 if (_previewResolutions == null)
182 _previewResolutions = new List<Size>();
184 Interop.CameraFeatures.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
186 _previewResolutions.Add(new Size(width, height));
189 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
190 "Failed to get the supported preview resolutions");
194 _previewResolutions = null;
199 return _previewResolutions;
204 /// Retrieves all the capture resolutions supported by the camera.
207 /// It returns a list containing all the supported capture resolutions.
209 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
210 public IEnumerable<Size> SupportedCaptureResolutions
214 if (_cameraResolutions == null)
218 _cameraResolutions = new List<Size>();
220 Interop.CameraFeatures.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
222 _cameraResolutions.Add(new Size(width, height));
225 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
226 "Failed to get the supported capture resolutions");
230 _cameraResolutions = null;
235 return _cameraResolutions;
240 /// Retrieves all the capture formats supported by the camera.
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> SupportedCapturePixelFormats
250 if (_captureFormats == null)
254 _captureFormats = new List<CameraPixelFormat>();
256 Interop.CameraFeatures.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
258 _captureFormats.Add(format);
261 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
262 "Failed to get the supported capture formats.");
266 _captureFormats = null;
271 return _captureFormats;
276 /// Retrieves all the preview formats supported by the camera.
279 /// It returns a list containing all the supported <see cref="CameraPixelFormat"/>.
281 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
282 public IEnumerable<CameraPixelFormat> SupportedPreviewPixelFormats
286 if (_previewFormats == null)
290 _previewFormats = new List<CameraPixelFormat>();
292 Interop.CameraFeatures.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
294 _previewFormats.Add(format);
297 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
298 "Failed to get the supported preview formats.");
302 _previewFormats = null;
307 return _previewFormats;
312 /// Retrieves all the fps supported by the camera.
315 /// It returns a list containing all the supported <see cref="CameraFps"/>.
317 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
318 public IEnumerable<CameraFps> SupportedPreviewFps
326 _fps = new List<CameraFps>();
328 Interop.CameraFeatures.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
333 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
334 "Failed to get the supported camera fps");
348 /// Retrieves all the fps by resolution supported by the camera.
351 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
353 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
354 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(int width, int height)
356 if (_fpsByResolution == null)
360 _fpsByResolution = new List<CameraFps>();
362 Interop.CameraFeatures.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
364 _fpsByResolution.Add(fps);
367 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedPreviewFpsByResolution(_camera.GetHandle(),
368 width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");
372 _fpsByResolution = null;
377 return _fpsByResolution;
381 /// Retrieves all the fps by resolution supported by the camera.
384 /// It returns a list containing all the supported <see cref="CameraFps"/> by resolution.
386 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
387 public IEnumerable<CameraFps> GetSupportedPreviewFpsByResolution(Size size)
389 return GetSupportedPreviewFpsByResolution(size.Width, size.Height);
393 /// Retrieves all the auto focus modes supported by the camera.
396 /// It returns a list containing all the supported <see cref="CameraAutoFocusMode"/>.
398 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
399 public IEnumerable<CameraAutoFocusMode> SupportedAutoFocusModes
403 if (_autoFocusModes == null)
407 _autoFocusModes = new List<CameraAutoFocusMode>();
409 Interop.CameraFeatures.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
411 _autoFocusModes.Add(mode);
414 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedAfModes(_camera.GetHandle(), callback, IntPtr.Zero),
415 "Failed to get the supported Auto focus modes.");
419 _autoFocusModes = null;
424 return _autoFocusModes;
429 /// Retrieves all the exposure modes supported by the camera.
432 /// It returns a list containing all the supported <see cref="CameraExposureMode"/>.
434 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
435 public IEnumerable<CameraExposureMode> SupportedExposureModes
439 if (_exposureModes == null)
443 _exposureModes = new List<CameraExposureMode>();
445 Interop.CameraFeatures.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
447 _exposureModes.Add(mode);
450 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero),
451 "Failed to get the supported Exposure modes.");
455 _exposureModes = null;
460 return _exposureModes;
465 /// Retrieves all the Iso level supported by the camera.
468 /// It returns a list containing all the supported <see cref="CameraIsoLevel"/>.
470 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
471 public IEnumerable<CameraIsoLevel> SupportedIsoLevels
475 if (_isoLevels == null)
479 _isoLevels = new List<CameraIsoLevel>();
481 Interop.CameraFeatures.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
486 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
487 "Failed to get the supported Iso levels.");
501 /// Retrieves all the theater modes supported by the camera.
504 /// It returns a list containing all the supported <see cref="CameraTheaterMode"/>.
506 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
507 public IEnumerable<CameraTheaterMode> SupportedTheaterModes
511 if (_theaterModes == null)
515 _theaterModes = new List<CameraTheaterMode>();
517 Interop.CameraFeatures.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
519 _theaterModes.Add(theaterMode);
522 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero),
523 "Failed to get the supported theater modes.");
527 _theaterModes = null;
532 return _theaterModes;
537 /// Retrieves all the whitebalance modes supported by the camera.
540 /// It returns a list containing all the supported <see cref="CameraWhiteBalance"/>.
542 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
543 public IEnumerable<CameraWhiteBalance> SupportedWhiteBalances
547 if (_whitebalances == null)
551 _whitebalances = new List<CameraWhiteBalance>();
553 Interop.CameraFeatures.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
555 _whitebalances.Add(whiteBalance);
558 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
559 "Failed to get the supported white balance.");
563 _whitebalances = null;
568 return _whitebalances;
573 /// Retrieves all the flash modes supported by the camera.
576 /// It returns a list containing all the supported <see cref="CameraFlashMode"/>.
578 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
579 public IEnumerable<CameraFlashMode> SupportedFlashModes
583 if (_flashModes == null)
587 _flashModes = new List<CameraFlashMode>();
589 Interop.CameraFeatures.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
591 _flashModes.Add(flashMode);
594 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero),
595 "Failed to get the supported flash modes.");
609 /// Retrieves all the scene modes supported by the camera.
612 /// It returns a list containing all the supported <see cref="CameraSceneMode"/>.
614 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
615 public IEnumerable<CameraSceneMode> SupportedSceneModes
619 if (_sceneModes == null)
623 _sceneModes = new List<CameraSceneMode>();
625 Interop.CameraFeatures.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
627 _sceneModes.Add(sceneMode);
630 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
631 "Failed to get the supported scene modes.");
645 /// Retrieves all the effect modes supported by the camera.
648 /// It returns a list containing all the supported <see cref="CameraEffectMode"/>.
650 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
651 public IEnumerable<CameraEffectMode> SupportedEffects
655 if (_effectModes == null)
659 _effectModes = new List<CameraEffectMode>();
661 Interop.CameraFeatures.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
663 _effectModes.Add(effect);
666 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
667 "Failed to get the supported camera effects.");
681 /// Retrieves all the stream rotation supported by the camera.
684 /// It returns a list containing all the supported <see cref="CameraRotation"/>.
686 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
687 public IEnumerable<CameraRotation> SupportedStreamRotations
691 if (_streamRotations == null)
695 _streamRotations = new List<CameraRotation>();
697 Interop.CameraFeatures.StreamRotationCallback callback = (CameraRotation streamRotation, IntPtr userData) =>
699 _streamRotations.Add(streamRotation);
702 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
703 "Failed to get the supported camera rotations.");
707 _streamRotations = null;
712 return _streamRotations;
717 /// Retrieves all the flips supported by the camera.
720 /// It returns a list containing all the supported <see cref="CameraFlip"/>.
722 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
723 public IEnumerable<CameraFlip> SupportedStreamFlips
727 if (_streamFlips == null)
731 _streamFlips = new List<CameraFlip>();
733 Interop.CameraFeatures.StreamFlipCallback callback = (CameraFlip streamFlip, IntPtr userData) =>
735 _streamFlips.Add(streamFlip);
738 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
739 "Failed to get the supported camera flips.");
753 /// Retrieves all the ptz types by the camera.
756 /// It returns a list containing all the supported <see cref="CameraPtzType"/>.
758 /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
759 public IEnumerable<CameraPtzType> SupportedPtzTypes
763 if (_ptzTypes.Count == 0)
767 _ptzTypes = new List<CameraPtzType>();
769 Interop.CameraFeatures.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
771 _ptzTypes.Add(ptzType);
774 CameraErrorFactory.ThrowIfError(Interop.CameraFeatures.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
775 "Failed to get the supported Ptz types.");