Commit 93f4a19f by aquilescanta Committed by Oliver Woodman

Expand check for muxed audio media tags to include uris that match variants

Issue:#5313
PiperOrigin-RevId: 228155222
parent 32bad691
...@@ -360,7 +360,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -360,7 +360,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
/* initializationData= */ null, /* initializationData= */ null,
selectionFlags, selectionFlags,
language); language);
if (uri == null) { if (isMediaTagMuxed(variants, uri)) {
muxedAudioFormat = format; muxedAudioFormat = format;
} else { } else {
audios.add(new HlsMasterPlaylist.HlsUrl(uri, format)); audios.add(new HlsMasterPlaylist.HlsUrl(uri, format));
...@@ -766,6 +766,20 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -766,6 +766,20 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return Pattern.compile(attribute + "=(" + BOOLEAN_FALSE + "|" + BOOLEAN_TRUE + ")"); return Pattern.compile(attribute + "=(" + BOOLEAN_FALSE + "|" + BOOLEAN_TRUE + ")");
} }
private static boolean isMediaTagMuxed(
List<HlsMasterPlaylist.HlsUrl> variants, String mediaTagUri) {
if (mediaTagUri == null) {
return true;
}
// The URI attribute is defined, but it may match the uri of a variant.
for (int i = 0; i < variants.size(); i++) {
if (mediaTagUri.equals(variants.get(i).url)) {
return true;
}
}
return false;
}
private static class LineIterator { private static class LineIterator {
private final BufferedReader reader; private final BufferedReader reader;
......
...@@ -134,6 +134,17 @@ public class HlsMasterPlaylistParserTest { ...@@ -134,6 +134,17 @@ public class HlsMasterPlaylistParserTest {
+ "#EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS=\"{$codecs}\"\n" + "#EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS=\"{$codecs}\"\n"
+ "http://example.com/{$tricky}\n"; + "http://example.com/{$tricky}\n";
private static final String PLAYLIST_WITH_MULTIPLE_MUXED_MEDIA_TAGS =
"#EXTM3U\n"
+ "#EXT-X-VERSION:3\n"
+ "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"a\",NAME=\"audio_0\",DEFAULT=YES,URI=\"0/0.m3u8\"\n"
+ "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"b\",NAME=\"audio_0\",DEFAULT=YES,URI=\"1/1.m3u8\"\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=140800,CODECS=\"mp4a.40.2\",AUDIO=\"a\"\n"
+ "0/0.m3u8\n"
+ "\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=281600,CODECS=\"mp4a.40.2\",AUDIO=\"b\"\n"
+ "1/1.m3u8\n";
@Test @Test
public void testParseMasterPlaylist() throws IOException { public void testParseMasterPlaylist() throws IOException {
HlsMasterPlaylist masterPlaylist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_SIMPLE); HlsMasterPlaylist masterPlaylist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_SIMPLE);
...@@ -271,6 +282,14 @@ public class HlsMasterPlaylistParserTest { ...@@ -271,6 +282,14 @@ public class HlsMasterPlaylistParserTest {
assertThat(variant.url).isEqualTo("http://example.com/This/{$nested}/reference/shouldnt/work"); assertThat(variant.url).isEqualTo("http://example.com/This/{$nested}/reference/shouldnt/work");
} }
@Test
public void testMultipleMuxedMediaTags() throws IOException {
HlsMasterPlaylist playlistWithMultipleMuxedMediaTags =
parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_MULTIPLE_MUXED_MEDIA_TAGS);
assertThat(playlistWithMultipleMuxedMediaTags.variants).hasSize(2);
assertThat(playlistWithMultipleMuxedMediaTags.audios).isEmpty();
}
private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString) private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString)
throws IOException { throws IOException {
Uri playlistUri = Uri.parse(uri); Uri playlistUri = Uri.parse(uri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment