Skip to content

Commit cc98d40

Browse files
authored
fix: Fix ts parser when using B-frames (#8696)
Fixes #8691
1 parent 1206dae commit cc98d40

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ module.exports = (config) => {
287287
{pattern: 'test/test/assets/hls-text-offset/*', included: false},
288288
{pattern: 'test/test/assets/hls-ts-aac/*', included: false},
289289
{pattern: 'test/test/assets/hls-ts-ac3/*', included: false},
290+
{pattern: 'test/test/assets/hls-ts-b-frames/*', included: false},
290291
{pattern: 'test/test/assets/hls-ts-ec3/*', included: false},
291292
{pattern: 'test/test/assets/hls-ts-h264/*', included: false},
292293
{pattern: 'test/test/assets/hls-ts-h265/*', included: false},

lib/util/ts_parser.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,11 @@ shaka.util.TsParser = class {
485485
this.referenceDts_ = dts;
486486
}
487487

488-
pes.dts = this.handleRollover_(dts, this.referenceDts_);
488+
if (pes.pts != pts) {
489+
pes.dts = this.handleRollover_(dts, this.referenceDts_);
490+
} else {
491+
pes.dts = dts;
492+
}
489493
}
490494
this.referenceDts_ = pes.dts;
491495
}
@@ -767,7 +771,9 @@ shaka.util.TsParser = class {
767771
this.videoPes_[this.videoPes_.length - 1] : null;
768772
if (pes && pes.pts != null && pes.dts != null && (!previousPes ||
769773
(previousPes.pts != pes.pts && previousPes.dts != pes.dts))) {
770-
if (this.videoPes_.length && pes.dts < (previousPes.dts || 0)) {
774+
if (previousPes && this.videoPes_.length &&
775+
pes.dts < (previousPes.dts || pes.dts) &&
776+
pes.pts < (previousPes.pts || pes.pts)) {
771777
sort = true;
772778
}
773779
this.videoPes_.push(pes);

test/test/assets/hls-ts-b-frames/1.ts

330 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#EXTM3U
2+
#EXT-X-VERSION:4
3+
#EXT-X-INDEPENDENT-SEGMENTS
4+
5+
#EXT-X-STREAM-INF:BANDWIDTH=857405,AVERAGE-BANDWIDTH=857405,RESOLUTION=1280x720,CODECS="avc1.64001F",FRAME-RATE=25
6+
playlist.m3u8
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#EXTM3U
2+
#EXT-X-VERSION:3
3+
#EXT-X-MEDIA-SEQUENCE:1
4+
#EXT-X-TARGETDURATION:6
5+
#EXT-X-PLAYLIST-TYPE:VOD
6+
#EXTINF:5.760,
7+
1.ts
8+
#EXT-X-ENDLIST

test/transmuxer/transmuxer_integration.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ describe('Transmuxer Player', () => {
253253
await player.unload();
254254
});
255255

256+
it('H.264 in TS with b-frames', async () => {
257+
await player.load('/base/test/test/assets/hls-ts-b-frames/index.m3u8');
258+
await video.play();
259+
expect(player.isLive()).toBe(false);
260+
261+
// Play for 30 seconds, but stop early if the video ends.
262+
await waiter.waitForEndOrTimeout(video, 30);
263+
264+
await player.unload();
265+
});
266+
256267
it('H.265 in TS', async () => {
257268
if (!await Util.isTypeSupported('video/mp4; codecs="hvc1.2.4.L123.B0"',
258269
/* width= */ 640, /* height= */ 360)) {

0 commit comments

Comments
 (0)