Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/base/audio_pull_fifo.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace media { | |
| 10 | |
| 11 AudioPullFifo::AudioPullFifo(int channels, int frames, | |
|
DaleCurtis
2012/09/07 13:48:38
Do we really need |read_frames|? It's kind of conf
henrika (OOO until Aug 14)
2012/09/07 16:06:42
Done.
| |
| 12 const ReadCB& read_cb, int read_frames) | |
| 13 : read_cb_(read_cb) { | |
| 14 DCHECK_LE(read_frames, frames); | |
|
DaleCurtis
2012/09/07 13:48:38
I don't think you should make this assumption sinc
henrika (OOO until Aug 14)
2012/09/07 16:06:42
Done.
| |
| 15 audio_fifo_.reset(new AudioFifo(channels, frames)); | |
| 16 audio_bus_ = AudioBus::Create(channels, read_frames); | |
| 17 } | |
| 18 | |
| 19 AudioPullFifo::~AudioPullFifo() { | |
| 20 read_cb_.Reset(); | |
| 21 } | |
| 22 | |
| 23 void AudioPullFifo::Consume(AudioBus* destination, int frames_to_consume) { | |
| 24 DCHECK(destination); | |
| 25 | |
| 26 if (frames_to_consume > audio_fifo_->frames_in_fifo()) { | |
| 27 // We don't have enough data in the FIFO to fulfill the request and must | |
| 28 // ask the provider for more data. | |
| 29 FillBuffer(frames_to_consume - audio_fifo_->frames_in_fifo()); | |
|
DaleCurtis
2012/09/07 13:48:38
Per my comment above, if you don't pre-consume the
henrika (OOO until Aug 14)
2012/09/07 16:06:42
Done.
| |
| 30 } | |
| 31 | |
| 32 // We are now able to copy the requested amount of data to the destination. | |
| 33 audio_fifo_->Consume(destination, frames_to_consume); | |
| 34 } | |
| 35 | |
| 36 void AudioPullFifo::FillBuffer(int frames) { | |
| 37 // Keep asking the provider to give us data until we have received at least | |
| 38 // |frames| number of audio data. Push new data to the FIFO in segments with | |
| 39 // the same size as the audio bus (set by |read_frames| in the ctor). | |
| 40 int frames_provided = 0; | |
| 41 while (frames_provided < frames) { | |
| 42 // Read audio data from the provider asking for |read_frames|. | |
| 43 read_cb_.Run(audio_bus_.get()); | |
| 44 | |
| 45 // Add the acquired data to the FIFO. | |
| 46 audio_fifo_->Push(audio_bus_.get()); | |
| 47 | |
| 48 // Keep adding to the FIFO until we have added at least |frames| number | |
| 49 // of frames. | |
| 50 frames_provided += audio_bus_->frames(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 } // namespace media | |
| OLD | NEW |