--- /dev/null
+/*
+ * 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.ComponentModel;
+using Native = Interop.Camera;
+
+namespace Tizen.Multimedia
+{
+ /// <summary>
+ /// This camera class provides methods to capture photos and supports setting up notifications
+ /// for state changes of capturing, previewing, focusing, and informing about the resolution and the binary format,
+ /// and functions for picture manipulations like sepia, negative, and many more.
+ /// It also notifies you when a significant picture parameter changes, (For example, focus).
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <feature> http://tizen.org/feature/camera </feature>
+ public partial class Camera : IDisposable, IDisplayable<CameraError>
+ {
+ /// <summary>
+ /// An event that occurs when the camera interrupt is started by the policy.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public event EventHandler<CameraInterruptStartedEventArgs> InterruptStarted;
+ private Native.InterruptStartedCallback _interruptStartedCallback;
+
+ /// <summary>
+ /// An event that occurs when an camera is interrupted by the policy.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<CameraInterruptedEventArgs> Interrupted;
+ private Native.InterruptedCallback _interruptedCallback;
+
+ /// <summary>
+ /// An event that occurs when there is an asynchronous error.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<CameraErrorOccurredEventArgs> ErrorOccurred;
+ private Native.ErrorCallback _errorCallback;
+
+ /// <summary>
+ /// An event that occurs when the auto focus state is changed.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<CameraFocusStateChangedEventArgs> FocusStateChanged;
+ private Native.FocusStateChangedCallback _focusStateChangedCallback;
+
+ /// <summary>
+ /// An event that occurs when a face is detected in the preview frame.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<FaceDetectedEventArgs> FaceDetected;
+ private Native.FaceDetectedCallback _faceDetectedCallback;
+
+ /// <summary>
+ /// An event that occurs during capture of an image.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<CameraCapturingEventArgs> Capturing;
+ private Native.CapturingCallback _capturingCallback;
+
+ /// <summary>
+ /// An event that occurs after the capture of the image.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<EventArgs> CaptureCompleted;
+ private Native.CaptureCompletedCallback _captureCompletedCallback;
+
+ private Native.HdrCaptureProgressCallback _hdrCaptureProgressCallback;
+ private event EventHandler<HdrCaptureProgressEventArgs> _hdrCaptureProgress;
+ private object _hdrCaptureProgressEventLock = new object();
+
+ /// <summary>
+ /// An event that occurs when there is a change in the HDR capture progress.
+ /// Checks whether the <see cref="CameraCapabilities.IsHdrCaptureSupported"/> is supported or not before adding this EventHandler.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <exception cref="NotSupportedException">In case of HDR feature is not supported.</exception>
+ public event EventHandler<HdrCaptureProgressEventArgs> HdrCaptureProgress
+ {
+ add
+ {
+ lock (_hdrCaptureProgressEventLock)
+ {
+ if (_hdrCaptureProgress == null)
+ {
+ RegisterHdrCaptureProgress();
+ }
+
+ _hdrCaptureProgress += value;
+ }
+ }
+
+ remove
+ {
+ lock (_hdrCaptureProgressEventLock)
+ {
+ _hdrCaptureProgress -= value;
+
+ if (_hdrCaptureProgress == null)
+ {
+ UnregisterHdrCaptureProgress();
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// An event that occurs when the camera state is changed.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<CameraStateChangedEventArgs> StateChanged;
+ private Native.StateChangedCallback _stateChangedCallback;
+
+ private static Native.DeviceStateChangedCallback _deviceStateChangedCallback;
+ private static event EventHandler<CameraDeviceStateChangedEventArgs> _deviceStateChanged;
+ private static object _deviceStateChangedEventLock = new object();
+ private static int _deviceStateCallbackId;
+
+ /// <summary>
+ /// An event that occurs after the <see cref="CameraDeviceState"/> is changed.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <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>
+ public static event EventHandler<CameraDeviceStateChangedEventArgs> DeviceStateChanged
+ {
+ add
+ {
+ lock (_deviceStateChangedEventLock)
+ {
+ if (_deviceStateChanged == null)
+ {
+ RegisterDeviceStateChangedCallback();
+ }
+
+ _deviceStateChanged += value;
+ }
+ }
+
+ remove
+ {
+ lock (_deviceStateChangedEventLock)
+ {
+ _deviceStateChanged -= value;
+
+ if (_deviceStateChanged == null)
+ {
+ UnregisterDeviceStateChangedCallback();
+ }
+ }
+ }
+ }
+
+ private Native.PreviewCallback _previewCallback;
+ private event EventHandler<PreviewEventArgs> _preview;
+ private object _previewEventLock = new object();
+ /// <summary>
+ /// An event that occurs once per frame when previewing.
+ /// Preview callback is registered when an user adds a callback explicitly to avoid useless P/Invoke.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<PreviewEventArgs> Preview
+ {
+ add
+ {
+ lock (_previewEventLock)
+ {
+ if (_preview == null)
+ {
+ RegisterPreviewCallback();
+ }
+
+ _preview += value;
+ }
+ }
+
+ remove
+ {
+ lock (_previewEventLock)
+ {
+ _preview -= value;
+
+ if (_preview == null)
+ {
+ UnregisterPreviewCallback();
+ }
+ }
+ }
+ }
+
+ private Native.MediaPacketPreviewCallback _mediaPacketPreviewCallback;
+ private EventHandler<MediaPacketPreviewEventArgs> _mediaPacketPreview;
+ private object _mediaPacketPreviewEventLock = new object();
+
+ /// <summary>
+ /// An event that occurs once per frame when previewing.
+ /// Preview callback is registered when an user adds a callback explicitly to avoid useless P/Invoke.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<MediaPacketPreviewEventArgs> MediaPacketPreview
+ {
+ add
+ {
+ lock (_mediaPacketPreviewEventLock)
+ {
+ if (_mediaPacketPreview == null)
+ {
+ RegisterMediaPacketPreviewCallback();
+ }
+
+ _mediaPacketPreview += value;
+ }
+ }
+
+ remove
+ {
+ lock (_mediaPacketPreviewEventLock)
+ {
+ _mediaPacketPreview -= value;
+
+ if (_mediaPacketPreview == null)
+ {
+ UnregisterMediaPacketPreviewCallback();
+ }
+ }
+ }
+ }
+
+ private Native.ExtraPreviewCallback _extraPreviewCallback;
+ private event EventHandler<ExtraPreviewEventArgs> _extraPreview;
+ /// <summary>
+ /// An event that occurs once per frame when previewing.
+ /// Preview callback is registered when an user adds a callback explicitly to avoid useless P/Invoke.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public event EventHandler<ExtraPreviewEventArgs> ExtraPreview
+ {
+ add
+ {
+ if (_extraPreview == null)
+ {
+ RegisterExtraPreviewCallback();
+ }
+
+ _extraPreview += value;
+ }
+
+ remove
+ {
+ _extraPreview -= value;
+
+ if (_extraPreview == null)
+ {
+ UnregisterExtraPreviewCallback();
+ }
+ }
+ }
+
+ private void RegisterCallbacks()
+ {
+ RegisterErrorCallback();
+ RegisterFocusStateChanged();
+ RegisterInterruptStartedCallback();
+ RegisterInterruptedCallback();
+ RegisterStateChangedCallback();
+
+ //Define capturing callback
+ _capturingCallback = (main, postview, thumbnail, userData) =>
+ {
+ Capturing?.Invoke(this, new CameraCapturingEventArgs(new StillImage(main),
+ postview == IntPtr.Zero ? null : new StillImage(postview),
+ thumbnail == IntPtr.Zero ? null : new StillImage(thumbnail)));
+ };
+
+ //Define captureCompleted callback
+ _captureCompletedCallback = _ =>
+ {
+ SetState(CameraState.Captured);
+ CaptureCompleted?.Invoke(this, EventArgs.Empty);
+ };
+ }
+
+ private void RegisterInterruptStartedCallback()
+ {
+ _interruptStartedCallback = (policy, state, _) =>
+ {
+ InterruptStarted?.Invoke(this, new CameraInterruptStartedEventArgs(policy, state));
+ };
+
+ Native.SetInterruptStartedCallback(_handle, _interruptStartedCallback).
+ ThrowIfFailed("Failed to set interrupt callback.");
+ }
+
+ private void RegisterInterruptedCallback()
+ {
+ _interruptedCallback = (policy, previous, current, _) =>
+ {
+ Interrupted?.Invoke(this, new CameraInterruptedEventArgs(policy, previous, current));
+ };
+
+ Native.SetInterruptedCallback(_handle, _interruptedCallback).
+ ThrowIfFailed("Failed to set interrupt callback.");
+ }
+
+ private void RegisterErrorCallback()
+ {
+ _errorCallback = (error, current, _) =>
+ {
+ ErrorOccurred?.Invoke(this, new CameraErrorOccurredEventArgs(error, current));
+ };
+
+ Native.SetErrorCallback(_handle, _errorCallback).
+ ThrowIfFailed("Setting error callback failed");
+ }
+
+ private void RegisterStateChangedCallback()
+ {
+ _stateChangedCallback = (previous, current, byPolicy, _) =>
+ {
+ SetState(current);
+ Log.Info(CameraLog.Tag, "Camera state changed " + previous.ToString() + " -> " + current.ToString());
+ StateChanged?.Invoke(this, new CameraStateChangedEventArgs(previous, current, byPolicy));
+ };
+
+ Native.SetStateChangedCallback(_handle, _stateChangedCallback).
+ ThrowIfFailed("Failed to set state changed callback.");
+ }
+
+ private static void RegisterDeviceStateChangedCallback()
+ {
+ _deviceStateChangedCallback = (device, state, _) =>
+ {
+ _deviceStateChanged?.Invoke(null, new CameraDeviceStateChangedEventArgs(device, state));
+ };
+
+ Native.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out _deviceStateCallbackId).
+ ThrowIfFailed("Failed to set device state changed callback.");
+
+ Log.Info(CameraLog.Tag, "add callbackId " + _deviceStateCallbackId.ToString());
+ }
+
+ private static void UnregisterDeviceStateChangedCallback()
+ {
+ Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId).
+ ThrowIfFailed("Failed to unset device state changed callback.");
+
+ _deviceStateChangedCallback = null;
+ _deviceStateCallbackId = 0;
+ }
+
+ private void RegisterFocusStateChanged()
+ {
+ _focusStateChangedCallback = (state, _) =>
+ {
+ FocusStateChanged?.Invoke(this, new CameraFocusStateChangedEventArgs(state));
+ };
+
+ Native.SetFocusStateChangedCallback(_handle, _focusStateChangedCallback).
+ ThrowIfFailed("Failed to set focus changed callback.");
+ }
+
+ private void RegisterHdrCaptureProgress()
+ {
+ _hdrCaptureProgressCallback = (percent, _) =>
+ {
+ _hdrCaptureProgress?.Invoke(this, new HdrCaptureProgressEventArgs(percent));
+ };
+
+ Native.SetHdrCaptureProgressCallback(_handle, _hdrCaptureProgressCallback).
+ ThrowIfFailed("Failed to set Hdr capture progress callback.");
+ }
+
+ private void UnregisterHdrCaptureProgress()
+ {
+ Native.UnsetHdrCaptureProgressCallback(_handle).
+ ThrowIfFailed("Failed to unset hdr capture progres callback.");
+
+ _hdrCaptureProgressCallback = null;
+ }
+
+ private void RegisterPreviewCallback()
+ {
+ _previewCallback = (frame, _) =>
+ {
+ _preview?.Invoke(this, new PreviewEventArgs(new PreviewFrame(frame)));
+ };
+
+ Native.SetPreviewCallback(_handle, _previewCallback).
+ ThrowIfFailed("Failed to set preview callback.");
+ }
+
+ private void UnregisterPreviewCallback()
+ {
+ Native.UnsetPreviewCallback(_handle).
+ ThrowIfFailed("Failed to unset preview callback.");
+
+ _previewCallback = null;
+ }
+
+ private void RegisterMediaPacketPreviewCallback()
+ {
+ _mediaPacketPreviewCallback = (mediaPacket, _) =>
+ {
+ MediaPacket packet = MediaPacket.From(mediaPacket);
+
+ var eventHandler = _mediaPacketPreview;
+
+ if (eventHandler != null)
+ {
+ eventHandler.Invoke(this, new MediaPacketPreviewEventArgs(packet));
+ }
+
+ packet.Dispose();
+ };
+
+ Native.SetMediaPacketPreviewCallback(_handle, _mediaPacketPreviewCallback).
+ ThrowIfFailed("Failed to set media packet preview callback.");
+ }
+
+ private void UnregisterMediaPacketPreviewCallback()
+ {
+ Native.UnsetMediaPacketPreviewCallback(_handle).
+ ThrowIfFailed("Failed to unset media packet preview callback.");
+
+ _mediaPacketPreviewCallback = null;
+ }
+
+ private void RegisterExtraPreviewCallback()
+ {
+ _extraPreviewCallback = (frame, streamId, _) =>
+ {
+ _extraPreview?.Invoke(this, new ExtraPreviewEventArgs(new PreviewFrame(frame), streamId));
+ };
+
+ Native.SetExtraPreviewCallback(_handle, _extraPreviewCallback).
+ ThrowIfFailed("Failed to set extra preview callback.");
+ }
+
+ private void UnregisterExtraPreviewCallback()
+ {
+ Native.UnsetPreviewCallback(_handle).
+ ThrowIfFailed("Failed to unset preview callback.");
+
+ _extraPreviewCallback = null;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Diagnostics;
+using static Interop;
+using Native = Interop.Camera;
+
+namespace Tizen.Multimedia
+{
+ /// <summary>
+ /// This camera class provides methods to capture photos and supports setting up notifications
+ /// for state changes of capturing, previewing, focusing, and informing about the resolution and the binary format,
+ /// and functions for picture manipulations like sepia, negative, and many more.
+ /// It also notifies you when a significant picture parameter changes, (For example, focus).
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <feature> http://tizen.org/feature/camera </feature>
+ public partial class Camera : IDisposable, IDisplayable<CameraError>
+ {
+ /// <summary>
+ /// Gets or sets the various camera settings.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public CameraSettings Settings { get; }
+
+ /// <summary>
+ /// Gets the various camera capabilities.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public CameraCapabilities Capabilities { get; }
+
+ /// <summary>
+ /// Get/set various camera display properties.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public CameraDisplaySettings DisplaySettings { get; }
+
+ private Display _display;
+
+ private CameraError SetDisplay(Display display)
+ {
+ if (display == null)
+ {
+ return CameraDisplay.SetDisplay(GetHandle(), DisplayType.None, IntPtr.Zero);
+ }
+
+ return display.ApplyTo(this);
+ }
+
+ private void ReplaceDisplay(Display newDisplay)
+ {
+ _display?.SetOwner(null);
+ _display = newDisplay;
+ _display?.SetOwner(this);
+ }
+
+ /// <summary>
+ /// Sets or gets the display type and handle to show preview images.
+ /// The camera must be in the <see cref="CameraState.Created"/> state.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <remarks>
+ /// This must be set before the StartPreview() method.
+ /// In custom ROI display mode, DisplayRoiArea property must be set before calling this method.
+ /// </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="ObjectDisposedException" > The camera already has been disposed of.</exception>
+ /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
+ public Display Display
+ {
+ get
+ {
+ return _display;
+ }
+
+ set
+ {
+ ValidateState(CameraState.Created);
+
+ if (value?.Owner != null)
+ {
+ if (ReferenceEquals(this, value.Owner))
+ {
+ return;
+ }
+
+ throw new ArgumentException("The display has already been assigned to another.");
+ }
+
+ SetDisplay(value).ThrowIfFailed("Failed to set the camera display");
+
+ ReplaceDisplay(value);
+ }
+ }
+
+ CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
+ {
+ Debug.Assert(_disposed == false);
+ ValidationUtil.ValidateEnum(typeof(DisplayType), type, nameof(type));
+
+ return CameraDisplay.SetDisplay(GetHandle(), type, evasObject);
+ }
+
+ CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle)
+ {
+ Debug.Assert(_disposed == false);
+
+ return CameraDisplay.SetEcoreDisplay(GetHandle(), windowHandle);
+ }
+
+ /// <summary>
+ /// Gets the state of the camera.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value> None, Created, Preview, Capturing, Captured.</value>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
+ public CameraState State
+ {
+ get
+ {
+ ValidateNotDisposed();
+
+ Native.GetState(_handle, out CameraState val).ThrowIfFailed("Failed to get camera state");
+
+ return val;
+ }
+ }
+
+ /// <summary>
+ /// The hint for the display reuse.
+ /// If the hint is set to true, the display will be reused when the camera device is changed with
+ /// the ChangeDevice method.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
+ /// <exception cref="InvalidOperationException">An invalid state.</exception>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
+ public bool DisplayReuseHint
+ {
+ get
+ {
+ ValidateNotDisposed();
+
+ Native.GetDisplayReuseHint(_handle, out bool val).ThrowIfFailed("Failed to get camera display reuse hint");
+
+ return val;
+ }
+
+ set
+ {
+ ValidateState(CameraState.Preview);
+
+ Native.SetDisplayReuseHint(_handle, value).ThrowIfFailed("Failed to set display reuse hint.");
+ }
+ }
+
+ /// <summary>
+ /// Gets the facing direction of the camera module.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>A <see cref="CameraFacingDirection"/> that specifies the facing direction of the camera device.</value>
+ /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
+ public CameraFacingDirection Direction
+ {
+ get
+ {
+ ValidateNotDisposed();
+
+ Native.GetFacingDirection(_handle, out var val).ThrowIfFailed("Failed to get camera direction");
+
+ return val;
+ }
+ }
+
+ /// <summary>
+ /// Gets the camera device count.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <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 of.</exception>
+ public int CameraCount
+ {
+ get
+ {
+ ValidateNotDisposed();
+
+ Native.GetDeviceCount(_handle, out int val).ThrowIfFailed("Failed to get camera device count");
+
+ return val;
+ }
+ }
+ }
+}
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
-using static Interop;
using Native = Interop.Camera;
namespace Tizen.Multimedia
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <feature> http://tizen.org/feature/camera </feature>
- public class Camera : IDisposable, IDisplayable<CameraError>
+ public partial class Camera : IDisposable, IDisplayable<CameraError>
{
private IntPtr _handle = IntPtr.Zero;
private bool _disposed = false;
}
#endregion Check camera state
- #region EventHandlers
- /// <summary>
- /// An event that occurs when the camera interrupt is started by the policy.
- /// </summary>
- /// <since_tizen> 4 </since_tizen>
- public event EventHandler<CameraInterruptStartedEventArgs> InterruptStarted;
- private Native.InterruptStartedCallback _interruptStartedCallback;
-
- /// <summary>
- /// An event that occurs when an camera is interrupted by the policy.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<CameraInterruptedEventArgs> Interrupted;
- private Native.InterruptedCallback _interruptedCallback;
-
- /// <summary>
- /// An event that occurs when there is an asynchronous error.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<CameraErrorOccurredEventArgs> ErrorOccurred;
- private Native.ErrorCallback _errorCallback;
-
- /// <summary>
- /// An event that occurs when the auto focus state is changed.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<CameraFocusStateChangedEventArgs> FocusStateChanged;
- private Native.FocusStateChangedCallback _focusStateChangedCallback;
-
- /// <summary>
- /// An event that occurs when a face is detected in the preview frame.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<FaceDetectedEventArgs> FaceDetected;
- private Native.FaceDetectedCallback _faceDetectedCallback;
-
- /// <summary>
- /// An event that occurs during capture of an image.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<CameraCapturingEventArgs> Capturing;
- private Native.CapturingCallback _capturingCallback;
-
- /// <summary>
- /// An event that occurs after the capture of the image.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<EventArgs> CaptureCompleted;
- private Native.CaptureCompletedCallback _captureCompletedCallback;
-
- private Native.HdrCaptureProgressCallback _hdrCaptureProgressCallback;
- private event EventHandler<HdrCaptureProgressEventArgs> _hdrCaptureProgress;
- private object _hdrCaptureProgressEventLock = new object();
-
- /// <summary>
- /// An event that occurs when there is a change in the HDR capture progress.
- /// Checks whether the <see cref="CameraCapabilities.IsHdrCaptureSupported"/> is supported or not before adding this EventHandler.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <exception cref="NotSupportedException">In case of HDR feature is not supported.</exception>
- public event EventHandler<HdrCaptureProgressEventArgs> HdrCaptureProgress
- {
- add
- {
- lock (_hdrCaptureProgressEventLock)
- {
- if (_hdrCaptureProgress == null)
- {
- RegisterHdrCaptureProgress();
- }
-
- _hdrCaptureProgress += value;
- }
- }
-
- remove
- {
- lock (_hdrCaptureProgressEventLock)
- {
- _hdrCaptureProgress -= value;
-
- if (_hdrCaptureProgress == null)
- {
- UnregisterHdrCaptureProgress();
- }
- }
- }
- }
-
- /// <summary>
- /// An event that occurs when the camera state is changed.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<CameraStateChangedEventArgs> StateChanged;
- private Native.StateChangedCallback _stateChangedCallback;
-
- private static Native.DeviceStateChangedCallback _deviceStateChangedCallback;
- private static event EventHandler<CameraDeviceStateChangedEventArgs> _deviceStateChanged;
- private static object _deviceStateChangedEventLock = new object();
- private static int _deviceStateCallbackId;
-
- /// <summary>
- /// An event that occurs after the <see cref="CameraDeviceState"/> is changed.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <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>
- public static event EventHandler<CameraDeviceStateChangedEventArgs> DeviceStateChanged
- {
- add
- {
- lock (_deviceStateChangedEventLock)
- {
- if (_deviceStateChanged == null)
- {
- RegisterDeviceStateChangedCallback();
- }
-
- _deviceStateChanged += value;
- }
- }
-
- remove
- {
- lock (_deviceStateChangedEventLock)
- {
- _deviceStateChanged -= value;
-
- if (_deviceStateChanged == null)
- {
- UnregisterDeviceStateChangedCallback();
- }
- }
- }
- }
-
- private Native.PreviewCallback _previewCallback;
- private event EventHandler<PreviewEventArgs> _preview;
- private object _previewEventLock = new object();
- /// <summary>
- /// An event that occurs once per frame when previewing.
- /// Preview callback is registered when an user adds a callback explicitly to avoid useless P/Invoke.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<PreviewEventArgs> Preview
- {
- add
- {
- lock (_previewEventLock)
- {
- if (_preview == null)
- {
- RegisterPreviewCallback();
- }
-
- _preview += value;
- }
- }
-
- remove
- {
- lock (_previewEventLock)
- {
- _preview -= value;
-
- if (_preview == null)
- {
- UnregisterPreviewCallback();
- }
- }
- }
- }
-
- private Native.MediaPacketPreviewCallback _mediaPacketPreviewCallback;
- private EventHandler<MediaPacketPreviewEventArgs> _mediaPacketPreview;
- private object _mediaPacketPreviewEventLock = new object();
-
- /// <summary>
- /// An event that occurs once per frame when previewing.
- /// Preview callback is registered when an user adds a callback explicitly to avoid useless P/Invoke.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public event EventHandler<MediaPacketPreviewEventArgs> MediaPacketPreview
- {
- add
- {
- lock (_mediaPacketPreviewEventLock)
- {
- if (_mediaPacketPreview == null)
- {
- RegisterMediaPacketPreviewCallback();
- }
-
- _mediaPacketPreview += value;
- }
- }
-
- remove
- {
- lock (_mediaPacketPreviewEventLock)
- {
- _mediaPacketPreview -= value;
-
- if (_mediaPacketPreview == null)
- {
- UnregisterMediaPacketPreviewCallback();
- }
- }
- }
- }
- #endregion EventHandlers
-
- #region Properties
- /// <summary>
- /// Gets or sets the various camera settings.
- /// </summary>
- /// <since_tizen> 4 </since_tizen>
- public CameraSettings Settings { get; }
-
- /// <summary>
- /// Gets the various camera capabilities.
- /// </summary>
- /// <since_tizen> 4 </since_tizen>
- public CameraCapabilities Capabilities { get; }
-
- /// <summary>
- /// Get/set various camera display properties.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- public CameraDisplaySettings DisplaySettings { get; }
-
- private Display _display;
-
- private CameraError SetDisplay(Display display)
- {
- if (display == null)
- {
- return CameraDisplay.SetDisplay(GetHandle(), DisplayType.None, IntPtr.Zero);
- }
-
- return display.ApplyTo(this);
- }
-
- private void ReplaceDisplay(Display newDisplay)
- {
- _display?.SetOwner(null);
- _display = newDisplay;
- _display?.SetOwner(this);
- }
-
- /// <summary>
- /// Sets or gets the display type and handle to show preview images.
- /// The camera must be in the <see cref="CameraState.Created"/> state.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <remarks>
- /// This must be set before the StartPreview() method.
- /// In custom ROI display mode, DisplayRoiArea property must be set before calling this method.
- /// </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="ObjectDisposedException" > The camera already has been disposed of.</exception>
- /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
- public Display Display
- {
- get
- {
- return _display;
- }
-
- set
- {
- ValidateState(CameraState.Created);
-
- if (value?.Owner != null)
- {
- if (ReferenceEquals(this, value.Owner))
- {
- return;
- }
-
- throw new ArgumentException("The display has already been assigned to another.");
- }
- SetDisplay(value).ThrowIfFailed("Failed to set the camera display");
-
- ReplaceDisplay(value);
- }
- }
-
- CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
- {
- Debug.Assert(_disposed == false);
- ValidationUtil.ValidateEnum(typeof(DisplayType), type, nameof(type));
-
- return CameraDisplay.SetDisplay(GetHandle(), type, evasObject);
- }
-
- CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle)
- {
- Debug.Assert(_disposed == false);
-
- return CameraDisplay.SetEcoreDisplay(GetHandle(), windowHandle);
- }
-
- /// <summary>
- /// Gets the state of the camera.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <value> None, Created, Preview, Capturing, Captured.</value>
- /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
- public CameraState State
- {
- get
- {
- ValidateNotDisposed();
-
- CameraState val = CameraState.None;
-
- Native.GetState(_handle, out val).ThrowIfFailed("Failed to get camera state");
-
- return val;
- }
- }
-
- /// <summary>
- /// The hint for the display reuse.
- /// If the hint is set to true, the display will be reused when the camera device is changed with
- /// the ChangeDevice method.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
- /// <exception cref="InvalidOperationException">An invalid state.</exception>
- /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
- public bool DisplayReuseHint
- {
- get
- {
- ValidateNotDisposed();
-
- Native.GetDisplayReuseHint(_handle, out bool val).ThrowIfFailed("Failed to get camera display reuse hint");
-
- return val;
- }
-
- set
- {
- ValidateState(CameraState.Preview);
-
- Native.SetDisplayReuseHint(_handle, value).ThrowIfFailed("Failed to set display reuse hint.");
- }
- }
-
- /// <summary>
- /// Gets the facing direction of the camera module.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <value>A <see cref="CameraFacingDirection"/> that specifies the facing direction of the camera device.</value>
- /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
- public CameraFacingDirection Direction
- {
- get
- {
- ValidateNotDisposed();
-
- Native.GetFacingDirection(_handle, out var val).ThrowIfFailed("Failed to get camera direction");
-
- return val;
- }
- }
-
- /// <summary>
- /// Gets the camera device count.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <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 of.</exception>
- public int CameraCount
- {
- get
- {
- ValidateNotDisposed();
-
- Native.GetDeviceCount(_handle, out int val).ThrowIfFailed("Failed to get camera device count");
-
- return val;
- }
- }
- #endregion Properties
#region Methods
/// <summary>
{
ValidateState(CameraState.Preview);
- Native.StartCapture(_handle, _capturingCallback, _captureCompletedCallback, IntPtr.Zero).
+ Native.StartCapture(_handle, _capturingCallback, _captureCompletedCallback).
ThrowIfFailed("Failed to start the camera capture.");
SetState(CameraState.Capturing);
});
}
- Native.StartContinuousCapture(_handle, count, interval, _capturingCallback, _captureCompletedCallback, IntPtr.Zero).
+ Native.StartContinuousCapture(_handle, count, interval, _capturingCallback, _captureCompletedCallback).
ThrowIfFailed("Failed to start the continuous capture.");
SetState(CameraState.Capturing);
FaceDetected?.Invoke(this, new FaceDetectedEventArgs(result));
};
- Native.StartFaceDetection(_handle, _faceDetectedCallback, IntPtr.Zero).
+ Native.StartFaceDetection(_handle, _faceDetectedCallback).
ThrowIfFailed("Failed to start face detection");
}
_faceDetectedCallback = null;
}
#endregion Methods
-
- #region Callback registrations
- private void RegisterCallbacks()
- {
- RegisterErrorCallback();
- RegisterFocusStateChanged();
- RegisterInterruptStartedCallback();
- RegisterInterruptedCallback();
- RegisterStateChangedCallback();
-
- //Define capturing callback
- _capturingCallback = (IntPtr main, IntPtr postview, IntPtr thumbnail, IntPtr userData) =>
- {
- Capturing?.Invoke(this, new CameraCapturingEventArgs(new StillImage(main),
- postview == IntPtr.Zero ? null : new StillImage(postview),
- thumbnail == IntPtr.Zero ? null : new StillImage(thumbnail)));
- };
-
- //Define captureCompleted callback
- _captureCompletedCallback = _ =>
- {
- SetState(CameraState.Captured);
- CaptureCompleted?.Invoke(this, EventArgs.Empty);
- };
- }
-
- private void RegisterInterruptStartedCallback()
- {
- _interruptStartedCallback = (CameraPolicy policy, CameraState state, IntPtr userData) =>
- {
- InterruptStarted?.Invoke(this, new CameraInterruptStartedEventArgs(policy, state));
- };
-
- Native.SetInterruptStartedCallback(_handle, _interruptStartedCallback, IntPtr.Zero).
- ThrowIfFailed("Failed to set interrupt callback");
- }
-
- private void RegisterInterruptedCallback()
- {
- _interruptedCallback = (CameraPolicy policy, CameraState previous, CameraState current, IntPtr userData) =>
- {
- Interrupted?.Invoke(this, new CameraInterruptedEventArgs(policy, previous, current));
- };
-
- Native.SetInterruptedCallback(_handle, _interruptedCallback, IntPtr.Zero).
- ThrowIfFailed("Failed to set interrupt callback");
- }
-
- private void RegisterErrorCallback()
- {
- _errorCallback = (CameraErrorCode error, CameraState current, IntPtr userData) =>
- {
- ErrorOccurred?.Invoke(this, new CameraErrorOccurredEventArgs(error, current));
- };
-
- Native.SetErrorCallback(_handle, _errorCallback, IntPtr.Zero).ThrowIfFailed("Setting error callback failed");
- }
-
- private void RegisterStateChangedCallback()
- {
- _stateChangedCallback = (CameraState previous, CameraState current, bool byPolicy, IntPtr _) =>
- {
- SetState(current);
- Log.Info(CameraLog.Tag, "Camera state changed " + previous.ToString() + " -> " + current.ToString());
- StateChanged?.Invoke(this, new CameraStateChangedEventArgs(previous, current, byPolicy));
- };
-
- Native.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero).
- ThrowIfFailed("Setting state changed callback failed");
- }
-
- private static void RegisterDeviceStateChangedCallback()
- {
- _deviceStateChangedCallback = (CameraDevice device, CameraDeviceState state, IntPtr userData) =>
- {
- _deviceStateChanged?.Invoke(null, new CameraDeviceStateChangedEventArgs(device, state));
- };
-
- Native.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out _deviceStateCallbackId).
- ThrowIfFailed("Failed to set device state changed callback");
-
- Log.Info(CameraLog.Tag, "add callbackId " + _deviceStateCallbackId.ToString());
- }
-
- private static void UnregisterDeviceStateChangedCallback()
- {
- Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId).
- ThrowIfFailed("Unsetting device state changed callback failed");
-
- _deviceStateChangedCallback = null;
- _deviceStateCallbackId = 0;
- }
-
- private void RegisterFocusStateChanged()
- {
- _focusStateChangedCallback = (CameraFocusState state, IntPtr userData) =>
- {
- FocusStateChanged?.Invoke(this, new CameraFocusStateChangedEventArgs(state));
- };
-
- Native.SetFocusStateChangedCallback(_handle, _focusStateChangedCallback, IntPtr.Zero).
- ThrowIfFailed("Setting focus changed callback failed");
- }
-
- private void RegisterHdrCaptureProgress()
- {
- _hdrCaptureProgressCallback = (int percent, IntPtr userData) =>
- {
- _hdrCaptureProgress?.Invoke(this, new HdrCaptureProgressEventArgs(percent));
- };
-
- Native.SetHdrCaptureProgressCallback(_handle, _hdrCaptureProgressCallback, IntPtr.Zero).
- ThrowIfFailed("Setting Hdr capture progress callback failed");
- }
-
- private void UnregisterHdrCaptureProgress()
- {
- Native.UnsetHdrCaptureProgressCallback(_handle).
- ThrowIfFailed("Unsetting hdr capture progress is failed");
-
- _hdrCaptureProgressCallback = null;
- }
-
- private void RegisterPreviewCallback()
- {
- _previewCallback = (IntPtr frame, IntPtr userData) =>
- {
- _preview?.Invoke(this, new PreviewEventArgs(new PreviewFrame(frame)));
- };
-
- Native.SetPreviewCallback(_handle, _previewCallback, IntPtr.Zero).
- ThrowIfFailed("Setting preview callback failed");
- }
-
- private void UnregisterPreviewCallback()
- {
- Native.UnsetPreviewCallback(_handle).ThrowIfFailed("Unsetting preview callback failed");
-
- _previewCallback = null;
- }
-
- private void RegisterMediaPacketPreviewCallback()
- {
- _mediaPacketPreviewCallback = (IntPtr mediaPacket, IntPtr userData) =>
- {
- MediaPacket packet = MediaPacket.From(mediaPacket);
-
- var eventHandler = _mediaPacketPreview;
-
- if (eventHandler != null)
- {
- eventHandler.Invoke(this, new MediaPacketPreviewEventArgs(packet));
- }
-
- packet.Dispose();
- };
-
- Native.SetMediaPacketPreviewCallback(_handle, _mediaPacketPreviewCallback, IntPtr.Zero).
- ThrowIfFailed("Setting media packet preview callback failed");
- }
-
- private void UnregisterMediaPacketPreviewCallback()
- {
- Native.UnsetMediaPacketPreviewCallback(_handle).
- ThrowIfFailed("Unsetting media packet preview callback failed");
-
- _mediaPacketPreviewCallback = null;
- }
- #endregion Callback registrations
}
}
#region Methods for getting supported values
private IList<Size> GetSupportedPreviewResolutions()
{
- List<Size> previewResolutions = new List<Size>();
+ var previewResolutions = new List<Size>();
- NativeCapabilities.PreviewResolutionCallback callback = (int width, int height, IntPtr userData) =>
+ NativeCapabilities.PreviewResolutionCallback callback = (width, height, _) =>
{
previewResolutions.Add(new Size(width, height));
return true;
};
- NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedPreviewResolutions(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported preview resolutions");
return previewResolutions.AsReadOnly();
private IList<Size> GetSupportedCaptureResolutions()
{
- List<Size> cameraResolutions = new List<Size>();
+ var cameraResolutions = new List<Size>();
- NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
+ NativeCapabilities.CaptureResolutionCallback callback = (width, height, _) =>
{
cameraResolutions.Add(new Size(width, height));
return true;
};
- NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported capture resolutions");
return cameraResolutions.AsReadOnly();
private IList<CameraPixelFormat> GetSupportedCapturePixelFormats()
{
- List<CameraPixelFormat> captureFormats = new List<CameraPixelFormat>();
+ var captureFormats = new List<CameraPixelFormat>();
- NativeCapabilities.CaptureFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
+ NativeCapabilities.CaptureFormatCallback callback = (format, _) =>
{
captureFormats.Add(format);
return true;
};
- NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedCapturePixelFormats(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported capture formats.");
return captureFormats.AsReadOnly();
private IList<CameraPixelFormat> GetSupportedPreviewPixelFormats()
{
- List<CameraPixelFormat> previewFormats = new List<CameraPixelFormat>();
+ var previewFormats = new List<CameraPixelFormat>();
- NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
+ NativeCapabilities.PreviewFormatCallback callback = (format, _) =>
{
previewFormats.Add(format);
return true;
};
- NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported preview formats.");
return previewFormats.AsReadOnly();
private IList<CameraFps> GetSupportedPreviewFps()
{
- List<CameraFps> previewFps = new List<CameraFps>();
+ var previewFps = new List<CameraFps>();
- NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
+ NativeCapabilities.FpsCallback callback = (fps, _) =>
{
previewFps.Add(fps);
return true;
};
- NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported camera fps");
return previewFps.AsReadOnly();
private IList<CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
{
- List<CameraFps> fpsByResolution = new List<CameraFps>();
+ var fpsByResolution = new List<CameraFps>();
- NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
+ NativeCapabilities.FpsByResolutionCallback callback = (fps, _) =>
{
fpsByResolution.Add(fps);
return true;
};
- NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback, IntPtr.Zero).
+ NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback).
ThrowIfFailed("Failed to get the supported fps by resolutions.");
return fpsByResolution.AsReadOnly();
private IList<CameraAutoFocusMode> GetSupportedAutoFocusModes()
{
- List<CameraAutoFocusMode> autoFocusModes = new List<CameraAutoFocusMode>();
+ var autoFocusModes = new List<CameraAutoFocusMode>();
- NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
+ NativeCapabilities.AfModeCallback callback = (mode, _) =>
{
autoFocusModes.Add(mode);
return true;
};
- NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported Auto focus modes.");
return autoFocusModes.AsReadOnly();
private IList<CameraExposureMode> GetSupportedExposureModes()
{
- List<CameraExposureMode> exposureModes = new List<CameraExposureMode>();
+ var exposureModes = new List<CameraExposureMode>();
- NativeCapabilities.ExposureModeCallback callback = (CameraExposureMode mode, IntPtr userData) =>
+ NativeCapabilities.ExposureModeCallback callback = (mode, _) =>
{
exposureModes.Add(mode);
return true;
};
- NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedExposureModes(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported Exposure modes.");
return exposureModes.AsReadOnly();
private IList<CameraIsoLevel> GetSupportedIsoLevels()
{
- List<CameraIsoLevel> isoLevels = new List<CameraIsoLevel>();
+ var isoLevels = new List<CameraIsoLevel>();
- NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
+ NativeCapabilities.IsoCallback callback = (iso, _) =>
{
isoLevels.Add(iso);
return true;
};
- NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedIso(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported Iso levels.");
return isoLevels.AsReadOnly();
private IList<CameraTheaterMode> GetSupportedTheaterModes()
{
- List<CameraTheaterMode> theaterModes = new List<CameraTheaterMode>();
+ var theaterModes = new List<CameraTheaterMode>();
- NativeCapabilities.TheaterModeCallback callback = (CameraTheaterMode theaterMode, IntPtr userData) =>
+ NativeCapabilities.TheaterModeCallback callback = (theaterMode, _) =>
{
theaterModes.Add(theaterMode);
return true;
};
- NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedTheaterModes(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported theater modes.");
return theaterModes.AsReadOnly();
private IList<CameraWhiteBalance> GetSupportedWhitebalances()
{
- List<CameraWhiteBalance> whitebalances = new List<CameraWhiteBalance>();
+ var whitebalances = new List<CameraWhiteBalance>();
- NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
+ NativeCapabilities.WhitebalanceCallback callback = (whiteBalance, _) =>
{
whitebalances.Add(whiteBalance);
return true;
};
- NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported white balance.");
return whitebalances.AsReadOnly();
private IList<CameraFlashMode> GetSupportedFlashModes()
{
- List<CameraFlashMode> flashModes = new List<CameraFlashMode>();
+ var flashModes = new List<CameraFlashMode>();
- NativeCapabilities.FlashModeCallback callback = (CameraFlashMode flashMode, IntPtr userData) =>
+ NativeCapabilities.FlashModeCallback callback = (flashMode, _) =>
{
flashModes.Add(flashMode);
return true;
};
- NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedFlashModes(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported flash modes.");
return flashModes.AsReadOnly();
private IList<CameraSceneMode> GetSupportedSceneModes()
{
- List<CameraSceneMode> sceneModes = new List<CameraSceneMode>();
+ var sceneModes = new List<CameraSceneMode>();
- NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
+ NativeCapabilities.SceneModeCallback callback = (sceneMode, _) =>
{
sceneModes.Add(sceneMode);
return true;
};
- NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported scene modes.");
return sceneModes.AsReadOnly();
private IList<CameraEffectMode> GetSupportedEffects()
{
- List<CameraEffectMode> effectModes = new List<CameraEffectMode>();
+ var effectModes = new List<CameraEffectMode>();
- NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
+ NativeCapabilities.EffectCallback callback = (effect, _) =>
{
effectModes.Add(effect);
return true;
};
- NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported camera effects.");
return effectModes.AsReadOnly();
private IList<Rotation> GetSupportedStreamRotations()
{
- List<Rotation> streamRotations = new List<Rotation>();
+ var streamRotations = new List<Rotation>();
- NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
+ NativeCapabilities.StreamRotationCallback callback = (streamRotation, _) =>
{
streamRotations.Add(streamRotation);
return true;
};
- NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported camera rotations.");
return streamRotations.AsReadOnly();
private IList<Flips> GetSupportedStreamFlips()
{
- List<Flips> streamFlips = new List<Flips>();
+ var streamFlips = new List<Flips>();
- NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
+ NativeCapabilities.StreamFlipCallback callback = (streamFlip, _) =>
{
streamFlips.Add(streamFlip);
return true;
};
- NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported camera flips.");
return streamFlips.AsReadOnly();
private IList<CameraPtzType> GetSupportedPtzTypes()
{
- List<CameraPtzType> ptzTypes = new List<CameraPtzType>();
+ var ptzTypes = new List<CameraPtzType>();
- NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
+ NativeCapabilities.PtzTypeCallback callback = (ptzType, _) =>
{
ptzTypes.Add(ptzType);
return true;
};
- NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero).
+ NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback).
ThrowIfFailed("Failed to get the supported Ptz types.");
return ptzTypes.AsReadOnly();
--- /dev/null
+/*
+ * Copyright (c) 2021 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.ComponentModel;
+
+namespace Tizen.Multimedia
+{
+ /// <summary>
+ /// Provides data for the <see cref="Camera.ExtraPreview"/> event.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class ExtraPreviewEventArgs : EventArgs
+ {
+ internal ExtraPreviewEventArgs(PreviewFrame preview, int streadId)
+ {
+ Preview = preview;
+ StreamId = streadId;
+ }
+
+ /// <summary>
+ /// Gets the preview frame data.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public PreviewFrame Preview { get; }
+
+ /// <summary>
+ /// Gets the stream ID.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public int StreamId { get; }
+ }
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
using System;
using System.Runtime.InteropServices;
using Tizen.Internals;
internal delegate void PreviewCallback(IntPtr frame, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void ExtraPreviewCallback(IntPtr frame, int streamId, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void MediaPacketPreviewCallback(IntPtr mediaPacketHandle, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[DllImport(Libraries.Camera, EntryPoint = "camera_start_capture")]
internal static extern CameraError StartCapture(IntPtr handle, CapturingCallback captureCallback,
- CaptureCompletedCallback completedCallback, IntPtr userData);
+ CaptureCompletedCallback completedCallback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_start_continuous_capture")]
internal static extern CameraError StartContinuousCapture(IntPtr handle, int count, int interval,
- CapturingCallback captureCallback, CaptureCompletedCallback completedCallback, IntPtr userData);
+ CapturingCallback captureCallback, CaptureCompletedCallback completedCallback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_stop_continuous_capture")]
internal static extern CameraError StopContinuousCapture(IntPtr handle);
internal static extern CameraError GetRecommendedPreviewResolution(IntPtr handle, out int width, out int height);
[DllImport(Libraries.Camera, EntryPoint = "camera_start_face_detection")]
- internal static extern CameraError StartFaceDetection(IntPtr handle, FaceDetectedCallback callback, IntPtr userData);
+ internal static extern CameraError StartFaceDetection(IntPtr handle, FaceDetectedCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_stop_face_detection")]
internal static extern CameraError StopFaceDetection(IntPtr handle);
internal static extern CameraError GetFlashState(CameraDevice device, out CameraFlashState state);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_preview_cb")]
- internal static extern CameraError SetPreviewCallback(IntPtr handle, PreviewCallback callback, IntPtr userData);
+ internal static extern CameraError SetPreviewCallback(IntPtr handle, PreviewCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_unset_preview_cb")]
internal static extern CameraError UnsetPreviewCallback(IntPtr handle);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_media_packet_preview_cb")]
- internal static extern CameraError SetMediaPacketPreviewCallback(IntPtr handle, MediaPacketPreviewCallback callback, IntPtr userData);
+ internal static extern CameraError SetMediaPacketPreviewCallback(IntPtr handle, MediaPacketPreviewCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_unset_media_packet_preview_cb")]
internal static extern CameraError UnsetMediaPacketPreviewCallback(IntPtr handle);
+ [DllImport(Libraries.Camera, EntryPoint = "camera_set_extra_preview_cb")]
+ internal static extern CameraError SetExtraPreviewCallback(IntPtr handle, ExtraPreviewCallback callback, IntPtr userData = default);
+
+ [DllImport(Libraries.Camera, EntryPoint = "camera_unset_extra_preview_cb")]
+ internal static extern CameraError UnsetExtraPreviewCallback(IntPtr handle);
+
[DllImport(Libraries.Camera, EntryPoint = "camera_set_state_changed_cb")]
- internal static extern CameraError SetStateChangedCallback(IntPtr handle, StateChangedCallback callback, IntPtr userData);
+ internal static extern CameraError SetStateChangedCallback(IntPtr handle, StateChangedCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_add_device_state_changed_cb")]
internal static extern CameraError SetDeviceStateChangedCallback(DeviceStateChangedCallback callback, IntPtr userData, out int callbackId);
internal static extern CameraError UnsetDeviceStateChangedCallback(int cbId);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_interrupt_started_cb")]
- internal static extern CameraError SetInterruptStartedCallback(IntPtr handle, InterruptStartedCallback callback, IntPtr userData);
+ internal static extern CameraError SetInterruptStartedCallback(IntPtr handle, InterruptStartedCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_unset_interrupt_started_cb")]
internal static extern CameraError UnsetInterruptStartedCallback(IntPtr handle);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_interrupted_cb")]
- internal static extern CameraError SetInterruptedCallback(IntPtr handle, InterruptedCallback callback, IntPtr userData);
+ internal static extern CameraError SetInterruptedCallback(IntPtr handle, InterruptedCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_unset_interrupted_cb")]
internal static extern CameraError UnsetInterruptedCallback(IntPtr handle);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_focus_changed_cb")]
- internal static extern CameraError SetFocusStateChangedCallback(IntPtr handle, FocusStateChangedCallback callback, IntPtr userData);
+ internal static extern CameraError SetFocusStateChangedCallback(IntPtr handle, FocusStateChangedCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_unset_focus_changed_cb")]
internal static extern CameraError UnsetFocusChangedCallback(IntPtr handle);
[DllImport(Libraries.Camera, EntryPoint = "camera_set_error_cb")]
- internal static extern CameraError SetErrorCallback(IntPtr handle, ErrorCallback callback, IntPtr userData);
+ internal static extern CameraError SetErrorCallback(IntPtr handle, ErrorCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_unset_error_cb")]
internal static extern CameraError UnsetErrorCallback(IntPtr handle);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_set_hdr_capture_progress_cb")]
- internal static extern CameraError SetHdrCaptureProgressCallback(IntPtr handle, HdrCaptureProgressCallback callback, IntPtr userData);
+ internal static extern CameraError SetHdrCaptureProgressCallback(IntPtr handle, HdrCaptureProgressCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_unset_hdr_capture_progress_cb")]
internal static extern CameraError UnsetHdrCaptureProgressCallback(IntPtr handle);
internal static extern bool IsAutoContrastSupported(IntPtr handle);
[DllImport(Libraries.Camera, EntryPoint = "camera_foreach_supported_preview_resolution")]
- internal static extern CameraError SupportedPreviewResolutions(IntPtr handle, PreviewResolutionCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedPreviewResolutions(IntPtr handle, PreviewResolutionCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_foreach_supported_capture_resolution")]
- internal static extern CameraError SupportedCaptureResolutions(IntPtr handle, CaptureResolutionCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedCaptureResolutions(IntPtr handle, CaptureResolutionCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_foreach_supported_capture_format")]
- internal static extern CameraError SupportedCapturePixelFormats(IntPtr handle, CaptureFormatCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedCapturePixelFormats(IntPtr handle, CaptureFormatCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_foreach_supported_preview_format")]
- internal static extern CameraError SupportedPreviewPixelFormats(IntPtr handle, PreviewFormatCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedPreviewPixelFormats(IntPtr handle, PreviewFormatCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_fps")]
- internal static extern CameraError SupportedPreviewFps(IntPtr handle, FpsCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedPreviewFps(IntPtr handle, FpsCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_fps_by_resolution")]
- internal static extern CameraError SupportedPreviewFpsByResolution(IntPtr handle, int width, int height, FpsByResolutionCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedPreviewFpsByResolution(IntPtr handle, int width, int height, FpsByResolutionCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_af_mode")]
- internal static extern CameraError SupportedAutoFocusModes(IntPtr handle, AfModeCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedAutoFocusModes(IntPtr handle, AfModeCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_exposure_mode")]
- internal static extern CameraError SupportedExposureModes(IntPtr handle, ExposureModeCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedExposureModes(IntPtr handle, ExposureModeCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_iso")]
- internal static extern CameraError SupportedIso(IntPtr handle, IsoCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedIso(IntPtr handle, IsoCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_theater_mode")]
- internal static extern CameraError SupportedTheaterModes(IntPtr handle, TheaterModeCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedTheaterModes(IntPtr handle, TheaterModeCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_whitebalance")]
- internal static extern CameraError SupportedWhitebalance(IntPtr handle, WhitebalanceCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedWhitebalance(IntPtr handle, WhitebalanceCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_effect")]
- internal static extern CameraError SupportedEffects(IntPtr handle, EffectCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedEffects(IntPtr handle, EffectCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_scene_mode")]
- internal static extern CameraError SupportedSceneModes(IntPtr handle, SceneModeCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedSceneModes(IntPtr handle, SceneModeCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_flash_mode")]
- internal static extern CameraError SupportedFlashModes(IntPtr handle, FlashModeCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedFlashModes(IntPtr handle, FlashModeCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_stream_rotation")]
- internal static extern CameraError SupportedStreamRotations(IntPtr handle, StreamRotationCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedStreamRotations(IntPtr handle, StreamRotationCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_stream_flip")]
- internal static extern CameraError SupportedStreamFlips(IntPtr handle, StreamFlipCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedStreamFlips(IntPtr handle, StreamFlipCallback callback, IntPtr userData = default);
[DllImport(Libraries.Camera, EntryPoint = "camera_attr_foreach_supported_ptz_type")]
- internal static extern CameraError SupportedPtzTypes(IntPtr handle, PtzTypeCallback callback, IntPtr userData);
+ internal static extern CameraError SupportedPtzTypes(IntPtr handle, PtzTypeCallback callback, IntPtr userData = default);
}
}