From a809c5384ac2af38ae44b8f5f4778d1e4b56e495 Mon Sep 17 00:00:00 2001 From: amtins Date: Tue, 9 May 2023 18:00:21 +0200 Subject: [PATCH 1/2] fix(aac): missing timestamp rollover --- lib/aac/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/aac/index.js b/lib/aac/index.js index 5a8e40f9..f350f62e 100644 --- a/lib/aac/index.js +++ b/lib/aac/index.js @@ -11,6 +11,8 @@ 'use strict'; var Stream = require('../utils/stream.js'); var aacUtils = require('./utils'); +var handleRollover = + require('../m2ts/timestamp-rollover-stream.js').handleRollover; // Constants var AacStream; @@ -22,7 +24,8 @@ var AacStream; AacStream = function() { var everything = new Uint8Array(), - timeStamp = 0; + timeStamp = 0, + referenceDTS; AacStream.prototype.init.call(this); @@ -94,11 +97,15 @@ AacStream = function() { break; } + if (referenceDTS === undefined) { + referenceDTS = timeStamp; + } + packet = { type: 'audio', data: everything.subarray(byteIndex, byteIndex + frameSize), - pts: timeStamp, - dts: timeStamp + pts: handleRollover(timeStamp, referenceDTS), + dts: handleRollover(timeStamp, referenceDTS) }; this.trigger('data', packet); byteIndex += frameSize; From b2b1179d381229305e9b997bb94fcc2cfa425cc4 Mon Sep 17 00:00:00 2001 From: amtins Date: Sat, 15 Jul 2023 14:59:33 +0200 Subject: [PATCH 2/2] test(aac): missing timestamp rollover --- test/aac-stream.test.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/aac-stream.test.js b/test/aac-stream.test.js index c238c9b8..7b50edca 100644 --- a/test/aac-stream.test.js +++ b/test/aac-stream.test.js @@ -287,3 +287,39 @@ QUnit.test('continues parsing after corrupted stream', function(assert) { assert.equal(adtsCount, 1); assert.equal(id3Count, 1); }); + +QUnit.test('handles timestamp rollover', function(assert) { + var + MAX_TS = 8589934592, + count = 0, + array = new Uint8Array(2048); + + array[0] = 255; + array[1] = 255; + array[2] = 0; + array[3] = 255; + array[4] = 255; + array[5] = 255; + array[6] = 255; + array[7] = 255; + array[8] = 0; + array[9] = 0; + + + aacStream.on('data', function(frame) { + if (frame.pts > MAX_TS && frame.dts > MAX_TS) { + count += 1; + } + }); + + aacStream.setTimestamp(MAX_TS); + aacStream.push(array); + + aacStream.setTimestamp(10); + aacStream.push(array); + + aacStream.setTimestamp(20); + aacStream.push(array); + + assert.equal(count, 2); +});