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

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

Issue 10829200: Fix VideoRendererBase end of stream logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments & removed natural_size() from MockVideoDecoder. Created 8 years, 4 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 "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::kLastFrameDuration() {
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
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 =
495 std::min(duration,
496 ready_frames_.back()->GetTimestamp() + kLastFrameDuration());
497 } else if (current_frame_) {
498 end_timestamp =
499 std::min(duration,
500 current_frame_->GetTimestamp() + kLastFrameDuration());
501 }
502 frame->SetTimestamp(end_timestamp);
DaleCurtis 2012/08/07 20:32:14 Since it wasn't immediately obvious to me: when en
acolwell GONE FROM CHROMIUM 2012/08/07 21:10:28 I'm pretty sure the only way to get kNoTimestamp i
503 } else if (frame->GetTimestamp() > duration) {
DaleCurtis 2012/08/07 20:32:14 nit: extra space.
acolwell GONE FROM CHROMIUM 2012/08/07 21:10:28 Done.
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 time_cb_.Run(frame->GetTimestamp());
scherkus (not reviewing) 2012/08/07 20:56:47 it's now possible to execute this w/ kNoTimestamp
acolwell GONE FROM CHROMIUM 2012/08/07 21:10:28 Whoops..No it isnt' Changed it to set the time to
494 frame_available_.Signal(); 510 frame_available_.Signal();
495 } 511 }
496 512
497 void VideoRendererBase::AttemptRead_Locked() { 513 void VideoRendererBase::AttemptRead_Locked() {
498 lock_.AssertAcquired(); 514 lock_.AssertAcquired();
499 DCHECK_NE(kEnded, state_); 515 DCHECK_NE(kEnded, state_);
500 516
501 if (pending_read_ || 517 if (pending_read_ ||
502 NumFrames_Locked() == limits::kMaxVideoFrames || 518 NumFrames_Locked() == limits::kMaxVideoFrames ||
503 (!ready_frames_.empty() && ready_frames_.back()->IsEndOfStream()) || 519 (!ready_frames_.empty() && ready_frames_.back()->IsEndOfStream()) ||
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 573
558 int VideoRendererBase::NumFrames_Locked() const { 574 int VideoRendererBase::NumFrames_Locked() const {
559 lock_.AssertAcquired(); 575 lock_.AssertAcquired();
560 int outstanding_frames = 576 int outstanding_frames =
561 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + 577 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) +
562 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); 578 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0);
563 return ready_frames_.size() + outstanding_frames; 579 return ready_frames_.size() + outstanding_frames;
564 } 580 }
565 581
566 } // namespace media 582 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698