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

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

Issue 177333003: Add support for midstream audio configuration changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ABS
Patch Set: Created 6 years, 9 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
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 // AudioConverter implementation. Uses MultiChannelSincResampler for resampling 5 // AudioConverter implementation. Uses MultiChannelSincResampler for resampling
6 // audio, ChannelMixer for channel mixing, and AudioPullFifo for buffering. 6 // audio, ChannelMixer for channel mixing, and AudioPullFifo for buffering.
7 // 7 //
8 // Delay estimates are provided to InputCallbacks based on the frame delay 8 // Delay estimates are provided to InputCallbacks based on the frame delay
9 // information reported via the resampler and FIFO units. 9 // information reported via the resampler and FIFO units.
10 10
(...skipping 10 matching lines...) Expand all
21 #include "media/base/vector_math.h" 21 #include "media/base/vector_math.h"
22 22
23 namespace media { 23 namespace media {
24 24
25 AudioConverter::AudioConverter(const AudioParameters& input_params, 25 AudioConverter::AudioConverter(const AudioParameters& input_params,
26 const AudioParameters& output_params, 26 const AudioParameters& output_params,
27 bool disable_fifo) 27 bool disable_fifo)
28 : chunk_size_(output_params.frames_per_buffer()), 28 : chunk_size_(output_params.frames_per_buffer()),
29 downmix_early_(false), 29 downmix_early_(false),
30 resampler_frame_delay_(0), 30 resampler_frame_delay_(0),
31 input_channel_count_(input_params.channels()) { 31 input_channel_count_(input_params.channels()),
32 io_sample_rate_ratio_(input_params.sample_rate() /
33 static_cast<double>(output_params.sample_rate())) {
32 CHECK(input_params.IsValid()); 34 CHECK(input_params.IsValid());
33 CHECK(output_params.IsValid()); 35 CHECK(output_params.IsValid());
34 36
35 // Handle different input and output channel layouts. 37 // Handle different input and output channel layouts.
36 if (input_params.channel_layout() != output_params.channel_layout()) { 38 if (input_params.channel_layout() != output_params.channel_layout()) {
37 DVLOG(1) << "Remixing channel layout from " << input_params.channel_layout() 39 DVLOG(1) << "Remixing channel layout from " << input_params.channel_layout()
38 << " to " << output_params.channel_layout() << "; from " 40 << " to " << output_params.channel_layout() << "; from "
39 << input_params.channels() << " channels to " 41 << input_params.channels() << " channels to "
40 << output_params.channels() << " channels."; 42 << output_params.channels() << " channels.";
41 channel_mixer_.reset(new ChannelMixer(input_params, output_params)); 43 channel_mixer_.reset(new ChannelMixer(input_params, output_params));
42 44
43 // Pare off data as early as we can for efficiency. 45 // Pare off data as early as we can for efficiency.
44 downmix_early_ = input_params.channels() > output_params.channels(); 46 downmix_early_ = input_params.channels() > output_params.channels();
45 } 47 }
46 48
47 // Only resample if necessary since it's expensive. 49 // Only resample if necessary since it's expensive.
48 if (input_params.sample_rate() != output_params.sample_rate()) { 50 if (input_params.sample_rate() != output_params.sample_rate()) {
49 DVLOG(1) << "Resampling from " << input_params.sample_rate() << " to " 51 DVLOG(1) << "Resampling from " << input_params.sample_rate() << " to "
50 << output_params.sample_rate(); 52 << output_params.sample_rate();
51 const double io_sample_rate_ratio = input_params.sample_rate() /
52 static_cast<double>(output_params.sample_rate());
53 const int request_size = disable_fifo ? SincResampler::kDefaultRequestSize : 53 const int request_size = disable_fifo ? SincResampler::kDefaultRequestSize :
54 input_params.frames_per_buffer(); 54 input_params.frames_per_buffer();
55 resampler_.reset(new MultiChannelResampler( 55 resampler_.reset(new MultiChannelResampler(
56 downmix_early_ ? output_params.channels() : 56 downmix_early_ ? output_params.channels() :
57 input_params.channels(), 57 input_params.channels(),
58 io_sample_rate_ratio, request_size, base::Bind( 58 io_sample_rate_ratio_, request_size, base::Bind(
59 &AudioConverter::ProvideInput, base::Unretained(this)))); 59 &AudioConverter::ProvideInput, base::Unretained(this))));
60 } 60 }
61 61
62 input_frame_duration_ = base::TimeDelta::FromMicroseconds( 62 input_frame_duration_ = base::TimeDelta::FromMicroseconds(
63 base::Time::kMicrosecondsPerSecond / 63 base::Time::kMicrosecondsPerSecond /
64 static_cast<double>(input_params.sample_rate())); 64 static_cast<double>(input_params.sample_rate()));
65 output_frame_duration_ = base::TimeDelta::FromMicroseconds( 65 output_frame_duration_ = base::TimeDelta::FromMicroseconds(
66 base::Time::kMicrosecondsPerSecond / 66 base::Time::kMicrosecondsPerSecond /
67 static_cast<double>(output_params.sample_rate())); 67 static_cast<double>(output_params.sample_rate()));
68 68
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (resampler_) 108 if (resampler_)
109 resampler_->Flush(); 109 resampler_->Flush();
110 } 110 }
111 111
112 int AudioConverter::ChunkSize() const { 112 int AudioConverter::ChunkSize() const {
113 if (!resampler_) 113 if (!resampler_)
114 return chunk_size_; 114 return chunk_size_;
115 return resampler_->ChunkSize(); 115 return resampler_->ChunkSize();
116 } 116 }
117 117
118 int AudioConverter::RequestSize() const {
119 if (resampler_)
120 return audio_fifo_ ? chunk_size_
121 : SincResampler::kDefaultRequestSize;
122 return chunk_size_;
123 }
124
118 void AudioConverter::ConvertWithDelay(const base::TimeDelta& initial_delay, 125 void AudioConverter::ConvertWithDelay(const base::TimeDelta& initial_delay,
119 AudioBus* dest) { 126 AudioBus* dest) {
120 initial_delay_ = initial_delay; 127 initial_delay_ = initial_delay;
121 128
122 if (transform_inputs_.empty()) { 129 if (transform_inputs_.empty()) {
123 dest->Zero(); 130 dest->Zero();
124 return; 131 return;
125 } 132 }
126 133
127 // Determine if channel mixing should be done and if it should be done before 134 // Determine if channel mixing should be done and if it should be done before
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 else 247 else
241 SourceCallback(0, dest); 248 SourceCallback(0, dest);
242 } 249 }
243 250
244 void AudioConverter::CreateUnmixedAudioIfNecessary(int frames) { 251 void AudioConverter::CreateUnmixedAudioIfNecessary(int frames) {
245 if (!unmixed_audio_ || unmixed_audio_->frames() != frames) 252 if (!unmixed_audio_ || unmixed_audio_->frames() != frames)
246 unmixed_audio_ = AudioBus::Create(input_channel_count_, frames); 253 unmixed_audio_ = AudioBus::Create(input_channel_count_, frames);
247 } 254 }
248 255
249 } // namespace media 256 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698