Chromium Code Reviews| Index: media/base/audio_pull_fifo.cc |
| diff --git a/media/base/audio_pull_fifo.cc b/media/base/audio_pull_fifo.cc |
| index 4943591b7c2cdd30c1b499b17250a083eb3654f9..88fdebf8533ccc24f0044d8cfc90d51536647a03 100644 |
| --- a/media/base/audio_pull_fifo.cc |
| +++ b/media/base/audio_pull_fifo.cc |
| @@ -7,53 +7,56 @@ |
| #include <algorithm> |
| #include "base/logging.h" |
| +#include "media/base/audio_bus.h" |
| namespace media { |
| AudioPullFifo::AudioPullFifo(int channels, int frames, const ReadCB& read_cb) |
| - : read_cb_(read_cb) { |
| - fifo_.reset(new AudioFifo(channels, frames)); |
| - bus_ = AudioBus::Create(channels, frames); |
| -} |
| + : read_cb_(read_cb), |
| + fifo_(AudioBus::Create(channels, frames)), |
| + fifo_index_(frames) {} |
| -AudioPullFifo::~AudioPullFifo() { |
| - read_cb_.Reset(); |
| -} |
| +AudioPullFifo::~AudioPullFifo() {} |
| void AudioPullFifo::Consume(AudioBus* destination, int frames_to_consume) { |
| - DCHECK(destination); |
| DCHECK_LE(frames_to_consume, destination->frames()); |
| - int write_pos = 0; |
| int remaining_frames_to_provide = frames_to_consume; |
| // Try to fulfill the request using what's available in the FIFO. |
| - ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos); |
| + int frames_read = ReadFromFifo(destination, remaining_frames_to_provide, 0); |
| + int write_pos = frames_read; |
| + remaining_frames_to_provide -= frames_read; |
| // Get the remaining audio frames from the producer using the callback. |
| while (remaining_frames_to_provide > 0) { |
| + DCHECK_EQ(fifo_index_, fifo_->frames()); |
| + fifo_index_ = 0; |
| + |
| // Fill up the FIFO by acquiring audio data from the producer. |
| - read_cb_.Run(write_pos, bus_.get()); |
| - fifo_->Push(bus_.get()); |
| + read_cb_.Run(write_pos, fifo_.get()); |
| // Try to fulfill the request using what's available in the FIFO. |
| - ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos); |
| + frames_read = |
| + ReadFromFifo(destination, remaining_frames_to_provide, write_pos); |
| + write_pos += frames_read; |
| + remaining_frames_to_provide -= frames_read; |
| } |
| } |
| -void AudioPullFifo::Clear() { |
| - fifo_->Clear(); |
| -} |
| +void AudioPullFifo::Clear() { fifo_index_ = fifo_->frames(); } |
| -void AudioPullFifo::ReadFromFifo(AudioBus* destination, |
| - int* frames_to_provide, |
| - int* write_pos) { |
| - DCHECK(frames_to_provide); |
| - DCHECK(write_pos); |
| - int frames = std::min(fifo_->frames(), *frames_to_provide); |
| - fifo_->Consume(destination, *write_pos, frames); |
| - *write_pos += frames; |
| - *frames_to_provide -= frames; |
| +int AudioPullFifo::ReadFromFifo(AudioBus* destination, |
| + int frames_to_provide, |
| + int write_pos) { |
| + int frames = std::min(frames_to_provide, fifo_->frames() - fifo_index_); |
|
no longer working on chromium
2013/05/20 08:56:00
nit, it seems it will be quite common for the |fra
DaleCurtis
2013/05/21 23:26:29
There's a frames > 0 check on the for() loop, but
|
| + for (int ch = 0; ch < fifo_->channels() && frames > 0; ++ch) { |
| + const float* src = fifo_->channel(ch) + fifo_index_; |
| + float* dest = destination->channel(ch) + write_pos; |
| + memcpy(dest, src, frames * sizeof(*src)); |
| + } |
| + fifo_index_ += frames; |
| + return frames; |
| } |
| } // namespace media |