Skip to content

Commit 0affbd7

Browse files
author
Prashant Kumar
committed
test(hls): Add unit test for EXT-X-DEFINE variable substitution in download path
Adds a test that verifies variables defined via EXT-X-DEFINE NAME/VALUE in the multivariant playlist are correctly resolved in media playlist segment URLs during download. Without the fix in HlsPlaylistParser, this test fails with unresolved {} in segment URLs.
1 parent fe74940 commit 0affbd7

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

libraries/exoplayer_hls/src/test/java/androidx/media3/exoplayer/hls/offline/HlsDownloaderTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,45 @@ public void downloadEncMediaPlaylist() throws Exception {
301301
assertCachedData(cache, fakeDataSet);
302302
}
303303

304+
@Test
305+
public void download_withVariableSubstitutionInSegmentUrls_resolvesVariables() throws Exception {
306+
// Multivariant playlist defines a variable via EXT-X-DEFINE NAME/VALUE
307+
byte[] multivariantPlaylistData =
308+
("#EXTM3U\n"
309+
+ "#EXT-X-DEFINE:NAME=\"cdnPrefix\",VALUE=\"https://cdn.example.com/\"\n"
310+
+ "#EXT-X-STREAM-INF:BANDWIDTH=232370,CODECS=\"mp4a.40.2, avc1.4d4015\"\n"
311+
+ "media_with_vars.m3u8\n")
312+
.getBytes(java.nio.charset.StandardCharsets.UTF_8);
313+
314+
// Media playlist uses the variable in segment URLs without IMPORT
315+
byte[] mediaPlaylistData =
316+
("#EXTM3U\n"
317+
+ "#EXT-X-TARGETDURATION:10\n"
318+
+ "#EXT-X-VERSION:8\n"
319+
+ "#EXT-X-MEDIA-SEQUENCE:0\n"
320+
+ "#EXT-X-PLAYLIST-TYPE:VOD\n"
321+
+ "#EXT-X-DEFINE:IMPORT=\"cdnPrefix\"\n"
322+
+ "#EXTINF:9.97667,\n"
323+
+ "{$cdnPrefix}segment0.ts\n"
324+
+ "#EXTINF:9.97667,\n"
325+
+ "{$cdnPrefix}segment1.ts\n"
326+
+ "#EXT-X-ENDLIST")
327+
.getBytes(java.nio.charset.StandardCharsets.UTF_8);
328+
329+
fakeDataSet =
330+
new FakeDataSet()
331+
.setData("master_vars.m3u8", multivariantPlaylistData)
332+
.setData("media_with_vars.m3u8", mediaPlaylistData)
333+
.setRandomData("https://cdn.example.com/segment0.ts", 10)
334+
.setRandomData("https://cdn.example.com/segment1.ts", 11);
335+
336+
HlsDownloader downloader = getHlsDownloader("master_vars.m3u8", getKeys(0));
337+
downloader.download(progressListener);
338+
339+
// Verify segments were downloaded with resolved URLs
340+
assertCachedData(cache, fakeDataSet);
341+
}
342+
304343
private HlsDownloader getHlsDownloader(String mediaPlaylistUri, List<StreamKey> keys) {
305344
CacheDataSource.Factory cacheDataSourceFactory =
306345
new CacheDataSource.Factory()

0 commit comments

Comments
 (0)