Parse min/max live offset from ServiceDescription.

Issue: #4904
PiperOrigin-RevId: 339215091
This commit is contained in:
tonihei 2020-10-27 10:16:52 +00:00 committed by Oliver Woodman
parent e57193676a
commit aee7e6087c
7 changed files with 42 additions and 12 deletions

View File

@ -250,18 +250,23 @@ public class DashManifestParser extends DefaultHandler
protected ServiceDescriptionElement parseServiceDescription(XmlPullParser xpp) protected ServiceDescriptionElement parseServiceDescription(XmlPullParser xpp)
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
long targetOffsetMs = C.TIME_UNSET; long targetOffsetMs = C.TIME_UNSET;
long minOffsetMs = C.TIME_UNSET;
long maxOffsetMs = C.TIME_UNSET;
float minPlaybackSpeed = C.RATE_UNSET; float minPlaybackSpeed = C.RATE_UNSET;
float maxPlaybackSpeed = C.RATE_UNSET; float maxPlaybackSpeed = C.RATE_UNSET;
do { do {
xpp.next(); xpp.next();
if (XmlPullParserUtil.isStartTag(xpp, "Latency")) { if (XmlPullParserUtil.isStartTag(xpp, "Latency")) {
targetOffsetMs = parseLong(xpp, "target", C.TIME_UNSET); targetOffsetMs = parseLong(xpp, "target", C.TIME_UNSET);
minOffsetMs = parseLong(xpp, "min", C.TIME_UNSET);
maxOffsetMs = parseLong(xpp, "max", C.TIME_UNSET);
} else if (XmlPullParserUtil.isStartTag(xpp, "PlaybackRate")) { } else if (XmlPullParserUtil.isStartTag(xpp, "PlaybackRate")) {
minPlaybackSpeed = parseFloat(xpp, "min", C.RATE_UNSET); minPlaybackSpeed = parseFloat(xpp, "min", C.RATE_UNSET);
maxPlaybackSpeed = parseFloat(xpp, "max", C.RATE_UNSET); maxPlaybackSpeed = parseFloat(xpp, "max", C.RATE_UNSET);
} }
} while (!XmlPullParserUtil.isEndTag(xpp, "ServiceDescription")); } while (!XmlPullParserUtil.isEndTag(xpp, "ServiceDescription"));
return new ServiceDescriptionElement(targetOffsetMs, minPlaybackSpeed, maxPlaybackSpeed); return new ServiceDescriptionElement(
targetOffsetMs, minOffsetMs, maxOffsetMs, minPlaybackSpeed, maxPlaybackSpeed);
} }
protected Pair<Period, Long> parsePeriod( protected Pair<Period, Long> parsePeriod(

View File

@ -22,6 +22,10 @@ public final class ServiceDescriptionElement {
/** The target live offset in milliseconds, or {@link C#TIME_UNSET} if undefined. */ /** The target live offset in milliseconds, or {@link C#TIME_UNSET} if undefined. */
public final long targetOffsetMs; public final long targetOffsetMs;
/** The minimum live offset in milliseconds, or {@link C#TIME_UNSET} if undefined. */
public final long minOffsetMs;
/** The maximum live offset in milliseconds, or {@link C#TIME_UNSET} if undefined. */
public final long maxOffsetMs;
/** The minimum playback speed for live speed adjustment, or {@link C#RATE_UNSET} if undefined. */ /** The minimum playback speed for live speed adjustment, or {@link C#RATE_UNSET} if undefined. */
public final float minPlaybackSpeed; public final float minPlaybackSpeed;
/** The maximum playback speed for live speed adjustment, or {@link C#RATE_UNSET} if undefined. */ /** The maximum playback speed for live speed adjustment, or {@link C#RATE_UNSET} if undefined. */
@ -32,14 +36,24 @@ public final class ServiceDescriptionElement {
* *
* @param targetOffsetMs The target live offset in milliseconds, or {@link C#TIME_UNSET} if * @param targetOffsetMs The target live offset in milliseconds, or {@link C#TIME_UNSET} if
* undefined. * undefined.
* @param minOffsetMs The minimum live offset in milliseconds, or {@link C#TIME_UNSET} if
* undefined.
* @param maxOffsetMs The maximum live offset in milliseconds, or {@link C#TIME_UNSET} if
* undefined.
* @param minPlaybackSpeed The minimum playback speed for live speed adjustment, or {@link * @param minPlaybackSpeed The minimum playback speed for live speed adjustment, or {@link
* C#RATE_UNSET} if undefined. * C#RATE_UNSET} if undefined.
* @param maxPlaybackSpeed The maximum playback speed for live speed adjustment, or {@link * @param maxPlaybackSpeed The maximum playback speed for live speed adjustment, or {@link
* C#RATE_UNSET} if undefined. * C#RATE_UNSET} if undefined.
*/ */
public ServiceDescriptionElement( public ServiceDescriptionElement(
long targetOffsetMs, float minPlaybackSpeed, float maxPlaybackSpeed) { long targetOffsetMs,
long minOffsetMs,
long maxOffsetMs,
float minPlaybackSpeed,
float maxPlaybackSpeed) {
this.targetOffsetMs = targetOffsetMs; this.targetOffsetMs = targetOffsetMs;
this.minOffsetMs = minOffsetMs;
this.maxOffsetMs = maxOffsetMs;
this.minPlaybackSpeed = minPlaybackSpeed; this.minPlaybackSpeed = minPlaybackSpeed;
this.maxPlaybackSpeed = maxPlaybackSpeed; this.maxPlaybackSpeed = maxPlaybackSpeed;
} }

View File

@ -59,10 +59,10 @@ public class DashManifestParserTest {
"media/mpd/sample_mpd_availabilityTimeOffset_segmentList"; "media/mpd/sample_mpd_availabilityTimeOffset_segmentList";
private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY = private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY =
"media/mpd/sample_mpd_service_description_low_latency"; "media/mpd/sample_mpd_service_description_low_latency";
private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_NO_TARGET_LATENCY = private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_ONLY_PLAYBACK_RATES =
"media/mpd/sample_mpd_service_description_low_latency_no_target_latency"; "media/mpd/sample_mpd_service_description_low_latency_only_playback_rates";
private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_NO_PLAYBACK_RATES = private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_ONLY_TARGET_LATENCY =
"media/mpd/sample_mpd_service_description_low_latency_no_playback_rates"; "media/mpd/sample_mpd_service_description_low_latency_only_target_latency";
private static final String NEXT_TAG_NAME = "Next"; private static final String NEXT_TAG_NAME = "Next";
private static final String NEXT_TAG = "<" + NEXT_TAG_NAME + "/>"; private static final String NEXT_TAG = "<" + NEXT_TAG_NAME + "/>";
@ -579,12 +579,14 @@ public class DashManifestParserTest {
assertThat(manifest.serviceDescription).isNotNull(); assertThat(manifest.serviceDescription).isNotNull();
assertThat(manifest.serviceDescription.targetOffsetMs).isEqualTo(20_000); assertThat(manifest.serviceDescription.targetOffsetMs).isEqualTo(20_000);
assertThat(manifest.serviceDescription.minOffsetMs).isEqualTo(1_000);
assertThat(manifest.serviceDescription.maxOffsetMs).isEqualTo(30_000);
assertThat(manifest.serviceDescription.minPlaybackSpeed).isEqualTo(0.1f); assertThat(manifest.serviceDescription.minPlaybackSpeed).isEqualTo(0.1f);
assertThat(manifest.serviceDescription.maxPlaybackSpeed).isEqualTo(99f); assertThat(manifest.serviceDescription.maxPlaybackSpeed).isEqualTo(99f);
} }
@Test @Test
public void serviceDescriptionElement_noLatency_isUnset() throws IOException { public void serviceDescriptionElement_onlyPlaybackRates_latencyValuesUnset() throws IOException {
DashManifestParser parser = new DashManifestParser(); DashManifestParser parser = new DashManifestParser();
DashManifest manifest = DashManifest manifest =
@ -592,16 +594,19 @@ public class DashManifestParserTest {
Uri.parse("https://example.com/test.mpd"), Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream( TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), ApplicationProvider.getApplicationContext(),
SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_NO_TARGET_LATENCY)); SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_ONLY_PLAYBACK_RATES));
assertThat(manifest.serviceDescription).isNotNull(); assertThat(manifest.serviceDescription).isNotNull();
assertThat(manifest.serviceDescription.targetOffsetMs).isEqualTo(C.TIME_UNSET); assertThat(manifest.serviceDescription.targetOffsetMs).isEqualTo(C.TIME_UNSET);
assertThat(manifest.serviceDescription.minOffsetMs).isEqualTo(C.TIME_UNSET);
assertThat(manifest.serviceDescription.maxOffsetMs).isEqualTo(C.TIME_UNSET);
assertThat(manifest.serviceDescription.minPlaybackSpeed).isEqualTo(0.1f); assertThat(manifest.serviceDescription.minPlaybackSpeed).isEqualTo(0.1f);
assertThat(manifest.serviceDescription.maxPlaybackSpeed).isEqualTo(99f); assertThat(manifest.serviceDescription.maxPlaybackSpeed).isEqualTo(99f);
} }
@Test @Test
public void serviceDescriptionElement_noPlaybackRates_isUnset() throws IOException { public void serviceDescriptionElement_onlyTargetLatency_playbackRatesAndMinMaxLatencyUnset()
throws IOException {
DashManifestParser parser = new DashManifestParser(); DashManifestParser parser = new DashManifestParser();
DashManifest manifest = DashManifest manifest =
@ -609,10 +614,12 @@ public class DashManifestParserTest {
Uri.parse("https://example.com/test.mpd"), Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream( TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), ApplicationProvider.getApplicationContext(),
SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_NO_PLAYBACK_RATES)); SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_ONLY_TARGET_LATENCY));
assertThat(manifest.serviceDescription).isNotNull(); assertThat(manifest.serviceDescription).isNotNull();
assertThat(manifest.serviceDescription.targetOffsetMs).isEqualTo(20_000); assertThat(manifest.serviceDescription.targetOffsetMs).isEqualTo(20_000);
assertThat(manifest.serviceDescription.minOffsetMs).isEqualTo(C.TIME_UNSET);
assertThat(manifest.serviceDescription.maxOffsetMs).isEqualTo(C.TIME_UNSET);
assertThat(manifest.serviceDescription.minPlaybackSpeed).isEqualTo(C.RATE_UNSET); assertThat(manifest.serviceDescription.minPlaybackSpeed).isEqualTo(C.RATE_UNSET);
assertThat(manifest.serviceDescription.maxPlaybackSpeed).isEqualTo(C.RATE_UNSET); assertThat(manifest.serviceDescription.maxPlaybackSpeed).isEqualTo(C.RATE_UNSET);
} }

View File

@ -43,7 +43,11 @@ public class DashManifestTest {
Representation[][][] representations = newRepresentations(3, 2, 3); Representation[][][] representations = newRepresentations(3, 2, 3);
ServiceDescriptionElement serviceDescriptionElement = ServiceDescriptionElement serviceDescriptionElement =
new ServiceDescriptionElement( new ServiceDescriptionElement(
/* targetOffsetMs= */ 20, /* minPlaybackSpeed= */ 0.9f, /* maxPlaybackSpeed= */ 1.1f); /* targetOffsetMs= */ 20,
/* minOffsetMs= */ 10,
/* maxOffsetMs= */ 40,
/* minPlaybackSpeed= */ 0.9f,
/* maxPlaybackSpeed= */ 1.1f);
DashManifest sourceManifest = DashManifest sourceManifest =
newDashManifest( newDashManifest(
10, 10,

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<MPD type="static" duration="1s" mediaPresentationDuration="PT1S"> <MPD type="static" duration="1s" mediaPresentationDuration="PT1S">
<ServiceDescription> <ServiceDescription>
<Latency target="20000"/> <Latency min="1000" target="20000" max="30000"/>
<PlaybackRate min="0.1" max="99"/> <PlaybackRate min="0.1" max="99"/>
</ServiceDescription> </ServiceDescription>
<Period> <Period>