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; }
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; }
public void Dispose() { _continueEvent.Set(); _stopEvent.Set(); _loopTask.Wait(); _buffer = null; _audioWriter.Dispose(); _audioWriter = null; _audioProvider.Dispose(); _audioProvider = null; }
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); } }
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(); }
/// <summary> /// Writes all the Data in the decoder to a file /// </summary> /// <param name="Writer">Audio File Writer to write to</param> /// <param name="Offset">+ve for forward, -ve for backward</param> public void Write(IAudioFileWriter Writer, int Offset = 0) { long InitialPosition = Position; Position += Offset; int BlockLength = (int)Seconds2Bytes(2); byte[] Buffer = new byte[BlockLength]; var gch = GCHandle.Alloc(Buffer, GCHandleType.Pinned); while (HasData) { Bass.ChannelGetData(Handle, gch.AddrOfPinnedObject(), BlockLength); Writer.Write(Buffer, BlockLength); } gch.Free(); Writer.Dispose(); Position = InitialPosition; }
/// <summary> /// Override this method with the code to stop recording. /// </summary> protected override void OnStop() { _audioProvider?.Dispose(); _writer?.Dispose(); }