diff options
author | ajm <ajm@chromium.org> | 2015-09-08 13:32:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-08 20:33:40 +0000 |
commit | 2e2f1c71bec505f3ae9d718dd8e875fedd4962e7 (patch) | |
tree | cbe6ef8143ddcef8dacf9fc1506dc9323c267e2c /media | |
parent | 4b000195a8d27e9c3c4bfdd77113674840286a48 (diff) | |
download | chromium_src-2e2f1c71bec505f3ae9d718dd8e875fedd4962e7.zip chromium_src-2e2f1c71bec505f3ae9d718dd8e875fedd4962e7.tar.gz chromium_src-2e2f1c71bec505f3ae9d718dd8e875fedd4962e7.tar.bz2 |
Refactor AudioParameters member setting.
Permit AudioParameters members to be set individually. Allows us to:
- Cut back to the one non-default constructor which is frequently used.
- Remove a bunch of boilerplate in the common case of updating one
member.
- Make adding future optional members (e.g. mic_positions)
transparent to most callers.
Maintain the Reset method but remove the channels parameter to have it
mirror the constructor.
Make it clear that channels_ is only required to be set explicitly with
CHANNEL_LAYOUT_DISCRETE.
BUG=497001
Review URL: https://codereview.chromium.org/1304973005
Cr-Commit-Position: refs/heads/master@{#347781}
Diffstat (limited to 'media')
22 files changed, 141 insertions, 203 deletions
diff --git a/media/audio/alsa/audio_manager_alsa.cc b/media/audio/alsa/audio_manager_alsa.cc index e44c8c8..325c372 100644 --- a/media/audio/alsa/audio_manager_alsa.cc +++ b/media/audio/alsa/audio_manager_alsa.cc @@ -327,9 +327,8 @@ AudioParameters AudioManagerAlsa::GetPreferredOutputStreamParameters( if (user_buffer_size) buffer_size = user_buffer_size; - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + sample_rate, bits_per_sample, buffer_size); } AudioOutputStream* AudioManagerAlsa::MakeOutputStream( diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc index 64b3b4b..38269bc 100644 --- a/media/audio/android/audio_android_unittest.cc +++ b/media/audio/android/audio_android_unittest.cc @@ -589,16 +589,11 @@ class AudioAndroidInputTest : public AudioAndroidOutputTest, AudioParameters GetInputStreamParameters() { GetDefaultInputStreamParametersOnAudioThread(); + AudioParameters params = audio_input_parameters(); // Override the platform effects setting to use the AudioRecord or OpenSLES // path as requested. - int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : - AudioParameters::NO_EFFECTS; - AudioParameters params(audio_input_parameters().format(), - audio_input_parameters().channel_layout(), - audio_input_parameters().sample_rate(), - audio_input_parameters().bits_per_sample(), - audio_input_parameters().frames_per_buffer(), - effects); + params.set_effects(GetParam() ? AudioParameters::ECHO_CANCELLER + : AudioParameters::NO_EFFECTS); return params; } @@ -796,13 +791,8 @@ TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { // a 10ms buffer size instead of the default size. TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacksNonDefaultParameters) { - AudioParameters native_params = GetInputStreamParameters(); - AudioParameters params(native_params.format(), - native_params.channel_layout(), - native_params.sample_rate(), - native_params.bits_per_sample(), - native_params.sample_rate() / 100, - native_params.effects()); + AudioParameters params = GetInputStreamParameters(); + params.set_frames_per_buffer(params.sample_rate() / 100); StartInputStreamCallbacks(params); } @@ -933,14 +923,8 @@ TEST_P(AudioAndroidInputTest, // parameters by selecting 10ms as buffer size. This will also ensure that // the output stream will be a mono stream since mono is default for input // audio on Android. - AudioParameters io_params(default_input_params.format(), - default_input_params.channel_layout(), - ChannelLayoutToChannelCount( - default_input_params.channel_layout()), - default_input_params.sample_rate(), - default_input_params.bits_per_sample(), - default_input_params.sample_rate() / 100, - default_input_params.effects()); + AudioParameters io_params = default_input_params; + default_input_params.set_frames_per_buffer(io_params.sample_rate() / 100); DVLOG(1) << io_params; // Create input and output streams using the common audio parameters. diff --git a/media/audio/android/audio_manager_android.cc b/media/audio/android/audio_manager_android.cc index 0590ffc..e231cd1 100644 --- a/media/audio/android/audio_manager_android.cc +++ b/media/audio/android/audio_manager_android.cc @@ -140,9 +140,9 @@ AudioParameters AudioManagerAndroid::GetInputStreamParameters( if (user_buffer_size) buffer_size = user_buffer_size; - AudioParameters params( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - GetNativeOutputSampleRate(), 16, buffer_size, effects); + AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + GetNativeOutputSampleRate(), 16, buffer_size); + params.set_effects(effects); return params; } @@ -306,9 +306,8 @@ AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters( if (user_buffer_size) buffer_size = user_buffer_size; - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + sample_rate, bits_per_sample, buffer_size); } bool AudioManagerAndroid::HasNoAudioInputStreams() { diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc index ebf1d36..43568cf 100644 --- a/media/audio/audio_manager_base.cc +++ b/media/audio/audio_manager_base.cc @@ -263,17 +263,11 @@ AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( << output_params.frames_per_buffer(); // Tell the AudioManager to create a fake output device. - output_params = AudioParameters( - AudioParameters::AUDIO_FAKE, params.channel_layout(), - params.sample_rate(), params.bits_per_sample(), - params.frames_per_buffer(), params.effects()); + output_params = params; + output_params.set_format(AudioParameters::AUDIO_FAKE); } else if (params.effects() != output_params.effects()) { // Turn off effects that weren't requested. - output_params = AudioParameters( - output_params.format(), output_params.channel_layout(), - output_params.channels(), output_params.sample_rate(), - output_params.bits_per_sample(), output_params.frames_per_buffer(), - params.effects() & output_params.effects()); + output_params.set_effects(params.effects() & output_params.effects()); } } diff --git a/media/audio/audio_output_device_unittest.cc b/media/audio/audio_output_device_unittest.cc index 3b3ee51..8747c79 100644 --- a/media/audio/audio_output_device_unittest.cc +++ b/media/audio/audio_output_device_unittest.cc @@ -121,9 +121,8 @@ int AudioOutputDeviceTest::CalculateMemorySize() { } AudioOutputDeviceTest::AudioOutputDeviceTest() { - default_audio_parameters_.Reset( - AudioParameters::AUDIO_PCM_LINEAR, - CHANNEL_LAYOUT_STEREO, 2, 48000, 16, 1024); + default_audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LINEAR, + CHANNEL_LAYOUT_STEREO, 48000, 16, 1024); audio_output_ipc_ = new MockAudioOutputIPC(); audio_device_ = new AudioOutputDevice( diff --git a/media/audio/audio_output_resampler.cc b/media/audio/audio_output_resampler.cc index 6fb970b..d85768b 100644 --- a/media/audio/audio_output_resampler.cc +++ b/media/audio/audio_output_resampler.cc @@ -241,10 +241,9 @@ bool AudioOutputResampler::OpenStream() { << "back to fake audio output."; // Finally fall back to a fake audio output device. - output_params_.Reset( - AudioParameters::AUDIO_FAKE, params_.channel_layout(), - params_.channels(), params_.sample_rate(), - params_.bits_per_sample(), params_.frames_per_buffer()); + output_params_ = params_; + output_params_.set_format(AudioParameters::AUDIO_FAKE); + Initialize(); if (dispatcher_->OpenStream()) { streams_opened_ = true; diff --git a/media/audio/audio_parameters.cc b/media/audio/audio_parameters.cc index 872413f..a78eb84 100644 --- a/media/audio/audio_parameters.cc +++ b/media/audio/audio_parameters.cc @@ -10,61 +10,29 @@ namespace media { AudioParameters::AudioParameters() - : format_(AUDIO_PCM_LINEAR), - channel_layout_(CHANNEL_LAYOUT_NONE), - sample_rate_(0), - bits_per_sample_(0), - frames_per_buffer_(0), - channels_(0), - effects_(NO_EFFECTS) { + : AudioParameters(AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_NONE, 0, 0, 0) {} + +AudioParameters::AudioParameters(Format format, + ChannelLayout channel_layout, + int sample_rate, + int bits_per_sample, + int frames_per_buffer) { + Reset(format, channel_layout, sample_rate, bits_per_sample, + frames_per_buffer); } -AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, - int sample_rate, int bits_per_sample, - int frames_per_buffer) - : format_(format), - channel_layout_(channel_layout), - sample_rate_(sample_rate), - bits_per_sample_(bits_per_sample), - frames_per_buffer_(frames_per_buffer), - channels_(ChannelLayoutToChannelCount(channel_layout)), - effects_(NO_EFFECTS) { -} - -AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, - int sample_rate, int bits_per_sample, - int frames_per_buffer, int effects) - : format_(format), - channel_layout_(channel_layout), - sample_rate_(sample_rate), - bits_per_sample_(bits_per_sample), - frames_per_buffer_(frames_per_buffer), - channels_(ChannelLayoutToChannelCount(channel_layout)), - effects_(effects) { -} - -AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, - int channels, int sample_rate, - int bits_per_sample, int frames_per_buffer, - int effects) - : format_(format), - channel_layout_(channel_layout), - sample_rate_(sample_rate), - bits_per_sample_(bits_per_sample), - frames_per_buffer_(frames_per_buffer), - channels_(channels), - effects_(effects) { -} - -void AudioParameters::Reset(Format format, ChannelLayout channel_layout, - int channels, int sample_rate, - int bits_per_sample, int frames_per_buffer) { +void AudioParameters::Reset(Format format, + ChannelLayout channel_layout, + int sample_rate, + int bits_per_sample, + int frames_per_buffer) { format_ = format; channel_layout_ = channel_layout; - channels_ = channels; + channels_ = ChannelLayoutToChannelCount(channel_layout); sample_rate_ = sample_rate; bits_per_sample_ = bits_per_sample; frames_per_buffer_ = frames_per_buffer; + effects_ = NO_EFFECTS; } bool AudioParameters::IsValid() const { @@ -82,12 +50,11 @@ bool AudioParameters::IsValid() const { std::string AudioParameters::AsHumanReadableString() const { std::ostringstream s; - s << "format: " << format() - << " channels: " << channels() - << " channel_layout: " << channel_layout() - << " sample_rate: " << sample_rate() + s << "format: " << format() << " channel_layout: " << channel_layout() + << " channels: " << channels() << " sample_rate: " << sample_rate() << " bits_per_sample: " << bits_per_sample() - << " frames_per_buffer: " << frames_per_buffer(); + << " frames_per_buffer: " << frames_per_buffer() + << " effects: " << effects(); return s.str(); } diff --git a/media/audio/audio_parameters.h b/media/audio/audio_parameters.h index a73982e..57fb960 100644 --- a/media/audio/audio_parameters.h +++ b/media/audio/audio_parameters.h @@ -80,18 +80,17 @@ class MEDIA_EXPORT AudioParameters { }; AudioParameters(); - AudioParameters(Format format, ChannelLayout channel_layout, - int sample_rate, int bits_per_sample, + AudioParameters(Format format, + ChannelLayout channel_layout, + int sample_rate, + int bits_per_sample, int frames_per_buffer); - AudioParameters(Format format, ChannelLayout channel_layout, - int sample_rate, int bits_per_sample, - int frames_per_buffer, int effects); - AudioParameters(Format format, ChannelLayout channel_layout, - int channels, int sample_rate, int bits_per_sample, - int frames_per_buffer, int effects); - - void Reset(Format format, ChannelLayout channel_layout, - int channels, int sample_rate, int bits_per_sample, + + // Re-initializes all members. + void Reset(Format format, + ChannelLayout channel_layout, + int sample_rate, + int bits_per_sample, int frames_per_buffer); // Checks that all values are in the expected range. All limits are specified @@ -118,25 +117,48 @@ class MEDIA_EXPORT AudioParameters { // Comparison with other AudioParams. bool Equals(const AudioParameters& other) const; + void set_format(Format format) { format_ = format; } Format format() const { return format_; } + + // A setter for channel_layout_ is intentionally excluded. ChannelLayout channel_layout() const { return channel_layout_; } + + // The number of channels is usually computed from channel_layout_. Setting + // this explictly is only required with CHANNEL_LAYOUT_DISCRETE. + void set_channels_for_discrete(int channels) { + DCHECK(channel_layout_ == CHANNEL_LAYOUT_DISCRETE || + channels == ChannelLayoutToChannelCount(channel_layout_)); + channels_ = channels; + } + int channels() const { return channels_; } + + void set_sample_rate(int sample_rate) { sample_rate_ = sample_rate; } int sample_rate() const { return sample_rate_; } + + void set_bits_per_sample(int bits_per_sample) { + bits_per_sample_ = bits_per_sample; + } int bits_per_sample() const { return bits_per_sample_; } + + void set_frames_per_buffer(int frames_per_buffer) { + frames_per_buffer_ = frames_per_buffer; + } int frames_per_buffer() const { return frames_per_buffer_; } - int channels() const { return channels_; } + + void set_effects(int effects) { effects_ = effects; } int effects() const { return effects_; } + AudioParameters(const AudioParameters&) = default; + AudioParameters& operator=(const AudioParameters&) = default; + private: - // These members are mutable to support entire struct assignment. They should - // not be mutated individually. Format format_; // Format of the stream. ChannelLayout channel_layout_; // Order of surround sound channels. + int channels_; // Number of channels. Value set based on + // |channel_layout|. int sample_rate_; // Sampling frequency/rate. int bits_per_sample_; // Number of bits per sample. int frames_per_buffer_; // Number of frames in a buffer. - - int channels_; // Number of channels. Value set based on - // |channel_layout|. int effects_; // Bitmask using PlatformEffectsMask. }; diff --git a/media/audio/audio_parameters_unittest.cc b/media/audio/audio_parameters_unittest.cc index 92677eb..2cf541d 100644 --- a/media/audio/audio_parameters_unittest.cc +++ b/media/audio/audio_parameters_unittest.cc @@ -205,20 +205,11 @@ TEST(AudioParameters, Compare) { TEST(AudioParameters, Constructor_ValidChannelCounts) { int expected_channels = 8; - ChannelLayout expected_layout = CHANNEL_LAYOUT_5_1; + ChannelLayout expected_layout = CHANNEL_LAYOUT_DISCRETE; AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, - expected_layout, expected_channels, 44100, 16, 880, - AudioParameters::NO_EFFECTS); - - EXPECT_EQ(expected_channels, params.channels()); - EXPECT_EQ(expected_layout, params.channel_layout()); - EXPECT_FALSE(params.IsValid()); - - expected_layout = CHANNEL_LAYOUT_DISCRETE; - params.Reset(AudioParameters::AUDIO_PCM_LOW_LATENCY, expected_layout, - expected_channels, 44100, 16, 880); - + expected_layout, 44100, 16, 880); + params.set_channels_for_discrete(expected_channels); EXPECT_EQ(expected_channels, params.channels()); EXPECT_EQ(expected_layout, params.channel_layout()); EXPECT_TRUE(params.IsValid()); diff --git a/media/audio/cras/audio_manager_cras.cc b/media/audio/cras/audio_manager_cras.cc index 86d12fc..31a1780 100644 --- a/media/audio/cras/audio_manager_cras.cc +++ b/media/audio/cras/audio_manager_cras.cc @@ -97,9 +97,11 @@ AudioParameters AudioManagerCras::GetInputStreamParameters( // TODO(hshi): Fine-tune audio parameters based on |device_id|. The optimal // parameters for the loopback stream may differ from the default. - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, - kDefaultSampleRate, 16, buffer_size, effects); + AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, kDefaultSampleRate, 16, + buffer_size); + params.set_effects(effects); + return params; } void AudioManagerCras::SetHasKeyboardMic() { @@ -156,9 +158,8 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( if (user_buffer_size) buffer_size = user_buffer_size; - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + sample_rate, bits_per_sample, buffer_size); } AudioOutputStream* AudioManagerCras::MakeOutputStream( diff --git a/media/audio/fake_audio_manager.cc b/media/audio/fake_audio_manager.cc index a181a2f..3d76401 100644 --- a/media/audio/fake_audio_manager.cc +++ b/media/audio/fake_audio_manager.cc @@ -65,9 +65,8 @@ AudioParameters FakeAudioManager::GetPreferredOutputStreamParameters( buffer_size = std::min(input_params.frames_per_buffer(), buffer_size); } - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + sample_rate, bits_per_sample, buffer_size); } AudioParameters FakeAudioManager::GetInputStreamParameters( diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc index 42651ff..33dbfdf 100644 --- a/media/audio/mac/audio_manager_mac.cc +++ b/media/audio/mac/audio_manager_mac.cc @@ -672,9 +672,10 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( channel_layout = CHANNEL_LAYOUT_DISCRETE; } - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, output_channels, - hardware_sample_rate, 16, buffer_size, AudioParameters::NO_EFFECTS); + AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + hardware_sample_rate, 16, buffer_size); + params.set_channels_for_discrete(output_channels); + return params; } void AudioManagerMac::InitializeOnAudioThread() { diff --git a/media/audio/pulse/audio_manager_pulse.cc b/media/audio/pulse/audio_manager_pulse.cc index c752a9e..3044f3c 100644 --- a/media/audio/pulse/audio_manager_pulse.cc +++ b/media/audio/pulse/audio_manager_pulse.cc @@ -189,9 +189,8 @@ AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( if (user_buffer_size) buffer_size = user_buffer_size; - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); + return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + sample_rate, bits_per_sample, buffer_size); } AudioOutputStream* AudioManagerPulse::MakeOutputStream( diff --git a/media/audio/win/audio_low_latency_input_win_unittest.cc b/media/audio/win/audio_low_latency_input_win_unittest.cc index 2af6e5e..5b8f46e 100644 --- a/media/audio/win/audio_low_latency_input_win_unittest.cc +++ b/media/audio/win/audio_low_latency_input_win_unittest.cc @@ -194,11 +194,10 @@ class AudioInputStreamWrapper { private: AudioInputStream* CreateInputStream() { + AudioParameters params = default_params_; + params.set_frames_per_buffer(frames_per_buffer_); AudioInputStream* ais = audio_man_->MakeAudioInputStream( - AudioParameters(format(), default_params_.channel_layout(), - sample_rate(), bits_per_sample(), frames_per_buffer_, - default_params_.effects()), - AudioManagerBase::kDefaultDeviceId); + params, AudioManagerBase::kDefaultDeviceId); EXPECT_TRUE(ais); return ais; } diff --git a/media/audio/win/audio_manager_win.cc b/media/audio/win/audio_manager_win.cc index 4a3b008..7ef9a84 100644 --- a/media/audio/win/audio_manager_win.cc +++ b/media/audio/win/audio_manager_win.cc @@ -317,17 +317,14 @@ AudioParameters AudioManagerWin::GetInputStreamParameters( if (FAILED(hr) || !parameters.IsValid()) { // Windows Wave implementation is being used. - parameters = AudioParameters( - AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 48000, 16, - kFallbackBufferSize, AudioParameters::NO_EFFECTS); + parameters = + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, + CHANNEL_LAYOUT_STEREO, 48000, 16, kFallbackBufferSize); } int user_buffer_size = GetUserBufferSize(); - if (user_buffer_size) { - parameters.Reset(parameters.format(), parameters.channel_layout(), - parameters.channels(), parameters.sample_rate(), - parameters.bits_per_sample(), user_buffer_size); - } + if (user_buffer_size) + parameters.set_frames_per_buffer(user_buffer_size); return parameters; } @@ -517,9 +514,10 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters( if (user_buffer_size) buffer_size = user_buffer_size; - return AudioParameters( - AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, - sample_rate, bits_per_sample, buffer_size, effects); + AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, + sample_rate, bits_per_sample, buffer_size); + params.set_effects(effects); + return params; } AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream( diff --git a/media/audio/win/core_audio_util_win.cc b/media/audio/win/core_audio_util_win.cc index 8442fc1..1ce0191 100644 --- a/media/audio/win/core_audio_util_win.cc +++ b/media/audio/win/core_audio_util_win.cc @@ -772,7 +772,7 @@ HRESULT CoreAudioUtil::GetPreferredAudioParameters(const std::string& device_id, // TODO(dalecurtis): Old code rewrote != 1 channels to stereo, do we still // need to do the same thing? if (params->channels() != 1) { - params->Reset(params->format(), CHANNEL_LAYOUT_STEREO, 2, + params->Reset(params->format(), CHANNEL_LAYOUT_STEREO, params->sample_rate(), params->bits_per_sample(), params->frames_per_buffer()); } diff --git a/media/base/audio_buffer_converter.cc b/media/base/audio_buffer_converter.cc index afdceb2..8c5ec1c 100644 --- a/media/base/audio_buffer_converter.cc +++ b/media/base/audio_buffer_converter.cc @@ -141,7 +141,6 @@ void AudioBufferConverter::ResetConverter( input_params_.Reset( input_params_.format(), buffer->channel_layout(), - buffer->channel_count(), buffer->sample_rate(), input_params_.bits_per_sample(), // If resampling is needed and the FIFO disabled, the AudioConverter will @@ -150,6 +149,7 @@ void AudioBufferConverter::ResetConverter( buffer->sample_rate() == output_params_.sample_rate() ? output_params_.frames_per_buffer() : SincResampler::kDefaultRequestSize); + input_params_.set_channels_for_discrete(buffer->channel_count()); io_sample_rate_ratio_ = static_cast<double>(input_params_.sample_rate()) / output_params_.sample_rate(); diff --git a/media/base/audio_buffer_converter_unittest.cc b/media/base/audio_buffer_converter_unittest.cc index 7045b70..b022523 100644 --- a/media/base/audio_buffer_converter_unittest.cc +++ b/media/base/audio_buffer_converter_unittest.cc @@ -207,13 +207,10 @@ TEST_F(AudioBufferConverterTest, ResetThenConvert) { } TEST_F(AudioBufferConverterTest, DiscreteChannelLayout) { - output_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, - CHANNEL_LAYOUT_DISCRETE, - 2, - kOutSampleRate, - 16, - 512, - 0); + output_params_ = + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_DISCRETE, kOutSampleRate, 16, 512); + output_params_.set_channels_for_discrete(2); audio_buffer_converter_.reset(new AudioBufferConverter(output_params_)); AddInput(MakeTestBuffer(kOutSampleRate, CHANNEL_LAYOUT_STEREO, 2, 512)); ConsumeAllOutput(); diff --git a/media/base/audio_converter_unittest.cc b/media/base/audio_converter_unittest.cc index dcc3db6..741027f 100644 --- a/media/base/audio_converter_unittest.cc +++ b/media/base/audio_converter_unittest.cc @@ -198,13 +198,13 @@ TEST(AudioConverterTest, AudioDelayAndDiscreteChannelCount) { // Choose input and output parameters such that the transform must make // multiple calls to fill the buffer. AudioParameters input_parameters(AudioParameters::AUDIO_PCM_LINEAR, - CHANNEL_LAYOUT_DISCRETE, 10, kSampleRate, - kBitsPerChannel, kLowLatencyBufferSize, - AudioParameters::NO_EFFECTS); + CHANNEL_LAYOUT_DISCRETE, kSampleRate, + kBitsPerChannel, kLowLatencyBufferSize); + input_parameters.set_channels_for_discrete(10); AudioParameters output_parameters(AudioParameters::AUDIO_PCM_LINEAR, - CHANNEL_LAYOUT_DISCRETE, 5, kSampleRate * 2, - kBitsPerChannel, kHighLatencyBufferSize, - AudioParameters::NO_EFFECTS); + CHANNEL_LAYOUT_DISCRETE, kSampleRate * 2, + kBitsPerChannel, kHighLatencyBufferSize); + output_parameters.set_channels_for_discrete(5); AudioConverter converter(input_parameters, output_parameters, false); FakeAudioRenderCallback callback(0.2); diff --git a/media/base/channel_mixer_unittest.cc b/media/base/channel_mixer_unittest.cc index 89b4eee..1eb2616 100644 --- a/media/base/channel_mixer_unittest.cc +++ b/media/base/channel_mixer_unittest.cc @@ -104,26 +104,19 @@ TEST_P(ChannelMixerTest, Mixing) { ChannelLayout input_layout = GetParam().input_layout; int input_channels = GetParam().input_channels; scoped_ptr<AudioBus> input_bus = AudioBus::Create(input_channels, kFrames); - AudioParameters input_audio(AudioParameters::AUDIO_PCM_LINEAR, - input_layout, - input_layout == CHANNEL_LAYOUT_DISCRETE ? - input_channels : - ChannelLayoutToChannelCount(input_layout), - AudioParameters::kAudioCDSampleRate, 16, - kFrames, - AudioParameters::NO_EFFECTS); + AudioParameters input_audio(AudioParameters::AUDIO_PCM_LINEAR, input_layout, + AudioParameters::kAudioCDSampleRate, 16, kFrames); + if (input_layout == CHANNEL_LAYOUT_DISCRETE) + input_audio.set_channels_for_discrete(input_channels); ChannelLayout output_layout = GetParam().output_layout; int output_channels = GetParam().output_channels; scoped_ptr<AudioBus> output_bus = AudioBus::Create(output_channels, kFrames); - AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, - output_layout, - output_layout == CHANNEL_LAYOUT_DISCRETE ? - output_channels : - ChannelLayoutToChannelCount(output_layout), + AudioParameters output_audio(AudioParameters::AUDIO_PCM_LINEAR, output_layout, AudioParameters::kAudioCDSampleRate, 16, - kFrames, - AudioParameters::NO_EFFECTS); + kFrames); + if (output_layout == CHANNEL_LAYOUT_DISCRETE) + output_audio.set_channels_for_discrete(output_channels); const float* channel_values = GetParam().channel_values; ASSERT_EQ(input_bus->channels(), GetParam().num_channel_values); diff --git a/media/cast/test/fake_media_source.cc b/media/cast/test/fake_media_source.cc index 184f69f..7288728 100644 --- a/media/cast/test/fake_media_source.cc +++ b/media/cast/test/fake_media_source.cc @@ -165,10 +165,11 @@ void FakeMediaSource::SetSourceFile(const base::FilePath& video_file, source_audio_params_.Reset( AudioParameters::AUDIO_PCM_LINEAR, layout, - av_codec_context->channels, av_codec_context->sample_rate, 8 * av_get_bytes_per_sample(av_codec_context->sample_fmt), av_codec_context->sample_rate / kAudioPacketsPerSecond); + source_audio_params_.set_channels_for_discrete( + av_codec_context->channels); CHECK(source_audio_params_.IsValid()); LOG(INFO) << "Source file has audio."; } else if (av_codec->type == AVMEDIA_TYPE_VIDEO) { @@ -375,10 +376,12 @@ bool FakeMediaSource::SendNextTranscodedAudio(base::TimeDelta elapsed_time) { void FakeMediaSource::SendNextFrame() { // Send as much as possible. Audio is sent according to // system time. - while (SendNextTranscodedAudio(clock_->NowTicks() - start_time_)); + while (SendNextTranscodedAudio(clock_->NowTicks() - start_time_)) { + } // Video is sync'ed to audio. - while (SendNextTranscodedVideo(audio_sent_ts_->GetTimestamp())); + while (SendNextTranscodedVideo(audio_sent_ts_->GetTimestamp())) { + } if (audio_bus_queue_.empty() && video_frame_queue_.empty()) { // Both queues are empty can only mean that we have reached diff --git a/media/renderers/audio_renderer_impl.cc b/media/renderers/audio_renderer_impl.cc index 90bfaaf..2d9879b 100644 --- a/media/renderers/audio_renderer_impl.cc +++ b/media/renderers/audio_renderer_impl.cc @@ -344,8 +344,6 @@ void AudioRendererImpl::Initialize( audio_parameters_.Reset( AudioParameters::AUDIO_PCM_LOW_LATENCY, stream->audio_decoder_config().channel_layout(), - ChannelLayoutToChannelCount( - stream->audio_decoder_config().channel_layout()), stream->audio_decoder_config().samples_per_second(), stream->audio_decoder_config().bits_per_channel(), buffer_size); @@ -353,15 +351,11 @@ void AudioRendererImpl::Initialize( } else { audio_parameters_.Reset( hw_params.format(), - // Always use the source's channel layout and channel count to avoid - // premature downmixing (http://crbug.com/379288), platform specific - // issues around channel layouts (http://crbug.com/266674), and - // unnecessary upmixing overhead. + // Always use the source's channel layout to avoid premature downmixing + // (http://crbug.com/379288), platform specific issues around channel + // layouts (http://crbug.com/266674), and unnecessary upmixing overhead. stream->audio_decoder_config().channel_layout(), - ChannelLayoutToChannelCount( - stream->audio_decoder_config().channel_layout()), - hw_params.sample_rate(), - hw_params.bits_per_sample(), + hw_params.sample_rate(), hw_params.bits_per_sample(), hardware_config_.GetHighLatencyBufferSize()); } |