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

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

Issue 870693002: Require Renderer::Initialize() to return a status code via callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Fix comments. Created 5 years, 11 months 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/filters/renderer_impl.h ('k') | media/filters/renderer_impl_unittest.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/filters/renderer_impl.h" 5 #include "media/filters/renderer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 RendererImpl::~RendererImpl() { 44 RendererImpl::~RendererImpl() {
45 DVLOG(1) << __FUNCTION__; 45 DVLOG(1) << __FUNCTION__;
46 DCHECK(task_runner_->BelongsToCurrentThread()); 46 DCHECK(task_runner_->BelongsToCurrentThread());
47 47
48 // Tear down in opposite order of construction as |video_renderer_| can still 48 // Tear down in opposite order of construction as |video_renderer_| can still
49 // need |time_source_| (which can be |audio_renderer_|) to be alive. 49 // need |time_source_| (which can be |audio_renderer_|) to be alive.
50 video_renderer_.reset(); 50 video_renderer_.reset();
51 audio_renderer_.reset(); 51 audio_renderer_.reset();
52 52
53 if (!init_cb_.is_null())
54 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT);
xhwang 2015/01/23 21:03:07 I don't think we could have |flush_cb| during init
DaleCurtis 2015/01/23 21:19:42 Changed to else.
55
53 FireAllPendingCallbacks(); 56 FireAllPendingCallbacks();
54 } 57 }
55 58
56 void RendererImpl::Initialize(DemuxerStreamProvider* demuxer_stream_provider, 59 void RendererImpl::Initialize(DemuxerStreamProvider* demuxer_stream_provider,
57 const base::Closure& init_cb, 60 const PipelineStatusCB& init_cb,
58 const StatisticsCB& statistics_cb, 61 const StatisticsCB& statistics_cb,
59 const BufferingStateCB& buffering_state_cb, 62 const BufferingStateCB& buffering_state_cb,
60 const PaintCB& paint_cb, 63 const PaintCB& paint_cb,
61 const base::Closure& ended_cb, 64 const base::Closure& ended_cb,
62 const PipelineStatusCB& error_cb) { 65 const PipelineStatusCB& error_cb) {
63 DVLOG(1) << __FUNCTION__; 66 DVLOG(1) << __FUNCTION__;
64 DCHECK(task_runner_->BelongsToCurrentThread()); 67 DCHECK(task_runner_->BelongsToCurrentThread());
65 DCHECK_EQ(state_, STATE_UNINITIALIZED); 68 DCHECK_EQ(state_, STATE_UNINITIALIZED);
66 DCHECK(!init_cb.is_null()); 69 DCHECK(!init_cb.is_null());
67 DCHECK(!statistics_cb.is_null()); 70 DCHECK(!statistics_cb.is_null());
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, 258 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_,
256 &audio_buffering_state_), 259 &audio_buffering_state_),
257 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), 260 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_),
258 base::Bind(&RendererImpl::OnError, weak_this_)); 261 base::Bind(&RendererImpl::OnError, weak_this_));
259 } 262 }
260 263
261 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { 264 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) {
262 DVLOG(1) << __FUNCTION__ << ": " << status; 265 DVLOG(1) << __FUNCTION__ << ": " << status;
263 DCHECK(task_runner_->BelongsToCurrentThread()); 266 DCHECK(task_runner_->BelongsToCurrentThread());
264 267
265 if (status != PIPELINE_OK)
266 OnError(status);
267
268 // OnError() may be fired at any time by the renderers, even if they thought 268 // OnError() may be fired at any time by the renderers, even if they thought
269 // they initialized successfully (due to delayed output device setup). 269 // they initialized successfully (due to delayed output device setup).
270 if (state_ != STATE_INITIALIZING) { 270 if (state_ != STATE_INITIALIZING) {
271 DCHECK(init_cb_.is_null());
271 audio_renderer_.reset(); 272 audio_renderer_.reset();
272 return; 273 return;
273 } 274 }
274 275
276 if (status != PIPELINE_OK) {
277 base::ResetAndReturn(&init_cb_).Run(status);
278 return;
279 }
280
275 DCHECK(!init_cb_.is_null()); 281 DCHECK(!init_cb_.is_null());
276 InitializeVideoRenderer(); 282 InitializeVideoRenderer();
277 } 283 }
278 284
279 void RendererImpl::InitializeVideoRenderer() { 285 void RendererImpl::InitializeVideoRenderer() {
280 DVLOG(1) << __FUNCTION__; 286 DVLOG(1) << __FUNCTION__;
281 DCHECK(task_runner_->BelongsToCurrentThread()); 287 DCHECK(task_runner_->BelongsToCurrentThread());
282 DCHECK_EQ(state_, STATE_INITIALIZING); 288 DCHECK_EQ(state_, STATE_INITIALIZING);
283 DCHECK(!init_cb_.is_null()); 289 DCHECK(!init_cb_.is_null());
284 290
(...skipping 16 matching lines...) Expand all
301 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), 307 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_),
302 base::Bind(&RendererImpl::OnError, weak_this_), 308 base::Bind(&RendererImpl::OnError, weak_this_),
303 base::Bind(&RendererImpl::GetMediaTimeForSyncingVideo, 309 base::Bind(&RendererImpl::GetMediaTimeForSyncingVideo,
304 base::Unretained(this))); 310 base::Unretained(this)));
305 } 311 }
306 312
307 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { 313 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) {
308 DVLOG(1) << __FUNCTION__ << ": " << status; 314 DVLOG(1) << __FUNCTION__ << ": " << status;
309 DCHECK(task_runner_->BelongsToCurrentThread()); 315 DCHECK(task_runner_->BelongsToCurrentThread());
310 316
311 if (status != PIPELINE_OK)
312 OnError(status);
313
314 // OnError() may be fired at any time by the renderers, even if they thought 317 // OnError() may be fired at any time by the renderers, even if they thought
315 // they initialized successfully (due to delayed output device setup). 318 // they initialized successfully (due to delayed output device setup).
316 if (state_ != STATE_INITIALIZING) { 319 if (state_ != STATE_INITIALIZING) {
320 DCHECK(init_cb_.is_null());
317 audio_renderer_.reset(); 321 audio_renderer_.reset();
318 video_renderer_.reset(); 322 video_renderer_.reset();
319 return; 323 return;
320 } 324 }
321 325
322 DCHECK(!init_cb_.is_null()); 326 DCHECK(!init_cb_.is_null());
323 327
328 if (status != PIPELINE_OK) {
329 base::ResetAndReturn(&init_cb_).Run(status);
330 return;
331 }
332
324 if (audio_renderer_) { 333 if (audio_renderer_) {
325 time_source_ = audio_renderer_->GetTimeSource(); 334 time_source_ = audio_renderer_->GetTimeSource();
326 } else { 335 } else {
327 wall_clock_time_source_.reset(new WallClockTimeSource()); 336 wall_clock_time_source_.reset(new WallClockTimeSource());
328 time_source_ = wall_clock_time_source_.get(); 337 time_source_ = wall_clock_time_source_.get();
329 } 338 }
330 339
331 state_ = STATE_PLAYING; 340 state_ = STATE_PLAYING;
332 DCHECK(time_source_); 341 DCHECK(time_source_);
333 DCHECK(audio_renderer_ || video_renderer_); 342 DCHECK(audio_renderer_ || video_renderer_);
334 base::ResetAndReturn(&init_cb_).Run(); 343 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
335 } 344 }
336 345
337 void RendererImpl::FlushAudioRenderer() { 346 void RendererImpl::FlushAudioRenderer() {
338 DVLOG(1) << __FUNCTION__; 347 DVLOG(1) << __FUNCTION__;
339 DCHECK(task_runner_->BelongsToCurrentThread()); 348 DCHECK(task_runner_->BelongsToCurrentThread());
340 DCHECK_EQ(state_, STATE_FLUSHING); 349 DCHECK_EQ(state_, STATE_FLUSHING);
341 DCHECK(!flush_cb_.is_null()); 350 DCHECK(!flush_cb_.is_null());
342 351
343 if (!audio_renderer_) { 352 if (!audio_renderer_) {
344 OnAudioRendererFlushDone(); 353 OnAudioRendererFlushDone();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 551
543 void RendererImpl::OnError(PipelineStatus error) { 552 void RendererImpl::OnError(PipelineStatus error) {
544 DVLOG(1) << __FUNCTION__ << "(" << error << ")"; 553 DVLOG(1) << __FUNCTION__ << "(" << error << ")";
545 DCHECK(task_runner_->BelongsToCurrentThread()); 554 DCHECK(task_runner_->BelongsToCurrentThread());
546 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; 555 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!";
547 556
548 // An error has already been delivered. 557 // An error has already been delivered.
549 if (state_ == STATE_ERROR) 558 if (state_ == STATE_ERROR)
550 return; 559 return;
551 560
561 const State old_state = state_;
552 state_ = STATE_ERROR; 562 state_ = STATE_ERROR;
553 563
564 if (old_state == STATE_INITIALIZING) {
565 base::ResetAndReturn(&init_cb_).Run(error);
566 return;
567 }
568
554 // Pipeline will destroy |this| as the result of error. 569 // Pipeline will destroy |this| as the result of error.
555 base::ResetAndReturn(&error_cb_).Run(error); 570 base::ResetAndReturn(&error_cb_).Run(error);
556
557 FireAllPendingCallbacks(); 571 FireAllPendingCallbacks();
558 } 572 }
559 573
560 void RendererImpl::FireAllPendingCallbacks() { 574 void RendererImpl::FireAllPendingCallbacks() {
xhwang 2015/01/23 21:03:07 Now this function only fires |flush_cb_|, maybe we
DaleCurtis 2015/01/23 21:19:42 Agreed.
561 DCHECK(task_runner_->BelongsToCurrentThread()); 575 DCHECK(task_runner_->BelongsToCurrentThread());
562
563 if (!init_cb_.is_null())
564 base::ResetAndReturn(&init_cb_).Run();
565
566 if (!flush_cb_.is_null()) 576 if (!flush_cb_.is_null())
567 base::ResetAndReturn(&flush_cb_).Run(); 577 base::ResetAndReturn(&flush_cb_).Run();
568 } 578 }
569 579
570 } // namespace media 580 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/renderer_impl.h ('k') | media/filters/renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698