mirror of
https://github.com/androidx/media.git
synced 2025-05-16 03:59:54 +08:00
Merge pull request #4911 from Comcast/feature/hls-audio-text-id-uniqueness
Create unique id for HLS audio and text tracks
This commit is contained in:
commit
0501b677ad
@ -341,6 +341,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
|
||||
String name = parseStringAttr(line, REGEX_NAME, variableDefinitions);
|
||||
String language = parseOptionalStringAttr(line, REGEX_LANGUAGE, variableDefinitions);
|
||||
String groupId = parseOptionalStringAttr(line, REGEX_GROUP_ID, variableDefinitions);
|
||||
String id = String.format("%s:%s", groupId, name);
|
||||
Format format;
|
||||
switch (parseStringAttr(line, REGEX_TYPE, variableDefinitions)) {
|
||||
case TYPE_AUDIO:
|
||||
@ -348,7 +349,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
|
||||
String sampleMimeType = codecs != null ? MimeTypes.getMediaMimeType(codecs) : null;
|
||||
format =
|
||||
Format.createAudioContainerFormat(
|
||||
/* id= */ name,
|
||||
/* id= */ id,
|
||||
/* label= */ name,
|
||||
/* containerMimeType= */ MimeTypes.APPLICATION_M3U8,
|
||||
sampleMimeType,
|
||||
@ -368,7 +369,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
|
||||
case TYPE_SUBTITLES:
|
||||
format =
|
||||
Format.createTextContainerFormat(
|
||||
/* id= */ name,
|
||||
/* id= */ id,
|
||||
/* label= */ name,
|
||||
/* containerMimeType= */ MimeTypes.APPLICATION_M3U8,
|
||||
/* sampleMimeType= */ MimeTypes.TEXT_VTT,
|
||||
@ -394,7 +395,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
|
||||
}
|
||||
muxedCaptionFormats.add(
|
||||
Format.createTextContainerFormat(
|
||||
/* id= */ name,
|
||||
/* id= */ id,
|
||||
/* label= */ name,
|
||||
/* containerMimeType= */ null,
|
||||
/* sampleMimeType= */ mimeType,
|
||||
|
@ -75,7 +75,7 @@ public class HlsMasterPlaylistParserTest {
|
||||
|
||||
private static final String PLAYLIST_WITH_CC =
|
||||
" #EXTM3U \n"
|
||||
+ "#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,"
|
||||
+ "#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID=\"cc1\","
|
||||
+ "LANGUAGE=\"es\",NAME=\"Eng\",INSTREAM-ID=\"SERVICE4\"\n"
|
||||
+ "#EXT-X-STREAM-INF:BANDWIDTH=1280000,"
|
||||
+ "CODECS=\"mp4a.40.2,avc1.66.30\",RESOLUTION=304x128\n"
|
||||
@ -90,6 +90,14 @@ public class HlsMasterPlaylistParserTest {
|
||||
+ "CLOSED-CAPTIONS=NONE\n"
|
||||
+ "http://example.com/low.m3u8\n";
|
||||
|
||||
private static final String PLAYLIST_WITH_SUBTITLES =
|
||||
" #EXTM3U \n"
|
||||
+ "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"sub1\","
|
||||
+ "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_AUDIO_MEDIA_TAG =
|
||||
"#EXTM3U\n"
|
||||
+ "#EXT-X-STREAM-INF:BANDWIDTH=2227464,CODECS=\"avc1.640020,mp4a.40.2\",AUDIO=\"aud1\"\n"
|
||||
@ -216,6 +224,33 @@ public class HlsMasterPlaylistParserTest {
|
||||
assertThat(secondAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AC3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAudioIdPropagation() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_AUDIO_MEDIA_TAG);
|
||||
|
||||
Format firstAudioFormat = playlist.audios.get(0).format;
|
||||
assertThat(firstAudioFormat.id).isEqualTo("aud1:English");
|
||||
|
||||
Format secondAudioFormat = playlist.audios.get(1).format;
|
||||
assertThat(secondAudioFormat.id).isEqualTo("aud2:English");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCCIdPropagation() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC);
|
||||
|
||||
Format firstTextFormat = playlist.muxedCaptionFormats.get(0);
|
||||
assertThat(firstTextFormat.id).isEqualTo("cc1:Eng");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtitleIdPropagation() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_SUBTITLES);
|
||||
|
||||
Format firstTextFormat = playlist.subtitles.get(0).format;
|
||||
assertThat(firstTextFormat.id).isEqualTo("sub1:Eng");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndependentSegments() throws IOException {
|
||||
HlsMasterPlaylist playlistWithIndependentSegments =
|
||||
|
Loading…
x
Reference in New Issue
Block a user