Parse NAME label from HLS Master Playlist

The HlsPlaylistParser now parses the "NAME" property
from the MasterHlsPlaylist and saves it in the Variant
This commit is contained in:
Rik Heijdens 2015-10-20 14:51:31 -04:00
parent 5b81612c3b
commit eb282639c5
3 changed files with 10 additions and 4 deletions

View file

@ -184,7 +184,7 @@ public class HlsChunkSource {
playlistParser = new HlsPlaylistParser(); playlistParser = new HlsPlaylistParser();
if (playlist.type == HlsPlaylist.TYPE_MEDIA) { if (playlist.type == HlsPlaylist.TYPE_MEDIA) {
variants = new Variant[] {new Variant(0, playlistUrl, 0, null, -1, -1)}; variants = new Variant[] {new Variant(0, null, playlistUrl, 0, null, -1, -1)};
variantPlaylists = new HlsMediaPlaylist[1]; variantPlaylists = new HlsMediaPlaylist[1];
variantLastPlaylistLoadTimesMs = new long[1]; variantLastPlaylistLoadTimesMs = new long[1];
variantBlacklistTimes = new long[1]; variantBlacklistTimes = new long[1];

View file

@ -143,6 +143,7 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
String codecs = null; String codecs = null;
int width = -1; int width = -1;
int height = -1; int height = -1;
String name = null;
boolean expectingStreamInfUrl = false; boolean expectingStreamInfUrl = false;
String line; String line;
@ -152,18 +153,20 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
String type = HlsParserUtil.parseStringAttr(line, TYPE_ATTR_REGEX, TYPE_ATTR); String type = HlsParserUtil.parseStringAttr(line, TYPE_ATTR_REGEX, TYPE_ATTR);
if (SUBTITLES_TYPE.equals(type)) { if (SUBTITLES_TYPE.equals(type)) {
// We assume all subtitles belong to the same group. // We assume all subtitles belong to the same group.
String name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR); name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR);
String uri = HlsParserUtil.parseStringAttr(line, URI_ATTR_REGEX, URI_ATTR); String uri = HlsParserUtil.parseStringAttr(line, URI_ATTR_REGEX, URI_ATTR);
String language = HlsParserUtil.parseOptionalStringAttr(line, LANGUAGE_ATTR_REGEX); String language = HlsParserUtil.parseOptionalStringAttr(line, LANGUAGE_ATTR_REGEX);
boolean isDefault = HlsParserUtil.parseOptionalBooleanAttr(line, DEFAULT_ATTR_REGEX); boolean isDefault = HlsParserUtil.parseOptionalBooleanAttr(line, DEFAULT_ATTR_REGEX);
boolean autoSelect = HlsParserUtil.parseOptionalBooleanAttr(line, AUTOSELECT_ATTR_REGEX); boolean autoSelect = HlsParserUtil.parseOptionalBooleanAttr(line, AUTOSELECT_ATTR_REGEX);
subtitles.add(new Subtitle(name, uri, language, isDefault, autoSelect)); subtitles.add(new Subtitle(name, uri, language, isDefault, autoSelect));
name = null;
} else { } else {
// TODO: Support other types of media tag. // TODO: Support other types of media tag.
} }
} else if (line.startsWith(STREAM_INF_TAG)) { } else if (line.startsWith(STREAM_INF_TAG)) {
bitrate = HlsParserUtil.parseIntAttr(line, BANDWIDTH_ATTR_REGEX, BANDWIDTH_ATTR); bitrate = HlsParserUtil.parseIntAttr(line, BANDWIDTH_ATTR_REGEX, BANDWIDTH_ATTR);
codecs = HlsParserUtil.parseOptionalStringAttr(line, CODECS_ATTR_REGEX); codecs = HlsParserUtil.parseOptionalStringAttr(line, CODECS_ATTR_REGEX);
name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR);
String resolutionString = HlsParserUtil.parseOptionalStringAttr(line, String resolutionString = HlsParserUtil.parseOptionalStringAttr(line,
RESOLUTION_ATTR_REGEX); RESOLUTION_ATTR_REGEX);
if (resolutionString != null) { if (resolutionString != null) {
@ -184,9 +187,10 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
} }
expectingStreamInfUrl = true; expectingStreamInfUrl = true;
} else if (!line.startsWith("#") && expectingStreamInfUrl) { } else if (!line.startsWith("#") && expectingStreamInfUrl) {
variants.add(new Variant(variants.size(), line, bitrate, codecs, width, height)); variants.add(new Variant(variants.size(), name, line, bitrate, codecs, width, height));
bitrate = 0; bitrate = 0;
codecs = null; codecs = null;
name = null;
width = -1; width = -1;
height = -1; height = -1;
expectingStreamInfUrl = false; expectingStreamInfUrl = false;

View file

@ -26,9 +26,11 @@ public final class Variant implements FormatWrapper {
public final String url; public final String url;
public final Format format; public final Format format;
public final String name;
public Variant(int index, String url, int bitrate, String codecs, int width, int height) { public Variant(int index, String name, String url, int bitrate, String codecs, int width, int height) {
this.url = url; this.url = url;
this.name = name;
format = new Format(Integer.toString(index), MimeTypes.APPLICATION_M3U8, width, height, -1, -1, format = new Format(Integer.toString(index), MimeTypes.APPLICATION_M3U8, width, height, -1, -1,
-1, bitrate, null, codecs); -1, bitrate, null, codecs);
} }