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> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "media/base/renderer_client.h" | 29 #include "media/base/renderer_client.h" |
| 30 #include "media/base/timestamp_constants.h" | 30 #include "media/base/timestamp_constants.h" |
| 31 #include "media/filters/audio_clock.h" | 31 #include "media/filters/audio_clock.h" |
| 32 #include "media/filters/decrypting_demuxer_stream.h" | 32 #include "media/filters/decrypting_demuxer_stream.h" |
| 33 | 33 |
| 34 namespace media { | 34 namespace media { |
| 35 | 35 |
| 36 AudioRendererImpl::AudioRendererImpl( | 36 AudioRendererImpl::AudioRendererImpl( |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 38 media::AudioRendererSink* sink, | 38 media::AudioRendererSink* sink, |
| 39 ScopedVector<AudioDecoder> decoders, | 39 const CreateAudioDecodersCB& create_audio_decoders_cb, |
| 40 const scoped_refptr<MediaLog>& media_log) | 40 const scoped_refptr<MediaLog>& media_log) |
| 41 : task_runner_(task_runner), | 41 : task_runner_(task_runner), |
| 42 expecting_config_changes_(false), | 42 expecting_config_changes_(false), |
| 43 sink_(sink), | 43 sink_(sink), |
| 44 audio_buffer_stream_( | |
| 45 new AudioBufferStream(task_runner, std::move(decoders), media_log)), | |
| 46 media_log_(media_log), | 44 media_log_(media_log), |
| 47 client_(nullptr), | 45 client_(nullptr), |
| 48 tick_clock_(new base::DefaultTickClock()), | 46 tick_clock_(new base::DefaultTickClock()), |
| 49 last_audio_memory_usage_(0), | 47 last_audio_memory_usage_(0), |
| 50 last_decoded_sample_rate_(0), | 48 last_decoded_sample_rate_(0), |
| 51 last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE), | 49 last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE), |
| 52 playback_rate_(0.0), | 50 playback_rate_(0.0), |
| 53 state_(kUninitialized), | 51 state_(kUninitialized), |
| 52 create_audio_decoders_cb_(create_audio_decoders_cb), | |
| 54 buffering_state_(BUFFERING_HAVE_NOTHING), | 53 buffering_state_(BUFFERING_HAVE_NOTHING), |
| 55 rendering_(false), | 54 rendering_(false), |
| 56 sink_playing_(false), | 55 sink_playing_(false), |
| 57 pending_read_(false), | 56 pending_read_(false), |
| 58 received_end_of_stream_(false), | 57 received_end_of_stream_(false), |
| 59 rendered_end_of_stream_(false), | 58 rendered_end_of_stream_(false), |
| 60 is_suspending_(false), | 59 is_suspending_(false), |
| 61 weak_factory_(this) { | 60 weak_factory_(this) { |
| 62 audio_buffer_stream_->set_config_change_observer(base::Bind( | 61 DCHECK(!create_audio_decoders_cb_.is_null()); |
|
xhwang
2017/03/27 19:13:53
FYI:
I think you can do this now:
DCHECK(create
servolk
2017/03/27 22:34:12
Nice, thanks, I didn't know about this. Done.
| |
| 63 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | |
| 64 | |
| 65 // Tests may not have a power monitor. | 62 // Tests may not have a power monitor. |
| 66 base::PowerMonitor* monitor = base::PowerMonitor::Get(); | 63 base::PowerMonitor* monitor = base::PowerMonitor::Get(); |
| 67 if (!monitor) | 64 if (!monitor) |
| 68 return; | 65 return; |
| 69 | 66 |
| 70 // PowerObserver's must be added and removed from the same thread, but we | 67 // PowerObserver's must be added and removed from the same thread, but we |
| 71 // won't remove the observer until we're destructed on |task_runner_| so we | 68 // won't remove the observer until we're destructed on |task_runner_| so we |
| 72 // must post it here if we're on the wrong thread. | 69 // must post it here if we're on the wrong thread. |
| 73 if (task_runner_->BelongsToCurrentThread()) { | 70 if (task_runner_->BelongsToCurrentThread()) { |
| 74 monitor->AddObserver(this); | 71 monitor->AddObserver(this); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 void AudioRendererImpl::Initialize(DemuxerStream* stream, | 324 void AudioRendererImpl::Initialize(DemuxerStream* stream, |
| 328 CdmContext* cdm_context, | 325 CdmContext* cdm_context, |
| 329 RendererClient* client, | 326 RendererClient* client, |
| 330 const PipelineStatusCB& init_cb) { | 327 const PipelineStatusCB& init_cb) { |
| 331 DVLOG(1) << __func__; | 328 DVLOG(1) << __func__; |
| 332 DCHECK(task_runner_->BelongsToCurrentThread()); | 329 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 333 DCHECK(client); | 330 DCHECK(client); |
| 334 DCHECK(stream); | 331 DCHECK(stream); |
| 335 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); | 332 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); |
| 336 DCHECK(!init_cb.is_null()); | 333 DCHECK(!init_cb.is_null()); |
| 337 DCHECK_EQ(kUninitialized, state_); | 334 DCHECK(state_ == kUninitialized || state_ == kFlushed); |
| 338 DCHECK(sink_.get()); | 335 DCHECK(sink_.get()); |
| 339 | 336 |
| 337 // If we are re-initializing playback (e.g. switching media tracks), stop the | |
| 338 // sink first. | |
| 339 if (state_ == kFlushed) | |
| 340 sink_->Stop(); | |
| 341 | |
| 340 state_ = kInitializing; | 342 state_ = kInitializing; |
| 341 client_ = client; | 343 client_ = client; |
| 342 | 344 |
| 345 audio_buffer_stream_ = base::MakeUnique<AudioBufferStream>( | |
| 346 task_runner_, create_audio_decoders_cb_.Run(), media_log_); | |
| 347 | |
| 348 audio_buffer_stream_->set_config_change_observer(base::Bind( | |
| 349 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | |
| 350 | |
| 343 // Always post |init_cb_| because |this| could be destroyed if initialization | 351 // Always post |init_cb_| because |this| could be destroyed if initialization |
| 344 // failed. | 352 // failed. |
| 345 init_cb_ = BindToCurrentLoop(init_cb); | 353 init_cb_ = BindToCurrentLoop(init_cb); |
| 346 | 354 |
| 347 auto output_device_info = sink_->GetOutputDeviceInfo(); | 355 auto output_device_info = sink_->GetOutputDeviceInfo(); |
| 348 const AudioParameters& hw_params = output_device_info.output_params(); | 356 const AudioParameters& hw_params = output_device_info.output_params(); |
| 349 expecting_config_changes_ = stream->SupportsConfigChanges(); | 357 expecting_config_changes_ = stream->SupportsConfigChanges(); |
| 350 if (!expecting_config_changes_ || !hw_params.IsValid() || | 358 if (!expecting_config_changes_ || !hw_params.IsValid() || |
| 351 hw_params.format() == AudioParameters::AUDIO_FAKE) { | 359 hw_params.format() == AudioParameters::AUDIO_FAKE) { |
| 352 // The actual buffer size is controlled via the size of the AudioBus | 360 // The actual buffer size is controlled via the size of the AudioBus |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 988 // All channels with a zero mix are muted and can be ignored. | 996 // All channels with a zero mix are muted and can be ignored. |
| 989 std::vector<bool> channel_mask(audio_parameters_.channels(), false); | 997 std::vector<bool> channel_mask(audio_parameters_.channels(), false); |
| 990 for (size_t ch = 0; ch < matrix.size(); ++ch) { | 998 for (size_t ch = 0; ch < matrix.size(); ++ch) { |
| 991 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), | 999 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), |
| 992 [](float mix) { return !!mix; }); | 1000 [](float mix) { return !!mix; }); |
| 993 } | 1001 } |
| 994 algorithm_->SetChannelMask(std::move(channel_mask)); | 1002 algorithm_->SetChannelMask(std::move(channel_mask)); |
| 995 } | 1003 } |
| 996 | 1004 |
| 997 } // namespace media | 1005 } // namespace media |
| OLD | NEW |