Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: media/base/audio_pull_fifo.cc

Issue 11410012: Collapse AudioRendererMixer and OnMoreDataResampler into AudioTransform. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: First draft. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/audio_pull_fifo.h" 5 #include "media/base/audio_pull_fifo.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 AudioPullFifo::AudioPullFifo(int channels, int frames, const ReadCB& read_cb) 13 AudioPullFifo::AudioPullFifo(int channels, int frames, const ReadCB& read_cb)
14 : read_cb_(read_cb) { 14 : read_cb_(read_cb),
15 output_frames_ready_(0) {
15 fifo_.reset(new AudioFifo(channels, frames)); 16 fifo_.reset(new AudioFifo(channels, frames));
16 bus_ = AudioBus::Create(channels, frames); 17 bus_ = AudioBus::Create(channels, frames);
17 } 18 }
18 19
19 AudioPullFifo::~AudioPullFifo() { 20 AudioPullFifo::~AudioPullFifo() {
20 read_cb_.Reset(); 21 read_cb_.Reset();
21 } 22 }
22 23
23 void AudioPullFifo::Consume(AudioBus* destination, int frames_to_consume) { 24 void AudioPullFifo::Consume(AudioBus* destination, int frames_to_consume) {
24 DCHECK(destination); 25 DCHECK(destination);
25 DCHECK_LE(frames_to_consume, destination->frames()); 26 DCHECK_LE(frames_to_consume, destination->frames());
26 27
27 int write_pos = 0; 28 int write_pos = 0;
28 int remaining_frames_to_provide = frames_to_consume; 29 int remaining_frames_to_provide = frames_to_consume;
29 30
30 // Try to fulfill the request using what's available in the FIFO. 31 // Try to fulfill the request using what's available in the FIFO.
31 ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos); 32 ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos);
32 33
33 // Get the remaining audio frames from the producer using the callback. 34 // Get the remaining audio frames from the producer using the callback.
34 while (remaining_frames_to_provide > 0) { 35 while (remaining_frames_to_provide > 0) {
36 output_frames_ready_ = write_pos;
scherkus (not reviewing) 2012/11/14 22:43:50 do we need to update output_frames_ready_ anywhere
DaleCurtis 2012/11/15 00:30:59 No, it's not valid to call Clear() during Consume(
37
35 // Fill up the FIFO by acquiring audio data from the producer. 38 // Fill up the FIFO by acquiring audio data from the producer.
36 read_cb_.Run(bus_.get()); 39 read_cb_.Run(bus_.get());
37 fifo_->Push(bus_.get()); 40 fifo_->Push(bus_.get());
38 41
39 // Try to fulfill the request using what's available in the FIFO. 42 // Try to fulfill the request using what's available in the FIFO.
40 ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos); 43 ReadFromFifo(destination, &remaining_frames_to_provide, &write_pos);
41 } 44 }
42 } 45 }
43 46
44 void AudioPullFifo::Clear() { 47 void AudioPullFifo::Clear() {
45 fifo_->Clear(); 48 fifo_->Clear();
46 } 49 }
47 50
48 void AudioPullFifo::ReadFromFifo(AudioBus* destination, 51 void AudioPullFifo::ReadFromFifo(AudioBus* destination,
49 int* frames_to_provide, 52 int* frames_to_provide,
50 int* write_pos) { 53 int* write_pos) {
51 DCHECK(frames_to_provide); 54 DCHECK(frames_to_provide);
52 DCHECK(write_pos); 55 DCHECK(write_pos);
53 int frames = std::min(fifo_->frames(), *frames_to_provide); 56 int frames = std::min(fifo_->frames(), *frames_to_provide);
54 fifo_->Consume(destination, *write_pos, frames); 57 fifo_->Consume(destination, *write_pos, frames);
55 *write_pos += frames; 58 *write_pos += frames;
56 *frames_to_provide -= frames; 59 *frames_to_provide -= frames;
57 } 60 }
58 61
59 } // namespace media 62 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698