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

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

Issue 389623002: Add a block based Audio FIFO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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_fifo.h" 5 #include "media/base/audio_fifo.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace media { 9 namespace media {
10 10
11 // Given current position in the FIFO, the maximum number of elements in the 11 AudioFifo::AudioFifo(int channels, int frames)
12 // FIFO and the size of the input; this method provides two output results: 12 : audio_bus_(AudioBus::Create(channels, frames)),
13 // |size| and |wrap_size|. These two results can then be utilized for memcopy 13 max_frames_(frames),
14 // operations to and from the FIFO. 14 frames_pushed_(0),
15 // Under "normal" circumstances, |size| will be equal to |in_size| and 15 frames_consumed_(0),
16 // |wrap_size| will be zero. This case corresponding to the non-wrapping case 16 read_pos_(0),
17 // where we have not yet reached the "edge" of the FIFO. If |pos| + |in_size| 17 write_pos_(0) {}
18 // exceeds the total size of the FIFO, we must wrap around and start reusing 18
19 // a part the allocated memory. The size of this part is given by |wrap_size|. 19 AudioFifo::~AudioFifo() {}
20 static void GetSizes( 20
21 int pos, int max_size, int in_size, int* size, int* wrap_size) { 21 // static.
22 void AudioFifo::GetSizes(int pos, int max_size, int in_size,
23 int* size, int* wrap_size) {
22 if (pos + in_size > max_size) { 24 if (pos + in_size > max_size) {
23 // Wrapping is required => derive size of each segment. 25 // Wrapping is required => derive size of each segment.
24 *size = max_size - pos; 26 *size = max_size - pos;
25 *wrap_size = in_size - *size; 27 *wrap_size = in_size - *size;
26 } else { 28 } else {
27 // Wrapping is not required. 29 // Wrapping is not required.
28 *size = in_size; 30 *size = in_size;
29 *wrap_size = 0; 31 *wrap_size = 0;
30 } 32 }
31 } 33 }
32 34
33 // Updates the read/write position with |step| modulo the maximum number of 35 // static.
34 // elements in the FIFO to ensure that the position counters wraps around at 36 int AudioFifo::UpdatePos(int pos, int step, int max_size) {
35 // the endpoint.
36 static int UpdatePos(int pos, int step, int max_size) {
37 return ((pos + step) % max_size); 37 return ((pos + step) % max_size);
38 } 38 }
39 39
40 AudioFifo::AudioFifo(int channels, int frames)
41 : audio_bus_(AudioBus::Create(channels, frames)),
42 max_frames_(frames),
43 frames_pushed_(0),
44 frames_consumed_(0),
45 read_pos_(0),
46 write_pos_(0) {}
47
48 AudioFifo::~AudioFifo() {}
49
50 int AudioFifo::frames() const { 40 int AudioFifo::frames() const {
51 int delta = frames_pushed_ - frames_consumed_; 41 int delta = frames_pushed_ - frames_consumed_;
52 return delta; 42 return delta;
53 } 43 }
54 44
55 void AudioFifo::Push(const AudioBus* source) { 45 void AudioFifo::Push(const AudioBus* source) {
56 DCHECK(source); 46 DCHECK(source);
57 DCHECK_EQ(source->channels(), audio_bus_->channels()); 47 DCHECK_EQ(source->channels(), audio_bus_->channels());
58 48
59 // Ensure that there is space for the new data in the FIFO. 49 // Ensure that there is space for the new data in the FIFO.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 114 }
125 115
126 void AudioFifo::Clear() { 116 void AudioFifo::Clear() {
127 frames_pushed_ = 0; 117 frames_pushed_ = 0;
128 frames_consumed_ = 0; 118 frames_consumed_ = 0;
129 read_pos_ = 0; 119 read_pos_ = 0;
130 write_pos_ = 0; 120 write_pos_ = 0;
131 } 121 }
132 122
133 } // namespace media 123 } // namespace media
OLDNEW
« media/base/audio_block_fifo.cc ('K') | « media/base/audio_fifo.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698