mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Parse min/max live offset from ServiceDescription.
Issue: #4904 PiperOrigin-RevId: 339215091
This commit is contained in:
parent
e57193676a
commit
aee7e6087c
@ -250,18 +250,23 @@ public class DashManifestParser extends DefaultHandler
|
||||
protected ServiceDescriptionElement parseServiceDescription(XmlPullParser xpp)
|
||||
throws XmlPullParserException, IOException {
|
||||
long targetOffsetMs = C.TIME_UNSET;
|
||||
long minOffsetMs = C.TIME_UNSET;
|
||||
long maxOffsetMs = C.TIME_UNSET;
|
||||
float minPlaybackSpeed = C.RATE_UNSET;
|
||||
float maxPlaybackSpeed = C.RATE_UNSET;
|
||||
do {
|
||||
xpp.next();
|
||||
if (XmlPullParserUtil.isStartTag(xpp, "Latency")) {
|
||||
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")) {
|
||||
minPlaybackSpeed = parseFloat(xpp, "min", C.RATE_UNSET);
|
||||
maxPlaybackSpeed = parseFloat(xpp, "max", C.RATE_UNSET);
|
||||
}
|
||||
} while (!XmlPullParserUtil.isEndTag(xpp, "ServiceDescription"));
|
||||
return new ServiceDescriptionElement(targetOffsetMs, minPlaybackSpeed, maxPlaybackSpeed);
|
||||
return new ServiceDescriptionElement(
|
||||
targetOffsetMs, minOffsetMs, maxOffsetMs, minPlaybackSpeed, maxPlaybackSpeed);
|
||||
}
|
||||
|
||||
protected Pair<Period, Long> parsePeriod(
|
||||
|
@ -22,6 +22,10 @@ public final class ServiceDescriptionElement {
|
||||
|
||||
/** The target live offset in milliseconds, or {@link C#TIME_UNSET} if undefined. */
|
||||
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. */
|
||||
public final float minPlaybackSpeed;
|
||||
/** 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
|
||||
* 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
|
||||
* C#RATE_UNSET} if undefined.
|
||||
* @param maxPlaybackSpeed The maximum playback speed for live speed adjustment, or {@link
|
||||
* C#RATE_UNSET} if undefined.
|
||||
*/
|
||||
public ServiceDescriptionElement(
|
||||
long targetOffsetMs, float minPlaybackSpeed, float maxPlaybackSpeed) {
|
||||
long targetOffsetMs,
|
||||
long minOffsetMs,
|
||||
long maxOffsetMs,
|
||||
float minPlaybackSpeed,
|
||||
float maxPlaybackSpeed) {
|
||||
this.targetOffsetMs = targetOffsetMs;
|
||||
this.minOffsetMs = minOffsetMs;
|
||||
this.maxOffsetMs = maxOffsetMs;
|
||||
this.minPlaybackSpeed = minPlaybackSpeed;
|
||||
this.maxPlaybackSpeed = maxPlaybackSpeed;
|
||||
}
|
||||
|
@ -59,10 +59,10 @@ public class DashManifestParserTest {
|
||||
"media/mpd/sample_mpd_availabilityTimeOffset_segmentList";
|
||||
private static final String 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 =
|
||||
"media/mpd/sample_mpd_service_description_low_latency_no_target_latency";
|
||||
private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_NO_PLAYBACK_RATES =
|
||||
"media/mpd/sample_mpd_service_description_low_latency_no_playback_rates";
|
||||
private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_ONLY_PLAYBACK_RATES =
|
||||
"media/mpd/sample_mpd_service_description_low_latency_only_playback_rates";
|
||||
private static final String SAMPLE_MPD_SERVICE_DESCRIPTION_LOW_LATENCY_ONLY_TARGET_LATENCY =
|
||||
"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 = "<" + NEXT_TAG_NAME + "/>";
|
||||
@ -579,12 +579,14 @@ public class DashManifestParserTest {
|
||||
|
||||
assertThat(manifest.serviceDescription).isNotNull();
|
||||
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.maxPlaybackSpeed).isEqualTo(99f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceDescriptionElement_noLatency_isUnset() throws IOException {
|
||||
public void serviceDescriptionElement_onlyPlaybackRates_latencyValuesUnset() throws IOException {
|
||||
DashManifestParser parser = new DashManifestParser();
|
||||
|
||||
DashManifest manifest =
|
||||
@ -592,16 +594,19 @@ public class DashManifestParserTest {
|
||||
Uri.parse("https://example.com/test.mpd"),
|
||||
TestUtil.getInputStream(
|
||||
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.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.maxPlaybackSpeed).isEqualTo(99f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceDescriptionElement_noPlaybackRates_isUnset() throws IOException {
|
||||
public void serviceDescriptionElement_onlyTargetLatency_playbackRatesAndMinMaxLatencyUnset()
|
||||
throws IOException {
|
||||
DashManifestParser parser = new DashManifestParser();
|
||||
|
||||
DashManifest manifest =
|
||||
@ -609,10 +614,12 @@ public class DashManifestParserTest {
|
||||
Uri.parse("https://example.com/test.mpd"),
|
||||
TestUtil.getInputStream(
|
||||
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.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.maxPlaybackSpeed).isEqualTo(C.RATE_UNSET);
|
||||
}
|
||||
|
@ -43,7 +43,11 @@ public class DashManifestTest {
|
||||
Representation[][][] representations = newRepresentations(3, 2, 3);
|
||||
ServiceDescriptionElement 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 =
|
||||
newDashManifest(
|
||||
10,
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MPD type="static" duration="1s" mediaPresentationDuration="PT1S">
|
||||
<ServiceDescription>
|
||||
<Latency target="20000"/>
|
||||
<Latency min="1000" target="20000" max="30000"/>
|
||||
<PlaybackRate min="0.1" max="99"/>
|
||||
</ServiceDescription>
|
||||
<Period>
|
||||
|
Loading…
x
Reference in New Issue
Block a user