Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: media/renderers/renderer_impl.cc

Issue 2570773002: Fix crash when pipeline is stopped while video restart is pending (Closed)
Patch Set: Added comments + addressed CR feedback Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/renderers/renderer_impl.h ('k') | media/test/pipeline_integration_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 state_ = STATE_SHUTDOWN;
xhwang 2017/01/04 18:29:09 Instead of adding a new state, does it make sense
servolk 2017/01/04 19:00:52 Yes, I guess we could try invalidating RendererImp
115
114 // Tear down in opposite order of construction as |video_renderer_| can still 116 // Tear down in opposite order of construction as |video_renderer_| can still
115 // need |time_source_| (which can be |audio_renderer_|) to be alive. 117 // need |time_source_| (which can be |audio_renderer_|) to be alive.
116 video_renderer_.reset(); 118 video_renderer_.reset();
117 audio_renderer_.reset(); 119 audio_renderer_.reset();
118 120
119 if (!init_cb_.is_null()) { 121 if (!init_cb_.is_null()) {
120 FinishInitialization(PIPELINE_ERROR_ABORT); 122 FinishInitialization(PIPELINE_ERROR_ABORT);
121 } else if (!flush_cb_.is_null()) { 123 } else if (!flush_cb_.is_null()) {
122 base::ResetAndReturn(&flush_cb_).Run(); 124 base::ResetAndReturn(&flush_cb_).Run();
123 } 125 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 time_source_->StopTicking(); 241 time_source_->StopTicking();
240 } 242 }
241 audio_renderer_->Flush( 243 audio_renderer_->Flush(
242 base::Bind(&RendererImpl::RestartAudioRenderer, weak_this_, time)); 244 base::Bind(&RendererImpl::RestartAudioRenderer, weak_this_, time));
243 } 245 }
244 } 246 }
245 247
246 void RendererImpl::RestartVideoRenderer(base::TimeDelta time) { 248 void RendererImpl::RestartVideoRenderer(base::TimeDelta time) {
247 DVLOG(3) << __func__; 249 DVLOG(3) << __func__;
248 DCHECK(task_runner_->BelongsToCurrentThread()); 250 DCHECK(task_runner_->BelongsToCurrentThread());
251 // We only need to actually restart video renderer if we are in the PLAYING
252 // state. In all other states we don't need to do anything, since either we
253 // are already shutting down, or the VideoRenderer::StartPlayingFrom will be
254 // called when RendererImpl transitions into PLAYING state.
255 if (state_ != STATE_PLAYING)
256 return;
249 DCHECK(video_renderer_); 257 DCHECK(video_renderer_);
250 DCHECK_EQ(state_, STATE_PLAYING);
251 video_ended_ = false; 258 video_ended_ = false;
252 video_renderer_->StartPlayingFrom(time); 259 video_renderer_->StartPlayingFrom(time);
253 } 260 }
254 261
255 void RendererImpl::RestartAudioRenderer(base::TimeDelta time) { 262 void RendererImpl::RestartAudioRenderer(base::TimeDelta time) {
256 DVLOG(3) << __func__; 263 DVLOG(3) << __func__;
257 DCHECK(task_runner_->BelongsToCurrentThread()); 264 DCHECK(task_runner_->BelongsToCurrentThread());
258 DCHECK_EQ(state_, STATE_PLAYING); 265 // We only need to actually restart audio renderer if we are in the PLAYING
266 // state. In all other states we don't need to do anything, since either we
267 // are already shutting down, or the AudioRenderer::StartPlayingFrom will be
268 // called when RendererImpl transitions into PLAYING state.
269 if (state_ != STATE_PLAYING)
270 return;
259 DCHECK(time_source_); 271 DCHECK(time_source_);
260 DCHECK(audio_renderer_); 272 DCHECK(audio_renderer_);
261 audio_ended_ = false; 273 audio_ended_ = false;
262 audio_renderer_->StartPlaying(); 274 audio_renderer_->StartPlaying();
263 } 275 }
264 276
265 void RendererImpl::SetPlaybackRate(double playback_rate) { 277 void RendererImpl::SetPlaybackRate(double playback_rate) {
266 DVLOG(1) << __func__ << "(" << playback_rate << ")"; 278 DVLOG(1) << __func__ << "(" << playback_rate << ")";
267 DCHECK(task_runner_->BelongsToCurrentThread()); 279 DCHECK(task_runner_->BelongsToCurrentThread());
268 280
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 729
718 break; 730 break;
719 731
720 case STATE_FLUSHING: 732 case STATE_FLUSHING:
721 // It's OK to pause playback when flushing. 733 // It's OK to pause playback when flushing.
722 break; 734 break;
723 735
724 case STATE_UNINITIALIZED: 736 case STATE_UNINITIALIZED:
725 case STATE_INIT_PENDING_CDM: 737 case STATE_INIT_PENDING_CDM:
726 case STATE_INITIALIZING: 738 case STATE_INITIALIZING:
739 case STATE_SHUTDOWN:
727 NOTREACHED() << "Invalid state: " << state_; 740 NOTREACHED() << "Invalid state: " << state_;
728 break; 741 break;
729 742
730 case STATE_ERROR: 743 case STATE_ERROR:
731 // An error state may occur at any time. 744 // An error state may occur at any time.
732 break; 745 break;
733 } 746 }
734 747
735 if (time_ticking_) { 748 if (time_ticking_) {
736 time_ticking_ = false; 749 time_ticking_ = false;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 DCHECK(task_runner_->BelongsToCurrentThread()); 847 DCHECK(task_runner_->BelongsToCurrentThread());
835 client_->OnVideoNaturalSizeChange(size); 848 client_->OnVideoNaturalSizeChange(size);
836 } 849 }
837 850
838 void RendererImpl::OnVideoOpacityChange(bool opaque) { 851 void RendererImpl::OnVideoOpacityChange(bool opaque) {
839 DCHECK(task_runner_->BelongsToCurrentThread()); 852 DCHECK(task_runner_->BelongsToCurrentThread());
840 client_->OnVideoOpacityChange(opaque); 853 client_->OnVideoOpacityChange(opaque);
841 } 854 }
842 855
843 } // namespace media 856 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/renderer_impl.h ('k') | media/test/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698