Skip to content

Commit

Permalink
fix(HLS): Ignore segments with zero duration (#5371)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Jun 29, 2023
1 parent 1ad75ec commit c25b26a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2981,6 +2981,10 @@ shaka.hls.HlsParser = class {
// We're interested in the duration part.
const extinfValues = extinfTag.value.split(',');
const duration = Number(extinfValues[0]);
// Skip segments without duration
if (duration == 0) {
return null;
}
endTime = startTime + duration;
} else {
endTime = partialSegmentRefs[partialSegmentRefs.length - 1].endTime;
Expand Down Expand Up @@ -3196,9 +3200,9 @@ shaka.hls.HlsParser = class {
mimeType,
lastDiscontinuityStartTime,
hlsAes128Key);
previousReference = reference;

if (reference) {
previousReference = reference;
reference.discontinuitySequence = discontinuitySequence;

if (this.config_.hls.ignoreManifestProgramDateTime &&
Expand Down
76 changes: 76 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,82 @@ describe('HlsParser', () => {
}
});

it('ignore segments with #EXTINF:0', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",',
'CHANNELS="2",URI="audio"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",',
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1"\n',
'video\n',
].join('');

const video = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'main.mp4\n',
'#EXTINF:0,\n',
'main.mp4\n',
'#EXTINF:5,\n',
'main.mp4\n',
].join('');

const audio = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'main.mp4\n',
'#EXTINF:0,\n',
'main.mp4\n',
'#EXTINF:5,\n',
'main.mp4\n',
].join('');

fakeNetEngine
.setResponseText('test:/master', master)
.setResponseText('test:/audio', audio)
.setResponseText('test:/video', video)
.setResponseValue('test:/init.mp4', initSegmentData)
.setResponseValue('test:/main.mp4', segmentData);

const actual = await parser.start('test:/master', playerInterface);
await loadAllStreamsFor(actual);

expect(actual.variants.length).toBe(1);

const variant = actual.variants[0];
expect(variant.video).toBeTruthy();
expect(variant.audio).toBeTruthy();

await variant.video.createSegmentIndex();
goog.asserts.assert(variant.video.segmentIndex != null,
'Null segmentIndex!');

const firstVideoReference = variant.video.segmentIndex.get(0);
const secondVideoReference = variant.video.segmentIndex.get(1);
const thirdVideoReference = variant.video.segmentIndex.get(2);

expect(firstVideoReference).not.toBe(null);
expect(secondVideoReference).not.toBe(null);
expect(thirdVideoReference).toBe(null);


await variant.audio.createSegmentIndex();
goog.asserts.assert(variant.audio.segmentIndex != null,
'Null segmentIndex!');

const firstAudioReference = variant.audio.segmentIndex.get(0);
const secondAudioReference = variant.audio.segmentIndex.get(1);
const thirdAudioReference = variant.audio.segmentIndex.get(2);

expect(firstAudioReference).not.toBe(null);
expect(secondAudioReference).not.toBe(null);
expect(thirdAudioReference).toBe(null);
});

it('Disable audio does not create audio streams', async () => {
const master = [
'#EXTM3U\n',
Expand Down

0 comments on commit c25b26a

Please sign in to comment.