Commit 6e262d54 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Fix calling AverageDuration() on wrong thread

This CL saves the last AverageDuration() value from DecoderStream on the
correct thread, to be used in IsBeforeStartTime(), which can be called
from a different thread.

Bug: 1096280
Change-Id: Ia098cb282d61a5ac610df4a32eccebab6742310a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274845
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784250}
parent 7f825966
...@@ -565,6 +565,7 @@ void VideoRendererImpl::FrameReady(VideoDecoderStream::ReadStatus status, ...@@ -565,6 +565,7 @@ void VideoRendererImpl::FrameReady(VideoDecoderStream::ReadStatus status,
} }
last_frame_ready_time_ = tick_clock_->NowTicks(); last_frame_ready_time_ = tick_clock_->NowTicks();
last_decoder_stream_avg_duration_ = video_decoder_stream_->AverageDuration();
const bool is_eos = frame->metadata()->end_of_stream; const bool is_eos = frame->metadata()->end_of_stream;
const bool is_before_start_time = !is_eos && IsBeforeStartTime(*frame); const bool is_before_start_time = !is_eos && IsBeforeStartTime(*frame);
...@@ -598,10 +599,8 @@ void VideoRendererImpl::FrameReady(VideoDecoderStream::ReadStatus status, ...@@ -598,10 +599,8 @@ void VideoRendererImpl::FrameReady(VideoDecoderStream::ReadStatus status,
// RemoveFramesForUnderflowOrBackgroundRendering() below to actually expire // RemoveFramesForUnderflowOrBackgroundRendering() below to actually expire
// this frame if it's too far behind the current media time. Without this, // this frame if it's too far behind the current media time. Without this,
// we may resume too soon after a track change in the low delay case. // we may resume too soon after a track change in the low delay case.
if (!frame->metadata()->frame_duration.has_value()) { if (!frame->metadata()->frame_duration.has_value())
frame->metadata()->frame_duration = frame->metadata()->frame_duration = last_decoder_stream_avg_duration_;
video_decoder_stream_->AverageDuration();
}
AddReadyFrame_Locked(std::move(frame)); AddReadyFrame_Locked(std::move(frame));
} }
...@@ -924,14 +923,8 @@ base::TimeTicks VideoRendererImpl::GetCurrentMediaTimeAsWallClockTime() { ...@@ -924,14 +923,8 @@ base::TimeTicks VideoRendererImpl::GetCurrentMediaTimeAsWallClockTime() {
bool VideoRendererImpl::IsBeforeStartTime(const VideoFrame& frame) { bool VideoRendererImpl::IsBeforeStartTime(const VideoFrame& frame) {
// Prefer the actual frame duration over the average if available. // Prefer the actual frame duration over the average if available.
if (frame.metadata()->frame_duration.has_value()) { return frame.timestamp() + frame.metadata()->frame_duration.value_or(
return frame.timestamp() + *frame.metadata()->frame_duration < last_decoder_stream_avg_duration_) <
start_timestamp_;
}
// TODO(tguilbert): video_decoder_stream_->AverageDuration() can be accessed
// from the wrong thread.
return frame.timestamp() + video_decoder_stream_->AverageDuration() <
start_timestamp_; start_timestamp_;
} }
......
...@@ -309,6 +309,9 @@ class MEDIA_EXPORT VideoRendererImpl ...@@ -309,6 +309,9 @@ class MEDIA_EXPORT VideoRendererImpl
gfx::Size last_frame_natural_size_; gfx::Size last_frame_natural_size_;
bool last_frame_opaque_; bool last_frame_opaque_;
// The last value from |video_decoder_stream_->AverageDuration()|.
base::TimeDelta last_decoder_stream_avg_duration_;
// Indicates if we've painted the first valid frame after StartPlayingFrom(). // Indicates if we've painted the first valid frame after StartPlayingFrom().
bool painted_first_frame_; bool painted_first_frame_;
......
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