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" | |
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); | |
DaleCurtis
2012/09/07 16:24:01
Add a DCHECK_LE(frames_to_consume, destination->fr
henrika (OOO until Aug 14)
2012/09/10 07:23:04
Done.
| |
25 | |
26 int frames_to_write = frames_to_consume; | |
27 int frames_left = std::min(fifo_->frames(), frames_to_consume); | |
28 fifo_->Consume(destination, 0, frames_left); | |
29 frames_to_write -= frames_left; | |
30 int write_pos = frames_left; | |
31 | |
32 while (frames_to_write > 0) { | |
33 read_cb_.Run(bus_.get()); | |
DaleCurtis
2012/09/07 16:24:01
This is the part we can optimize later, as right n
| |
34 fifo_->Push(bus_.get()); | |
35 int to_consume = std::min(bus_->frames(), frames_to_write); | |
36 fifo_->Consume(destination, write_pos, to_consume); | |
37 write_pos += to_consume; | |
38 frames_to_write -= to_consume; | |
39 } | |
40 } | |
41 | |
42 } // namespace media | |
OLD | NEW |