Ignore invalid interstitials instead of throwing

The HLS spec says so in rfc8216bis (4.4.5.1)

PiperOrigin-RevId: 705829265
This commit is contained in:
bachinger 2024-12-13 03:56:32 -08:00 committed by Copybara-Service
parent 522883bf16
commit 07b658a6da
2 changed files with 33 additions and 32 deletions

View file

@ -1003,12 +1003,6 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
if (assetListUriString != null) { if (assetListUriString != null) {
assetListUri = Uri.parse(assetListUriString); assetListUri = Uri.parse(assetListUriString);
} }
if ((assetUri == null && assetListUri == null)
|| (assetUri != null && assetListUri != null)) {
throw ParserException.createForMalformedManifest(
"#EXT-X-DATARANGE: Exactly one of X-ASSET-URI or X-ASSET-LIST must be included",
/* cause= */ null);
}
long startDateUnixUs = long startDateUnixUs =
msToUs(parseXsDateTime(parseStringAttr(line, REGEX_START_DATE, variableDefinitions))); msToUs(parseXsDateTime(parseStringAttr(line, REGEX_START_DATE, variableDefinitions)));
long endDateUnixUs = C.TIME_UNSET; long endDateUnixUs = C.TIME_UNSET;
@ -1115,22 +1109,25 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
break; break;
} }
} }
interstitials.add( if ((assetListUri == null && assetUri != null)
new Interstitial( || (assetListUri != null && assetUri == null)) {
id, interstitials.add(
assetUri, new Interstitial(
assetListUri, id,
startDateUnixUs, assetUri,
endDateUnixUs, assetListUri,
durationUs, startDateUnixUs,
plannedDurationUs, endDateUnixUs,
cue, durationUs,
endOnNext, plannedDurationUs,
resumeOffsetUs, cue,
playoutLimitUs, endOnNext,
snapTypes, resumeOffsetUs,
restrictions, playoutLimitUs,
clientDefinedAttributes.build())); snapTypes,
restrictions,
clientDefinedAttributes.build()));
}
} else if (!line.startsWith("#")) { } else if (!line.startsWith("#")) {
@Nullable @Nullable
String segmentEncryptionIV = String segmentEncryptionIV =

View file

@ -1469,7 +1469,8 @@ public class HlsMediaPlaylistParserTest {
} }
@Test @Test
public void parseMediaPlaylist_withInterstitialWithAssetUriAndList_throwsParserException() { public void parseMediaPlaylist_withInterstitialWithAssetUriAndList_interstitialIgnored()
throws IOException {
Uri playlistUri = Uri.parse("https://example.com/test.m3u8"); Uri playlistUri = Uri.parse("https://example.com/test.m3u8");
String playlistString = String playlistString =
"#EXTM3U\n" "#EXTM3U\n"
@ -1487,16 +1488,18 @@ public class HlsMediaPlaylistParserTest {
+ "X-ASSET-LIST=\"http://example.com/ad2-assets.json\"\n"; + "X-ASSET-LIST=\"http://example.com/ad2-assets.json\"\n";
HlsPlaylistParser hlsPlaylistParser = new HlsPlaylistParser(); HlsPlaylistParser hlsPlaylistParser = new HlsPlaylistParser();
assertThrows( HlsMediaPlaylist hlsMediaPlaylist =
ParserException.class, (HlsMediaPlaylist)
() ->
hlsPlaylistParser.parse( hlsPlaylistParser.parse(
playlistUri, new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)))); playlistUri, new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)));
assertThat(hlsMediaPlaylist.interstitials).isEmpty();
} }
@Test @Test
public void public void
parseMediaPlaylist_withInterstitialWithNeitherAssetUriNorAssetList_throwsParserException() { parseMediaPlaylist_withInterstitialWithNeitherAssetUriNorAssetList_interstitialIgnored()
throws IOException {
Uri playlistUri = Uri.parse("https://example.com/test.m3u8"); Uri playlistUri = Uri.parse("https://example.com/test.m3u8");
String playlistString = String playlistString =
"#EXTM3U\n" "#EXTM3U\n"
@ -1512,11 +1515,12 @@ public class HlsMediaPlaylistParserTest {
+ "START-DATE=\"2020-01-02T21:55:44.000Z\"\n"; + "START-DATE=\"2020-01-02T21:55:44.000Z\"\n";
HlsPlaylistParser hlsPlaylistParser = new HlsPlaylistParser(); HlsPlaylistParser hlsPlaylistParser = new HlsPlaylistParser();
assertThrows( HlsMediaPlaylist hlsMediaPlaylist =
ParserException.class, (HlsMediaPlaylist)
() ->
hlsPlaylistParser.parse( hlsPlaylistParser.parse(
playlistUri, new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)))); playlistUri, new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)));
assertThat(hlsMediaPlaylist.interstitials).isEmpty();
} }
@Test @Test