OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer_impl.h" | 5 #include "media/renderers/renderer_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 playback_rate_(0.0), | 87 playback_rate_(0.0), |
88 audio_buffering_state_(BUFFERING_HAVE_NOTHING), | 88 audio_buffering_state_(BUFFERING_HAVE_NOTHING), |
89 video_buffering_state_(BUFFERING_HAVE_NOTHING), | 89 video_buffering_state_(BUFFERING_HAVE_NOTHING), |
90 audio_ended_(false), | 90 audio_ended_(false), |
91 video_ended_(false), | 91 video_ended_(false), |
92 cdm_context_(nullptr), | 92 cdm_context_(nullptr), |
93 underflow_disabled_for_testing_(false), | 93 underflow_disabled_for_testing_(false), |
94 clockless_video_playback_enabled_for_testing_(false), | 94 clockless_video_playback_enabled_for_testing_(false), |
95 video_underflow_threshold_( | 95 video_underflow_threshold_( |
96 base::TimeDelta::FromMilliseconds(kDefaultVideoUnderflowThresholdMs)), | 96 base::TimeDelta::FromMilliseconds(kDefaultVideoUnderflowThresholdMs)), |
97 restarting_audio_time_(kNoTimestamp), | |
DaleCurtis
2017/05/23 23:35:53
Can inline initialize this too?
servolk
2017/05/23 23:45:22
Done.
| |
97 weak_factory_(this) { | 98 weak_factory_(this) { |
98 weak_this_ = weak_factory_.GetWeakPtr(); | 99 weak_this_ = weak_factory_.GetWeakPtr(); |
99 DVLOG(1) << __func__; | 100 DVLOG(1) << __func__; |
100 | 101 |
101 // TODO(dalecurtis): Remove once experiments for http://crbug.com/470940 are | 102 // TODO(dalecurtis): Remove once experiments for http://crbug.com/470940 are |
102 // complete. | 103 // complete. |
103 int threshold_ms = 0; | 104 int threshold_ms = 0; |
104 std::string threshold_ms_str( | 105 std::string threshold_ms_str( |
105 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 106 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
106 switches::kVideoUnderflowThresholdMs)); | 107 switches::kVideoUnderflowThresholdMs)); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 DVLOG(1) << __func__; | 258 DVLOG(1) << __func__; |
258 DCHECK(task_runner_->BelongsToCurrentThread()); | 259 DCHECK(task_runner_->BelongsToCurrentThread()); |
259 | 260 |
260 if (audio_renderer_) | 261 if (audio_renderer_) |
261 audio_renderer_->SetVolume(volume); | 262 audio_renderer_->SetVolume(volume); |
262 } | 263 } |
263 | 264 |
264 base::TimeDelta RendererImpl::GetMediaTime() { | 265 base::TimeDelta RendererImpl::GetMediaTime() { |
265 // No BelongsToCurrentThread() checking because this can be called from other | 266 // No BelongsToCurrentThread() checking because this can be called from other |
266 // threads. | 267 // threads. |
268 base::AutoLock lock(restarting_audio_lock_); | |
269 if (restarting_audio_) { | |
270 DCHECK_NE(kNoTimestamp, restarting_audio_time_); | |
271 return restarting_audio_time_; | |
272 } | |
267 return time_source_->CurrentMediaTime(); | 273 return time_source_->CurrentMediaTime(); |
268 } | 274 } |
269 | 275 |
270 void RendererImpl::DisableUnderflowForTesting() { | 276 void RendererImpl::DisableUnderflowForTesting() { |
271 DVLOG(1) << __func__; | 277 DVLOG(1) << __func__; |
272 DCHECK(task_runner_->BelongsToCurrentThread()); | 278 DCHECK(task_runner_->BelongsToCurrentThread()); |
273 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 279 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
274 | 280 |
275 underflow_disabled_for_testing_ = true; | 281 underflow_disabled_for_testing_ = true; |
276 } | 282 } |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 ? &RendererImpl::RestartVideoRenderer | 574 ? &RendererImpl::RestartVideoRenderer |
569 : &RendererImpl::ReinitializeVideoRenderer, | 575 : &RendererImpl::ReinitializeVideoRenderer, |
570 weak_this_, stream, time); | 576 weak_this_, stream, time); |
571 if (state_ == STATE_FLUSHED) | 577 if (state_ == STATE_FLUSHED) |
572 handle_track_status_cb.Run(); | 578 handle_track_status_cb.Run(); |
573 else | 579 else |
574 video_renderer_->Flush(handle_track_status_cb); | 580 video_renderer_->Flush(handle_track_status_cb); |
575 } else if (stream->type() == DemuxerStream::AUDIO) { | 581 } else if (stream->type() == DemuxerStream::AUDIO) { |
576 DCHECK(audio_renderer_); | 582 DCHECK(audio_renderer_); |
577 DCHECK(time_source_); | 583 DCHECK(time_source_); |
578 restarting_audio_ = true; | 584 { |
585 base::AutoLock lock(restarting_audio_lock_); | |
586 restarting_audio_time_ = time; | |
587 restarting_audio_ = true; | |
588 } | |
579 base::Closure handle_track_status_cb = | 589 base::Closure handle_track_status_cb = |
580 base::Bind(stream == current_audio_stream_ | 590 base::Bind(stream == current_audio_stream_ |
581 ? &RendererImpl::RestartAudioRenderer | 591 ? &RendererImpl::RestartAudioRenderer |
582 : &RendererImpl::ReinitializeAudioRenderer, | 592 : &RendererImpl::ReinitializeAudioRenderer, |
583 weak_this_, stream, time); | 593 weak_this_, stream, time); |
584 if (state_ == STATE_FLUSHED) { | 594 if (state_ == STATE_FLUSHED) { |
585 handle_track_status_cb.Run(); | 595 handle_track_status_cb.Run(); |
586 return; | 596 return; |
587 } | 597 } |
588 // Stop ticking (transition into paused state) in audio renderer before | 598 // Stop ticking (transition into paused state) in audio renderer before |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 } | 772 } |
763 } | 773 } |
764 return false; | 774 return false; |
765 } | 775 } |
766 | 776 |
767 void RendererImpl::OnStreamRestartCompleted() { | 777 void RendererImpl::OnStreamRestartCompleted() { |
768 DVLOG(3) << __func__ << " restarting_audio_=" << restarting_audio_ | 778 DVLOG(3) << __func__ << " restarting_audio_=" << restarting_audio_ |
769 << " restarting_video_=" << restarting_video_; | 779 << " restarting_video_=" << restarting_video_; |
770 DCHECK(task_runner_->BelongsToCurrentThread()); | 780 DCHECK(task_runner_->BelongsToCurrentThread()); |
771 DCHECK(restarting_audio_ || restarting_video_); | 781 DCHECK(restarting_audio_ || restarting_video_); |
772 restarting_audio_ = false; | 782 { |
783 base::AutoLock lock(restarting_audio_lock_); | |
784 restarting_audio_ = false; | |
785 restarting_audio_time_ = kNoTimestamp; | |
786 } | |
773 restarting_video_ = false; | 787 restarting_video_ = false; |
774 if (!pending_actions_.empty()) { | 788 if (!pending_actions_.empty()) { |
775 base::Closure closure = pending_actions_.front(); | 789 base::Closure closure = pending_actions_.front(); |
776 pending_actions_.pop_front(); | 790 pending_actions_.pop_front(); |
777 closure.Run(); | 791 closure.Run(); |
778 } | 792 } |
779 } | 793 } |
780 | 794 |
781 void RendererImpl::OnBufferingStateChange(DemuxerStream::Type type, | 795 void RendererImpl::OnBufferingStateChange(DemuxerStream::Type type, |
782 BufferingState new_buffering_state) { | 796 BufferingState new_buffering_state) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
991 DCHECK(task_runner_->BelongsToCurrentThread()); | 1005 DCHECK(task_runner_->BelongsToCurrentThread()); |
992 client_->OnVideoNaturalSizeChange(size); | 1006 client_->OnVideoNaturalSizeChange(size); |
993 } | 1007 } |
994 | 1008 |
995 void RendererImpl::OnVideoOpacityChange(bool opaque) { | 1009 void RendererImpl::OnVideoOpacityChange(bool opaque) { |
996 DCHECK(task_runner_->BelongsToCurrentThread()); | 1010 DCHECK(task_runner_->BelongsToCurrentThread()); |
997 client_->OnVideoOpacityChange(opaque); | 1011 client_->OnVideoOpacityChange(opaque); |
998 } | 1012 } |
999 | 1013 |
1000 } // namespace media | 1014 } // namespace media |
OLD | NEW |