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

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

            _hdrCaptureProgressCallback = null;
        }
Example #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);
        }
Example #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.");
        }
Example #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");
        }
Example #6
0
 private static void UnregisterDeviceStateChangedCallback()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId),
                                     "Unsetting device state changed callback failed");
     _deviceStateChangedCallback = null;
     _deviceStateCallbackId      = 0;
 }
Example #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.");
        }
Example #8
0
        private static void UnregisterDeviceStateChangedCallback()
        {
            Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId).
            ThrowIfFailed("Unsetting device state changed callback failed");

            _deviceStateChangedCallback = null;
            _deviceStateCallbackId      = 0;
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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");
 }
Example #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);
        }
Example #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);
        }
Example #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");
 }
Example #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");
 }
Example #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");
 }
Example #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");
 }
Example #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");
        }
Example #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");
 }
Example #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;
        }
Example #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());
        }
Example #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);
        }
Example #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);
        }
Example #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;
            }
        }
Example #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");
        }
Example #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");
        }
Example #29
0
 private void UnregisterPreviewCallback()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetPreviewCallback(_handle),
                                     "Unsetting preview callback failed");
     _previewCallback = null;
 }
Example #30
0
 private void UnregisterHdrCaptureProgress()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetHdrCaptureProgressCallback(_handle),
                                     "Unsetting hdr capture progress is failed");
     _hdrCaptureProgressCallback = null;
 }