示例#1
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <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);
        }
示例#2
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <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.");
        }
示例#3
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <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.");
        }
示例#4
0
文件: Camera.cs 项目: yourina/TizenFX
 private static void UnregisterDeviceStateChangedCallback()
 {
     CameraErrorFactory.ThrowIfError(Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId),
                                     "Unsetting device state changed callback failed");
     _deviceStateChangedCallback = null;
     _deviceStateCallbackId      = 0;
 }
示例#5
0
        /// <summary>
        /// Sets the position to move horizontally.
        /// </summary>
        /// <param name="type">The PTZ move type. <seealso cref="CameraPtzMoveType"/>.</param>
        /// <param name="panStep">The pan step.</param>
        /// <since_tizen> 3 </since_tizen>
        /// <feature> http://tizen.org/feature/camera </feature>
        /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
        /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception>
        public void SetPan(CameraPtzMoveType type, int panStep)
        {
            ValidationUtil.ValidateEnum(typeof(CameraPtzMoveType), type, nameof(type));

            CameraErrorFactory.ThrowIfError(Native.SetPan(_camera.GetHandle(), type, panStep),
                                            "Failed to set the camera pan type.");
        }
示例#6
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <summary>
        /// Changes the camera device.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="device">The hardware camera to access.</param>
        /// <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));

            CameraErrorFactory.ThrowIfError(Native.ChangeDevice(_handle, device),
                                            "Failed to change the camera device");
        }
示例#7
0
文件: Camera.cs 项目: yourina/TizenFX
 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");
 }
示例#8
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <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);
        }
示例#9
0
文件: Camera.cs 项目: yourina/TizenFX
 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");
 }
示例#10
0
文件: Camera.cs 项目: yourina/TizenFX
 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");
 }
示例#11
0
文件: Camera.cs 项目: yourina/TizenFX
 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");
 }
示例#12
0
文件: Camera.cs 项目: yourina/TizenFX
 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");
 }
示例#13
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <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);
        }
示例#14
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <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>
        /// <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);

            CameraErrorFactory.ThrowIfError(Native.StartPreview(_handle),
                                            "Failed to start the camera preview.");

            // Update by StateChangedCallback can be delayed for dozens of milliseconds.
            SetState(CameraState.Preview);
        }
示例#15
0
文件: Camera.cs 项目: yourina/TizenFX
 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");
 }
示例#16
0
文件: Camera.cs 项目: yourina/TizenFX
        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());
        }
示例#17
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <summary>
        /// Stops face detection.
        /// </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 StopFaceDetection()
        {
            if (_faceDetectedCallback == null)
            {
                throw new InvalidOperationException("The face detection is not started.");
            }

            CameraErrorFactory.ThrowIfError(Native.StopFaceDetection(_handle),
                                            "Failed to stop the face detection.");

            _faceDetectedCallback = null;
        }
示例#18
0
        private IList <CameraPixelFormat> GetSupportedPreviewPixelFormats()
        {
            List <CameraPixelFormat> previewFormats = new List <CameraPixelFormat>();

            NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) =>
            {
                previewFormats.Add(format);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported preview formats.");

            return(previewFormats.AsReadOnly());
        }
示例#19
0
        private IList <CameraEffectMode> GetSupportedEffects()
        {
            List <CameraEffectMode> effectModes = new List <CameraEffectMode>();

            NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) =>
            {
                effectModes.Add(effect);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported camera effects.");

            return(effectModes.AsReadOnly());
        }
示例#20
0
        private IList <Rotation> GetSupportedStreamRotations()
        {
            List <Rotation> streamRotations = new List <Rotation>();

            NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) =>
            {
                streamRotations.Add(streamRotation);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported camera rotations.");

            return(streamRotations.AsReadOnly());
        }
示例#21
0
        private IList <CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height)
        {
            List <CameraFps> fpsByResolution = new List <CameraFps>();

            NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) =>
            {
                fpsByResolution.Add(fps);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(),
                                                                                               width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions.");

            return(fpsByResolution.AsReadOnly());
        }
示例#22
0
        private IList <CameraFps> GetSupportedPreviewFps()
        {
            List <CameraFps> previewFps = new List <CameraFps>();

            NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) =>
            {
                previewFps.Add(fps);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported camera fps");

            return(previewFps.AsReadOnly());
        }
示例#23
0
        private IList <CameraSceneMode> GetSupportedSceneModes()
        {
            List <CameraSceneMode> sceneModes = new List <CameraSceneMode>();

            NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) =>
            {
                sceneModes.Add(sceneMode);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported scene modes.");

            return(sceneModes.AsReadOnly());
        }
示例#24
0
        private IList <Flips> GetSupportedStreamFlips()
        {
            List <Flips> streamFlips = new List <Flips>();

            NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) =>
            {
                streamFlips.Add(streamFlip);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported camera flips.");

            return(streamFlips.AsReadOnly());
        }
示例#25
0
        private IList <CameraPtzType> GetSupportedPtzTypes()
        {
            List <CameraPtzType> ptzTypes = new List <CameraPtzType>();

            NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) =>
            {
                ptzTypes.Add(ptzType);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported Ptz types.");

            return(ptzTypes.AsReadOnly());
        }
示例#26
0
        private IList <Size> GetSupportedCaptureResolutions()
        {
            List <Size> cameraResolutions = new List <Size>();

            NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) =>
            {
                cameraResolutions.Add(new Size(width, height));
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported capture resolutions");

            return(cameraResolutions.AsReadOnly());
        }
示例#27
0
        private IList <CameraIsoLevel> GetSupportedIsoLevels()
        {
            List <CameraIsoLevel> isoLevels = new List <CameraIsoLevel>();

            NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) =>
            {
                isoLevels.Add(iso);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported Iso levels.");

            return(isoLevels.AsReadOnly());
        }
示例#28
0
        private IList <CameraAutoFocusMode> GetSupportedAutoFocusModes()
        {
            List <CameraAutoFocusMode> autoFocusModes = new List <CameraAutoFocusMode>();

            NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) =>
            {
                autoFocusModes.Add(mode);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported Auto focus modes.");

            return(autoFocusModes.AsReadOnly());
        }
示例#29
0
        private IList <CameraWhiteBalance> GetSupportedWhitebalances()
        {
            List <CameraWhiteBalance> whitebalances = new List <CameraWhiteBalance>();

            NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) =>
            {
                whitebalances.Add(whiteBalance);
                return(true);
            };
            CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero),
                                            "Failed to get the supported white balance.");

            return(whitebalances.AsReadOnly());
        }
示例#30
0
文件: Camera.cs 项目: yourina/TizenFX
        /// <summary>
        /// Initializes a new instance of the <see cref="Camera"/> class.
        /// </summary>
        /// <feature>http://tizen.org/feature/camera</feature>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="device">The camera device to access.</param>
        public Camera(CameraDevice device)
        {
            if (!Features.IsSupported(CameraFeatures.Camera))
            {
                throw new NotSupportedException("Camera feature is not supported.");
            }

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

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

            RegisterCallbacks();

            SetState(CameraState.Created);
        }