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 <algorithm> | |
6 | |
7 #include "media/base/audio_pull_fifo.h" | |
DaleCurtis
2012/09/10 08:28:26
Needs to be first include, move above <algorithm>
henrika (OOO until Aug 14)
2012/09/10 09:35:31
Done.
| |
8 | |
9 #include "base/logging.h" | |
10 | |
11 namespace media { | |
12 | |
13 AudioPullFifo::AudioPullFifo(int channels, int frames, const ReadCB& read_cb) | |
14 : read_cb_(read_cb) { | |
15 fifo_.reset(new AudioFifo(channels, frames)); | |
16 bus_ = AudioBus::Create(channels, 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 DCHECK_LE(frames_to_consume, destination->frames()); | |
26 | |
27 int write_pos = 0; | |
28 int remaining_frames_to_provide = frames_to_consume; | |
29 | |
30 // Try to fulfill the request using what's available in the FIFO. | |
31 ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos); | |
32 | |
33 // Get the remaining audio frames from the producer using the callback. | |
34 while (remaining_frames_to_provide > 0) { | |
35 // Fill up the FIFO by acquiring audio data from the producer. | |
36 read_cb_.Run(bus_.get()); | |
37 fifo_->Push(bus_.get()); | |
38 | |
39 // Try to fulfill the request using what's available in the FIFO. | |
40 ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos); | |
41 } | |
42 } | |
43 | |
44 void AudioPullFifo::ReadFromFifo(AudioBus* destination, | |
45 int* frames_to_provide, | |
46 int* write_pos) { | |
47 int frames = std::min(fifo_->frames(), *frames_to_provide); | |
DaleCurtis
2012/09/10 08:28:26
DCHECK() frames_to_provide and write_pos.
henrika (OOO until Aug 14)
2012/09/10 09:35:31
Done.
| |
48 fifo_->Consume(destination, *write_pos, frames); | |
49 *write_pos += frames; | |
50 *frames_to_provide -= frames; | |
51 } | |
52 | |
53 } // namespace media | |
OLD | NEW |