Ejemplo n.º 1
0
        private void UnregisterMediaPacketPreviewCallback()
        {
            Native.UnsetMediaPacketPreviewCallback(_handle).
            ThrowIfFailed("Unsetting media packet preview callback failed");

            _mediaPacketPreviewCallback = null;
        }
Ejemplo n.º 2
0
        private void UnregisterHdrCaptureProgress()
        {
            Native.UnsetHdrCaptureProgressCallback(_handle).
            ThrowIfFailed("Unsetting hdr capture progress is failed");

            _hdrCaptureProgressCallback = null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts continuously capturing still images.
        /// 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>
        /// <since_tizen> 3 </since_tizen>
        /// <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="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 the <see cref="Capturing"/> event.
        /// The preview should be restarted by calling the <see cref="StartPreview"/> method after capture is completed.
        /// </remarks>
        /// <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 of.</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);

            if (count < 2)
            {
                throw new ArgumentOutOfRangeException(nameof(count), count, $"{nameof(count)} should be greater than one.");
            }

            if (interval < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(interval), interval, $"{nameof(interval)} should be greater than or equal to zero.");
            }

            //Handle CancellationToken
            if (cancellationToken != CancellationToken.None)
            {
                cancellationToken.Register(() =>
                {
                    CameraErrorFactory.ThrowIfError(Native.StopContinuousCapture(_handle),
                                                    "Failed to cancel the continuous capture");
                    SetState(CameraState.Captured);
                });
            }

            CameraErrorFactory.ThrowIfError(Native.StartContinuousCapture(_handle, count, interval,
                                                                          _capturingCallback, _captureCompletedCallback, IntPtr.Zero), "Failed to start the continuous capture.");

            SetState(CameraState.Capturing);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts camera auto-focusing, asynchronously.
        /// The camera must be in the <see cref="CameraState.Preview"/> or the <see cref="CameraState.Captured"/> state.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <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="ObjectDisposedException">The camera already has been disposed of.</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);

            CameraErrorFactory.ThrowIfError(Native.StartFocusing(_handle, continuous),
                                            "Failed to cancel the camera focus.");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Changes the camera device.
        /// </summary>
        /// <param name="device">The hardware camera to access.</param>
        /// <since_tizen> 3 </since_tizen>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <remarks>
        /// If display reuse is set using <see cref="DisplayReuseHint"/>
        /// before stopping the preview, the display will be reused and last frame on the display
        /// can be kept even though camera device is changed.
        /// The camera must be in the <see cref="CameraState.Created"/>.
        /// </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 the ChangeDevice feature is not supported.</exception>
        /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
        public void ChangeDevice(CameraDevice device)
        {
            ValidateState(CameraState.Created);
            ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));

            Native.ChangeDevice(_handle, device).ThrowIfFailed("Failed to change the camera device");
        }
Ejemplo n.º 6
0
 private static void UnregisterDeviceStateChangedCallback()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId),
                                     "Unsetting device state changed callback failed");
     _deviceStateChangedCallback = null;
     _deviceStateCallbackId      = 0;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Stops camera auto focusing.
        /// The camera must be in the <see cref="CameraState.Preview"/> or the <see cref="CameraState.Captured"/> state.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <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="ObjectDisposedException">The camera already has been disposed of.</exception>
        /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
        public void StopFocusing()
        {
            ValidateState(CameraState.Preview, CameraState.Captured);

            CameraErrorFactory.ThrowIfError(Native.CancelFocusing(_handle),
                                            "Failed to cancel the camera focus.");
        }
Ejemplo n.º 8
0
        private static void UnregisterDeviceStateChangedCallback()
        {
            Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId).
            ThrowIfFailed("Unsetting device state changed callback failed");

            _deviceStateChangedCallback = null;
            _deviceStateCallbackId      = 0;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Stops capturing and drawing preview frames on the screen.
        /// The camera must be in the <see cref="CameraState.Preview"/> state.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege> http://tizen.org/privilege/camera </privilege>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <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 void StopPreview()
        {
            ValidateState(CameraState.Preview);

            Native.StopPreview(_handle).ThrowIfFailed("Failed to stop the camera preview.");

            SetState(CameraState.Created);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the flash state.
        /// </summary>
        /// <param name="device">The device to get the state.</param>
        /// <returns>Returns the flash state of the camera device.</returns>
        /// <since_tizen> 3 </since_tizen>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <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)
        {
            ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));

            Native.GetFlashState(device, out var val).ThrowIfFailed("Failed to get camera flash state");

            return(val);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the device state.
        /// </summary>
        /// <param name="device">The device to get the state.</param>
        /// <returns>Returns the state of the camera device.</returns>
        /// <since_tizen> 4 </since_tizen>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <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 CameraDeviceState GetDeviceState(CameraDevice device)
        {
            ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));

            Native.GetDeviceState(device, out var val).ThrowIfFailed("Failed to get the camera device state.");

            return(val);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Starts capturing of still images.
        /// 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>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>
        /// http://tizen.org/privilege/camera
        /// </privilege>
        /// <remarks>
        /// This function causes the transition of the camera state from capturing to captured
        /// automatically and the corresponding EventHandlers will be invoked.
        /// The preview should be restarted by calling the <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="ObjectDisposedException">The camera already has been disposed of.</exception>
        /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
        public void StartCapture()
        {
            ValidateState(CameraState.Preview);

            CameraErrorFactory.ThrowIfError(Native.StartCapture(_handle, _capturingCallback, _captureCompletedCallback, IntPtr.Zero),
                                            "Failed to start the camera capture.");

            SetState(CameraState.Capturing);
        }
Ejemplo n.º 13
0
 private void RegisterHdrCaptureProgress()
 {
     _hdrCaptureProgressCallback = (int percent, IntPtr userData) =>
     {
         _hdrCaptureProgress?.Invoke(this, new HdrCaptureProgressEventArgs(percent));
     };
     CameraErrorFactory.ThrowIfError(Native.SetHdrCaptureProgressCallback(_handle, _hdrCaptureProgressCallback, IntPtr.Zero),
                                     "Setting Hdr capture progress callback failed");
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Starts capturing and drawing preview frames on the screen.
        /// The display property must be set using <see cref="Display"/> before using this method.
        /// 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 the <see cref="CameraState.Captured"/> state.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege> http://tizen.org/privilege/camera </privilege>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <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 void StartPreview()
        {
            ValidateState(CameraState.Created, CameraState.Captured);

            Native.StartPreview(_handle).ThrowIfFailed("Failed to start the camera preview.");

            // Update by StateChangedCallback can be delayed for dozens of milliseconds.
            SetState(CameraState.Preview);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Stops capturing and drawing preview frames on the screen.
        /// The camera must be in the <see cref="CameraState.Preview"/> state.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <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="ObjectDisposedException">The camera already has been disposed of.</exception>
        /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
        public void StopPreview()
        {
            ValidateState(CameraState.Preview);

            CameraErrorFactory.ThrowIfError(Native.StopPreview(_handle),
                                            "Failed to stop the camera preview.");

            SetState(CameraState.Created);
        }
Ejemplo n.º 16
0
 private void RegisterPreviewCallback()
 {
     _previewCallback = (IntPtr frame, IntPtr userData) =>
     {
         _preview?.Invoke(this, new PreviewEventArgs(new PreviewFrame(frame)));
     };
     CameraErrorFactory.ThrowIfError(Native.SetPreviewCallback(_handle, _previewCallback, IntPtr.Zero),
                                     "Setting preview callback failed");
 }
Ejemplo n.º 17
0
 private void RegisterErrorCallback()
 {
     _errorCallback = (CameraErrorCode error, CameraState current, IntPtr userData) =>
     {
         ErrorOccurred?.Invoke(this, new CameraErrorOccurredEventArgs(error, current));
     };
     CameraErrorFactory.ThrowIfError(Native.SetErrorCallback(_handle, _errorCallback, IntPtr.Zero),
                                     "Setting error callback failed");
 }
Ejemplo n.º 18
0
 private void RegisterInterruptedCallback()
 {
     _interruptedCallback = (CameraPolicy policy, CameraState previous, CameraState current, IntPtr userData) =>
     {
         Interrupted?.Invoke(this, new CameraInterruptedEventArgs(policy, previous, current));
     };
     CameraErrorFactory.ThrowIfError(Native.SetInterruptedCallback(_handle, _interruptedCallback, IntPtr.Zero),
                                     "Failed to set interrupt callback");
 }
Ejemplo n.º 19
0
 private void RegisterFocusStateChanged()
 {
     _focusStateChangedCallback = (CameraFocusState state, IntPtr userData) =>
     {
         FocusStateChanged?.Invoke(this, new CameraFocusStateChangedEventArgs(state));
     };
     CameraErrorFactory.ThrowIfError(Native.SetFocusStateChangedCallback(_handle, _focusStateChangedCallback, IntPtr.Zero),
                                     "Setting focus changed callback failed");
 }
Ejemplo n.º 20
0
        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");
        }
Ejemplo n.º 21
0
 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));
     };
     CameraErrorFactory.ThrowIfError(Native.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero),
                                     "Setting state changed callback failed");
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Stops face detection.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege> http://tizen.org/privilege/camera </privilege>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <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 void StopFaceDetection()
        {
            if (_faceDetectedCallback == null)
            {
                throw new InvalidOperationException("The face detection is not started.");
            }

            Native.StopFaceDetection(_handle).ThrowIfFailed("Failed to stop the face detection.");

            _faceDetectedCallback = null;
        }
Ejemplo n.º 23
0
        private static void RegisterDeviceStateChangedCallback()
        {
            _deviceStateChangedCallback = (CameraDevice device, CameraDeviceState state, IntPtr userData) =>
            {
                _deviceStateChanged?.Invoke(null, new CameraDeviceStateChangedEventArgs(device, state));
            };

            CameraErrorFactory.ThrowIfError(Native.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out _deviceStateCallbackId),
                                            "Failed to set device state changed callback");

            Log.Info(CameraLog.Tag, "add callbackId " + _deviceStateCallbackId.ToString());
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Camera"/> class.
        /// </summary>
        /// <param name="device">The camera device to access.</param>
        /// <exception cref="ArgumentException">Invalid CameraDevice type.</exception>
        /// <exception cref="NotSupportedException">The camera feature is not supported.</exception>
        /// <since_tizen> 3 </since_tizen>
        /// <feature> http://tizen.org/feature/camera </feature>
        public Camera(CameraDevice device)
        {
            Native.Create(device, out _handle).ThrowIfFailed("Failed to create camera instance");

            Capabilities    = new CameraCapabilities(this);
            Settings        = new CameraSettings(this);
            DisplaySettings = new CameraDisplaySettings(this);

            RegisterCallbacks();

            SetState(CameraState.Created);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Camera"/> class.
        /// </summary>
        /// <param name="device">The camera device to access.</param>
        /// <exception cref="ArgumentException">Invalid CameraDevice type.</exception>
        /// <exception cref="NotSupportedException">The camera feature is not supported.</exception>
        /// <since_tizen> 3 </since_tizen>
        /// <feature> http://tizen.org/feature/camera </feature>
        public Camera(CameraDevice device)
        {
            if (!Features.IsSupported(CameraFeatures.Camera))
            {
                throw new NotSupportedException("Camera feature is not supported.");
            }

            Native.Create(device, out _handle).ThrowIfFailed("Failed to create camera instance");

            Capabilities    = new CameraCapabilities(this);
            Settings        = new CameraSettings(this);
            DisplaySettings = new CameraDisplaySettings(this);

            RegisterCallbacks();

            SetState(CameraState.Created);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Releases the unmanaged resources used by the camera.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        /// <since_tizen> 3 </since_tizen>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // to be used if there are any other disposable objects
                }

                if (_handle != IntPtr.Zero)
                {
                    Native.Destroy(_handle);
                    _handle = IntPtr.Zero;
                }

                _disposed = true;
            }
        }
Ejemplo n.º 27
0
        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));
                }
                else
                {
                    packet.Dispose();
                }
            };
            CameraErrorFactory.ThrowIfError(Native.SetMediaPacketPreviewCallback(_handle, _mediaPacketPreviewCallback, IntPtr.Zero),
                                            "Setting media packet preview callback failed");
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Starts face detection.
        /// The camera must be in the <see cref="CameraState.Preview"/> state.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>
        /// http://tizen.org/privilege/camera
        /// </privilege>
        /// <remarks>
        /// This should be called after <see cref="StartPreview"/> is started.
        /// The Eventhandler set using <see cref="FaceDetected"/> is invoked when the face is detected in the preview frame.
        /// Internally, it starts continuously 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="ObjectDisposedException">The camera already has been disposed of.</exception>
        /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
        public void StartFaceDetection()
        {
            ValidateState(CameraState.Preview);

            _faceDetectedCallback = (IntPtr faces, int count, IntPtr userData) =>
            {
                var    result  = new List <FaceDetectionData>();
                IntPtr current = faces;

                for (int i = 0; i < count; i++)
                {
                    result.Add(new FaceDetectionData(current));
                    current = IntPtr.Add(current, Marshal.SizeOf <Native.DetectedFaceStruct>());
                }

                FaceDetected?.Invoke(this, new FaceDetectedEventArgs(result));
            };
            CameraErrorFactory.ThrowIfError(Native.StartFaceDetection(_handle, _faceDetectedCallback, IntPtr.Zero),
                                            "Failed to start face detection");
        }
Ejemplo n.º 29
0
 private void UnregisterPreviewCallback()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetPreviewCallback(_handle),
                                     "Unsetting preview callback failed");
     _previewCallback = null;
 }
Ejemplo n.º 30
0
 private void UnregisterHdrCaptureProgress()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetHdrCaptureProgressCallback(_handle),
                                     "Unsetting hdr capture progress is failed");
     _hdrCaptureProgressCallback = null;
 }