private void UnregisterExtraPreviewCallback() { Native.UnsetExtraPreviewCallback(_handle). ThrowIfFailed("Failed to unset extra preview callback."); _extraPreviewCallback = null; }
private void Create(CameraDevice device) { CameraDeviceType cameraDeviceType = CameraDeviceType.BuiltIn; try { using (var cameraDeviceManager = new CameraDeviceManager()) { var deviceInfo = cameraDeviceManager.GetDeviceInformation(); if (!deviceInfo.Any()) { throw new InvalidOperationException("There's no available camera device."); } cameraDeviceType = deviceInfo.First().Type; } } catch (NotSupportedException e) { Log.Info(CameraLog.Tag, $"CameraDeviceManager is not supported. {e.Message}. Not error."); } if (cameraDeviceType == CameraDeviceType.BuiltIn || cameraDeviceType == CameraDeviceType.Usb) { Native.Create(device, out _handle). ThrowIfFailed($"Failed to create {cameraDeviceType.ToString()} camera"); } else { Native.CreateNetworkCamera(device, out _handle). ThrowIfFailed($"Failed to create {cameraDeviceType.ToString()} camera"); } }
private void Create(CameraDevice device) { CameraDeviceType cameraDeviceType = CameraDeviceType.BuiltIn; try { _cameraDeviceManager = new CameraDeviceManager(); var deviceInfo = _cameraDeviceManager.GetDeviceInformation(); Log.Info(CameraLog.Tag, deviceInfo.ToString()); cameraDeviceType = deviceInfo.First().Type; } catch (NotSupportedException e) { Tizen.Log.Info(CameraLog.Tag, $"CameraDeviceManager is not supported. {e.Message}. Not error."); } if (cameraDeviceType == CameraDeviceType.BuiltIn || cameraDeviceType == CameraDeviceType.Usb) { Native.Create(device, out _handle). ThrowIfFailed($"Failed to create {cameraDeviceType.ToString()} camera"); } else { Native.CreateNetworkCamera(device, out _handle). ThrowIfFailed($"Failed to create {cameraDeviceType.ToString()} camera"); } }
private void UnregisterHdrCaptureProgress() { Native.UnsetHdrCaptureProgressCallback(_handle). ThrowIfFailed("Failed to unset hdr capture progres callback."); _hdrCaptureProgressCallback = null; }
/// <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"); }
private void UnregisterMediaPacketPreviewCallback() { Native.UnsetMediaPacketPreviewCallback(_handle). ThrowIfFailed("Failed to unset media packet preview callback."); _mediaPacketPreviewCallback = null; }
/// <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> /// <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"/> /// <since_tizen> 3 </since_tizen> /// <privilege> http://tizen.org/privilege/camera </privilege> /// <feature> http://tizen.org/feature/camera </feature> /// <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(() => { Native.StopContinuousCapture(_handle).ThrowIfFailed("Failed to cancel the continuous capture"); SetState(CameraState.Captured); }); } Native.StartContinuousCapture(_handle, count, interval, _capturingCallback, _captureCompletedCallback). ThrowIfFailed("Failed to start the continuous capture."); SetState(CameraState.Capturing); }
/// <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); }
/// <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); }
private static void UnregisterDeviceStateChangedCallback() { Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId). ThrowIfFailed("Failed to unset device state changed callback."); _deviceStateChangedCallback = null; _deviceStateCallbackId = 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); }
/// <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); }
private void UnregisterPreviewCallback() { Native.UnsetPreviewCallback(_handle). ThrowIfFailed("Failed to unset preview callback."); _previewBuffer?.Dispose(); _previewBuffer = null; _previewCallback = null; }
/// <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> /// <feature> http://tizen.org/feature/camera </feature> /// <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); Native.StartCapture(_handle, _capturingCallback, _captureCompletedCallback). ThrowIfFailed("Failed to start the camera capture."); SetState(CameraState.Capturing); }
private void RegisterErrorCallback() { _errorCallback = (error, current, _) => { ErrorOccurred?.Invoke(this, new CameraErrorOccurredEventArgs(error, current)); }; Native.SetErrorCallback(_handle, _errorCallback). ThrowIfFailed("Setting error callback failed"); }
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 RegisterHdrCaptureProgress() { _hdrCaptureProgressCallback = (percent, _) => { _hdrCaptureProgress?.Invoke(this, new HdrCaptureProgressEventArgs(percent)); }; Native.SetHdrCaptureProgressCallback(_handle, _hdrCaptureProgressCallback). ThrowIfFailed("Failed to set Hdr capture progress callback."); }
private void RegisterFocusStateChanged() { _focusStateChangedCallback = (state, _) => { FocusStateChanged?.Invoke(this, new CameraFocusStateChangedEventArgs(state)); }; Native.SetFocusStateChangedCallback(_handle, _focusStateChangedCallback). ThrowIfFailed("Failed to set focus changed callback."); }
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 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 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()); }
/// <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() { ValidateNotDisposed(); if (_faceDetectedCallback == null) { throw new InvalidOperationException("The face detection is not started."); } Native.StopFaceDetection(_handle).ThrowIfFailed("Failed to stop the face detection."); _faceDetectedCallback = null; }
private void CreateNativeCameraDevice(CameraDeviceType type, CameraDevice device) { if (type == CameraDeviceType.BuiltIn || type == CameraDeviceType.Usb) { Native.Create(device, out _handle). ThrowIfFailed($"Failed to create {type} camera"); } else { Native.CreateNetworkCamera(device, out _handle). ThrowIfFailed($"Failed to create {type} camera"); } }
/// <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; } }
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."); }
/// <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> /// <feature> http://tizen.org/feature/camera </feature> /// <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)); }; Native.StartFaceDetection(_handle, _faceDetectedCallback). ThrowIfFailed("Failed to start face detection"); }
/// <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> /// <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 StopFocusing() { ValidateState(CameraState.Preview, CameraState.Captured); Native.CancelFocusing(_handle).ThrowIfFailed("Failed to cancel the camera focus."); }
/// <summary> /// Starts camera auto-focusing, asynchronously. /// The camera must be in the <see cref="CameraState.Preview"/> or the <see cref="CameraState.Captured"/> state. /// </summary> /// <param name="continuous">Continuous auto focus.</param> /// <since_tizen> 3 </since_tizen> /// <privilege> http://tizen.org/privilege/camera </privilege> /// <feature> http://tizen.org/feature/camera </feature> /// <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); Native.StartFocusing(_handle, continuous).ThrowIfFailed("Failed to cancel the camera focus."); }