Chromium Code Reviews| Index: media/renderers/audio_renderer_impl.cc |
| diff --git a/media/renderers/audio_renderer_impl.cc b/media/renderers/audio_renderer_impl.cc |
| index a351b9a84ec0a7ae9207f94af19cc412237dc0ee..7abe17163b9e01ac2aedcb3c5dae479a76b7d2e8 100644 |
| --- a/media/renderers/audio_renderer_impl.cc |
| +++ b/media/renderers/audio_renderer_impl.cc |
| @@ -48,6 +48,7 @@ AudioRendererImpl::AudioRendererImpl( |
| last_decoded_sample_rate_(0), |
| last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE), |
| is_encrypted_(false), |
| + last_decoded_channels_(0), |
| playback_rate_(0.0), |
| state_(kUninitialized), |
| create_audio_decoders_cb_(create_audio_decoders_cb), |
| @@ -369,9 +370,17 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream, |
| auto output_device_info = sink_->GetOutputDeviceInfo(); |
| const AudioParameters& hw_params = output_device_info.output_params(); |
| expecting_config_changes_ = stream->SupportsConfigChanges(); |
| - if (!expecting_config_changes_ || !hw_params.IsValid() || |
| - hw_params.format() == AudioParameters::AUDIO_FAKE || |
| - !sink_->IsOptimizedForHardwareParameters()) { |
| + |
| + bool use_stream_params = !expecting_config_changes_ || !hw_params.IsValid() || |
| + hw_params.format() == AudioParameters::AUDIO_FAKE || |
| + !sink_->IsOptimizedForHardwareParameters(); |
| + |
| + if (stream->audio_decoder_config().channel_layout() == |
|
DaleCurtis
2017/05/25 00:29:16
Why do we need this? I think what you had before i
flim-chromium
2017/05/25 00:46:06
Yep, that's still there in line 376. But if webaud
DaleCurtis
2017/05/25 00:53:38
Seems like you could just drop this and always cal
flim-chromium
2017/05/25 02:16:41
We'd have to set the channels in AudioRendererMixe
DaleCurtis
2017/05/25 18:51:01
Hmm, I was proposing a simplified logic, but after
flim-chromium
2017/05/25 22:00:40
Done.
|
| + CHANNEL_LAYOUT_DISCRETE && |
| + sink_->IsOptimizedForHardwareParameters()) |
| + use_stream_params = false; |
| + |
| + if (use_stream_params) { |
| // The actual buffer size is controlled via the size of the AudioBus |
| // provided to Render(), but we should choose a value here based on hardware |
| // parameters if possible since it affects the initial buffer size used by |
| @@ -384,6 +393,8 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream, |
| stream->audio_decoder_config().samples_per_second(), |
| stream->audio_decoder_config().bits_per_channel(), |
| buffer_size); |
| + audio_parameters_.set_channels_for_discrete( |
| + stream->audio_decoder_config().channels()); |
| buffer_converter_.reset(); |
| } else { |
| // To allow for seamless sample rate adaptations (i.e. changes from say |
| @@ -401,8 +412,7 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream, |
| } |
| #endif |
| - int stream_channel_count = ChannelLayoutToChannelCount( |
| - stream->audio_decoder_config().channel_layout()); |
| + int stream_channel_count = stream->audio_decoder_config().channels(); |
| bool try_supported_channel_layouts = false; |
| #if defined(OS_WIN) |
| @@ -458,6 +468,8 @@ void AudioRendererImpl::Initialize(DemuxerStream* stream, |
| is_encrypted_ = stream->audio_decoder_config().is_encrypted(); |
| + last_decoded_channels_ = stream->audio_decoder_config().channels(); |
| + |
| audio_clock_.reset( |
| new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); |
| @@ -605,6 +617,7 @@ void AudioRendererImpl::DecodedAudioReady( |
| if (last_decoded_channel_layout_ != buffer->channel_layout()) { |
| last_decoded_channel_layout_ = buffer->channel_layout(); |
| + last_decoded_channels_ = buffer->channel_count(); |
| // Input layouts should never be discrete. |
| DCHECK_NE(last_decoded_channel_layout_, CHANNEL_LAYOUT_DISCRETE); |
| @@ -990,14 +1003,10 @@ void AudioRendererImpl::ConfigureChannelMask() { |
| DCHECK(audio_parameters_.IsValid()); |
| DCHECK_NE(last_decoded_channel_layout_, CHANNEL_LAYOUT_NONE); |
| DCHECK_NE(last_decoded_channel_layout_, CHANNEL_LAYOUT_UNSUPPORTED); |
| - DCHECK_NE(last_decoded_channel_layout_, CHANNEL_LAYOUT_DISCRETE); |
| - |
| - const int input_channel_count = |
| - ChannelLayoutToChannelCount(last_decoded_channel_layout_); |
| // If we're actually downmixing the signal, no mask is necessary, but ensure |
| // we clear any existing mask if present. |
| - if (input_channel_count >= audio_parameters_.channels()) { |
| + if (last_decoded_channels_ >= audio_parameters_.channels()) { |
| algorithm_->SetChannelMask( |
| std::vector<bool>(audio_parameters_.channels(), true)); |
| return; |
| @@ -1005,7 +1014,7 @@ void AudioRendererImpl::ConfigureChannelMask() { |
| // Determine the matrix used to upmix the channels. |
| std::vector<std::vector<float>> matrix; |
| - ChannelMixingMatrix(last_decoded_channel_layout_, input_channel_count, |
| + ChannelMixingMatrix(last_decoded_channel_layout_, last_decoded_channels_, |
| audio_parameters_.channel_layout(), |
| audio_parameters_.channels()) |
| .CreateTransformationMatrix(&matrix); |