HlsPlaylistParser: ignore subtitles without URI

Issue: #8323
PiperOrigin-RevId: 347827615
This commit is contained in:
christosts 2020-12-16 16:31:15 +00:00 committed by Christos Tsilopoulos
parent 3b277b2810
commit 8da4eaa377
2 changed files with 23 additions and 1 deletions

View File

@ -38,6 +38,7 @@ import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Rendit
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
import com.google.android.exoplayer2.upstream.ParsingLoadable;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.UriUtil;
import com.google.android.exoplayer2.util.Util;
@ -66,6 +67,8 @@ import org.checkerframework.checker.nullness.qual.PolyNull;
*/
public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlaylist> {
private static final String LOG_TAG = "HlsPlaylistParser";
private static final String PLAYLIST_HEADER = "#EXTM3U";
private static final String TAG_PREFIX = "#EXT";
@ -516,7 +519,11 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
sampleMimeType = MimeTypes.TEXT_VTT;
}
formatBuilder.setSampleMimeType(sampleMimeType).setMetadata(metadata);
if (uri != null) {
subtitles.add(new Rendition(uri, formatBuilder.build(), groupId, name));
} else {
Log.w(LOG_TAG, "EXT-X-MEDIA tag with missing mandatory URI attribute: skipping");
}
break;
case TYPE_CLOSED_CAPTIONS:
String instreamId = parseStringAttr(line, REGEX_INSTREAM_ID, variableDefinitions);

View File

@ -108,6 +108,14 @@ public class HlsMasterPlaylistParserTest {
+ "http://example.com/low.m3u8\n";
private static final String PLAYLIST_WITH_SUBTITLES =
" #EXTM3U \n"
+ "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"sub1\",URI=\"s1/en/prog_index.m3u8\","
+ "LANGUAGE=\"es\",NAME=\"Eng\"\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=1280000,"
+ "CODECS=\"mp4a.40.2,avc1.66.30\",RESOLUTION=304x128\n"
+ "http://example.com/low.m3u8\n";
private static final String PLAYLIST_WITH_SUBTITLES_NO_URI =
" #EXTM3U \n"
+ "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"sub1\","
+ "LANGUAGE=\"es\",NAME=\"Eng\"\n"
@ -354,6 +362,13 @@ public class HlsMasterPlaylistParserTest {
assertThat(firstTextFormat.sampleMimeType).isEqualTo(MimeTypes.TEXT_VTT);
}
@Test
public void parseMasterPlaylist_subtitlesWithoutUri_skipsSubtitles() throws IOException {
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_SUBTITLES_NO_URI);
assertThat(playlist.subtitles).isEmpty();
}
@Test
public void parseMasterPlaylist_withIndependentSegments_hasNoIndenpendentSegments()
throws IOException {