예제 #1
0
        /// <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;
        }
예제 #2
0
        public void Stop()
        {
            logger.Debug("MfWriter::Stop()");

            if (sinkWriter != null)
            {
                sinkWriter.Finalize();
            }
        }
예제 #3
0
        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();
        }
예제 #4
0
 public void Dispose()
 {
     _writer.Finalize();
     _writer.Dispose();
 }