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;
20 using System.Xml.Schema;
22 namespace Tizen.Multimedia
25 /// The CameraFeature class provides properties
26 /// to get various capability information of the camera device.
28 public class CameraFeature
30 internal readonly IntPtr _cameraHandle;
31 private readonly List<CameraResolution> _previewResolution;
32 private readonly List<CameraResolution> _cameraResolution;
33 private readonly List<CameraPixelFormat> _captureFormat;
34 private readonly List<CameraPixelFormat> _previewFormat;
35 private readonly List<CameraFps> _fps;
36 private readonly List<CameraFps> _fpsResolution;
37 private readonly List<CameraAutoFocusMode> _afMode;
38 private readonly List<CameraExposureMode> _exposureMode;
39 private readonly List<CameraTheaterMode> _theater;
40 private readonly List<CameraWhitebalance> _whitebalance;
41 private readonly List<CameraIsoLevel> _iso;
42 private readonly List<CameraEffectMode> _effect;
43 private readonly List<CameraSceneMode> _sceneMode;
44 private readonly List<CameraFlashMode> _flashMode;
45 private readonly List<CameraRotation> _streamRotation;
46 private readonly List<CameraFlip> _streamFlip;
47 private readonly List<CameraPtzType> _ptzType;
49 internal CameraFeature(IntPtr _handle)
51 _cameraHandle = _handle;
52 _previewResolution = new List<CameraResolution>();
53 _cameraResolution = new List<CameraResolution>();
54 _captureFormat = new List<CameraPixelFormat>();
55 _previewFormat = new List<CameraPixelFormat>();
56 _fps = new List<CameraFps>();
57 _fpsResolution = new List<CameraFps>();
58 _afMode = new List<CameraAutoFocusMode>();
59 _exposureMode = new List<CameraExposureMode>();
60 _theater = new List<CameraTheaterMode>();
61 _whitebalance = new List<CameraWhitebalance>();
62 _iso = new List<CameraIsoLevel>();
63 _effect = new List<CameraEffectMode>();
64 _sceneMode = new List<CameraSceneMode>();
65 _flashMode = new List<CameraFlashMode>();
66 _streamRotation = new List<CameraRotation>();
67 _streamFlip = new List<CameraFlip>();
68 _ptzType = new List<CameraPtzType>();
72 /// Gets continuous capture feature's supported state.
73 /// true if supported, otherwise false.
75 public bool ContinuousCaptureSupport
81 val = Interop.CameraFeature.ContinuousCaptureSupport(_cameraHandle);
82 int ret = ErrorFacts.GetLastResult();
83 if ((CameraError)ret != CameraError.None)
85 CameraError err = (CameraError)ret;
86 Log.Error(CameraLog.Tag, "Failed to get continuous feature support, " + err.ToString());
94 /// Gets the face detection feature's supported state.
95 /// true if supported, otherwise false.
97 public bool FaceDetectionSupport
103 val = Interop.CameraFeature.FaceDetectionSupport(_cameraHandle);
104 int ret = ErrorFacts.GetLastResult();
105 if ((CameraError)ret != CameraError.None)
107 CameraError err = (CameraError)ret;
108 Log.Error(CameraLog.Tag, "Failed to get face detection support, " + err.ToString());
116 /// Gets the zero shutter lag feature's supported state.
117 /// true if supported, otherwise false.
119 public bool ZeroShutterLagSupport
125 val = Interop.CameraFeature.ZeroShutterLagSupport(_cameraHandle);
126 int ret = ErrorFacts.GetLastResult();
127 if ((CameraError)ret != CameraError.None)
129 CameraError err = (CameraError)ret;
130 Log.Error(CameraLog.Tag, "Failed to get zero shutter lag support, " + err.ToString());
138 /// Gets the media packet preview callback feature's supported state.
139 /// true if supported, otherwise false.
141 public bool MediaPacketPreviewCallbackSupport
147 val = Interop.CameraFeature.MediaPacketPreviewCallbackSupport(_cameraHandle);
148 int ret = ErrorFacts.GetLastResult();
149 if ((CameraError)ret != CameraError.None)
151 CameraError err = (CameraError)ret;
152 Log.Error(CameraLog.Tag, "Failed to get media packet preview callback support, " + err.ToString());
160 /// Gets the support state of HDR capture.
161 /// true if supported, otherwise false.
163 public bool HdrCaptureSupport
169 val = Interop.CameraFeature.HdrCaptureSupport(_cameraHandle);
170 int ret = ErrorFacts.GetLastResult();
171 if ((CameraError)ret != CameraError.None)
173 CameraError err = (CameraError)ret;
174 Log.Error(CameraLog.Tag, "Failed to get hdr capture feature support, " + err.ToString());
182 /// Gets the support state of the anti-shake feature.
183 /// true if supported, otherwise false.
185 public bool AntiShakeSupport
191 val = Interop.CameraFeature.AntiShakeSupport(_cameraHandle);
192 int ret = ErrorFacts.GetLastResult();
193 if ((CameraError)ret != CameraError.None)
195 CameraError err = (CameraError)ret;
196 Log.Error(CameraLog.Tag, "Failed to get anti shake feature support, " + err.ToString());
204 /// Gets the support state of the video stabilization feature.
205 /// true if supported, otherwise false.
207 public bool VideoStabilizationSupport
213 val = Interop.CameraFeature.VideoStabilizationSupport(_cameraHandle);
214 int ret = ErrorFacts.GetLastResult();
215 if ((CameraError)ret != CameraError.None)
217 CameraError err = (CameraError)ret;
218 Log.Error(CameraLog.Tag, "Failed to get video stabilization feature support, " + err.ToString());
226 /// Gets state of support of auto contrast feature.
227 /// true if supported, otherwise false.
229 public bool AutoContrastSupport
235 val = Interop.CameraFeature.AutoContrastSupport(_cameraHandle);
236 int ret = ErrorFacts.GetLastResult();
237 if ((CameraError)ret != CameraError.None)
239 CameraError err = (CameraError)ret;
240 Log.Error(CameraLog.Tag, "Failed to get auto contrast feature support, " + err.ToString());
248 /// Retrieves all the preview resolutions supported by the camera.
251 /// It returns a list containing all the supported preview resolutions.
254 public IEnumerable<CameraResolution> PreviewResolutions
258 if (_previewResolution.Count == 0)
260 Interop.CameraFeature.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
262 CameraResolution temp = new CameraResolution(width, height);
263 _previewResolution.Add(temp);
267 int ret = Interop.CameraFeature.SupportedPreviewResolutions(_cameraHandle, callback, IntPtr.Zero);
268 if (ret != (int)CameraError.None)
270 CameraErrorFactory.ThrowException(ret, "Failed to get the supported preview resolutions");
274 return _previewResolution;
279 /// Retrieves all the capture resolutions supported by the camera.
282 /// It returns a list containing all the supported capture resolutions.
284 public IEnumerable<CameraResolution> CaptureResolutions
288 if (_cameraResolution.Count == 0)
290 Interop.CameraFeature.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
292 CameraResolution temp = new CameraResolution(width, height);
293 _cameraResolution.Add(temp);
297 int ret = Interop.CameraFeature.SupportedCaptureResolutions(_cameraHandle, callback, IntPtr.Zero);
298 if (ret != (int)CameraError.None)
300 CameraErrorFactory.ThrowException(ret, "Failed to get the supported capture resolutions");
304 return _cameraResolution;
309 /// Retrieves all the capture formats supported by the camera.
312 /// It returns a list containing all the supported capture formats.
314 public IEnumerable<CameraPixelFormat> CaptureFormats
318 if (_captureFormat.Count == 0)
320 Interop.CameraFeature.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
322 _captureFormat.Add(format);
326 int ret = Interop.CameraFeature.SupportedCaptureFormats(_cameraHandle, callback, IntPtr.Zero);
327 if (ret != (int)CameraError.None)
329 CameraErrorFactory.ThrowException(ret, "Failed to get the supported capture formats.");
333 return _captureFormat;
338 /// Retrieves all the preview formats supported by the camera.
341 /// It returns a list containing all the supported preview formats.
343 public IEnumerable<CameraPixelFormat> PreviewFormats
347 if (_previewFormat.Count == 0)
349 Interop.CameraFeature.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
351 _previewFormat.Add(format);
355 int ret = Interop.CameraFeature.SupportedPreviewFormats(_cameraHandle, callback, IntPtr.Zero);
356 if (ret != (int)CameraError.None)
358 CameraErrorFactory.ThrowException(ret, "Failed to get the supported preview formats.");
362 return _previewFormat;
367 /// Retrieves all the fps supported by the camera.
370 /// It returns a list containing all the supported fps.
372 public IEnumerable<CameraFps> Fps
378 Interop.CameraFeature.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
384 int ret = Interop.CameraFeature.SupportedFps(_cameraHandle, callback, IntPtr.Zero);
385 if (ret != (int)CameraError.None)
387 CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera fps");
395 private bool resolutionCallback(CameraFps fps, IntPtr userData)
397 _fpsResolution.Add(fps);
402 /// Retrieves all the fps by resolution supported by the camera.
405 /// It returns a list containing all the supported fps by resolution.
407 public IEnumerable<CameraFps> FpsByResolution(int width, int height)
409 if (_fpsResolution.Count == 0)
411 int ret = Interop.CameraFeature.SupportedFpsByResolution(_cameraHandle, width, height, resolutionCallback, IntPtr.Zero);
412 if (ret != (int)CameraError.None)
414 CameraErrorFactory.ThrowException(ret, "Failed to get the supported fps by resolutions.");
418 return _fpsResolution;
422 /// Retrieves all the fps by resolution supported by the camera.
425 /// It returns a list containing all the supported fps by resolution.
427 public IEnumerable<CameraAutoFocusMode> AfMode
431 if (_afMode.Count == 0)
433 Interop.CameraFeature.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
439 int ret = Interop.CameraFeature.SupportedAfModes(_cameraHandle, callback, IntPtr.Zero);
440 if (ret != (int)CameraError.None)
442 CameraErrorFactory.ThrowException(ret, "Failed to get the supported Auto focus modes.");
451 /// Retrieves all the exposure modes supported by the camera.
454 /// It returns a list containing all the supported camera exposure modes.
456 public IEnumerable<CameraExposureMode> ExposureModes
460 if (_exposureMode.Count == 0)
462 Interop.CameraFeature.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
464 _exposureMode.Add(mode);
468 int ret = Interop.CameraFeature.SupportedExposureModes(_cameraHandle, callback, IntPtr.Zero);
469 if (ret != (int)CameraError.None)
471 CameraErrorFactory.ThrowException(ret, "Failed to get the supported Exposure modes.");
475 return _exposureMode;
480 /// Retrieves all the Iso level supported by the camera.
483 /// It returns a list containing all the supported camera Iso levels.
485 public IEnumerable<CameraIsoLevel> IsoLevel
491 Interop.CameraFeature.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
497 int ret = Interop.CameraFeature.SupportedIso(_cameraHandle, callback, IntPtr.Zero);
498 if (ret != (int)CameraError.None)
500 CameraErrorFactory.ThrowException(ret, "Failed to get the supported Iso levels.");
509 /// Retrieves all the theater modes supported by the camera.
512 /// It returns a list containing all the supported camera theater modes.
514 public IEnumerable<CameraTheaterMode> TheaterMode
518 if (_theater.Count == 0)
520 Interop.CameraFeature.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
522 _theater.Add(theaterMode);
526 int ret = Interop.CameraFeature.SupportedTheaterModes(_cameraHandle, callback, IntPtr.Zero);
527 if (ret != (int)CameraError.None)
529 CameraErrorFactory.ThrowException(ret, "Failed to get the supported theater modes.");
538 /// Retrieves all the whitebalance mode supported by the camera.
541 /// It returns a list containing all the supported camera white balance modes.
543 public IEnumerable<CameraWhitebalance> Whitebalance
547 if (_whitebalance.Count == 0)
549 Interop.CameraFeature.WhitebalanceCallback callback = (CameraWhitebalance whitebalance, IntPtr userData) =>
551 _whitebalance.Add(whitebalance);
554 int ret = Interop.CameraFeature.SupportedWhitebalance(_cameraHandle, callback, IntPtr.Zero);
555 if (ret != (int)CameraError.None)
557 CameraErrorFactory.ThrowException(ret, "Failed to get the supported white balance.");
561 return _whitebalance;
566 /// Retrieves all the flash modes supported by the camera.
569 /// It returns a list containing all the supported camera flash modes.
571 public IEnumerable<CameraFlashMode> FlashMode
575 if (_flashMode.Count == 0)
577 Interop.CameraFeature.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
579 _flashMode.Add(flashMode);
582 int ret = Interop.CameraFeature.SupportedFlashModes(_cameraHandle, callback, IntPtr.Zero);
583 if (ret != (int)CameraError.None)
585 CameraErrorFactory.ThrowException(ret, "Failed to get the supported flash modes.");
594 /// Retrieves all the scene modes supported by the camera.
597 /// It returns a list containing all the supported camera scene modes.
599 public IEnumerable<CameraSceneMode> SceneMode
603 if (_sceneMode.Count == 0)
605 Interop.CameraFeature.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
607 _sceneMode.Add(sceneMode);
610 int ret = Interop.CameraFeature.SupportedSceneModes(_cameraHandle, callback, IntPtr.Zero);
611 if (ret != (int)CameraError.None)
613 CameraErrorFactory.ThrowException(ret, "Failed to get the supported scene modes.");
622 /// Retrieves all the effects supported by the camera.
625 /// It returns a list containing all the supported camera effects.
627 public IEnumerable<CameraEffectMode> Effect
631 if (_effect.Count == 0)
633 Interop.CameraFeature.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
638 int ret = Interop.CameraFeature.SupportedEffects(_cameraHandle, callback, IntPtr.Zero);
639 if (ret != (int)CameraError.None)
641 CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera effects.");
650 /// Retrieves all the stream rotation supported by the camera.
653 /// It returns a list containing all the supported camera stream rotations.
655 public IEnumerable<CameraRotation> StreamRotation
659 if (_streamRotation.Count == 0)
661 Interop.CameraFeature.StreamRotationCallback callback = (CameraRotation streamRotation, IntPtr userData) =>
663 _streamRotation.Add(streamRotation);
666 int ret = Interop.CameraFeature.SupportedStreamRotations(_cameraHandle, callback, IntPtr.Zero);
667 if (ret != (int)CameraError.None)
669 CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera rotations.");
673 return _streamRotation;
678 /// Retrieves all the flips supported by the camera.
681 /// It returns a list containing all the supported camera flip.
683 public IEnumerable<CameraFlip> StreamFlip
687 if (_streamFlip.Count == 0)
689 Interop.CameraFeature.StreamFlipCallback callback = (CameraFlip streamFlip, IntPtr userData) =>
691 _streamFlip.Add(streamFlip);
694 int ret = Interop.CameraFeature.SupportedStreamFlips(_cameraHandle, callback, IntPtr.Zero);
695 if (ret != (int)CameraError.None)
697 CameraErrorFactory.ThrowException(ret, "Failed to get the supported camera flips.");
706 /// Retrieves all the ptz types by the camera.
709 /// It returns a list containing all the supported ptz types.
711 public IEnumerable<CameraPtzType> PtzType
715 if (_ptzType.Count == 0)
717 Interop.CameraFeature.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
719 _ptzType.Add(ptzType);
722 int ret = Interop.CameraFeature.SupportedPtzTypes(_cameraHandle, callback, IntPtr.Zero);
723 if (ret != (int)CameraError.None)
725 CameraErrorFactory.ThrowException(ret, "Failed to get the supported Ptz types.");