/// <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)
                {
                    //thanks to martin48 (and naudio??) for providing the following source code (see http://cscore.codeplex.com/discussions/574280):
                    MFSinkWriterStatistics statistics = _sinkWriter.GetStatistics(_streamIndex);
                    if (statistics.ByteCountQueued > 0 || statistics.NumSamplesReceived > 0)
                    {
                        _sinkWriter.FinalizeWriting();
                    }

                    _sinkWriter.Dispose();
                    _sinkWriter = null;
                }
                if (_targetStream != null)
                {
                    _targetStream.Flush();
                    _targetStream.Dispose();
                    _targetStream = null;
                }
                if (_targetBaseStream != null && !_targetBaseStream.IsClosed())
                {
                    _targetBaseStream.Flush();
                    _targetBaseStream.Dispose();
                }
            }
            _disposed = true;
        }
示例#2
0
 /// <summary>
 /// Gets statistics about the performance of the sink writer.
 /// </summary>
 /// <returns>HRESULT</returns>
 public unsafe int GetStatisticsNative(int streamIndex, out MFSinkWriterStatistics statistics)
 {
     fixed(void *ptr = &statistics)
     {
         return(InteropCalls.CalliMethodPtr(_basePtr, streamIndex, ptr, ((void **)(*(void **)_basePtr))[13]));
     }
 }
示例#3
0
 /// <summary>
 /// Gets statistics about the performance of the sink writer.
 /// </summary>
 /// <param name="streamIndex">The zero-based index of a stream to query, or <see cref="MF_SINK_WRITER_ALL_STREAMS"/> to query the media sink itself.</param>
 /// <param name="statistics">Receives statistics about the performance of the sink writer.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetStatisticsNative(int streamIndex, out MFSinkWriterStatistics statistics)
 {
     statistics    = default(MFSinkWriterStatistics);
     statistics.Cb = Marshal.SizeOf(statistics);
     fixed(void *ptr = &statistics)
     {
         return(InteropCalls.CalliMethodPtr(UnsafeBasePtr, streamIndex, ptr, ((void **)(*(void **)UnsafeBasePtr))[13]));
     }
 }
示例#4
0
 /// <summary>
 /// Gets statistics about the performance of the sink writer.
 /// </summary>
 /// <returns>HRESULT</returns>
 public unsafe int GetStatisticsNative(int streamIndex, out MFSinkWriterStatistics statistics)
 {
     fixed (void* ptr = &statistics)
     {
         return InteropCalls.CalliMethodPtr(_basePtr, streamIndex, ptr, ((void**)(*(void**)_basePtr))[13]);
     }
 }
示例#5
0
 /// <summary>
 /// Gets statistics about the performance of the sink writer.
 /// </summary>
 /// <param name="streamIndex">The zero-based index of a stream to query, or <see cref="MF_SINK_WRITER_ALL_STREAMS"/> to query the media sink itself.</param>
 /// <param name="statistics">Receives statistics about the performance of the sink writer.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetStatisticsNative(int streamIndex, out MFSinkWriterStatistics statistics)
 {
     statistics = default(MFSinkWriterStatistics);
     statistics.Cb = Marshal.SizeOf(statistics);
     fixed (void* ptr = &statistics)
     {
         return InteropCalls.CalliMethodPtr(UnsafeBasePtr, streamIndex, ptr, ((void**)(*(void**)UnsafeBasePtr))[13]);
     }
 }