static internal class CameraLog
{
internal const string Tag = "Tizen.Multimedia.Camera";
+ internal const string Enter = "[Enter]";
+ internal const string Leave = "[Leave]";
}
/// <summary>
/// Initializes a new instance of the <see cref="Camera"/> Class.
/// </summary>
/// <param name="device">The camera device to access</param>
+ /// <privilege>
+ /// http://tizen.org/privilege/camera
+ /// </privilege>
public Camera(CameraDevice device)
{
CameraErrorFactory.ThrowIfError(Interop.Camera.Create((int)device, out _handle),
RegisterCallbacks();
- _state = CameraState.Created;
+ SetState(CameraState.Created);
}
/// <summary>
{
if (_disposed)
{
+ Log.Error(CameraLog.Tag, "Camera handle is disposed.");
throw new ObjectDisposedException(nameof(Camera));
}
}
/// <summary>
/// Gets the state of the camera.
/// </summary>
+ /// <value> None, Created, Preview, Capturing, Captured </value>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
public CameraState State
{
get
{
+ ValidateNotDisposed();
+
CameraState val = CameraState.None;
CameraErrorFactory.ThrowIfError(Interop.Camera.GetState(_handle, out val),
"Failed to get camera state");
/// If the hint is set to true, the display will be reused when the camera device is changed with
/// ChangeDevice method.
/// </summary>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
+ /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">Invalid state.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
public bool DisplayReuseHint
{
get
{
+ ValidateNotDisposed();
+
bool val = false;
CameraErrorFactory.ThrowIfError(Interop.Camera.GetDisplayReuseHint(_handle, out val),
set
{
+ ValidateState(CameraState.Preview);
+
CameraErrorFactory.ThrowIfError(Interop.Camera.SetDisplayReuseHint(_handle, value),
"Failed to set display reuse hint.");
}
/// <summary>
/// Gets the facing direction of camera module.
/// </summary>
+ /// <value>A <see cref="CameraFacingDirection"/> that specifies the facing direction of camera device.</value>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
public CameraFacingDirection Direction
{
get
{
+ ValidateNotDisposed();
+
CameraFacingDirection val = 0;
CameraErrorFactory.ThrowIfError(Interop.Camera.GetFacingDirection(_handle, out val),
/// <summary>
/// Gets the camera device count.
/// </summary>
- /// <remarks>
- /// This returns 2, if the device supports primary and secondary cameras.
- /// Otherwise 1, if the device only supports primary camera.
- /// </remarks>
+ /// <value>This returns 2, if the device supports primary and secondary cameras.
+ /// Otherwise 1, if the device only supports primary camera.</value>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
public int CameraCount
{
get
{
+ ValidateNotDisposed();
+
int val = 0;
CameraErrorFactory.ThrowIfError(Interop.Camera.GetDeviceCount(_handle, out val),
return val;
}
}
-#endregion Properties
+ #endregion Properties
-#region Methods
+ #region Methods
/// <summary>
/// Changes the camera device.
/// </summary>
/// can be kept even though camera device is changed.
/// The camera must be in the <see cref="CameraState.Created"/> or <see cref="CameraState.Preview"/> state.
/// </remarks>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of ChangeDevice feature is not supported</exception>
+ /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of ChangeDevice feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
public void ChangeDevice(CameraDevice device)
{
ValidateState(CameraState.Created, CameraState.Preview);
/// </privilege>
/// <param name="device">The device to get state.</param>
/// <returns>Returns the state of camera device</returns>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
+ /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
public CameraDeviceState GetDeviceState(CameraDevice device)
{
int val = 0;
return (CameraDeviceState)val;
}
+ /// <summary>
+ /// Gets the flash state.
+ /// </summary>
+ /// <privilege>
+ /// http://tizen.org/privilege/camera
+ /// </privilege>
+ /// <param name="device">The device to get state.</param>
+ /// <returns>Returns the flash state of camera device</returns>
+ /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
public static CameraFlashState GetFlashState(CameraDevice device)
{
CameraFlashState val = CameraFlashState.NotUsed;
/// <summary>
/// Starts capturing and drawing preview frames on the screen.
- /// The display handle must be set using <see cref="Tizen.Multimedia.Camera.SetDisplay"/>
+ /// The display handle must be set using <see cref="CameraDisplay.SetInfo"/>
/// before using this method.
- /// If needed set fps <see cref="Tizen.Multimedia.CameraSetting.PreviewFps"/>, preview resolution
- /// <see cref="Tizen.Multimedia.Camera.PreviewResolution"/>, or preview format <see cref="Tizen.Multimedia.Camera.PreviewFormat"/>
+ /// If needed set fps <see cref="CameraSettings.PreviewFps"/>, preview resolution
+ /// <see cref="CameraSettings.PreviewResolution"/>, or preview format <see cref="CameraSettings.PreviewPixelFormat"/>
/// before using this method.
+ /// The camera must be in the <see cref="CameraState.Created"/> or <see cref="CameraState.Captured"/> state.
/// </summary>
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StartPreview()
{
ValidateState(CameraState.Created, CameraState.Captured);
/// <summary>
/// Stops capturing and drawing preview frames on the screen.
+ /// The camera must be in the <see cref="CameraState.Preview"/> state.
/// </summary>
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StopPreview()
{
+ ValidateState(CameraState.Preview);
+
CameraErrorFactory.ThrowIfError(Interop.Camera.StopPreview(_handle),
"Failed to stop the camera preview.");
/// <summary>
/// Starts capturing of still images.
- /// EventHandler must be set for capturing using <see cref="Tizen.Multimedia.Camera.Capturing"/>
- /// and for completed using <see cref="Tizen.Multimedia.Camera.CaptureCompleted"/> before
- /// calling this method.
+ /// EventHandler must be set for capturing using <see cref="Capturing"/>
+ /// and for completed using <see cref="CaptureCompleted"/> before calling this method.
+ /// The camera must be in the <see cref="CameraState.Preview"/> state.
/// </summary>
/// <privilege>
/// http://tizen.org/privilege/camera
/// <remarks>
/// This function causes the transition of the camera state from Capturing to Captured
/// automatically and the corresponding EventHandlers will be invoked.
- /// The camera's preview should be restarted by calling <see cref="Tizen.Multimedia.Camera.StartPreview"/>
- /// method.
+ /// The preview should be restarted by calling <see cref="StartPreview"/> method after capture is completed.
/// </remarks>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StartCapture()
{
ValidateState(CameraState.Preview);
/// <summary>
/// Starts continuously capturing still images.
- /// EventHandler must be set for capturing using <see cref="Tizen.Multimedia.Camera.Capturing"/>
- /// and for completed using <see cref="Tizen.Multimedia.Camera.CaptureCompleted"/> before
- /// calling this method.
+ /// EventHandler must be set for capturing using <see cref="Capturing"/>
+ /// and for completed using <see cref="CaptureCompleted"/> before calling this method.
+ /// The camera must be in the <see cref="CameraState.Preview"/> state.
/// </summary>
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
/// <param name="count">The number of still images.</param>
/// <param name="interval">The interval of the capture(milliseconds).</param>
+ /// <param name="cancellationToken">The cancellation token to cancel capturing.</param>
+ /// <seealso cref="System.Threading.CancellationToken"/>
/// <remarks>
/// If this is not supported zero shutter lag occurs. The capture resolution could be
/// changed to the preview resolution. This function causes the transition of the camera state
/// from Capturing to Captured automatically and the corresponding Eventhandlers will be invoked.
- /// Each captured image will be delivered through Eventhandler set using <see cref="Tizen.Multimedia.Camera.Capturing"/> event.
- /// The camera's preview should be restarted by calling <see cref="Tizen.Multimedia.Camera.StartPreview"/> method.
+ /// Each captured image will be delivered through Eventhandler set using <see cref="Capturing"/> event.
+ /// The preview should be restarted by calling <see cref="StartPreview"/> method after capture is completed.
/// </remarks>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="ArgumentOutOfRangeException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StartCapture(int count, int interval, CancellationToken cancellationToken)
{
ValidateState(CameraState.Preview);
/// <summary>
/// Starts camera auto-focusing, asynchronously.
+ /// The camera must be in the <see cref="CameraState.Preview"/> or <see cref="CameraState.Captured"/> state.
/// </summary>
- /// <param name="continuous">Continuous.</param>
+ /// <param name="continuous">Continuous auto focus</param>
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
/// <remarks>
/// If continuous status is true, the camera continuously tries to focus.
/// </remarks>
- /// <exception cref="ArgumentException">In case of invalid parameters</exception>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StartFocusing(bool continuous)
{
ValidateState(CameraState.Preview, CameraState.Captured);
/// <summary>
/// Stops camera auto focusing.
+ /// The camera must be in the <see cref="CameraState.Preview"/> or <see cref="CameraState.Captured"/> state.
/// </summary>
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StopFocusing()
{
ValidateState(CameraState.Preview, CameraState.Captured);
/// <summary>
/// Starts face detection.
+ /// The camera must be in the <see cref="CameraState.Preview"/> state.
/// </summary>
/// <privilege>
/// http://tizen.org/privilege/camera
/// </privilege>
/// <remarks>
- /// This should be called after <see cref="Tizen.Multimedia.Camera.StartPreview"/> is started.
- /// The Eventhandler set using <see cref="Tizen.Multimedia.Camera.FaceDetected"/> invoked when the face is detected in preview frame.
+ /// This should be called after <see cref="StartPreview"/> is started.
+ /// The Eventhandler set using <see cref="FaceDetected"/> invoked when the face is detected in preview frame.
/// Internally it starts continuous focus and focusing on the detected face.
/// </remarks>
- /// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
- /// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
+ /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
+ /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public void StartFaceDetection()
{
ValidateState(CameraState.Preview);
/// </privilege>
/// <exception cref="InvalidOperationException">In case of any invalid operations</exception>
/// <exception cref="NotSupportedException">In case of this feature is not supported</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
/// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted</exception>
public void StopFaceDetection()
{
{
_stateChangedCallback = (CameraState previous, CameraState current, bool byPolicy, IntPtr _) =>
{
- _state = current;
+ SetState(current);
Log.Info(CameraLog.Tag, "Camera state changed " + previous.ToString() + " -> " + current.ToString());
StateChanged?.Invoke(this, new CameraStateChangedEventArgs(previous, current, byPolicy));
};