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

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

Issue 9717021: Make Callback::Reset() return a copy to support use-cases where Run() ends up modifying |*this|. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "media/base/buffers.h" 8 #include "media/base/buffers.h"
9 #include "media/base/filter_host.h" 9 #include "media/base/filter_host.h"
10 #include "media/base/limits.h" 10 #include "media/base/limits.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 360 }
361 361
362 if (!frame) { 362 if (!frame) {
363 if (state_ != kSeeking) 363 if (state_ != kSeeking)
364 return; 364 return;
365 365
366 // Abort seek early for a NULL frame because we won't get more frames. 366 // Abort seek early for a NULL frame because we won't get more frames.
367 // A new seek will be requested after this one completes so there is no 367 // A new seek will be requested after this one completes so there is no
368 // point trying to collect more frames. 368 // point trying to collect more frames.
369 state_ = kPrerolled; 369 state_ = kPrerolled;
370 ResetAndRunCB(&seek_cb_, PIPELINE_OK); 370 seek_cb_.ResetAndRun(PIPELINE_OK);
371 return; 371 return;
372 } 372 }
373 373
374 // Discard frames until we reach our desired seek timestamp. 374 // Discard frames until we reach our desired seek timestamp.
375 if (state_ == kSeeking && !frame->IsEndOfStream() && 375 if (state_ == kSeeking && !frame->IsEndOfStream() &&
376 (frame->GetTimestamp() + frame->GetDuration()) <= seek_timestamp_) { 376 (frame->GetTimestamp() + frame->GetDuration()) <= seek_timestamp_) {
377 AttemptRead_Locked(); 377 AttemptRead_Locked();
378 return; 378 return;
379 } 379 }
380 380
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // Because we might remain in the prerolled state for an undetermined amount 419 // Because we might remain in the prerolled state for an undetermined amount
420 // of time (i.e., we were not playing before we received a seek), we'll 420 // of time (i.e., we were not playing before we received a seek), we'll
421 // manually update the current frame and notify the subclass below. 421 // manually update the current frame and notify the subclass below.
422 if (!ready_frames_.front()->IsEndOfStream()) { 422 if (!ready_frames_.front()->IsEndOfStream()) {
423 current_frame_ = ready_frames_.front(); 423 current_frame_ = ready_frames_.front();
424 ready_frames_.pop_front(); 424 ready_frames_.pop_front();
425 } 425 }
426 426
427 // ...and we're done seeking! 427 // ...and we're done seeking!
428 DCHECK(!seek_cb_.is_null()); 428 DCHECK(!seek_cb_.is_null());
429 ResetAndRunCB(&seek_cb_, PIPELINE_OK); 429 seek_cb_.ResetAndRun(PIPELINE_OK);
430 430
431 base::AutoUnlock ul(lock_); 431 base::AutoUnlock ul(lock_);
432 paint_cb_.Run(); 432 paint_cb_.Run();
433 } 433 }
434 } 434 }
435 435
436 void VideoRendererBase::AttemptRead_Locked() { 436 void VideoRendererBase::AttemptRead_Locked() {
437 lock_.AssertAcquired(); 437 lock_.AssertAcquired();
438 DCHECK_NE(kEnded, state_); 438 DCHECK_NE(kEnded, state_);
439 439
(...skipping 10 matching lines...) Expand all
450 void VideoRendererBase::AttemptFlush_Locked() { 450 void VideoRendererBase::AttemptFlush_Locked() {
451 lock_.AssertAcquired(); 451 lock_.AssertAcquired();
452 DCHECK_EQ(kFlushing, state_); 452 DCHECK_EQ(kFlushing, state_);
453 453
454 // Get rid of any ready frames. 454 // Get rid of any ready frames.
455 ready_frames_.clear(); 455 ready_frames_.clear();
456 456
457 if (!pending_paint_ && !pending_read_) { 457 if (!pending_paint_ && !pending_read_) {
458 state_ = kFlushed; 458 state_ = kFlushed;
459 current_frame_ = NULL; 459 current_frame_ = NULL;
460 ResetAndRunCB(&flush_cb_); 460 flush_cb_.ResetAndRun();
461 } 461 }
462 } 462 }
463 463
464 base::TimeDelta VideoRendererBase::CalculateSleepDuration( 464 base::TimeDelta VideoRendererBase::CalculateSleepDuration(
465 const scoped_refptr<VideoFrame>& next_frame, 465 const scoped_refptr<VideoFrame>& next_frame,
466 float playback_rate) { 466 float playback_rate) {
467 // Determine the current and next presentation timestamps. 467 // Determine the current and next presentation timestamps.
468 base::TimeDelta now = host()->GetTime(); 468 base::TimeDelta now = host()->GetTime();
469 base::TimeDelta this_pts = current_frame_->GetTimestamp(); 469 base::TimeDelta this_pts = current_frame_->GetTimestamp();
470 base::TimeDelta next_pts; 470 base::TimeDelta next_pts;
(...skipping 20 matching lines...) Expand all
491 491
492 int VideoRendererBase::NumFrames_Locked() const { 492 int VideoRendererBase::NumFrames_Locked() const {
493 lock_.AssertAcquired(); 493 lock_.AssertAcquired();
494 int outstanding_frames = 494 int outstanding_frames =
495 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + 495 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) +
496 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); 496 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0);
497 return ready_frames_.size() + outstanding_frames; 497 return ready_frames_.size() + outstanding_frames;
498 } 498 }
499 499
500 } // namespace media 500 } // namespace media
OLDNEW
« base/callback_unittest.cc ('K') | « media/filters/gpu_video_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698