Skip to content

Commit

Permalink
Set the PTS and DTS for TS timestamp ID3 tags (#115)
Browse files Browse the repository at this point in the history
The special PRIV frame that specifies the timestamp in raw AAC data would not itself receive a timestamp since it was already parsed when the base timestamp was set. Add special case handling for that ID3 tag so that it does not end up with a cueTime of NaN when picked up by the CoalesceStream in the MP4 transmuxer.
  • Loading branch information
dmlap committed Sep 8, 2016
1 parent 13436a8 commit 27a8fd0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
11 changes: 11 additions & 0 deletions lib/m2ts/metadata-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ MetadataStream = function(options) {
frame.key = frame.id;
if (tagParsers[frame.id]) {
tagParsers[frame.id](frame);

// handle the special PRIV frame used to indicate the start
// time for raw AAC data
if (frame.owner === 'com.apple.streaming.transportStreamTimestamp') {
var
d = frame.data,
Expand All @@ -221,6 +224,14 @@ MetadataStream = function(options) {
size *= 4;
size += d[7] & 0x03;
frame.timeStamp = size;
// in raw AAC, all subsequent data will be timestamped based
// on the value of this frame
// we couldn't have known the appropriate pts and dts before
// parsing this ID3 tag so set those values now
if (tag.pts === undefined && tag.dts === undefined) {
tag.pts = frame.timeStamp;
tag.dts = frame.timeStamp;
}
this.trigger('timestamp', frame);
}
}
Expand Down
19 changes: 13 additions & 6 deletions test/metadata-stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,26 @@ QUnit.test('can parse TXXX frames in web worker', function(assert) {
});

QUnit.test('triggers special event after parsing a timestamp ID3 tag', function() {
var array = new Uint8Array(73),
var
array = new Uint8Array(73),
streamTimestamp = 'com.apple.streaming.transportStreamTimestamp',
priv = 'PRIV',
count = 0,
frame,
tag,
metadataStream,
chunk,
i;

metadataStream = new mp2t.MetadataStream();

metadataStream.on('timestamp', function(frame) {
QUnit.equal(frame.timeStamp, 900000, 'Initial timestamp fired and calculated correctly');
metadataStream.on('timestamp', function(f) {
frame = f;
count += 1;
});
metadataStream.on('data', function(t) {
tag = t;
});

array[0] = 73;
array[1] = 68;
array[2] = 51;
Expand All @@ -534,19 +540,20 @@ QUnit.test('triggers special event after parsing a timestamp ID3 tag', function(
array[70] = 13;
array[71] = 187;
array[72] = 160;

for (i = 0; i < priv.length; i++) {
array[i + 10] = priv.charCodeAt(i);
}
for (i = 0; i < streamTimestamp.length; i++) {
array[i + 20] = streamTimestamp.charCodeAt(i);
}

chunk = {
type: 'timed-metadata',
data: array
};

metadataStream.push(chunk);
QUnit.equal(count, 1, 'timestamp event triggered once');
QUnit.equal(frame.timeStamp, 900000, 'Initial timestamp fired and calculated correctly');
QUnit.equal(tag.pts, 10 * 90e3, 'set tag PTS');
QUnit.equal(tag.dts, 10 * 90e3, 'set tag DTS');
});

0 comments on commit 27a8fd0

Please sign in to comment.