Rename transmux components for clarity
Try to be a bit more descriptive about the purpose and function of individual parts of the transmux pipeline. Prefix the MPEG-2 Transport Stream specific streams with "transport" to indicate their purpose unpacking the TS container. Rename ProgramStream to ElementaryStream so it's less likely to be confused with the MPEG-2 Program Stream container format, instead of the underlying Program Elementary Stream that it's actually associated with. Add more explanatory comments.
Showing
2 changed files
with
46 additions
and
29 deletions
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | 'use strict'; | 15 | 'use strict'; |
16 | 16 | ||
17 | var | 17 | var |
18 | PacketStream, ParseStream, ProgramStream, VideoSegmentStream, | 18 | TransportPacketStream, TransportParseStream, ElementaryStream, VideoSegmentStream, |
19 | Transmuxer, AacStream, H264Stream, NalByteStream, | 19 | Transmuxer, AacStream, H264Stream, NalByteStream, |
20 | MP2T_PACKET_LENGTH, H264_STREAM_TYPE, ADTS_STREAM_TYPE, mp4; | 20 | MP2T_PACKET_LENGTH, H264_STREAM_TYPE, ADTS_STREAM_TYPE, mp4; |
21 | 21 | ||
... | @@ -25,14 +25,15 @@ ADTS_STREAM_TYPE = 0x0f; | ... | @@ -25,14 +25,15 @@ ADTS_STREAM_TYPE = 0x0f; |
25 | mp4 = videojs.mp4; | 25 | mp4 = videojs.mp4; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * Splits an incoming stream of binary data into MP2T packets. | 28 | * Splits an incoming stream of binary data into MPEG-2 Transport |
29 | * Stream packets. | ||
29 | */ | 30 | */ |
30 | PacketStream = function() { | 31 | TransportPacketStream = function() { |
31 | var | 32 | var |
32 | buffer = new Uint8Array(MP2T_PACKET_LENGTH), | 33 | buffer = new Uint8Array(MP2T_PACKET_LENGTH), |
33 | end = 0; | 34 | end = 0; |
34 | 35 | ||
35 | PacketStream.prototype.init.call(this); | 36 | TransportPacketStream.prototype.init.call(this); |
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Deliver new bytes to the stream. | 39 | * Deliver new bytes to the stream. |
... | @@ -76,15 +77,15 @@ PacketStream = function() { | ... | @@ -76,15 +77,15 @@ PacketStream = function() { |
76 | } | 77 | } |
77 | }; | 78 | }; |
78 | }; | 79 | }; |
79 | PacketStream.prototype = new videojs.Hls.Stream(); | 80 | TransportPacketStream.prototype = new videojs.Hls.Stream(); |
80 | 81 | ||
81 | /** | 82 | /** |
82 | * Accepts an MP2T PacketStream and emits data events with parsed | 83 | * Accepts an MP2T TransportPacketStream and emits data events with parsed |
83 | * forms of the individual packets. | 84 | * forms of the individual transport stream packets. |
84 | */ | 85 | */ |
85 | ParseStream = function() { | 86 | TransportParseStream = function() { |
86 | var parsePsi, parsePat, parsePmt, parsePes, self; | 87 | var parsePsi, parsePat, parsePmt, parsePes, self; |
87 | ParseStream.prototype.init.call(this); | 88 | TransportParseStream.prototype.init.call(this); |
88 | self = this; | 89 | self = this; |
89 | 90 | ||
90 | this.programMapTable = {}; | 91 | this.programMapTable = {}; |
... | @@ -255,16 +256,21 @@ ParseStream = function() { | ... | @@ -255,16 +256,21 @@ ParseStream = function() { |
255 | this.trigger('data', result); | 256 | this.trigger('data', result); |
256 | }; | 257 | }; |
257 | }; | 258 | }; |
258 | ParseStream.prototype = new videojs.Hls.Stream(); | 259 | TransportParseStream.prototype = new videojs.Hls.Stream(); |
259 | ParseStream.STREAM_TYPES = { | 260 | TransportParseStream.STREAM_TYPES = { |
260 | h264: 0x1b, | 261 | h264: 0x1b, |
261 | adts: 0x0f | 262 | adts: 0x0f |
262 | }; | 263 | }; |
263 | 264 | ||
264 | /** | 265 | /** |
265 | * Reconsistutes program stream packets from multiple transport stream packets. | 266 | * Reconsistutes program elementary stream (PES) packets from parsed |
267 | * transport stream packets. That is, if you pipe an | ||
268 | * mp2t.TransportParseStream into a mp2t.ElementaryStream, the output | ||
269 | * events will be events which capture the bytes for individual PES | ||
270 | * packets plus relevant metadata that has been extracted from the | ||
271 | * container. | ||
266 | */ | 272 | */ |
267 | ProgramStream = function() { | 273 | ElementaryStream = function() { |
268 | var | 274 | var |
269 | // PES packet fragments | 275 | // PES packet fragments |
270 | video = { | 276 | video = { |
... | @@ -305,7 +311,7 @@ ProgramStream = function() { | ... | @@ -305,7 +311,7 @@ ProgramStream = function() { |
305 | }, | 311 | }, |
306 | self; | 312 | self; |
307 | 313 | ||
308 | ProgramStream.prototype.init.call(this); | 314 | ElementaryStream.prototype.init.call(this); |
309 | self = this; | 315 | self = this; |
310 | 316 | ||
311 | this.push = function(data) { | 317 | this.push = function(data) { |
... | @@ -380,10 +386,10 @@ ProgramStream = function() { | ... | @@ -380,10 +386,10 @@ ProgramStream = function() { |
380 | flushStream(audio, 'audio'); | 386 | flushStream(audio, 'audio'); |
381 | }; | 387 | }; |
382 | }; | 388 | }; |
383 | ProgramStream.prototype = new videojs.Hls.Stream(); | 389 | ElementaryStream.prototype = new videojs.Hls.Stream(); |
384 | 390 | ||
385 | /* | 391 | /* |
386 | * Accepts a ProgramStream and emits data events with parsed | 392 | * Accepts a ElementaryStream and emits data events with parsed |
387 | * AAC Audio Frames of the individual packets. | 393 | * AAC Audio Frames of the individual packets. |
388 | */ | 394 | */ |
389 | AacStream = function() { | 395 | AacStream = function() { |
... | @@ -486,7 +492,7 @@ NalByteStream = function() { | ... | @@ -486,7 +492,7 @@ NalByteStream = function() { |
486 | NalByteStream.prototype = new videojs.Hls.Stream(); | 492 | NalByteStream.prototype = new videojs.Hls.Stream(); |
487 | 493 | ||
488 | /** | 494 | /** |
489 | * Accepts input from a ProgramStream and produces H.264 NAL unit data | 495 | * Accepts input from a ElementaryStream and produces H.264 NAL unit data |
490 | * events. | 496 | * events. |
491 | */ | 497 | */ |
492 | H264Stream = function() { | 498 | H264Stream = function() { |
... | @@ -681,6 +687,9 @@ H264Stream = function() { | ... | @@ -681,6 +687,9 @@ H264Stream = function() { |
681 | H264Stream.prototype = new videojs.Hls.Stream(); | 687 | H264Stream.prototype = new videojs.Hls.Stream(); |
682 | 688 | ||
683 | /** | 689 | /** |
690 | * Constructs a single-track, ISO BMFF media segment from H264 data | ||
691 | * events. The output of this stream can be fed to a SourceBuffer | ||
692 | * configured with a suitable initialization segment. | ||
684 | * @param track {object} track metadata configuration | 693 | * @param track {object} track metadata configuration |
685 | */ | 694 | */ |
686 | VideoSegmentStream = function(track) { | 695 | VideoSegmentStream = function(track) { |
... | @@ -778,6 +787,14 @@ VideoSegmentStream = function(track) { | ... | @@ -778,6 +787,14 @@ VideoSegmentStream = function(track) { |
778 | }; | 787 | }; |
779 | VideoSegmentStream.prototype = new videojs.Hls.Stream(); | 788 | VideoSegmentStream.prototype = new videojs.Hls.Stream(); |
780 | 789 | ||
790 | /** | ||
791 | * A Stream that expects MP2T binary data as input and produces | ||
792 | * corresponding media segments, suitable for use with Media Source | ||
793 | * Extension (MSE) implementations that support the ISO BMFF byte | ||
794 | * stream format, like Chrome. | ||
795 | * @see test/muxer/mse-demo.html for sample usage of a Transmuxer with | ||
796 | * MSE | ||
797 | */ | ||
781 | Transmuxer = function() { | 798 | Transmuxer = function() { |
782 | var | 799 | var |
783 | self = this, | 800 | self = this, |
... | @@ -785,21 +802,21 @@ Transmuxer = function() { | ... | @@ -785,21 +802,21 @@ Transmuxer = function() { |
785 | config, | 802 | config, |
786 | pps, | 803 | pps, |
787 | 804 | ||
788 | packetStream, parseStream, programStream, aacStream, h264Stream, videoSegmentStream; | 805 | packetStream, parseStream, elementaryStream, aacStream, h264Stream, videoSegmentStream; |
789 | 806 | ||
790 | Transmuxer.prototype.init.call(this); | 807 | Transmuxer.prototype.init.call(this); |
791 | 808 | ||
792 | // set up the parsing pipeline | 809 | // set up the parsing pipeline |
793 | packetStream = new PacketStream(); | 810 | packetStream = new TransportPacketStream(); |
794 | parseStream = new ParseStream(); | 811 | parseStream = new TransportParseStream(); |
795 | programStream = new ProgramStream(); | 812 | elementaryStream = new ElementaryStream(); |
796 | aacStream = new AacStream(); | 813 | aacStream = new AacStream(); |
797 | h264Stream = new H264Stream(); | 814 | h264Stream = new H264Stream(); |
798 | 815 | ||
799 | packetStream.pipe(parseStream); | 816 | packetStream.pipe(parseStream); |
800 | parseStream.pipe(programStream); | 817 | parseStream.pipe(elementaryStream); |
801 | programStream.pipe(aacStream); | 818 | elementaryStream.pipe(aacStream); |
802 | programStream.pipe(h264Stream); | 819 | elementaryStream.pipe(h264Stream); |
803 | 820 | ||
804 | // handle incoming data events | 821 | // handle incoming data events |
805 | h264Stream.on('data', function(data) { | 822 | h264Stream.on('data', function(data) { |
... | @@ -835,7 +852,7 @@ Transmuxer = function() { | ... | @@ -835,7 +852,7 @@ Transmuxer = function() { |
835 | } | 852 | } |
836 | }); | 853 | }); |
837 | // hook up the video segment stream once track metadata is delivered | 854 | // hook up the video segment stream once track metadata is delivered |
838 | programStream.on('data', function(data) { | 855 | elementaryStream.on('data', function(data) { |
839 | var i, triggerData = function(segment) { | 856 | var i, triggerData = function(segment) { |
840 | self.trigger('data', { | 857 | self.trigger('data', { |
841 | data: segment | 858 | data: segment |
... | @@ -863,7 +880,7 @@ Transmuxer = function() { | ... | @@ -863,7 +880,7 @@ Transmuxer = function() { |
863 | }; | 880 | }; |
864 | // flush any buffered data | 881 | // flush any buffered data |
865 | this.end = function() { | 882 | this.end = function() { |
866 | programStream.end(); | 883 | elementaryStream.end(); |
867 | h264Stream.end(); | 884 | h264Stream.end(); |
868 | videoSegmentStream.end(); | 885 | videoSegmentStream.end(); |
869 | }; | 886 | }; |
... | @@ -875,9 +892,9 @@ window.videojs.mp2t = { | ... | @@ -875,9 +892,9 @@ window.videojs.mp2t = { |
875 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH, | 892 | MP2T_PACKET_LENGTH: MP2T_PACKET_LENGTH, |
876 | H264_STREAM_TYPE: H264_STREAM_TYPE, | 893 | H264_STREAM_TYPE: H264_STREAM_TYPE, |
877 | ADTS_STREAM_TYPE: ADTS_STREAM_TYPE, | 894 | ADTS_STREAM_TYPE: ADTS_STREAM_TYPE, |
878 | PacketStream: PacketStream, | 895 | TransportPacketStream: TransportPacketStream, |
879 | ParseStream: ParseStream, | 896 | TransportParseStream: TransportParseStream, |
880 | ProgramStream: ProgramStream, | 897 | ElementaryStream: ElementaryStream, |
881 | VideoSegmentStream: VideoSegmentStream, | 898 | VideoSegmentStream: VideoSegmentStream, |
882 | Transmuxer: Transmuxer, | 899 | Transmuxer: Transmuxer, |
883 | AacStream: AacStream, | 900 | AacStream: AacStream, | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment