Commit c22fd76b by christosts Committed by Ian Baker

HlsPlaylistParser: ignore subtitles without URI

Issue: #8323
PiperOrigin-RevId: 347827615
parent d0e6dec1
...@@ -34,6 +34,7 @@ import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.Varia ...@@ -34,6 +34,7 @@ import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.Varia
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment; import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment;
import com.google.android.exoplayer2.upstream.ParsingLoadable; import com.google.android.exoplayer2.upstream.ParsingLoadable;
import com.google.android.exoplayer2.util.Assertions; 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.MimeTypes;
import com.google.android.exoplayer2.util.UriUtil; import com.google.android.exoplayer2.util.UriUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -61,6 +62,8 @@ import org.checkerframework.checker.nullness.qual.PolyNull; ...@@ -61,6 +62,8 @@ import org.checkerframework.checker.nullness.qual.PolyNull;
*/ */
public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlaylist> { 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 PLAYLIST_HEADER = "#EXTM3U";
private static final String TAG_PREFIX = "#EXT"; private static final String TAG_PREFIX = "#EXT";
...@@ -480,7 +483,11 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -480,7 +483,11 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
sampleMimeType = MimeTypes.TEXT_VTT; sampleMimeType = MimeTypes.TEXT_VTT;
} }
formatBuilder.setSampleMimeType(sampleMimeType).setMetadata(metadata); formatBuilder.setSampleMimeType(sampleMimeType).setMetadata(metadata);
subtitles.add(new Rendition(uri, formatBuilder.build(), groupId, name)); 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; break;
case TYPE_CLOSED_CAPTIONS: case TYPE_CLOSED_CAPTIONS:
String instreamId = parseStringAttr(line, REGEX_INSTREAM_ID, variableDefinitions); String instreamId = parseStringAttr(line, REGEX_INSTREAM_ID, variableDefinitions);
......
...@@ -109,6 +109,14 @@ public class HlsMasterPlaylistParserTest { ...@@ -109,6 +109,14 @@ public class HlsMasterPlaylistParserTest {
private static final String PLAYLIST_WITH_SUBTITLES = private static final String PLAYLIST_WITH_SUBTITLES =
" #EXTM3U \n" " #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\"," + "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"sub1\","
+ "LANGUAGE=\"es\",NAME=\"Eng\"\n" + "LANGUAGE=\"es\",NAME=\"Eng\"\n"
+ "#EXT-X-STREAM-INF:BANDWIDTH=1280000," + "#EXT-X-STREAM-INF:BANDWIDTH=1280000,"
...@@ -355,6 +363,13 @@ public class HlsMasterPlaylistParserTest { ...@@ -355,6 +363,13 @@ public class HlsMasterPlaylistParserTest {
} }
@Test @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() public void parseMasterPlaylist_withIndependentSegments_hasNoIndenpendentSegments()
throws IOException { throws IOException {
HlsMasterPlaylist playlistWithIndependentSegments = HlsMasterPlaylist playlistWithIndependentSegments =
......
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