| Index: media/base/audio_pull_fifo.cc
|
| diff --git a/media/base/audio_pull_fifo.cc b/media/base/audio_pull_fifo.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d28106a16884116789f039ee6798e274f9c6a267
|
| --- /dev/null
|
| +++ b/media/base/audio_pull_fifo.cc
|
| @@ -0,0 +1,54 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "media/base/audio_pull_fifo.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace media {
|
| +
|
| +AudioPullFifo::AudioPullFifo(int channels, int frames,
|
| + const ReadCB& read_cb, int read_frames)
|
| + : read_cb_(read_cb) {
|
| + DCHECK_LE(read_frames, frames);
|
| + audio_fifo_.reset(new AudioFifo(channels, frames));
|
| + audio_bus_ = AudioBus::Create(channels, read_frames);
|
| +}
|
| +
|
| +AudioPullFifo::~AudioPullFifo() {
|
| + read_cb_.Reset();
|
| +}
|
| +
|
| +void AudioPullFifo::Consume(AudioBus* destination, int frames_to_consume) {
|
| + DCHECK(destination);
|
| +
|
| + if (frames_to_consume > audio_fifo_->frames()) {
|
| + // We don't have enough data in the FIFO to fulfill the request and must
|
| + // ask the provider for more data.
|
| + FillBuffer(frames_to_consume - audio_fifo_->frames());
|
| + }
|
| +
|
| + // We are now able to copy the requested amount of data to the destination.
|
| + audio_fifo_->Consume(destination, frames_to_consume);
|
| +}
|
| +
|
| +void AudioPullFifo::FillBuffer(int frames) {
|
| + // Keep asking the provider to give us data until we have received at least
|
| + // |frames| number of audio data. Push new data to the FIFO in segments with
|
| + // the same size as the audio bus (set by |read_frames| in the ctor).
|
| + int frames_provided = 0;
|
| + while (frames_provided < frames) {
|
| + // Read audio data from the provider asking for |read_frames|.
|
| + read_cb_.Run(audio_bus_.get());
|
| +
|
| + // Add the acquired data to the FIFO.
|
| + audio_fifo_->Push(audio_bus_.get());
|
| +
|
| + // Keep adding to the FIFO until we have added at least |frames| number
|
| + // of frames.
|
| + frames_provided += audio_bus_->frames();
|
| + }
|
| +}
|
| +
|
| +} // namespace media
|
|
|