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.
Showing
3 changed files
with
22 additions
and
5 deletions
... | @@ -417,6 +417,10 @@ | ... | @@ -417,6 +417,10 @@ |
417 | 417 | ||
418 | // the length of the entry descriptor | 418 | // the length of the entry descriptor |
419 | ESInfolength = (data[offset + 3] & 0x0F) << 8 | data[offset + 4]; | 419 | ESInfolength = (data[offset + 3] & 0x0F) << 8 | data[offset + 4]; |
420 | // capture the stream descriptor for metadata streams | ||
421 | if (streamType === STREAM_TYPES.metadata) { | ||
422 | self.metadataStream.descriptor = new Uint8Array(data.subarray(offset + 5, offset + 5 + ESInfolength)); | ||
423 | } | ||
420 | // move to the first byte after the end of this entry | 424 | // move to the first byte after the end of this entry |
421 | offset += 5 + ESInfolength; | 425 | offset += 5 + ESInfolength; |
422 | pmtSectionLength -= 5 + ESInfolength; | 426 | pmtSectionLength -= 5 + ESInfolength; | ... | ... |
... | @@ -77,16 +77,25 @@ videojs.Hls.prototype.src = function(src) { | ... | @@ -77,16 +77,25 @@ videojs.Hls.prototype.src = function(src) { |
77 | // if the stream contains ID3 metadata, expose that as a metadata | 77 | // if the stream contains ID3 metadata, expose that as a metadata |
78 | // text track | 78 | // text track |
79 | (function() { | 79 | (function() { |
80 | var textTrack; | 80 | var |
81 | metadataStream = tech.segmentParser_.metadataStream, | ||
82 | textTrack; | ||
81 | 83 | ||
82 | tech.segmentParser_.metadataStream.on('data', function(metadata) { | 84 | metadataStream.on('data', function(metadata) { |
83 | var i, frame, time; | 85 | var i, frame, time, hexDigit; |
84 | 86 | ||
85 | // create the metadata track if this is the first ID3 tag we've | 87 | // create the metadata track if this is the first ID3 tag we've |
86 | // seen | 88 | // seen |
87 | if (!textTrack) { | 89 | if (!textTrack) { |
88 | textTrack = tech.player().addTextTrack('metadata', 'Timed Metadata'); | 90 | textTrack = tech.player().addTextTrack('metadata', 'Timed Metadata'); |
89 | textTrack.inBandMetadataTrackDispatchType = metadata.dispatchType; | 91 | |
92 | // build the dispatch type from the stream descriptor | ||
93 | // https://html.spec.whatwg.org/multipage/embedded-content.html#steps-to-expose-a-media-resource-specific-text-track | ||
94 | textTrack.inBandMetadataTrackDispatchType = videojs.Hls.SegmentParser.STREAM_TYPES.metadata.toString(16); | ||
95 | for (i = 0; i < metadataStream.descriptor.length; i++) { | ||
96 | hexDigit = ('00' + metadataStream.descriptor[i].toString(16)).slice(-2); | ||
97 | textTrack.inBandMetadataTrackDispatchType += hexDigit; | ||
98 | } | ||
90 | } | 99 | } |
91 | 100 | ||
92 | for (i = 0; i < metadata.frames.length; i++) { | 101 | for (i = 0; i < metadata.frames.length; i++) { | ... | ... |
... | @@ -925,9 +925,13 @@ test('exposes in-band metadata events as cues', function() { | ... | @@ -925,9 +925,13 @@ test('exposes in-band metadata events as cues', function() { |
925 | openMediaSource(player); | 925 | openMediaSource(player); |
926 | 926 | ||
927 | player.hls.segmentParser_.parseSegmentBinaryData = function() { | 927 | player.hls.segmentParser_.parseSegmentBinaryData = function() { |
928 | // fake out a descriptor | ||
929 | player.hls.segmentParser_.metadataStream.descriptor = new Uint8Array([ | ||
930 | 1, 2, 3 | ||
931 | ]); | ||
932 | // trigger a metadata event | ||
928 | player.hls.segmentParser_.metadataStream.trigger('data', { | 933 | player.hls.segmentParser_.metadataStream.trigger('data', { |
929 | pts: 2000, | 934 | pts: 2000, |
930 | dispatchType: '15010203', | ||
931 | data: new Uint8Array([]), | 935 | data: new Uint8Array([]), |
932 | frames: [{ | 936 | frames: [{ |
933 | type: 'TXXX', | 937 | type: 'TXXX', | ... | ... |
-
Please register or sign in to post a comment