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

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

Issue 2788483003: Introduce AudioBufferMemoryPool to avoid thrashing on audio buffers. (Closed)
Patch Set: Add class comments. Created 3 years, 8 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
« no previous file with comments | « media/base/audio_buffer_converter.h ('k') | media/base/audio_buffer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_buffer_converter.h" 5 #include "media/base/audio_buffer_converter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "media/base/audio_buffer.h"
12 #include "media/base/audio_bus.h" 11 #include "media/base/audio_bus.h"
13 #include "media/base/audio_decoder_config.h" 12 #include "media/base/audio_decoder_config.h"
14 #include "media/base/audio_timestamp_helper.h" 13 #include "media/base/audio_timestamp_helper.h"
15 #include "media/base/sinc_resampler.h" 14 #include "media/base/sinc_resampler.h"
16 #include "media/base/timestamp_constants.h" 15 #include "media/base/timestamp_constants.h"
17 #include "media/base/vector_math.h" 16 #include "media/base/vector_math.h"
18 17
19 namespace media { 18 namespace media {
20 19
21 // Is the config presented by |buffer| a config change from |params|? 20 // Is the config presented by |buffer| a config change from |params|?
22 static bool IsConfigChange(const AudioParameters& params, 21 static bool IsConfigChange(const AudioParameters& params,
23 const scoped_refptr<AudioBuffer>& buffer) { 22 const scoped_refptr<AudioBuffer>& buffer) {
24 return buffer->sample_rate() != params.sample_rate() || 23 return buffer->sample_rate() != params.sample_rate() ||
25 buffer->channel_count() != params.channels() || 24 buffer->channel_count() != params.channels() ||
26 buffer->channel_layout() != params.channel_layout(); 25 buffer->channel_layout() != params.channel_layout();
27 } 26 }
28 27
29 AudioBufferConverter::AudioBufferConverter(const AudioParameters& output_params) 28 AudioBufferConverter::AudioBufferConverter(const AudioParameters& output_params)
30 : output_params_(output_params), 29 : output_params_(output_params),
31 input_params_(output_params), 30 input_params_(output_params),
32 last_input_buffer_offset_(0), 31 last_input_buffer_offset_(0),
33 input_frames_(0), 32 input_frames_(0),
34 buffered_input_frames_(0.0), 33 buffered_input_frames_(0.0),
35 io_sample_rate_ratio_(1.0), 34 io_sample_rate_ratio_(1.0),
36 timestamp_helper_(output_params_.sample_rate()), 35 timestamp_helper_(output_params_.sample_rate()),
37 is_flushing_(false) {} 36 is_flushing_(false),
37 pool_(new AudioBufferMemoryPool()) {}
38 38
39 AudioBufferConverter::~AudioBufferConverter() {} 39 AudioBufferConverter::~AudioBufferConverter() {}
40 40
41 void AudioBufferConverter::AddInput(const scoped_refptr<AudioBuffer>& buffer) { 41 void AudioBufferConverter::AddInput(const scoped_refptr<AudioBuffer>& buffer) {
42 // On EOS flush any remaining buffered data. 42 // On EOS flush any remaining buffered data.
43 if (buffer->end_of_stream()) { 43 if (buffer->end_of_stream()) {
44 Flush(); 44 Flush();
45 queued_outputs_.push_back(buffer); 45 queued_outputs_.push_back(buffer);
46 return; 46 return;
47 } 47 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // How many calls to ProvideInput() we can satisfy completely. 180 // How many calls to ProvideInput() we can satisfy completely.
181 int chunks = input_frames_ / input_params_.frames_per_buffer(); 181 int chunks = input_frames_ / input_params_.frames_per_buffer();
182 182
183 // How many output frames that corresponds to: 183 // How many output frames that corresponds to:
184 request_frames = chunks * audio_converter_->ChunkSize(); 184 request_frames = chunks * audio_converter_->ChunkSize();
185 } 185 }
186 186
187 if (!request_frames) 187 if (!request_frames)
188 return; 188 return;
189 189
190 scoped_refptr<AudioBuffer> output_buffer = 190 scoped_refptr<AudioBuffer> output_buffer = AudioBuffer::CreateBuffer(
191 AudioBuffer::CreateBuffer(kSampleFormatPlanarF32, 191 kSampleFormatPlanarF32, output_params_.channel_layout(),
192 output_params_.channel_layout(), 192 output_params_.channels(), output_params_.sample_rate(), request_frames,
193 output_params_.channels(), 193 pool_);
194 output_params_.sample_rate(),
195 request_frames);
196 std::unique_ptr<AudioBus> output_bus = 194 std::unique_ptr<AudioBus> output_bus =
197 AudioBus::CreateWrapper(output_buffer->channel_count()); 195 AudioBus::CreateWrapper(output_buffer->channel_count());
198 196
199 int frames_remaining = request_frames; 197 int frames_remaining = request_frames;
200 198
201 // The AudioConverter wants requests of a fixed size, so we'll slide an 199 // The AudioConverter wants requests of a fixed size, so we'll slide an
202 // AudioBus of that size across the |output_buffer|. 200 // AudioBus of that size across the |output_buffer|.
203 while (frames_remaining != 0) { 201 while (frames_remaining != 0) {
204 // It's important that this is a multiple of AudioBus::kChannelAlignment in 202 // It's important that this is a multiple of AudioBus::kChannelAlignment in
205 // all requests except for the last, otherwise downstream SIMD optimizations 203 // all requests except for the last, otherwise downstream SIMD optimizations
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 is_flushing_ = false; 238 is_flushing_ = false;
241 audio_converter_->Reset(); 239 audio_converter_->Reset();
242 DCHECK_EQ(input_frames_, 0); 240 DCHECK_EQ(input_frames_, 0);
243 DCHECK_EQ(last_input_buffer_offset_, 0); 241 DCHECK_EQ(last_input_buffer_offset_, 0);
244 DCHECK_LT(buffered_input_frames_, 1.0); 242 DCHECK_LT(buffered_input_frames_, 1.0);
245 DCHECK(queued_inputs_.empty()); 243 DCHECK(queued_inputs_.empty());
246 buffered_input_frames_ = 0.0; 244 buffered_input_frames_ = 0.0;
247 } 245 }
248 246
249 } // namespace media 247 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_buffer_converter.h ('k') | media/base/audio_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698