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

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: time_cb_ -> max_time_cb_ 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
« no previous file with comments | « media/filters/video_renderer_base.h ('k') | media/filters/video_renderer_base_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 (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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 callback.Run(); 67 callback.Run();
64 return; 68 return;
65 } 69 }
66 70
67 base::PlatformThreadHandle thread_to_join = base::kNullThreadHandle; 71 base::PlatformThreadHandle thread_to_join = base::kNullThreadHandle;
68 { 72 {
69 base::AutoLock auto_lock(lock_); 73 base::AutoLock auto_lock(lock_);
70 state_ = kStopped; 74 state_ = kStopped;
71 75
72 statistics_cb_.Reset(); 76 statistics_cb_.Reset();
73 time_cb_.Reset(); 77 max_time_cb_.Reset();
74 if (!pending_paint_ && !pending_paint_with_last_available_) 78 if (!pending_paint_ && !pending_paint_with_last_available_)
75 DoStopOrError_Locked(); 79 DoStopOrError_Locked();
76 80
77 // Clean up our thread if present. 81 // Clean up our thread if present.
78 if (thread_ != base::kNullThreadHandle) { 82 if (thread_ != base::kNullThreadHandle) {
79 // Signal the thread since it's possible to get stopped with the video 83 // Signal the thread since it's possible to get stopped with the video
80 // thread waiting for a read to complete. 84 // thread waiting for a read to complete.
81 frame_available_.Signal(); 85 frame_available_.Signal();
82 thread_to_join = thread_; 86 thread_to_join = thread_;
83 thread_ = base::kNullThreadHandle; 87 thread_ = base::kNullThreadHandle;
(...skipping 20 matching lines...) Expand all
104 state_ = kPrerolling; 108 state_ = kPrerolling;
105 preroll_cb_ = cb; 109 preroll_cb_ = cb;
106 preroll_timestamp_ = time; 110 preroll_timestamp_ = time;
107 prerolling_delayed_frame_ = NULL; 111 prerolling_delayed_frame_ = NULL;
108 AttemptRead_Locked(); 112 AttemptRead_Locked();
109 } 113 }
110 114
111 void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder, 115 void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
112 const PipelineStatusCB& init_cb, 116 const PipelineStatusCB& init_cb,
113 const StatisticsCB& statistics_cb, 117 const StatisticsCB& statistics_cb,
114 const TimeCB& time_cb, 118 const TimeCB& max_time_cb,
115 const NaturalSizeChangedCB& size_changed_cb, 119 const NaturalSizeChangedCB& size_changed_cb,
116 const base::Closure& ended_cb, 120 const base::Closure& ended_cb,
117 const PipelineStatusCB& error_cb, 121 const PipelineStatusCB& error_cb,
118 const TimeDeltaCB& get_time_cb, 122 const TimeDeltaCB& get_time_cb,
119 const TimeDeltaCB& get_duration_cb) { 123 const TimeDeltaCB& get_duration_cb) {
120 base::AutoLock auto_lock(lock_); 124 base::AutoLock auto_lock(lock_);
121 DCHECK(decoder); 125 DCHECK(decoder);
122 DCHECK(!init_cb.is_null()); 126 DCHECK(!init_cb.is_null());
123 DCHECK(!statistics_cb.is_null()); 127 DCHECK(!statistics_cb.is_null());
124 DCHECK(!time_cb.is_null()); 128 DCHECK(!max_time_cb.is_null());
125 DCHECK(!size_changed_cb.is_null()); 129 DCHECK(!size_changed_cb.is_null());
126 DCHECK(!ended_cb.is_null()); 130 DCHECK(!ended_cb.is_null());
127 DCHECK(!get_time_cb.is_null()); 131 DCHECK(!get_time_cb.is_null());
128 DCHECK(!get_duration_cb.is_null()); 132 DCHECK(!get_duration_cb.is_null());
129 DCHECK_EQ(kUninitialized, state_); 133 DCHECK_EQ(kUninitialized, state_);
130 decoder_ = decoder; 134 decoder_ = decoder;
131 135
132 statistics_cb_ = statistics_cb; 136 statistics_cb_ = statistics_cb;
133 time_cb_ = time_cb; 137 max_time_cb_ = max_time_cb;
134 size_changed_cb_ = size_changed_cb; 138 size_changed_cb_ = size_changed_cb;
135 ended_cb_ = ended_cb; 139 ended_cb_ = ended_cb;
136 error_cb_ = error_cb; 140 error_cb_ = error_cb;
137 get_time_cb_ = get_time_cb; 141 get_time_cb_ = get_time_cb;
138 get_duration_cb_ = get_duration_cb; 142 get_duration_cb_ = get_duration_cb;
139 143
140 // We're all good! Consider ourselves flushed. (ThreadMain() should never 144 // We're all good! Consider ourselves flushed. (ThreadMain() should never
141 // see us in the kUninitialized state). 145 // see us in the kUninitialized state).
142 // Since we had an initial Preroll(), we consider ourself flushed, because we 146 // Since we had an initial Preroll(), we consider ourself flushed, because we
143 // have not populated any buffers yet. 147 // have not populated any buffers yet.
(...skipping 333 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 = 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 max_clock_time =
511 frame->IsEndOfStream() ? duration : frame->GetTimestamp();
512 DCHECK(max_clock_time != kNoTimestamp());
513 max_time_cb_.Run(max_clock_time);
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
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
OLDNEW
« no previous file with comments | « media/filters/video_renderer_base.h ('k') | media/filters/video_renderer_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698