Skip to content

Commit

Permalink
fix(WebVTT): Remove rollover logic because we always transmux TS (#6397)
Browse files Browse the repository at this point in the history
Fixes #6320
  • Loading branch information
avelad committed Apr 4, 2024
1 parent d9da783 commit 286126e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 69 deletions.
17 changes: 1 addition & 16 deletions lib/text/vtt_text_parser.js
Expand Up @@ -160,17 +160,9 @@ shaka.text.VttTextParser = class {
shaka.util.Error.Code.INVALID_TEXT_HEADER);
}

let mpegTime = Number(mpegTimeMatch[1]);
const mpegTime = Number(mpegTimeMatch[1]);
const mpegTimescale = shaka.text.VttTextParser.MPEG_TIMESCALE_;

const rolloverSeconds =
shaka.text.VttTextParser.TS_ROLLOVER_ / mpegTimescale;
let segmentStart = time.segmentStart - time.periodStart;
while (segmentStart >= rolloverSeconds) {
segmentStart -= rolloverSeconds;
mpegTime += shaka.text.VttTextParser.TS_ROLLOVER_;
}

return time.periodStart + mpegTime / mpegTimescale - cueTime;
}

Expand Down Expand Up @@ -1015,13 +1007,6 @@ shaka.text.VttTextParser = class {
*/
shaka.text.VttTextParser.MPEG_TIMESCALE_ = 90000;

/**
* At this value, timestamps roll over in TS content.
* @const {number}
* @private
*/
shaka.text.VttTextParser.TS_ROLLOVER_ = 0x200000000;

/**
* @const
* @private {!RegExp}
Expand Down
53 changes: 0 additions & 53 deletions test/text/vtt_text_parser_unit.js
Expand Up @@ -583,59 +583,6 @@ describe('VttTextParser', () => {
/* hls= */ true, /* sequenceMode= */ true);
});

it('handles timestamp rollover with X-TIMESTAMP-MAP header', () => {
verifyHelper(
[
{startTime: 95443, endTime: 95445, payload: 'Test'},
],
// 8589870000/90000 = 95443 sec, so expect every timestamp to be 95443
// seconds ahead of what is specified.
'WEBVTT\n' +
'X-TIMESTAMP-MAP=MPEGTS:8589870000,LOCAL:00:00:00.000\n\n' +
'00:00:00.000 --> 00:00:02.000 line:0\n' +
'Test',
// Non-null segmentStart takes precedence over X-TIMESTAMP-MAP.
// This protects us from rollover in the MPEGTS field.
{periodStart: 0, segmentStart: 95440, segmentEnd: 95550, vttOffset: 0},
/* hls= */ true, /* sequenceMode= */ true);

verifyHelper(
[
{startTime: 95552, endTime: 95554, payload: 'Test2'},
],
// 95550 is larger than the roll over timestamp, so the timestamp offset
// gets rolled over.
// (9745408 + 0x200000000) / 90000 = 95552 sec
'WEBVTT\n' +
'X-TIMESTAMP-MAP=MPEGTS:9745408,LOCAL:00:00:00.000\n\n' +
'00:00:00.000 --> 00:00:02.000 line:0\n' +
'Test2',
{periodStart: 0, segmentStart: 95550, segmentEnd: 95560, vttOffset: 0},
/* hls= */ true, /* sequenceMode= */ true);
});

// A mock-up of HLS live subs as seen in b/253104251.
it('handles timestamp rollover and negative offset in HLS live', () => {
// Similar to values seen in b/253104251, for a realistic regression test.
// When using sequence mode on live HLS, we get negative offsets that
// represent the timestamp of our first append in sequence mode.
verifyHelper(
[
{startTime: 3600, endTime: 3602, payload: 'Test'},
],
'WEBVTT\n' +
'X-TIMESTAMP-MAP=MPEGTS:8355814896,LOCAL:00:00:00.000\n\n' +
'00:00:00.000 --> 00:00:02.000 line:0\n' +
'Test',
{
periodStart: -1234567,
segmentStart: 3600,
segmentEnd: 3610,
vttOffset: -1234567,
},
/* hls= */ true, /* sequenceMode= */ true);
});

it('supports global style blocks', () => {
const textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
verifyHelper(
Expand Down

0 comments on commit 286126e

Please sign in to comment.