Commit 5c9821ee authored by acolwell@chromium.org's avatar acolwell@chromium.org

Fix VideoRendererBase end of stream logic to use a default

last frame duration if the last frame is far away from the clip duration.


BUG=None
TEST=VideoRendererBaseTest.EndOfStream_DefaultFrameDuration, VideoRendererBaseTest.EndOfStream_DefaultFrameDuration

Review URL: https://chromiumcodereview.appspot.com/10829200

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150467 0039d316-1c4b-4281-b951-d872f2087c98
parent cea1d623
......@@ -102,7 +102,6 @@ class MockVideoDecoder : public VideoDecoder {
MOCK_METHOD1(Read, void(const ReadCB&));
MOCK_METHOD1(Reset, void(const base::Closure&));
MOCK_METHOD1(Stop, void(const base::Closure&));
MOCK_METHOD0(natural_size, const gfx::Size&());
MOCK_CONST_METHOD0(HasAlpha, bool());
protected:
......
......@@ -15,6 +15,10 @@
namespace media {
base::TimeDelta VideoRendererBase::kMaxLastFrameDuration() {
return base::TimeDelta::FromMilliseconds(250);
}
VideoRendererBase::VideoRendererBase(const base::Closure& paint_cb,
const SetOpaqueCB& set_opaque_cb,
bool drop_frames)
......@@ -70,7 +74,7 @@ void VideoRendererBase::Stop(const base::Closure& callback) {
state_ = kStopped;
statistics_cb_.Reset();
time_cb_.Reset();
max_time_cb_.Reset();
if (!pending_paint_ && !pending_paint_with_last_available_)
DoStopOrError_Locked();
......@@ -111,7 +115,7 @@ void VideoRendererBase::Preroll(base::TimeDelta time,
void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
const PipelineStatusCB& init_cb,
const StatisticsCB& statistics_cb,
const TimeCB& time_cb,
const TimeCB& max_time_cb,
const NaturalSizeChangedCB& size_changed_cb,
const base::Closure& ended_cb,
const PipelineStatusCB& error_cb,
......@@ -121,7 +125,7 @@ void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
DCHECK(decoder);
DCHECK(!init_cb.is_null());
DCHECK(!statistics_cb.is_null());
DCHECK(!time_cb.is_null());
DCHECK(!max_time_cb.is_null());
DCHECK(!size_changed_cb.is_null());
DCHECK(!ended_cb.is_null());
DCHECK(!get_time_cb.is_null());
......@@ -130,7 +134,7 @@ void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
decoder_ = decoder;
statistics_cb_ = statistics_cb;
time_cb_ = time_cb;
max_time_cb_ = max_time_cb;
size_changed_cb_ = size_changed_cb;
ended_cb_ = ended_cb;
error_cb_ = error_cb;
......@@ -484,13 +488,30 @@ void VideoRendererBase::AddReadyFrame(const scoped_refptr<VideoFrame>& frame) {
// frame rate. Another way for this to happen is for the container to state a
// smaller duration than the largest packet timestamp.
base::TimeDelta duration = get_duration_cb_.Run();
if (frame->GetTimestamp() > duration || frame->IsEndOfStream()) {
if (frame->IsEndOfStream()) {
base::TimeDelta end_timestamp = kNoTimestamp();
if (!ready_frames_.empty()) {
end_timestamp = std::min(
duration,
ready_frames_.back()->GetTimestamp() + kMaxLastFrameDuration());
} else if (current_frame_) {
end_timestamp =
std::min(duration,
current_frame_->GetTimestamp() + kMaxLastFrameDuration());
}
frame->SetTimestamp(end_timestamp);
} else if (frame->GetTimestamp() > duration) {
frame->SetTimestamp(duration);
}
ready_frames_.push_back(frame);
DCHECK_LE(NumFrames_Locked(), limits::kMaxVideoFrames);
time_cb_.Run(frame->GetTimestamp());
base::TimeDelta max_clock_time =
frame->IsEndOfStream() ? duration : frame->GetTimestamp();
DCHECK(max_clock_time != kNoTimestamp());
max_time_cb_.Run(max_clock_time);
frame_available_.Signal();
}
......
......@@ -28,6 +28,9 @@ class MEDIA_EXPORT VideoRendererBase
public:
typedef base::Callback<void(bool)> SetOpaqueCB;
// Maximum duration of the last frame.
static base::TimeDelta kMaxLastFrameDuration();
// |paint_cb| is executed on the video frame timing thread whenever a new
// frame is available for painting via GetCurrentFrame().
//
......@@ -50,7 +53,7 @@ class MEDIA_EXPORT VideoRendererBase
virtual void Initialize(const scoped_refptr<VideoDecoder>& decoder,
const PipelineStatusCB& init_cb,
const StatisticsCB& statistics_cb,
const TimeCB& time_cb,
const TimeCB& max_time_cb,
const NaturalSizeChangedCB& size_changed_cb,
const base::Closure& ended_cb,
const PipelineStatusCB& error_cb,
......@@ -209,7 +212,7 @@ class MEDIA_EXPORT VideoRendererBase
// Event callbacks.
StatisticsCB statistics_cb_;
TimeCB time_cb_;
TimeCB max_time_cb_;
NaturalSizeChangedCB size_changed_cb_;
base::Closure ended_cb_;
PipelineStatusCB error_cb_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment