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) {
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 =
msToUs(parseXsDateTime(parseStringAttr(line, REGEX_START_DATE, variableDefinitions)));
long endDateUnixUs = C.TIME_UNSET;
@ -1115,22 +1109,25 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
break;
}
}
interstitials.add(
new Interstitial(
id,
assetUri,
assetListUri,
startDateUnixUs,
endDateUnixUs,
durationUs,
plannedDurationUs,
cue,
endOnNext,
resumeOffsetUs,
playoutLimitUs,
snapTypes,
restrictions,
clientDefinedAttributes.build()));
if ((assetListUri == null && assetUri != null)
|| (assetListUri != null && assetUri == null)) {
interstitials.add(
new Interstitial(
id,
assetUri,
assetListUri,
startDateUnixUs,
endDateUnixUs,
durationUs,
plannedDurationUs,
cue,
endOnNext,
resumeOffsetUs,
playoutLimitUs,
snapTypes,
restrictions,
clientDefinedAttributes.build()));
}
} else if (!line.startsWith("#")) {
@Nullable
String segmentEncryptionIV =

View file

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