Skip to content

fix(aac): missing timestamp rollover #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/aac/index.js
Original file line number Diff line number Diff line change
@@ -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;
36 changes: 36 additions & 0 deletions test/aac-stream.test.js
Original file line number Diff line number Diff line change
@@ -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);
});