| OLD | NEW |
| 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 355 } |
| 356 | 356 |
| 357 if (!frame) { | 357 if (!frame) { |
| 358 if (state_ != kSeeking) | 358 if (state_ != kSeeking) |
| 359 return; | 359 return; |
| 360 | 360 |
| 361 // Abort seek early for a NULL frame because we won't get more frames. | 361 // Abort seek early for a NULL frame because we won't get more frames. |
| 362 // A new seek will be requested after this one completes so there is no | 362 // A new seek will be requested after this one completes so there is no |
| 363 // point trying to collect more frames. | 363 // point trying to collect more frames. |
| 364 state_ = kPrerolled; | 364 state_ = kPrerolled; |
| 365 ResetAndRunCB(&seek_cb_, PIPELINE_OK); | 365 seek_cb_.ResetAndRun(PIPELINE_OK); |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 | 368 |
| 369 // Discard frames until we reach our desired seek timestamp. | 369 // Discard frames until we reach our desired seek timestamp. |
| 370 if (state_ == kSeeking && !frame->IsEndOfStream() && | 370 if (state_ == kSeeking && !frame->IsEndOfStream() && |
| 371 (frame->GetTimestamp() + frame->GetDuration()) <= seek_timestamp_) { | 371 (frame->GetTimestamp() + frame->GetDuration()) <= seek_timestamp_) { |
| 372 AttemptRead_Locked(); | 372 AttemptRead_Locked(); |
| 373 return; | 373 return; |
| 374 } | 374 } |
| 375 | 375 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 // Because we might remain in the prerolled state for an undetermined amount | 414 // Because we might remain in the prerolled state for an undetermined amount |
| 415 // of time (i.e., we were not playing before we received a seek), we'll | 415 // of time (i.e., we were not playing before we received a seek), we'll |
| 416 // manually update the current frame and notify the subclass below. | 416 // manually update the current frame and notify the subclass below. |
| 417 if (!ready_frames_.front()->IsEndOfStream()) { | 417 if (!ready_frames_.front()->IsEndOfStream()) { |
| 418 current_frame_ = ready_frames_.front(); | 418 current_frame_ = ready_frames_.front(); |
| 419 ready_frames_.pop_front(); | 419 ready_frames_.pop_front(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 // ...and we're done seeking! | 422 // ...and we're done seeking! |
| 423 DCHECK(!seek_cb_.is_null()); | 423 DCHECK(!seek_cb_.is_null()); |
| 424 ResetAndRunCB(&seek_cb_, PIPELINE_OK); | 424 seek_cb_.ResetAndRun(PIPELINE_OK); |
| 425 | 425 |
| 426 base::AutoUnlock ul(lock_); | 426 base::AutoUnlock ul(lock_); |
| 427 paint_cb_.Run(); | 427 paint_cb_.Run(); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 void VideoRendererBase::AttemptRead_Locked() { | 431 void VideoRendererBase::AttemptRead_Locked() { |
| 432 lock_.AssertAcquired(); | 432 lock_.AssertAcquired(); |
| 433 DCHECK_NE(kEnded, state_); | 433 DCHECK_NE(kEnded, state_); |
| 434 | 434 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 445 void VideoRendererBase::AttemptFlush_Locked() { | 445 void VideoRendererBase::AttemptFlush_Locked() { |
| 446 lock_.AssertAcquired(); | 446 lock_.AssertAcquired(); |
| 447 DCHECK_EQ(kFlushing, state_); | 447 DCHECK_EQ(kFlushing, state_); |
| 448 | 448 |
| 449 // Get rid of any ready frames. | 449 // Get rid of any ready frames. |
| 450 ready_frames_.clear(); | 450 ready_frames_.clear(); |
| 451 | 451 |
| 452 if (!pending_paint_ && !pending_read_) { | 452 if (!pending_paint_ && !pending_read_) { |
| 453 state_ = kFlushed; | 453 state_ = kFlushed; |
| 454 current_frame_ = NULL; | 454 current_frame_ = NULL; |
| 455 ResetAndRunCB(&flush_cb_); | 455 flush_cb_.ResetAndRun(); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 base::TimeDelta VideoRendererBase::CalculateSleepDuration( | 459 base::TimeDelta VideoRendererBase::CalculateSleepDuration( |
| 460 const scoped_refptr<VideoFrame>& next_frame, | 460 const scoped_refptr<VideoFrame>& next_frame, |
| 461 float playback_rate) { | 461 float playback_rate) { |
| 462 // Determine the current and next presentation timestamps. | 462 // Determine the current and next presentation timestamps. |
| 463 base::TimeDelta now = host()->GetTime(); | 463 base::TimeDelta now = host()->GetTime(); |
| 464 base::TimeDelta this_pts = current_frame_->GetTimestamp(); | 464 base::TimeDelta this_pts = current_frame_->GetTimestamp(); |
| 465 base::TimeDelta next_pts; | 465 base::TimeDelta next_pts; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 486 | 486 |
| 487 int VideoRendererBase::NumFrames_Locked() const { | 487 int VideoRendererBase::NumFrames_Locked() const { |
| 488 lock_.AssertAcquired(); | 488 lock_.AssertAcquired(); |
| 489 int outstanding_frames = | 489 int outstanding_frames = |
| 490 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + | 490 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + |
| 491 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); | 491 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); |
| 492 return ready_frames_.size() + outstanding_frames; | 492 return ready_frames_.size() + outstanding_frames; |
| 493 } | 493 } |
| 494 | 494 |
| 495 } // namespace media | 495 } // namespace media |
| OLD | NEW |