/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using NativeCapabilities = Interop.CameraCapabilities;
using NativeSettings = Interop.CameraSettings;
namespace Tizen.Multimedia
{
///
/// The CameraCapabilities class provides properties
/// to get various capability information of the camera device.
///
/// 4
public class CameraCapabilities
{
internal readonly Camera _camera;
private IList _previewResolutions;
private IList _cameraResolutions;
private IList _captureFormats;
private IList _previewFormats;
private IList _fps;
private IList _autoFocusModes;
private IList _exposureModes;
private IList _isoLevels;
private IList _theaterModes;
private IList _whitebalances;
private IList _flashModes;
private IList _sceneModes;
private IList _effectModes;
private IList _streamRotations;
private IList _streamFlips;
private IList _ptzTypes;
private delegate CameraError GetRangeDelegate(IntPtr handle, out int min, out int max);
private delegate bool IsSupportedDelegate(IntPtr handle);
internal CameraCapabilities(Camera camera)
{
_camera = camera;
IsFaceDetectionSupported = IsFeatureSupported(NativeCapabilities.IsFaceDetectionSupported);
IsMediaPacketPreviewCallbackSupported = IsFeatureSupported(NativeCapabilities.IsMediaPacketPreviewCallbackSupported);
IsZeroShutterLagSupported = IsFeatureSupported(NativeCapabilities.IsZeroShutterLagSupported);
IsContinuousCaptureSupported = IsFeatureSupported(NativeCapabilities.IsContinuousCaptureSupported);
IsHdrCaptureSupported = IsFeatureSupported(NativeCapabilities.IsHdrCaptureSupported);
IsAntiShakeSupported = IsFeatureSupported(NativeCapabilities.IsAntiShakeSupported);
IsVideoStabilizationSupported = IsFeatureSupported(NativeCapabilities.IsVideoStabilizationSupported);
IsAutoContrastSupported = IsFeatureSupported(NativeCapabilities.IsAutoContrastSupported);
IsBrigtnessSupported = CheckRangeValid(NativeSettings.GetBrightnessRange);
IsExposureSupported = CheckRangeValid(NativeSettings.GetExposureRange);
IsZoomSupported = CheckRangeValid(NativeSettings.GetZoomRange);
IsPanSupported = CheckRangeValid(NativeSettings.GetPanRange);
IsTiltSupported = CheckRangeValid(NativeSettings.GetTiltRange);
IsHueSupported = CheckRangeValid(NativeSettings.GetHueRange);
}
private bool IsFeatureSupported(IsSupportedDelegate func)
{
return func(_camera.GetHandle());
}
private bool CheckRangeValid(GetRangeDelegate func)
{
func(_camera.GetHandle(), out int min, out int max).
ThrowIfFailed("Failed to check feature is suported or not.");
return min < max;
}
///
/// Gets the face detection feature's supported state.
///
/// true if supported, otherwise false.
/// 4
public bool IsFaceDetectionSupported { get; }
///
/// Gets the media packet preview callback feature's supported state.
///
/// true if supported, otherwise false.
/// 4
public bool IsMediaPacketPreviewCallbackSupported { get; }
///
/// Gets the zero shutter lag feature's supported state.
///
/// true if supported, otherwise false.
/// 4
public bool IsZeroShutterLagSupported { get; }
///
/// Gets the continuous capture feature's supported state.
///
/// true if supported, otherwise false.
/// 4
public bool IsContinuousCaptureSupported { get; }
///
/// Gets the support state of the HDR capture.
///
/// true if supported, otherwise false.
/// 4
public bool IsHdrCaptureSupported { get; }
///
/// Gets the support state of the anti-shake feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsAntiShakeSupported { get; }
///
/// Gets the support state of the video stabilization feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsVideoStabilizationSupported { get; }
///
/// Gets the support state of auto contrast feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsAutoContrastSupported { get; }
///
/// Gets the support state of the brightness feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsBrigtnessSupported { get; }
///
/// Gets the support state of the exposure feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsExposureSupported { get; }
///
/// Gets the support state of the zoom feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsZoomSupported { get; }
///
/// Gets the support state of the pan feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsPanSupported { get; }
///
/// Gets the support state of the tilt feature.
///
/// true if supported, otherwise false.
/// 4
public bool IsTiltSupported { get; }
///
/// Gets the support state of the hue feature.
///
/// true if supported, otherwise false.
/// 5
public bool IsHueSupported { get; }
///
/// Retrieves all the preview resolutions supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported preview resolutions.
///
/// The camera already has been disposed of.
public IEnumerable SupportedPreviewResolutions
{
get
{
if (_previewResolutions == null)
{
_previewResolutions = GetSupportedPreviewResolutions();
}
return _previewResolutions;
}
}
///
/// Retrieves all the capture resolutions supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported capture resolutions.
///
/// The camera already has been disposed of.
public IEnumerable SupportedCaptureResolutions
{
get
{
if (_cameraResolutions == null)
{
_cameraResolutions = GetSupportedCaptureResolutions();
}
return _cameraResolutions;
}
}
///
/// Retrieves all the capture formats supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedCapturePixelFormats
{
get
{
if (_captureFormats == null)
{
_captureFormats = GetSupportedCapturePixelFormats();
}
return _captureFormats;
}
}
///
/// Retrieves all the preview formats supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedPreviewPixelFormats
{
get
{
if (_previewFormats == null)
{
_previewFormats = GetSupportedPreviewPixelFormats();
}
return _previewFormats;
}
}
///
/// Retrieves all the fps supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedPreviewFps
{
get
{
if (_fps == null)
{
_fps = GetSupportedPreviewFps();
}
return _fps;
}
}
///
/// Retrieves all the fps by resolution supported by the camera.
///
/// The width of required preview resolution.
/// The height of required preview resolution.
///
/// It returns a list containing all the supported by resolution.
///
/// 4
/// http://tizen.org/feature/camera
/// The camera already has been disposed of.
public IEnumerable GetSupportedPreviewFpsByResolution(int width, int height)
{
return GetSupportedPreviewFpsByResolutions(width, height);
}
///
/// Retrieves all the fps by resolution supported by the camera.
///
/// The size of required preview resolution.
///
/// It returns a list containing all the supported by resolution.
///
/// 4
/// http://tizen.org/feature/camera
/// The camera already has been disposed of.
public IEnumerable GetSupportedPreviewFpsByResolution(Size size)
{
return GetSupportedPreviewFpsByResolutions(size.Width, size.Height);
}
///
/// Retrieves all the auto focus modes supported by the camera.
///
///
/// It returns a list containing all the supported .
///
/// 4
/// The camera already has been disposed of.
public IEnumerable SupportedAutoFocusModes
{
get
{
if (_autoFocusModes == null)
{
_autoFocusModes = GetSupportedAutoFocusModes();
}
return _autoFocusModes;
}
}
///
/// Retrieves all the exposure modes supported by the camera.
///
///
/// It returns a list containing all the supported .
///
/// 4
/// The camera already has been disposed of.
public IEnumerable SupportedExposureModes
{
get
{
if (_exposureModes == null)
{
_exposureModes = GetSupportedExposureModes();
}
return _exposureModes;
}
}
///
/// Retrieves all the ISO levels supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedIsoLevels
{
get
{
if (_isoLevels == null)
{
_isoLevels = GetSupportedIsoLevels();
}
return _isoLevels;
}
}
///
/// Retrieves all the theater modes supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedTheaterModes
{
get
{
if (_theaterModes == null)
{
_theaterModes = GetSupportedTheaterModes();
}
return _theaterModes;
}
}
///
/// Retrieves all the white balance modes supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedWhiteBalances
{
get
{
if (_whitebalances == null)
{
_whitebalances = GetSupportedWhitebalances();
}
return _whitebalances;
}
}
///
/// Retrieves all the flash modes supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedFlashModes
{
get
{
if (_flashModes == null)
{
_flashModes = GetSupportedFlashModes();
}
return _flashModes;
}
}
///
/// Retrieves all the scene modes supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedSceneModes
{
get
{
if (_sceneModes == null)
{
_sceneModes = GetSupportedSceneModes();
}
return _sceneModes;
}
}
///
/// Retrieves all the effect modes supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedEffects
{
get
{
if (_effectModes == null)
{
_effectModes = GetSupportedEffects();
}
return _effectModes;
}
}
///
/// Retrieves all the stream rotations supported by the camera.
///
/// 4
///
/// An IEnumerable containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedStreamRotations
{
get
{
if (_streamRotations == null)
{
_streamRotations = GetSupportedStreamRotations();
}
return _streamRotations;
}
}
///
/// Retrieves all the flips supported by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedStreamFlips
{
get
{
if (_streamFlips == null)
{
_streamFlips = GetSupportedStreamFlips();
}
return _streamFlips;
}
}
///
/// Retrieves all the PTZ types by the camera.
///
/// 4
///
/// It returns a list containing all the supported .
///
/// The camera already has been disposed of.
public IEnumerable SupportedPtzTypes
{
get
{
if (_ptzTypes.Count == 0)
{
_ptzTypes = GetSupportedPtzTypes();
}
return _ptzTypes;
}
}
#region Methods for getting supported values
private IList GetSupportedPreviewResolutions()
{
List previewResolutions = new List();
NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
{
previewResolutions.Add(new Size(width, height));
return true;
};
NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported preview resolutions");
return previewResolutions.AsReadOnly();
}
private IList GetSupportedCaptureResolutions()
{
List cameraResolutions = new List();
NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
{
cameraResolutions.Add(new Size(width, height));
return true;
};
NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported capture resolutions");
return cameraResolutions.AsReadOnly();
}
private IList GetSupportedCapturePixelFormats()
{
List captureFormats = new List();
NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
{
captureFormats.Add(format);
return true;
};
NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported capture formats.");
return captureFormats.AsReadOnly();
}
private IList GetSupportedPreviewPixelFormats()
{
List previewFormats = new List();
NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
{
previewFormats.Add(format);
return true;
};
NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported preview formats.");
return previewFormats.AsReadOnly();
}
private IList GetSupportedPreviewFps()
{
List previewFps = new List();
NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
{
previewFps.Add(fps);
return true;
};
NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported camera fps");
return previewFps.AsReadOnly();
}
private IList GetSupportedPreviewFpsByResolutions(int width, int height)
{
List fpsByResolution = new List();
NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
{
fpsByResolution.Add(fps);
return true;
};
NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported fps by resolutions.");
return fpsByResolution.AsReadOnly();
}
private IList GetSupportedAutoFocusModes()
{
List autoFocusModes = new List();
NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
{
autoFocusModes.Add(mode);
return true;
};
NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported Auto focus modes.");
return autoFocusModes.AsReadOnly();
}
private IList GetSupportedExposureModes()
{
List exposureModes = new List();
NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
{
exposureModes.Add(mode);
return true;
};
NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported Exposure modes.");
return exposureModes.AsReadOnly();
}
private IList GetSupportedIsoLevels()
{
List isoLevels = new List();
NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
{
isoLevels.Add(iso);
return true;
};
NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported Iso levels.");
return isoLevels.AsReadOnly();
}
private IList GetSupportedTheaterModes()
{
List theaterModes = new List();
NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
{
theaterModes.Add(theaterMode);
return true;
};
NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported theater modes.");
return theaterModes.AsReadOnly();
}
private IList GetSupportedWhitebalances()
{
List whitebalances = new List();
NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
{
whitebalances.Add(whiteBalance);
return true;
};
NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported white balance.");
return whitebalances.AsReadOnly();
}
private IList GetSupportedFlashModes()
{
List flashModes = new List();
NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
{
flashModes.Add(flashMode);
return true;
};
NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported flash modes.");
return flashModes.AsReadOnly();
}
private IList GetSupportedSceneModes()
{
List sceneModes = new List();
NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
{
sceneModes.Add(sceneMode);
return true;
};
NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported scene modes.");
return sceneModes.AsReadOnly();
}
private IList GetSupportedEffects()
{
List effectModes = new List();
NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
{
effectModes.Add(effect);
return true;
};
NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported camera effects.");
return effectModes.AsReadOnly();
}
private IList GetSupportedStreamRotations()
{
List streamRotations = new List();
NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
{
streamRotations.Add(streamRotation);
return true;
};
NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported camera rotations.");
return streamRotations.AsReadOnly();
}
private IList GetSupportedStreamFlips()
{
List streamFlips = new List();
NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
{
streamFlips.Add(streamFlip);
return true;
};
NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported camera flips.");
return streamFlips.AsReadOnly();
}
private IList GetSupportedPtzTypes()
{
List ptzTypes = new List();
NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
{
ptzTypes.Add(ptzType);
return true;
};
NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero).
ThrowIfFailed("Failed to get the supported Ptz types.");
return ptzTypes.AsReadOnly();
}
#endregion Methods for getting supported values
}
}