508d9d77 by David LaPalomento

Don't ignore metadata packets without PUSI set

Metadata packets that were not the start of a new payload unit were being silently dropped. Move the handler so that they are correctly routed to the metadata stream. Also, keep track of the number of bytes shifted off of the buffer when processing ID3 frames so that more than a single frame can be processed.
1 parent 1dc8dc12
......@@ -152,6 +152,7 @@
for (i = 0; i < tagSize;) {
tag.data.set(buffer[0].data, i);
i += buffer[0].data.byteLength;
bufferSize -= buffer[0].data.byteLength;
buffer.shift();
}
......
......@@ -368,12 +368,6 @@
aacStream.setNextTimeStamp(pts,
pesPacketSize,
dataAlignmentIndicator);
} else {
self.metadataStream.push({
pts: pts,
dts: dts,
data: data.subarray(offset)
});
}
}
......@@ -381,6 +375,12 @@
aacStream.writeBytes(data, offset, end - offset);
} else if (pid === self.stream.programMapTable[STREAM_TYPES.h264]) {
h264Stream.writeBytes(data, offset, end - offset);
} else if (pid === self.stream.programMapTable[STREAM_TYPES.metadata]) {
self.metadataStream.push({
pts: pts,
dts: dts,
data: data.subarray(offset)
});
}
} else if (self.stream.pmtPid === pid) {
// similarly to the PAT, jump to the first byte of the section
......
......@@ -60,11 +60,13 @@
], frames),
size;
// size is stored as a sequence of four 7-bit integers with the
// high bit of each byte set to zero
size = result.length - 10;
result[6] = (size >>> 24) & 0xff;
result[7] = (size >>> 16) & 0xff;
result[8] = (size >>> 8) & 0xff;
result[9] = (size) & 0xff;
result[6] = (size >>> 21) & 0x7f;
result[7] = (size >>> 14) & 0x7f;
result[8] = (size >>> 7) & 0x7f;
result[9] = (size) & 0x7f;
return result;
};
......@@ -351,6 +353,25 @@
equal(events[0].frames[0].data.byteLength,
owner.length + payload.length,
'collected data across pushes');
// parses subsequent fragmented tags
tag = new Uint8Array(id3Tag(id3Frame('PRIV',
owner, payload, payload)));
front = tag.subarray(0, 188);
back = tag.subarray(188);
metadataStream.push({
trackId: 7,
pts: 2000,
dts: 2000,
data: front
});
metadataStream.push({
trackId: 7,
pts: 2000,
dts: 2000,
data: back
});
equal(events.length, 2, 'parsed a subseqent frame');
});
test('ignores tags when the header is fragmented', function() {
......
......@@ -177,7 +177,8 @@
// sync_byte
result.push(0x47);
// transport_error_indicator payload_unit_start_indicator transport_priority PID
result.push((settings.pid & 0x1f) << 8 | 0x40);
result.push((settings.pid & 0x1f) << 8 |
(settings.payloadUnitStartIndicator ? 0x40 : 0x00));
result.push(settings.pid & 0xff);
// transport_scrambling_control adaptation_field_control continuity_counter
result.push(0x10);
......@@ -226,6 +227,29 @@
equal(parser.stream.programMapTable[0x15], 0x02, 'metadata is PID 2');
});
test('recognizes subsequent metadata packets after the payload start', function() {
var packets = [];
parser.metadataStream.push = function(packet) {
packets.push(packet);
};
parser.parseSegmentBinaryData(new Uint8Array(makePacket({
programs: {
0x01: [0x01]
}
}).concat(makePacket({
pid: 0x01,
pids: {
// Rec. ITU-T H.222.0 (06/2012), Table 2-34
0x02: 0x15 // Metadata carried in PES packets
}
})).concat(makePacket({
pid: 0x02,
payloadUnitStartIndicator: false
}))));
equal(packets.length, 1, 'parsed non-payload metadata packet');
});
test('parses the first bipbop segment', function() {
parser.parseSegmentBinaryData(window.bcSegment);
......