Fix MIGHT_NOT_USE_FULL_NETWORK_SPEED for VOD DASH streams.

The flag compared against the nowTime in the period that is only
set to a positive value for live streams.

PiperOrigin-RevId: 350514934
This commit is contained in:
tonihei 2021-01-07 10:03:16 +00:00 committed by Ian Baker
parent 855db95fb3
commit 2c925a4109
3 changed files with 78 additions and 3 deletions

View File

@ -499,8 +499,10 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
private long getNowPeriodTimeUs(long nowUnixTimeUs) {
return nowUnixTimeUs
- C.msToUs(manifest.availabilityStartTimeMs + manifest.getPeriod(periodIndex).startMs);
return manifest.availabilityStartTimeMs == C.TIME_UNSET
? C.TIME_UNSET
: nowUnixTimeUs
- C.msToUs(manifest.availabilityStartTimeMs + manifest.getPeriod(periodIndex).startMs);
}
protected Chunk newInitializationChunk(
@ -797,7 +799,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
public boolean isSegmentAvailableAtFullNetworkSpeed(long segmentNum, long nowPeriodTimeUs) {
return getSegmentEndTimeUs(segmentNum) <= nowPeriodTimeUs;
return nowPeriodTimeUs == C.TIME_UNSET || getSegmentEndTimeUs(segmentNum) <= nowPeriodTimeUs;
}
@Nullable

View File

@ -43,6 +43,8 @@ public class DefaultDashChunkSourceTest {
private static final String SAMPLE_MPD_LIVE_WITH_OFFSET_INSIDE_WINDOW =
"media/mpd/sample_mpd_live_with_offset_inside_window";
private static final String SAMPLE_MPD_VOD = "media/mpd/sample_mpd_vod";
@Test
public void getNextChunk_forLowLatencyManifest_setsCorrectMayNotLoadAtFullNetworkSpeedFlag()
throws Exception {
@ -89,4 +91,41 @@ public class DefaultDashChunkSourceTest {
assertThat(output.chunk.dataSpec.flags & DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED)
.isNotEqualTo(0);
}
@Test
public void getNextChunk_forVodManifest_doesNotSetMayNotLoadAtFullNetworkSpeedFlag()
throws Exception {
long nowMs = 2_000_000_000_000L;
SystemClock.setCurrentTimeMillis(nowMs);
DashManifest manifest =
new DashManifestParser()
.parse(
Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_VOD));
DefaultDashChunkSource chunkSource =
new DefaultDashChunkSource(
new LoaderErrorThrower.Dummy(),
manifest,
/* periodIndex= */ 0,
/* adaptationSetIndices= */ new int[] {0},
new FixedTrackSelection(new TrackGroup(new Format.Builder().build()), /* track= */ 0),
C.TRACK_TYPE_VIDEO,
new FakeDataSource(),
/* elapsedRealtimeOffsetMs= */ 0,
/* maxSegmentsPerLoad= */ 1,
/* enableEventMessageTrack= */ false,
/* closedCaptionFormats */ ImmutableList.of(),
/* playerTrackEmsgHandler= */ null);
ChunkHolder output = new ChunkHolder();
chunkSource.getNextChunk(
/* playbackPositionUs= */ 0,
/* loadPositionUs= */ 0,
/* queue= */ ImmutableList.of(),
output);
assertThat(output.chunk.dataSpec.flags & DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED)
.isEqualTo(0);
}
}

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:mpeg:dash:schema:mpd:2011"
xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011"
minBufferTime="PT1S"
profiles="urn:mpeg:dash:profile:isoff-main:2011"
type="static"
mediaPresentationDuration="PT904S">
<Period id="1" duration="PT904S" start="PT0S">
<AdaptationSet id="0" mimeType="video/mp4" contentType="video" segmentAlignment="true" startWithSAP="1">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
<SegmentTemplate presentationTimeOffset="0" media="video_$Time$_$Bandwidth$.m4s" timescale="1000" >
<SegmentTimeline>
<S d="4000" r="225"/>
</SegmentTimeline>
</SegmentTemplate>
<Representation id="0" codecs="avc1.4d401e" width="768" height="432" frameRate="25" bandwidth="1300000"/>
<Representation id="1" codecs="avc1.4d4015" width="512" height="288" frameRate="25" bandwidth="700000"/>
<Representation id="2" codecs="avc1.4d4015" width="512" height="288" frameRate="25" bandwidth="452000"/>
<Representation id="3" codecs="avc1.42c00c" width="400" height="224" frameRate="25/2" bandwidth="250000"/>
<Representation id="4" codecs="avc1.42c00b" width="400" height="224" frameRate="5" bandwidth="50000"/>
</AdaptationSet>
<AdaptationSet id="1" lang="fr" mimeType="audio/mp4" contentType="audio" codecs="mp4a.40.2" segmentAlignment="true" startWithSAP="1">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:mpegB:cicp:ChannelConfiguration" value="2"/>
<SegmentTemplate presentationTimeOffset="0" media="audio_$Time$_$Bandwidth$.m4s" timescale="1000" >
<SegmentTimeline>
<S d="3200" r="281"/>
<S d="1600"/>
</SegmentTimeline>
</SegmentTemplate>
<Representation id="5" bandwidth="128000"/>
</AdaptationSet>
</Period>
</MPD>