/// <summary> /// Disposes the <see cref="MediaFoundationEncoder" />. /// </summary> /// <param name="disposing"> /// True to release both managed and unmanaged resources; false to release only unmanaged /// resources. /// </param> protected virtual void Dispose(bool disposing) { if (!_disposed) { if (_sinkWriter != null && !_sinkWriter.IsDisposed) { //thanks to martin48 (and naudio??) for providing the following source code (see http://cscore.codeplex.com/discussions/574280): SinkWriterStatistics statistics = _sinkWriter.GetStatistics(_streamIndex); if (statistics.DwByteCountQueued > 0 || statistics.QwNumSamplesReceived > 0) { _sinkWriter.Finalize(); } _sinkWriter.Dispose(); _sinkWriter = null; } if (_targetStream != null) { _targetStream.Flush(); _targetStream.Dispose(); _targetStream = null; } } _disposed = true; }
public void Stop() { logger.Debug("MfWriter::Stop()"); if (sinkWriter != null) { sinkWriter.Finalize(); } }
private void PerformEncode(SinkWriter writer, int streamIndex, IWaveProvider inputProvider) { int maxLength = inputProvider.WaveFormat.AverageBytesPerSecond * 4; var managedBuffer = new byte[maxLength]; writer.BeginWriting(); long position = 0; long duration; do { duration = ConvertOneBuffer(writer, streamIndex, inputProvider, position, managedBuffer); position += duration; } while (duration > 0); writer.Finalize(); }
public void Dispose() { _writer.Finalize(); _writer.Dispose(); }