| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (base::StringToInt(threshold_ms_str, &threshold_ms) && threshold_ms > 0) { | 104 if (base::StringToInt(threshold_ms_str, &threshold_ms) && threshold_ms > 0) { |
| 105 video_underflow_threshold_ = | 105 video_underflow_threshold_ = |
| 106 base::TimeDelta::FromMilliseconds(threshold_ms); | 106 base::TimeDelta::FromMilliseconds(threshold_ms); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 RendererImpl::~RendererImpl() { | 110 RendererImpl::~RendererImpl() { |
| 111 DVLOG(1) << __func__; | 111 DVLOG(1) << __func__; |
| 112 DCHECK(task_runner_->BelongsToCurrentThread()); | 112 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 113 | 113 |
| 114 // RendererImpl is being destroyed, so invalidate weak pointers right away to |
| 115 // avoid getting callbacks which might try to access fields that has been |
| 116 // destroyed, e.g. audio_renderer_/video_renderer_ below (crbug.com/668963). |
| 117 weak_factory_.InvalidateWeakPtrs(); |
| 118 |
| 114 // Tear down in opposite order of construction as |video_renderer_| can still | 119 // Tear down in opposite order of construction as |video_renderer_| can still |
| 115 // need |time_source_| (which can be |audio_renderer_|) to be alive. | 120 // need |time_source_| (which can be |audio_renderer_|) to be alive. |
| 116 video_renderer_.reset(); | 121 video_renderer_.reset(); |
| 117 audio_renderer_.reset(); | 122 audio_renderer_.reset(); |
| 118 | 123 |
| 119 if (!init_cb_.is_null()) { | 124 if (!init_cb_.is_null()) { |
| 120 FinishInitialization(PIPELINE_ERROR_ABORT); | 125 FinishInitialization(PIPELINE_ERROR_ABORT); |
| 121 } else if (!flush_cb_.is_null()) { | 126 } else if (!flush_cb_.is_null()) { |
| 122 base::ResetAndReturn(&flush_cb_).Run(); | 127 base::ResetAndReturn(&flush_cb_).Run(); |
| 123 } | 128 } |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // for some time to avoid unnecessary glitches in audio; see | 650 // for some time to avoid unnecessary glitches in audio; see |
| 646 // http://crbug.com/144683#c53. | 651 // http://crbug.com/144683#c53. |
| 647 if (audio_renderer_ && type == DemuxerStream::VIDEO && | 652 if (audio_renderer_ && type == DemuxerStream::VIDEO && |
| 648 state_ == STATE_PLAYING) { | 653 state_ == STATE_PLAYING) { |
| 649 if (video_buffering_state_ == BUFFERING_HAVE_ENOUGH && | 654 if (video_buffering_state_ == BUFFERING_HAVE_ENOUGH && |
| 650 audio_buffering_state_ == BUFFERING_HAVE_ENOUGH && | 655 audio_buffering_state_ == BUFFERING_HAVE_ENOUGH && |
| 651 new_buffering_state == BUFFERING_HAVE_NOTHING && | 656 new_buffering_state == BUFFERING_HAVE_NOTHING && |
| 652 deferred_video_underflow_cb_.IsCancelled()) { | 657 deferred_video_underflow_cb_.IsCancelled()) { |
| 653 DVLOG(4) << __func__ << " Deferring HAVE_NOTHING for video stream."; | 658 DVLOG(4) << __func__ << " Deferring HAVE_NOTHING for video stream."; |
| 654 deferred_video_underflow_cb_.Reset( | 659 deferred_video_underflow_cb_.Reset( |
| 655 base::Bind(&RendererImpl::OnBufferingStateChange, | 660 base::Bind(&RendererImpl::OnBufferingStateChange, weak_this_, type, |
| 656 weak_factory_.GetWeakPtr(), type, new_buffering_state)); | 661 new_buffering_state)); |
| 657 task_runner_->PostDelayedTask(FROM_HERE, | 662 task_runner_->PostDelayedTask(FROM_HERE, |
| 658 deferred_video_underflow_cb_.callback(), | 663 deferred_video_underflow_cb_.callback(), |
| 659 video_underflow_threshold_); | 664 video_underflow_threshold_); |
| 660 return; | 665 return; |
| 661 } | 666 } |
| 662 | 667 |
| 663 DVLOG(4) << "deferred_video_underflow_cb_.Cancel()"; | 668 DVLOG(4) << "deferred_video_underflow_cb_.Cancel()"; |
| 664 deferred_video_underflow_cb_.Cancel(); | 669 deferred_video_underflow_cb_.Cancel(); |
| 665 } else if (!deferred_video_underflow_cb_.IsCancelled() && | 670 } else if (!deferred_video_underflow_cb_.IsCancelled() && |
| 666 type == DemuxerStream::AUDIO && | 671 type == DemuxerStream::AUDIO && |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 DCHECK(task_runner_->BelongsToCurrentThread()); | 839 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 835 client_->OnVideoNaturalSizeChange(size); | 840 client_->OnVideoNaturalSizeChange(size); |
| 836 } | 841 } |
| 837 | 842 |
| 838 void RendererImpl::OnVideoOpacityChange(bool opaque) { | 843 void RendererImpl::OnVideoOpacityChange(bool opaque) { |
| 839 DCHECK(task_runner_->BelongsToCurrentThread()); | 844 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 840 client_->OnVideoOpacityChange(opaque); | 845 client_->OnVideoOpacityChange(opaque); |
| 841 } | 846 } |
| 842 | 847 |
| 843 } // namespace media | 848 } // namespace media |
| OLD | NEW |