Chromium Code Reviews| 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] = | |
| 444 std::find_if(matrix[ch].begin(), matrix[ch].end(), | |
| 445 [](float mix) { return !!mix; }) != matrix[ch].end(); | |
|
sandersd (OOO until July 31)
2016/11/22 00:59:24
Nit: Would be more clear using std::any_of().
DaleCurtis
2016/11/22 01:07:49
Ah, didn't know about that one. Done.
| |
| 446 } | |
| 447 } | |
| 429 } | 448 } |
| 430 | 449 |
| 431 audio_clock_.reset( | 450 audio_clock_.reset( |
| 432 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); | 451 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); |
| 433 | 452 |
| 434 audio_buffer_stream_->Initialize( | 453 audio_buffer_stream_->Initialize( |
| 435 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, | 454 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, |
| 436 weak_factory_.GetWeakPtr()), | 455 weak_factory_.GetWeakPtr()), |
| 437 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, | 456 cdm_context, base::Bind(&AudioRendererImpl::OnStatisticsUpdate, |
| 438 weak_factory_.GetWeakPtr()), | 457 weak_factory_.GetWeakPtr()), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 459 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); | 478 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 460 return; | 479 return; |
| 461 } | 480 } |
| 462 | 481 |
| 463 if (expecting_config_changes_) | 482 if (expecting_config_changes_) |
| 464 buffer_converter_.reset(new AudioBufferConverter(audio_parameters_)); | 483 buffer_converter_.reset(new AudioBufferConverter(audio_parameters_)); |
| 465 | 484 |
| 466 // We're all good! Continue initializing the rest of the audio renderer | 485 // We're all good! Continue initializing the rest of the audio renderer |
| 467 // based on the decoder format. | 486 // based on the decoder format. |
| 468 algorithm_.reset(new AudioRendererAlgorithm()); | 487 algorithm_.reset(new AudioRendererAlgorithm()); |
| 469 algorithm_->Initialize(audio_parameters_); | 488 algorithm_->Initialize(audio_parameters_, channel_mask_); |
| 470 | 489 |
| 471 ChangeState_Locked(kFlushed); | 490 ChangeState_Locked(kFlushed); |
| 472 | 491 |
| 473 { | 492 { |
| 474 base::AutoUnlock auto_unlock(lock_); | 493 base::AutoUnlock auto_unlock(lock_); |
| 475 sink_->Initialize(audio_parameters_, this); | 494 sink_->Initialize(audio_parameters_, this); |
| 476 sink_->Start(); | 495 sink_->Start(); |
| 477 | 496 |
| 478 // Some sinks play on start... | 497 // Some sinks play on start... |
| 479 sink_->Pause(); | 498 sink_->Pause(); |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 DCHECK_NE(buffering_state_, buffering_state); | 951 DCHECK_NE(buffering_state_, buffering_state); |
| 933 lock_.AssertAcquired(); | 952 lock_.AssertAcquired(); |
| 934 buffering_state_ = buffering_state; | 953 buffering_state_ = buffering_state; |
| 935 | 954 |
| 936 task_runner_->PostTask( | 955 task_runner_->PostTask( |
| 937 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 956 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
| 938 weak_factory_.GetWeakPtr(), buffering_state_)); | 957 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 939 } | 958 } |
| 940 | 959 |
| 941 } // namespace media | 960 } // namespace media |
| OLD | NEW |