public void StartRecoding(String savePath) { FileSavePath = savePath + "BAR-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".avi"; //图像 IImageProvider imgProvider = null; try { imgProvider = GetImageProvider(); } catch (Exception e) { MessageBox.Show(e.Message); imgProvider?.Dispose(); return; } //声音 IAudioProvider audioProvider = null; try { Settings.Audio.Enabled = true; if (Settings.Audio.Enabled && !Settings.Audio.SeparateFilePerSource) { audioProvider = _audioSource.GetMixedAudioProvider(); } } catch (Exception e) { MessageBox.Show(e.Message); _audioSource?.Dispose(); return; } //视频写入 IVideoFileWriter videoEncoder; try { videoEncoder = GetVideoFileWriterWithPreview(imgProvider, audioProvider); } catch (Exception e) { MessageBox.Show(e.Message); imgProvider?.Dispose(); audioProvider?.Dispose(); return; } _recorder = new Recorder(videoEncoder, imgProvider, Settings.Video.FrameRate, audioProvider); _recorder.Start(); }
void Dispose(bool TerminateRecord, bool TerminateWrite) { if (_disposed) { return; } _disposed = true; _audioProvider?.Stop(); _audioProvider?.Dispose(); if (_videoWriter != null) { _cancellationTokenSource.Cancel(); _continueCapturing.Set(); if (TerminateRecord) { _recordTask.Wait(); } _videoWriter.Dispose(); _continueCapturing.Dispose(); } else { _audioWriter.Dispose(); } _imageProvider?.Dispose(); }
/// <summary> /// Frees all resources used by this instance. /// </summary> public void Dispose() { ThrowIfDisposed(); _audioProvider?.Stop(); _audioProvider?.Dispose(); if (_videoWriter != null) { _frames.CompleteAdding(); _continueCapturing.Set(); _recordTask.Wait(); _writeTask.Wait(); _videoWriter.Dispose(); _frames.Dispose(); _continueCapturing.Close(); } else { _audioWriter.Dispose(); } _imageProvider?.Dispose(); _disposed = true; }
/// <inheritdoc /> public void Dispose() { _imageProvider.Dispose(); foreach (var overlay in _overlays) { overlay?.Dispose(); } }
private void Dispose(bool terminateRecord) { if (_disposed) { return; } _disposed = true; if (_audioProvider != null) { _audioProvider.DataAvailable -= AudioProvider_DataAvailable; _audioProvider.Stop(); _audioProvider.Dispose(); _audioProvider = null; } if (_videoWriter != null) { _cancellationTokenSource.Cancel(); // Resume record loop if paused so it can exit _continueCapturing.Set(); if (terminateRecord) { _recordTask.Wait(); } try { if (_task != null && !_task.IsCompleted) { _task.GetAwaiter().GetResult(); } } catch { // Ignored in dispose } _videoWriter.Dispose(); _videoWriter = null; _continueCapturing.Dispose(); } else { _audioWriter.Dispose(); _audioWriter = null; } _imageProvider?.Dispose(); _imageProvider = null; }
async void Dispose(bool TerminateRecord) { if (_disposed) { return; } _disposed = true; _cancellationTokenSource.Cancel(); // Resume record loop if paused so it can exit _continueCapturing.Set(); // Ensure all threads exit before disposing resources. if (TerminateRecord) { _recordTask.Wait(); } try { if (_frameWriteTask != null) { await _frameWriteTask; } } catch { } try { if (_audioWriteTask != null) { await _audioWriteTask; } } catch { } if (_audioProvider != null) { _audioProvider.Stop(); _audioProvider.Dispose(); _audioProvider = null; } _imageProvider?.Dispose(); _imageProvider = null; _videoWriter.Dispose(); _videoWriter = null; _audioBuffer = _silenceBuffer = null; _continueCapturing.Dispose(); }
/// <summary> /// Frees resources. /// </summary> public void Dispose() { // Resume if Paused _continueCapturing?.Set(); // Video _stopCapturing.Set(); _recordThread.Join(); _imageProvider.Dispose(); _videoEncoder.Dispose(); }
/// <inheritdoc /> public void Dispose() { _imageProvider.Dispose(); if (_overlays == null) { return; } foreach (var overlay in _overlays) { overlay?.Dispose(); } }
/// <summary> /// Override this method with the code to stop recording. /// </summary> protected override void OnStop() { // Resume if Paused _continueCapturing?.Set(); // Video if (_recordThread != null) { if (_stopCapturing != null && !_stopCapturing.SafeWaitHandle.IsClosed) { _stopCapturing.Set(); } if (!_recordThread.Join(500)) { _recordThread.Abort(); } _recordThread = null; } if (_imageProvider != null) { _imageProvider.Dispose(); _imageProvider = null; } // WaitHandles if (_stopCapturing != null && !_stopCapturing.SafeWaitHandle.IsClosed) { _stopCapturing.Dispose(); _stopCapturing = null; } if (_continueCapturing != null && !_continueCapturing.SafeWaitHandle.IsClosed) { _continueCapturing.Dispose(); _continueCapturing = null; } // Writers if (_videoEncoder == null) { return; } _videoEncoder.Dispose(); _videoEncoder = null; }
public void Dispose() { _recording = false; _hook.Dispose(); _cancellationTokenSource.Cancel(); _recordTask.Wait(); _videoWriter.Dispose(); _videoWriter = null; _imageProvider?.Dispose(); _imageProvider = null; }
void Dispose(bool ErrorOccured) { // Resume if Paused _continueCapturing?.Set(); _stopCapturing.Set(); if (!ErrorOccured) { _recordTask.Wait(); } _imageProvider.Dispose(); _videoEncoder.Dispose(); }
void Dispose(bool TerminateRecord, bool TerminateWrite) { try { ThrowIfDisposed(); _audioProvider?.Stop(); _audioProvider?.Dispose(); if (_videoWriter != null) { _frames.CompleteAdding(); _continueCapturing.Set(); if (TerminateRecord) { _recordTask.Wait(); } if (TerminateWrite) { _writeTask.Wait(); } _videoWriter.Dispose(); _frames.Dispose(); _continueCapturing.Close(); } else { _audioWriter.Dispose(); } _imageProvider?.Dispose(); _disposed = true; } catch (Exception e) { Console.WriteLine(e); } }
private void Dispose(bool errorOccurred) { // Resume if Paused _continueCapturing.Set(); _stopCapturing.Set(); if (!errorOccurred) { _recordTask.Wait(); } _continueCapturing.Dispose(); _stopCapturing.Dispose(); _timing.Stop(); _imageProvider.Dispose(); _videoEncoder.Dispose(); }
void Dispose(bool TerminateRecord, bool TerminateWrite) { if (_disposed) { return; } _disposed = true; _audioProvider?.Stop(); _audioProvider?.Dispose(); if (_videoWriter != null) { _frames.CompleteAdding(); _continueCapturing.Set(); if (TerminateRecord) { _recordTask.Wait(); } if (TerminateWrite) { _writeTask.Wait(); } _videoWriter.Dispose(); _frames.Dispose(); _continueCapturing.Dispose(); } else { _audioWriter.Dispose(); } _imageProvider?.Dispose(); }
public void Dispose() { _imageSource.Dispose(); }
public void Dispose() { _regionProvider.Dispose(); }
public void Dispose() { _imageProvider.Dispose(); }