Chromium Code Reviews| 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 "media/filters/video_renderer_base.h" | 5 #include "media/filters/video_renderer_base.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/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 11 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
| 12 #include "media/base/limits.h" | 12 #include "media/base/limits.h" |
| 13 #include "media/base/pipeline.h" | 13 #include "media/base/pipeline.h" |
| 14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 base::TimeDelta VideoRendererBase::kMaxLastFrameDuration() { | |
| 19 return base::TimeDelta::FromMilliseconds(250); | |
| 20 } | |
| 21 | |
| 18 VideoRendererBase::VideoRendererBase(const base::Closure& paint_cb, | 22 VideoRendererBase::VideoRendererBase(const base::Closure& paint_cb, |
| 19 const SetOpaqueCB& set_opaque_cb, | 23 const SetOpaqueCB& set_opaque_cb, |
| 20 bool drop_frames) | 24 bool drop_frames) |
| 21 : frame_available_(&lock_), | 25 : frame_available_(&lock_), |
| 22 state_(kUninitialized), | 26 state_(kUninitialized), |
| 23 thread_(base::kNullThreadHandle), | 27 thread_(base::kNullThreadHandle), |
| 24 pending_read_(false), | 28 pending_read_(false), |
| 25 pending_paint_(false), | 29 pending_paint_(false), |
| 26 pending_paint_with_last_available_(false), | 30 pending_paint_with_last_available_(false), |
| 27 drop_frames_(drop_frames), | 31 drop_frames_(drop_frames), |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 } | 481 } |
| 478 } | 482 } |
| 479 | 483 |
| 480 void VideoRendererBase::AddReadyFrame(const scoped_refptr<VideoFrame>& frame) { | 484 void VideoRendererBase::AddReadyFrame(const scoped_refptr<VideoFrame>& frame) { |
| 481 // Adjust the incoming frame if its rendering stop time is past the duration | 485 // Adjust the incoming frame if its rendering stop time is past the duration |
| 482 // of the video itself. This is typically the last frame of the video and | 486 // of the video itself. This is typically the last frame of the video and |
| 483 // occurs if the container specifies a duration that isn't a multiple of the | 487 // occurs if the container specifies a duration that isn't a multiple of the |
| 484 // frame rate. Another way for this to happen is for the container to state a | 488 // frame rate. Another way for this to happen is for the container to state a |
| 485 // smaller duration than the largest packet timestamp. | 489 // smaller duration than the largest packet timestamp. |
| 486 base::TimeDelta duration = get_duration_cb_.Run(); | 490 base::TimeDelta duration = get_duration_cb_.Run(); |
| 487 if (frame->GetTimestamp() > duration || frame->IsEndOfStream()) { | 491 if (frame->IsEndOfStream()) { |
| 492 base::TimeDelta end_timestamp = kNoTimestamp(); | |
| 493 if (!ready_frames_.empty()) { | |
| 494 end_timestamp = std::min( | |
| 495 duration, | |
| 496 ready_frames_.back()->GetTimestamp() + kMaxLastFrameDuration()); | |
| 497 } else if (current_frame_) { | |
| 498 end_timestamp = | |
| 499 std::min(duration, | |
| 500 current_frame_->GetTimestamp() + kMaxLastFrameDuration()); | |
| 501 } | |
| 502 frame->SetTimestamp(end_timestamp); | |
| 503 } else if (frame->GetTimestamp() > duration) { | |
| 488 frame->SetTimestamp(duration); | 504 frame->SetTimestamp(duration); |
| 489 } | 505 } |
| 490 | 506 |
| 491 ready_frames_.push_back(frame); | 507 ready_frames_.push_back(frame); |
| 492 DCHECK_LE(NumFrames_Locked(), limits::kMaxVideoFrames); | 508 DCHECK_LE(NumFrames_Locked(), limits::kMaxVideoFrames); |
| 493 time_cb_.Run(frame->GetTimestamp()); | 509 |
| 510 base::TimeDelta maxClockTime = | |
|
scherkus (not reviewing)
2012/08/07 23:03:19
unix_hacker
| |
| 511 frame->IsEndOfStream() ? duration : frame->GetTimestamp(); | |
| 512 DCHECK(maxClockTime != kNoTimestamp()); | |
| 513 time_cb_.Run(maxClockTime); | |
|
scherkus (not reviewing)
2012/08/07 22:01:00
wait a tick -- what is this time_cb_ used for agai
scherkus (not reviewing)
2012/08/07 23:03:19
Discussed offline -- this is really a max_time_cb_
| |
| 514 | |
| 494 frame_available_.Signal(); | 515 frame_available_.Signal(); |
| 495 } | 516 } |
| 496 | 517 |
| 497 void VideoRendererBase::AttemptRead_Locked() { | 518 void VideoRendererBase::AttemptRead_Locked() { |
| 498 lock_.AssertAcquired(); | 519 lock_.AssertAcquired(); |
| 499 DCHECK_NE(kEnded, state_); | 520 DCHECK_NE(kEnded, state_); |
| 500 | 521 |
| 501 if (pending_read_ || | 522 if (pending_read_ || |
| 502 NumFrames_Locked() == limits::kMaxVideoFrames || | 523 NumFrames_Locked() == limits::kMaxVideoFrames || |
| 503 (!ready_frames_.empty() && ready_frames_.back()->IsEndOfStream()) || | 524 (!ready_frames_.empty() && ready_frames_.back()->IsEndOfStream()) || |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 | 578 |
| 558 int VideoRendererBase::NumFrames_Locked() const { | 579 int VideoRendererBase::NumFrames_Locked() const { |
| 559 lock_.AssertAcquired(); | 580 lock_.AssertAcquired(); |
| 560 int outstanding_frames = | 581 int outstanding_frames = |
| 561 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + | 582 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + |
| 562 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); | 583 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); |
| 563 return ready_frames_.size() + outstanding_frames; | 584 return ready_frames_.size() + outstanding_frames; |
| 564 } | 585 } |
| 565 | 586 |
| 566 } // namespace media | 587 } // namespace media |
| OLD | NEW |