84e4c4b4 by David LaPalomento

Expose dispatchType for in-band tracks

Parse the elementary stream descriptor out of the PMT declaring the metadata stream, if present. Use those bytes to build the inBandMetadataDispatchType field on the generated text track.
1 parent 64026629
......@@ -417,6 +417,10 @@
// the length of the entry descriptor
ESInfolength = (data[offset + 3] & 0x0F) << 8 | data[offset + 4];
// capture the stream descriptor for metadata streams
if (streamType === STREAM_TYPES.metadata) {
self.metadataStream.descriptor = new Uint8Array(data.subarray(offset + 5, offset + 5 + ESInfolength));
}
// move to the first byte after the end of this entry
offset += 5 + ESInfolength;
pmtSectionLength -= 5 + ESInfolength;
......
......@@ -77,16 +77,25 @@ videojs.Hls.prototype.src = function(src) {
// if the stream contains ID3 metadata, expose that as a metadata
// text track
(function() {
var textTrack;
var
metadataStream = tech.segmentParser_.metadataStream,
textTrack;
tech.segmentParser_.metadataStream.on('data', function(metadata) {
var i, frame, time;
metadataStream.on('data', function(metadata) {
var i, frame, time, hexDigit;
// create the metadata track if this is the first ID3 tag we've
// seen
if (!textTrack) {
textTrack = tech.player().addTextTrack('metadata', 'Timed Metadata');
textTrack.inBandMetadataTrackDispatchType = metadata.dispatchType;
// build the dispatch type from the stream descriptor
// https://html.spec.whatwg.org/multipage/embedded-content.html#steps-to-expose-a-media-resource-specific-text-track
textTrack.inBandMetadataTrackDispatchType = videojs.Hls.SegmentParser.STREAM_TYPES.metadata.toString(16);
for (i = 0; i < metadataStream.descriptor.length; i++) {
hexDigit = ('00' + metadataStream.descriptor[i].toString(16)).slice(-2);
textTrack.inBandMetadataTrackDispatchType += hexDigit;
}
}
for (i = 0; i < metadata.frames.length; i++) {
......
......@@ -925,9 +925,13 @@ test('exposes in-band metadata events as cues', function() {
openMediaSource(player);
player.hls.segmentParser_.parseSegmentBinaryData = function() {
// fake out a descriptor
player.hls.segmentParser_.metadataStream.descriptor = new Uint8Array([
1, 2, 3
]);
// trigger a metadata event
player.hls.segmentParser_.metadataStream.trigger('data', {
pts: 2000,
dispatchType: '15010203',
data: new Uint8Array([]),
frames: [{
type: 'TXXX',
......