/// <summary> /// Use Source Reader to allocate a sample /// </summary> /// <param name="sourceReader">The Source Reader</param> /// <param name="dwStreamIndex">The stream to pull data from</param> /// <param name="dwControlFlags">A bitwise OR of zero or more flags from the MF_SOURCE_READER_CONTROL_FLAG enumeration</param> /// <param name="pdwActualStreamIndex">Receives the zero-based index of the stream</param> /// <param name="pdwStreamFlags">Receives a bitwise OR of zero or more flags from the MF_SOURCE_READER_FLAG enumeration</param> /// <param name="pllTimestamp">Receives the time stamp of the sample, or the time of the stream event indicated in pdwStreamFlags. The time is given in 100-nanosecond units</param> public void ReadSampleFrom( IMFSourceReader sourceReader, uint dwStreamIndex, uint dwControlFlags, out uint pdwActualStreamIndex, out uint pdwStreamFlags, out ulong pllTimestamp) { // Once a sample is read avoid reading more samples if (this.read) { throw new InvalidOperationException("Already holding a sample"); } sourceReader.ReadSample(dwStreamIndex, dwControlFlags, out pdwActualStreamIndex, out pdwStreamFlags, out pllTimestamp, out this.sample); if (this.sample != null) { // Get the size of the media sample in bytes IMFMediaBuffer buffer = null; this.sample.GetBufferByIndex(0, out buffer); buffer.GetCurrentLength(out this.bufferSize); // Add the memory pressure of unmanaged memory to improve the garbage collector performance GC.AddMemoryPressure(this.bufferSize); } this.read = true; }
private void invokeDecodeComplete(IMFMediaBuffer buffer, int bufferLen) { if (buffer == null) { return; } int len = 0; buffer.GetCurrentLength(out len); if (bufferLen != len) { //todo: throw invalid data exception. return; } invokeDecodeCompleteEvent(buffer); }