Commit 4cfb4416 authored by Fredrik Hubinette's avatar Fredrik Hubinette Committed by Commit Bot

Reland "Improve suspending logic."

This is a reland of d2506f13
Original change's description:
> Improve suspending logic.
> 
> When loading takes too long, we can suspend the codec before
> we have a chance to load the first frame. This is all normal,
> but should only happen when we are waiting on the network.
> This CL makes sure that we have additional progress callbacks
> expected before suspending.
> 
> Bug: 728468
> Change-Id: I815520e0ba832617b04948f7fbefb88498cf79b7
> Reviewed-on: https://chromium-review.googlesource.com/614360
> Reviewed-by: Dan Sanders <sandersd@chromium.org>
> Commit-Queue: Fredrik Hubinette <hubbe@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#494212}

Bug: 728468
Change-Id: Ide175e6e5c8d2ecaeeb81b0055352f66c917d099
Reviewed-on: https://chromium-review.googlesource.com/627616Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Fredrik Hubinette <hubbe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496513}
parent 001698f7
......@@ -57,12 +57,9 @@ int64_t BufferedDataSourceHostImpl::UnloadedBytesInInterval(
void BufferedDataSourceHostImpl::AddBufferedByteRange(int64_t start,
int64_t end) {
int64_t new_bytes = UnloadedBytesInInterval(Interval<int64_t>(start, end));
if (new_bytes == 0) {
// No change
return;
}
if (new_bytes > 0)
did_loading_progress_ = true;
buffered_byte_ranges_.SetInterval(start, end, 1);
did_loading_progress_ = true;
base::TimeTicks now = tick_clock_->NowTicks();
int64_t bytes_so_far = 0;
......
......@@ -938,6 +938,16 @@ bool WebMediaPlayerImpl::IsPrerollAttemptNeeded() {
if (highest_ready_state_ >= ReadyState::kReadyStateHaveFutureData)
return false;
// To suspend before we reach kReadyStateHaveCurrentData is only ok
// if we know we're going to get woken up when we get more data, which
// will only happen if the network is in the "Loading" state.
// This happens when the network is fast, but multiple videos are loading
// and multiplexing gets held up waiting for available threads.
if (highest_ready_state_ <= ReadyState::kReadyStateHaveMetadata &&
network_state_ != WebMediaPlayer::kNetworkStateLoading) {
return true;
}
if (preroll_attempt_pending_)
return true;
......
......@@ -270,6 +270,9 @@ class WebMediaPlayerImplTest : public testing::Test {
}
protected:
void SetNetworkState(blink::WebMediaPlayer::NetworkState state) {
wmpi_->SetNetworkState(state);
}
void SetReadyState(blink::WebMediaPlayer::ReadyState state) {
wmpi_->SetReadyState(state);
}
......@@ -427,11 +430,9 @@ TEST_F(WebMediaPlayerImplTest, ConstructAndDestroy) {
EXPECT_FALSE(IsSuspended());
}
TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledBeforeLoadingBegins) {
TEST_F(WebMediaPlayerImplTest, IdleSuspendBeforeLoadingBegins) {
InitializeWebMediaPlayerImpl();
EXPECT_TRUE(delegate_.ExpireForTesting());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsSuspended());
EXPECT_FALSE(delegate_.ExpireForTesting());
}
TEST_F(WebMediaPlayerImplTest,
......@@ -451,6 +452,7 @@ TEST_F(WebMediaPlayerImplTest,
TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledIfLoadingHasStalled) {
InitializeWebMediaPlayerImpl();
SetNetworkState(blink::WebMediaPlayer::kNetworkStateLoading);
base::SimpleTestTickClock* clock = new base::SimpleTestTickClock();
clock->Advance(base::TimeDelta::FromSeconds(1));
SetTickClock(clock);
......@@ -466,6 +468,7 @@ TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledIfLoadingHasStalled) {
TEST_F(WebMediaPlayerImplTest, DidLoadingProgressTriggersResume) {
// Same setup as IdleSuspendIsEnabledBeforeLoadingBegins.
InitializeWebMediaPlayerImpl();
SetNetworkState(blink::WebMediaPlayer::kNetworkStateLoading);
EXPECT_TRUE(delegate_.ExpireForTesting());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsSuspended());
......
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