Skip to content

Commit

Permalink
Read last data from Output Buffer before discarding it
Browse files Browse the repository at this point in the history
  • Loading branch information
goddogthedoggod committed Mar 9, 2020
1 parent 1f2cbc7 commit 341d92b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions NAudio/MediaFoundation/MediaFoundationTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public int Read(byte[] buffer, int offset, int count)
EndStreamAndDrain();
// resampler might have given us a little bit more to return
bytesWritten += ReadFromOutputBuffer(buffer, offset + bytesWritten, count - bytesWritten);
ClearOutputBuffer();
break;
}

Expand Down Expand Up @@ -170,14 +171,18 @@ private void EndStreamAndDrain()
{
read = ReadFromTransform();
} while (read > 0);
outputBufferCount = 0;
outputBufferOffset = 0;
inputPosition = 0;
outputPosition = 0;
transform.ProcessMessage(MFT_MESSAGE_TYPE.MFT_MESSAGE_NOTIFY_END_STREAMING, IntPtr.Zero);
initializedForStreaming = false;
}

private void ClearOutputBuffer()
{
outputBufferCount = 0;
outputBufferOffset = 0;
}

/// <summary>
/// Attempts to read from the transform
/// Some useful info here:
Expand Down Expand Up @@ -280,6 +285,7 @@ public void Reposition()
if (initializedForStreaming)
{
EndStreamAndDrain();
ClearOutputBuffer();
InitializeTransformForStreaming();
}
}
Expand Down

0 comments on commit 341d92b

Please sign in to comment.