| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/power_monitor/power_monitor.h" | 17 #include "base/power_monitor/power_monitor.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/time/default_tick_clock.h" | 19 #include "base/time/default_tick_clock.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "media/base/audio_buffer.h" | 21 #include "media/base/audio_buffer.h" |
| 22 #include "media/base/audio_buffer_converter.h" | 22 #include "media/base/audio_buffer_converter.h" |
| 23 #include "media/base/audio_latency.h" | 23 #include "media/base/audio_latency.h" |
| 24 #include "media/base/bind_to_current_loop.h" | 24 #include "media/base/bind_to_current_loop.h" |
| 25 #include "media/base/channel_mixing_matrix.h" |
| 25 #include "media/base/demuxer_stream.h" | 26 #include "media/base/demuxer_stream.h" |
| 26 #include "media/base/media_log.h" | 27 #include "media/base/media_log.h" |
| 27 #include "media/base/media_switches.h" | 28 #include "media/base/media_switches.h" |
| 28 #include "media/base/renderer_client.h" | 29 #include "media/base/renderer_client.h" |
| 29 #include "media/base/timestamp_constants.h" | 30 #include "media/base/timestamp_constants.h" |
| 30 #include "media/filters/audio_clock.h" | 31 #include "media/filters/audio_clock.h" |
| 31 #include "media/filters/decrypting_demuxer_stream.h" | 32 #include "media/filters/decrypting_demuxer_stream.h" |
| 32 | 33 |
| 33 namespace media { | 34 namespace media { |
| 34 | 35 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 // down-mixing and use the data from all stream channels. | 420 // down-mixing and use the data from all stream channels. |
| 420 ChannelLayout renderer_channel_layout = | 421 ChannelLayout renderer_channel_layout = |
| 421 hw_channel_count > stream_channel_count | 422 hw_channel_count > stream_channel_count |
| 422 ? hw_channel_layout | 423 ? hw_channel_layout |
| 423 : stream->audio_decoder_config().channel_layout(); | 424 : stream->audio_decoder_config().channel_layout(); |
| 424 | 425 |
| 425 audio_parameters_.Reset(hw_params.format(), renderer_channel_layout, | 426 audio_parameters_.Reset(hw_params.format(), renderer_channel_layout, |
| 426 sample_rate, hw_params.bits_per_sample(), | 427 sample_rate, hw_params.bits_per_sample(), |
| 427 media::AudioLatency::GetHighLatencyBufferSize( | 428 media::AudioLatency::GetHighLatencyBufferSize( |
| 428 sample_rate, preferred_buffer_size)); | 429 sample_rate, preferred_buffer_size)); |
| 430 |
| 431 // Figure out if there are muted channels that we should ignore when |
| 432 // playback rate adapatation is requested (it's expensive). |
| 433 if (stream_channel_count < audio_parameters_.channels()) { |
| 434 std::vector<std::vector<float>> matrix; |
| 435 ChannelMixingMatrix( |
| 436 stream->audio_decoder_config().channel_layout(), stream_channel_count, |
| 437 audio_parameters_.channel_layout(), audio_parameters_.channels()) |
| 438 .CreateTransformationMatrix(&matrix); |
| 439 |
| 440 // All channels with a zero mix are muted and can be ignored. |
| 441 channel_mask_ = std::vector<bool>(audio_parameters_.channels(), false); |
| 442 for (size_t ch = 0; ch < matrix.size(); ++ch) { |
| 443 channel_mask_[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), |
| 444 [](float mix) { return !!mix; }); |
| 445 } |
| 446 } |
| 429 } | 447 } |
| 430 | 448 |
| 431 audio_clock_.reset( | 449 audio_clock_.reset( |
| 432 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); | 450 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); |
| 433 | 451 |
| 434 audio_buffer_stream_->Initialize( | 452 audio_buffer_stream_->Initialize( |
| 435 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, | 453 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, |
| 436 weak_factory_.GetWeakPtr()), | 454 weak_factory_.GetWeakPtr()), |
| 437 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, | 455 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, |
| 438 weak_factory_.GetWeakPtr()), | 456 weak_factory_.GetWeakPtr()), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 459 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); | 477 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 460 return; | 478 return; |
| 461 } | 479 } |
| 462 | 480 |
| 463 if (expecting_config_changes_) | 481 if (expecting_config_changes_) |
| 464 buffer_converter_.reset(new AudioBufferConverter(audio_parameters_)); | 482 buffer_converter_.reset(new AudioBufferConverter(audio_parameters_)); |
| 465 | 483 |
| 466 // We're all good! Continue initializing the rest of the audio renderer | 484 // We're all good! Continue initializing the rest of the audio renderer |
| 467 // based on the decoder format. | 485 // based on the decoder format. |
| 468 algorithm_.reset(new AudioRendererAlgorithm()); | 486 algorithm_.reset(new AudioRendererAlgorithm()); |
| 469 algorithm_->Initialize(audio_parameters_); | 487 algorithm_->Initialize(audio_parameters_, channel_mask_); |
| 470 | 488 |
| 471 ChangeState_Locked(kFlushed); | 489 ChangeState_Locked(kFlushed); |
| 472 | 490 |
| 473 { | 491 { |
| 474 base::AutoUnlock auto_unlock(lock_); | 492 base::AutoUnlock auto_unlock(lock_); |
| 475 sink_->Initialize(audio_parameters_, this); | 493 sink_->Initialize(audio_parameters_, this); |
| 476 sink_->Start(); | 494 sink_->Start(); |
| 477 | 495 |
| 478 // Some sinks play on start... | 496 // Some sinks play on start... |
| 479 sink_->Pause(); | 497 sink_->Pause(); |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 DCHECK_NE(buffering_state_, buffering_state); | 950 DCHECK_NE(buffering_state_, buffering_state); |
| 933 lock_.AssertAcquired(); | 951 lock_.AssertAcquired(); |
| 934 buffering_state_ = buffering_state; | 952 buffering_state_ = buffering_state; |
| 935 | 953 |
| 936 task_runner_->PostTask( | 954 task_runner_->PostTask( |
| 937 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 955 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
| 938 weak_factory_.GetWeakPtr(), buffering_state_)); | 956 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 939 } | 957 } |
| 940 | 958 |
| 941 } // namespace media | 959 } // namespace media |
| OLD | NEW |