From 24749339db7dfd8a602809bfd4b28558128f1e0a Mon Sep 17 00:00:00 2001 From: olly Date: Fri, 4 Feb 2022 15:05:45 +0000 Subject: [PATCH] Support relative MPD.Location URIs #minor-release Issue: google/ExoPlayer#9939 PiperOrigin-RevId: 426394339 --- .../dash/manifest/DashManifestParser.java | 2 +- .../dash/manifest/DashManifestParserTest.java | 30 +++++++++++++++++++ ...sample_mpd_live_location_redirect_absolute | 21 +++++++++++++ ...sample_mpd_live_location_redirect_relative | 21 +++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_absolute create mode 100644 libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_relative diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/DashManifestParser.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/DashManifestParser.java index e1d4e070b6..9ca9fc2102 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/DashManifestParser.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/manifest/DashManifestParser.java @@ -163,7 +163,7 @@ public class DashManifestParser extends DefaultHandler } else if (XmlPullParserUtil.isStartTag(xpp, "UTCTiming")) { utcTiming = parseUtcTiming(xpp); } else if (XmlPullParserUtil.isStartTag(xpp, "Location")) { - location = Uri.parse(xpp.nextText()); + location = UriUtil.resolveToUri(documentBaseUri.toString(), xpp.nextText()); } else if (XmlPullParserUtil.isStartTag(xpp, "ServiceDescription")) { serviceDescription = parseServiceDescription(xpp); } else if (XmlPullParserUtil.isStartTag(xpp, "Period") && !seenEarlyAccessPeriod) { diff --git a/libraries/exoplayer_dash/src/test/java/androidx/media3/exoplayer/dash/manifest/DashManifestParserTest.java b/libraries/exoplayer_dash/src/test/java/androidx/media3/exoplayer/dash/manifest/DashManifestParserTest.java index cc6d480e0e..1238d756fd 100644 --- a/libraries/exoplayer_dash/src/test/java/androidx/media3/exoplayer/dash/manifest/DashManifestParserTest.java +++ b/libraries/exoplayer_dash/src/test/java/androidx/media3/exoplayer/dash/manifest/DashManifestParserTest.java @@ -46,6 +46,10 @@ import org.xmlpull.v1.XmlPullParserFactory; public class DashManifestParserTest { private static final String SAMPLE_MPD_LIVE = "media/mpd/sample_mpd_live"; + private static final String SAMPLE_MPD_LIVE_LOCATION_REDIRECT_RELATIVE = + "media/mpd/sample_mpd_live_location_redirect_relative"; + private static final String SAMPLE_MPD_LIVE_LOCATION_REDIRECT_ABSOLUTE = + "media/mpd/sample_mpd_live_location_redirect_absolute"; private static final String SAMPLE_MPD_UNKNOWN_MIME_TYPE = "media/mpd/sample_mpd_unknown_mime_type"; private static final String SAMPLE_MPD_SEGMENT_TEMPLATE = "media/mpd/sample_mpd_segment_template"; @@ -201,6 +205,32 @@ public class DashManifestParserTest { assertThat(manifest.programInformation).isEqualTo(expectedProgramInformation); } + @Test + public void parseMediaPresentationDescription_locationRedirectRelative() throws IOException { + DashManifestParser parser = new DashManifestParser(); + DashManifest manifest = + parser.parse( + Uri.parse("https://example.com/a/b/test.mpd"), + TestUtil.getInputStream( + ApplicationProvider.getApplicationContext(), + SAMPLE_MPD_LIVE_LOCATION_REDIRECT_RELATIVE)); + Uri expectedLocation = Uri.parse("https://example.com/a/relative/redirect.mpd"); + assertThat(manifest.location).isEqualTo(expectedLocation); + } + + @Test + public void parseMediaPresentationDescription_locationRedirectAbsolute() throws IOException { + DashManifestParser parser = new DashManifestParser(); + DashManifest manifest = + parser.parse( + Uri.parse("https://example.com/a/b/test.mpd"), + TestUtil.getInputStream( + ApplicationProvider.getApplicationContext(), + SAMPLE_MPD_LIVE_LOCATION_REDIRECT_ABSOLUTE)); + Uri expectedLocation = Uri.parse("https://example2.com/absolute/redirect.mpd"); + assertThat(manifest.location).isEqualTo(expectedLocation); + } + @Test public void parseMediaPresentationDescription_images() throws IOException { DashManifestParser parser = new DashManifestParser(); diff --git a/libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_absolute b/libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_absolute new file mode 100644 index 0000000000..a6b368e163 --- /dev/null +++ b/libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_absolute @@ -0,0 +1,21 @@ + + + https://example2.com/absolute/redirect.mpd + + + + + + + + + diff --git a/libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_relative b/libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_relative new file mode 100644 index 0000000000..63db7de219 --- /dev/null +++ b/libraries/test_data/src/test/assets/media/mpd/sample_mpd_live_location_redirect_relative @@ -0,0 +1,21 @@ + + + ../relative/redirect.mpd + + + + + + + + +