/// <summary> /// Reads a resampled sequence of bytes from the <see cref="DmoResampler" /> and advances the position within the /// stream by the /// number of bytes read. /// </summary> /// <param name="buffer"> /// An array of bytes. When this method returns, the <paramref name="buffer" /> contains the specified /// byte array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + /// <paramref name="count" /> - 1) replaced by the bytes read from the current source. /// </param> /// <param name="offset"> /// The zero-based byte offset in the <paramref name="buffer" /> at which to begin storing the data /// read from the current stream. /// </param> /// <param name="count">The maximum number of bytes to read from the current source.</param> /// <returns>The total number of bytes read into the buffer.</returns> public override int Read(byte[] buffer, int offset, int count) { lock (LockObj) { int read = 0; while (read < count) { MediaObject mediaObject = Resampler.MediaObject; if (mediaObject.IsReadyForInput(0)) { var bytesToRead = (int)OutputToInput(count - read); _readBuffer = _readBuffer.CheckBuffer(bytesToRead); int bytesRead = base.Read(_readBuffer, 0, bytesToRead); if (bytesRead <= 0) { break; } if (_disposed) { break; } if (InputBuffer.MaxLength < bytesRead) { InputBuffer.Dispose(); InputBuffer = new MediaBuffer(bytesRead); } InputBuffer.Write(_readBuffer, 0, bytesRead); mediaObject.ProcessInput(0, InputBuffer); OutputBuffer.Reset(); do { var outputBuffer = (MediaBuffer)OutputBuffer.Buffer; if (outputBuffer.MaxLength < count) { outputBuffer.Dispose(); OutputBuffer.Buffer = new MediaBuffer(count); } OutputBuffer.Buffer.SetLength(0); mediaObject.ProcessOutput(ProcessOutputFlags.None, new[] { OutputBuffer }, 1); if (OutputBuffer.Length <= 0) { Debug.WriteLine("DmoResampler::Read: No data in output buffer."); break; } OutputBuffer.Read(buffer, offset + read); read += OutputBuffer.Length; } while (/*_outputBuffer.DataAvailable*/ false); //todo: Implement DataAvailable } else { Debug.WriteLine("Case of not ready for input is not implemented yet."); //todo: . } } return(read); } }