示例#1
0
        public RecordingModel(Settings Settings,
                              ILocalizationProvider Loc,
                              ISystemTray SystemTray,
                              IPreviewWindow PreviewWindow,
                              IAudioSource AudioSource,
                              WebcamModel WebcamModel,
                              KeymapViewModel Keymap,
                              TimerModel TimerModel,
                              IMessageProvider MessageProvider,
                              IFFmpegViewsProvider FFmpegViewsProvider,
                              IFpsManager FpsManager) : base(Settings, Loc)
        {
            _systemTray          = SystemTray;
            _previewWindow       = PreviewWindow;
            _audioSource         = AudioSource;
            _webcamModel         = WebcamModel;
            _keymap              = Keymap;
            _timerModel          = TimerModel;
            _messageProvider     = MessageProvider;
            _ffmpegViewsProvider = FFmpegViewsProvider;
            _fpsManager          = FpsManager;

            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            TimerModel.CountdownElapsed += InternalStartRecording;
        }
示例#2
0
        public RecordingModel(Settings Settings,
                              ISystemTray SystemTray,
                              IPreviewWindow PreviewWindow,
                              IAudioSource AudioSource,
                              KeymapViewModel Keymap,
                              TimerModel TimerModel,
                              IFpsManager FpsManager) : base(Settings)
        {
            _systemTray    = SystemTray;
            _previewWindow = PreviewWindow;
            _audioSource   = AudioSource;
            _keymap        = Keymap;
            _timerModel    = TimerModel;
            _fpsManager    = FpsManager;

            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            TimerModel.CountdownElapsed += InternalStartRecording;
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of <see cref="IRecorder"/> writing to <see cref="IVideoFileWriter"/>.
        /// </summary>
        /// <param name="VideoWriter">The <see cref="IVideoFileWriter"/> to write to.</param>
        /// <param name="ImageProvider">The image source.</param>
        /// <param name="FrameRate">Video Frame Rate.</param>
        /// <param name="AudioProvider">The audio source. null = no audio.</param>
        public Recorder(IVideoFileWriter VideoWriter, IImageProvider ImageProvider, int FrameRate,
                        IAudioProvider AudioProvider = null,
                        IFpsManager FpsManager       = null)
        {
            _videoWriter   = VideoWriter ?? throw new ArgumentNullException(nameof(VideoWriter));
            _imageProvider = ImageProvider ?? throw new ArgumentNullException(nameof(ImageProvider));
            _audioProvider = AudioProvider;
            _fpsManager    = FpsManager;

            _cancellationTokenSource = new CancellationTokenSource();
            _cancellationToken       = _cancellationTokenSource.Token;

            if (FrameRate <= 0)
            {
                throw new ArgumentException("Frame Rate must be possitive", nameof(FrameRate));
            }

            _frameRate = FrameRate;

            _continueCapturing = new ManualResetEvent(false);

            if (VideoWriter.SupportsAudio && AudioProvider != null)
            {
                var wf = AudioProvider.WaveFormat;

                _audioBytesPerFrame = (int)((1.0 / FrameRate)
                                            * wf.SampleRate
                                            * wf.Channels
                                            * (wf.BitsPerSample / 8.0));

                _audioChunkBytes = (int)(_audioBytesPerFrame * (FrameRate * AudioChunkLengthMs / 1000.0));
            }
            else
            {
                _audioProvider = null;
            }

            _sw = new Stopwatch();

            _recordTask = Task.Factory.StartNew(async() => await DoRecord(), TaskCreationOptions.LongRunning);
        }