| OLD | NEW |
| 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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | 363 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); |
| 364 | 364 |
| 365 // Always post |init_cb_| because |this| could be destroyed if initialization | 365 // Always post |init_cb_| because |this| could be destroyed if initialization |
| 366 // failed. | 366 // failed. |
| 367 init_cb_ = BindToCurrentLoop(init_cb); | 367 init_cb_ = BindToCurrentLoop(init_cb); |
| 368 | 368 |
| 369 auto output_device_info = sink_->GetOutputDeviceInfo(); | 369 auto output_device_info = sink_->GetOutputDeviceInfo(); |
| 370 const AudioParameters& hw_params = output_device_info.output_params(); | 370 const AudioParameters& hw_params = output_device_info.output_params(); |
| 371 expecting_config_changes_ = stream->SupportsConfigChanges(); | 371 expecting_config_changes_ = stream->SupportsConfigChanges(); |
| 372 if (!expecting_config_changes_ || !hw_params.IsValid() || | 372 if (!expecting_config_changes_ || !hw_params.IsValid() || |
| 373 hw_params.format() == AudioParameters::AUDIO_FAKE) { | 373 hw_params.format() == AudioParameters::AUDIO_FAKE || |
| 374 !sink_->IsOptimizedForHardwareParameters()) { |
| 374 // The actual buffer size is controlled via the size of the AudioBus | 375 // The actual buffer size is controlled via the size of the AudioBus |
| 375 // provided to Render(), but we should choose a value here based on hardware | 376 // provided to Render(), but we should choose a value here based on hardware |
| 376 // parameters if possible since it affects the initial buffer size used by | 377 // parameters if possible since it affects the initial buffer size used by |
| 377 // the algorithm. Too little will cause underflow on Bluetooth devices. | 378 // the algorithm. Too little will cause underflow on Bluetooth devices. |
| 378 int buffer_size = | 379 int buffer_size = |
| 379 std::max(stream->audio_decoder_config().samples_per_second() / 100, | 380 std::max(stream->audio_decoder_config().samples_per_second() / 100, |
| 380 hw_params.IsValid() ? hw_params.frames_per_buffer() : 0); | 381 hw_params.IsValid() ? hw_params.frames_per_buffer() : 0); |
| 381 audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 382 audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 382 stream->audio_decoder_config().channel_layout(), | 383 stream->audio_decoder_config().channel_layout(), |
| 383 stream->audio_decoder_config().samples_per_second(), | 384 stream->audio_decoder_config().samples_per_second(), |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 // All channels with a zero mix are muted and can be ignored. | 1013 // All channels with a zero mix are muted and can be ignored. |
| 1013 std::vector<bool> channel_mask(audio_parameters_.channels(), false); | 1014 std::vector<bool> channel_mask(audio_parameters_.channels(), false); |
| 1014 for (size_t ch = 0; ch < matrix.size(); ++ch) { | 1015 for (size_t ch = 0; ch < matrix.size(); ++ch) { |
| 1015 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), | 1016 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), |
| 1016 [](float mix) { return !!mix; }); | 1017 [](float mix) { return !!mix; }); |
| 1017 } | 1018 } |
| 1018 algorithm_->SetChannelMask(std::move(channel_mask)); | 1019 algorithm_->SetChannelMask(std::move(channel_mask)); |
| 1019 } | 1020 } |
| 1020 | 1021 |
| 1021 } // namespace media | 1022 } // namespace media |
| OLD | NEW |