Skip to content

Commit

Permalink
Expand check for muxed audio media tags to include uris that match va…
Browse files Browse the repository at this point in the history
…riants

Issue:#5313
PiperOrigin-RevId: 228155222
  • Loading branch information
AquilesCanta authored and ojw28 committed Jan 8, 2019
1 parent 147deaf commit be69d5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, Stri
/* initializationData= */ null,
selectionFlags,
language);
if (uri == null) {
if (isMediaTagMuxed(variants, uri)) {
muxedAudioFormat = format;
} else {
audios.add(new HlsMasterPlaylist.HlsUrl(uri, format));
Expand Down Expand Up @@ -766,6 +766,20 @@ private static Pattern compileBooleanAttrPattern(String attribute) {
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 final BufferedReader reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public class HlsMasterPlaylistParserTest {
+ "#EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS=\"{$codecs}\"\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
public void testParseMasterPlaylist() throws IOException {
HlsMasterPlaylist masterPlaylist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_SIMPLE);
Expand Down Expand Up @@ -271,6 +282,14 @@ public void testVariableSubstitution() throws IOException {
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)
throws IOException {
Uri playlistUri = Uri.parse(uri);
Expand Down

0 comments on commit be69d5b

Please sign in to comment.