fb549ef2 by David LaPalomento

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.
1 parent b4175dda
...@@ -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,
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
21 throws(block, [expected], [message]) 21 throws(block, [expected], [message])
22 */ 22 */
23 var 23 var
24 PacketStream = videojs.mp2t.PacketStream, 24 TransportPacketStream = videojs.mp2t.TransportPacketStream,
25 packetStream, 25 transportPacketStream,
26 ParseStream = videojs.mp2t.ParseStream, 26 TransportParseStream = videojs.mp2t.TransportParseStream,
27 parseStream, 27 transportParseStream,
28 ProgramStream = videojs.mp2t.ProgramStream, 28 ElementaryStream = videojs.mp2t.ElementaryStream,
29 programStream, 29 elementaryStream,
30 H264Stream = videojs.mp2t.H264Stream, 30 H264Stream = videojs.mp2t.H264Stream,
31 h264Stream, 31 h264Stream,
32 VideoSegmentStream = videojs.mp2t.VideoSegmentStream, 32 VideoSegmentStream = videojs.mp2t.VideoSegmentStream,
...@@ -49,20 +49,20 @@ var ...@@ -49,20 +49,20 @@ var
49 49
50 module('MP2T Packet Stream', { 50 module('MP2T Packet Stream', {
51 setup: function() { 51 setup: function() {
52 packetStream = new PacketStream(); 52 transportPacketStream = new TransportPacketStream();
53 } 53 }
54 }); 54 });
55 55
56 test('empty input does not error', function() { 56 test('empty input does not error', function() {
57 packetStream.push(new Uint8Array([])); 57 transportPacketStream.push(new Uint8Array([]));
58 ok(true, 'did not throw'); 58 ok(true, 'did not throw');
59 }); 59 });
60 test('parses a generic packet', function() { 60 test('parses a generic packet', function() {
61 var datas = []; 61 var datas = [];
62 packetStream.on('data', function(event) { 62 transportPacketStream.on('data', function(event) {
63 datas.push(event); 63 datas.push(event);
64 }); 64 });
65 packetStream.push(new Uint8Array(188)); 65 transportPacketStream.push(new Uint8Array(188));
66 66
67 equal(1, datas.length, 'fired one event'); 67 equal(1, datas.length, 'fired one event');
68 equal(datas[0].byteLength, 188, 'delivered the packet'); 68 equal(datas[0].byteLength, 188, 'delivered the packet');
...@@ -70,14 +70,14 @@ test('parses a generic packet', function() { ...@@ -70,14 +70,14 @@ test('parses a generic packet', function() {
70 70
71 test('buffers partial packets', function() { 71 test('buffers partial packets', function() {
72 var datas = []; 72 var datas = [];
73 packetStream.on('data', function(event) { 73 transportPacketStream.on('data', function(event) {
74 datas.push(event); 74 datas.push(event);
75 }); 75 });
76 packetStream.push(new Uint8Array(187)); 76 transportPacketStream.push(new Uint8Array(187));
77 77
78 equal(0, datas.length, 'did not fire an event'); 78 equal(0, datas.length, 'did not fire an event');
79 79
80 packetStream.push(new Uint8Array(189)); 80 transportPacketStream.push(new Uint8Array(189));
81 equal(2, datas.length, 'fired events'); 81 equal(2, datas.length, 'fired events');
82 equal(188, datas[0].byteLength, 'parsed the first packet'); 82 equal(188, datas[0].byteLength, 'parsed the first packet');
83 equal(188, datas[1].byteLength, 'parsed the second packet'); 83 equal(188, datas[1].byteLength, 'parsed the second packet');
...@@ -85,11 +85,11 @@ test('buffers partial packets', function() { ...@@ -85,11 +85,11 @@ test('buffers partial packets', function() {
85 85
86 test('parses multiple packets delivered at once', function() { 86 test('parses multiple packets delivered at once', function() {
87 var datas = []; 87 var datas = [];
88 packetStream.on('data', function(event) { 88 transportPacketStream.on('data', function(event) {
89 datas.push(event); 89 datas.push(event);
90 }); 90 });
91 91
92 packetStream.push(new Uint8Array(188 * 3)); 92 transportPacketStream.push(new Uint8Array(188 * 3));
93 equal(3, datas.length, 'fired three events'); 93 equal(3, datas.length, 'fired three events');
94 equal(188, datas[0].byteLength, 'parsed the first packet'); 94 equal(188, datas[0].byteLength, 'parsed the first packet');
95 equal(188, datas[1].byteLength, 'parsed the second packet'); 95 equal(188, datas[1].byteLength, 'parsed the second packet');
...@@ -98,46 +98,46 @@ test('parses multiple packets delivered at once', function() { ...@@ -98,46 +98,46 @@ test('parses multiple packets delivered at once', function() {
98 98
99 test('buffers extra after multiple packets', function() { 99 test('buffers extra after multiple packets', function() {
100 var datas = []; 100 var datas = [];
101 packetStream.on('data', function(event) { 101 transportPacketStream.on('data', function(event) {
102 datas.push(event); 102 datas.push(event);
103 }); 103 });
104 104
105 packetStream.push(new Uint8Array(188 * 2 + 10)); 105 transportPacketStream.push(new Uint8Array(188 * 2 + 10));
106 equal(2, datas.length, 'fired two events'); 106 equal(2, datas.length, 'fired two events');
107 equal(188, datas[0].byteLength, 'parsed the first packet'); 107 equal(188, datas[0].byteLength, 'parsed the first packet');
108 equal(188, datas[1].byteLength, 'parsed the second packet'); 108 equal(188, datas[1].byteLength, 'parsed the second packet');
109 109
110 packetStream.push(new Uint8Array(178)); 110 transportPacketStream.push(new Uint8Array(178));
111 equal(3, datas.length, 'fired a final event'); 111 equal(3, datas.length, 'fired a final event');
112 equal(188, datas[2].length, 'parsed the finel packet'); 112 equal(188, datas[2].length, 'parsed the finel packet');
113 }); 113 });
114 114
115 module('MP2T ParseStream', { 115 module('MP2T TransportParseStream', {
116 setup: function() { 116 setup: function() {
117 packetStream = new PacketStream(); 117 transportPacketStream = new TransportPacketStream();
118 parseStream = new ParseStream(); 118 transportParseStream = new TransportParseStream();
119 119
120 packetStream.pipe(parseStream); 120 transportPacketStream.pipe(transportParseStream);
121 } 121 }
122 }); 122 });
123 123
124 test('emits an error on an invalid packet', function() { 124 test('emits an error on an invalid packet', function() {
125 var errors = []; 125 var errors = [];
126 parseStream.on('error', function(error) { 126 transportParseStream.on('error', function(error) {
127 errors.push(error); 127 errors.push(error);
128 }); 128 });
129 parseStream.push(new Uint8Array(188)); 129 transportParseStream.push(new Uint8Array(188));
130 130
131 equal(1, errors.length, 'emitted an error'); 131 equal(1, errors.length, 'emitted an error');
132 }); 132 });
133 133
134 test('parses generic packet properties', function() { 134 test('parses generic packet properties', function() {
135 var packet; 135 var packet;
136 parseStream.on('data', function(data) { 136 transportParseStream.on('data', function(data) {
137 packet = data; 137 packet = data;
138 }); 138 });
139 139
140 parseStream.push(new Uint8Array([ 140 transportParseStream.push(new Uint8Array([
141 0x47, // sync byte 141 0x47, // sync byte
142 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0001 tsc:01 afc:10 cc:11 padding: 00 142 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0001 tsc:01 afc:10 cc:11 padding: 00
143 0x40, 0x01, 0x6c 143 0x40, 0x01, 0x6c
...@@ -148,11 +148,11 @@ test('parses generic packet properties', function() { ...@@ -148,11 +148,11 @@ test('parses generic packet properties', function() {
148 148
149 test('parses piped data events', function() { 149 test('parses piped data events', function() {
150 var packet; 150 var packet;
151 parseStream.on('data', function(data) { 151 transportParseStream.on('data', function(data) {
152 packet = data; 152 packet = data;
153 }); 153 });
154 154
155 parseStream.push(new Uint8Array([ 155 transportParseStream.push(new Uint8Array([
156 0x47, // sync byte 156 0x47, // sync byte
157 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0001 tsc:01 afc:10 cc:11 padding: 00 157 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0001 tsc:01 afc:10 cc:11 padding: 00
158 0x40, 0x01, 0x6c 158 0x40, 0x01, 0x6c
...@@ -163,11 +163,11 @@ test('parses piped data events', function() { ...@@ -163,11 +163,11 @@ test('parses piped data events', function() {
163 163
164 test('parses a data packet with adaptation fields', function() { 164 test('parses a data packet with adaptation fields', function() {
165 var packet; 165 var packet;
166 parseStream.on('data', function(data) { 166 transportParseStream.on('data', function(data) {
167 packet = data; 167 packet = data;
168 }); 168 });
169 169
170 parseStream.push(new Uint8Array([ 170 transportParseStream.push(new Uint8Array([
171 0x47, // sync byte 171 0x47, // sync byte
172 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0000 tsc:01 afc:10 cc:11 afl:00 0000 00 stuffing:00 0000 00 pscp:00 0001 padding:0000 172 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0000 tsc:01 afc:10 cc:11 afl:00 0000 00 stuffing:00 0000 00 pscp:00 0001 padding:0000
173 0x40, 0x00, 0x6c, 0x00, 0x00, 0x10 173 0x40, 0x00, 0x6c, 0x00, 0x00, 0x10
...@@ -177,16 +177,16 @@ test('parses a data packet with adaptation fields', function() { ...@@ -177,16 +177,16 @@ test('parses a data packet with adaptation fields', function() {
177 177
178 test('parses a PES packet', function() { 178 test('parses a PES packet', function() {
179 var packet; 179 var packet;
180 parseStream.on('data', function(data) { 180 transportParseStream.on('data', function(data) {
181 packet = data; 181 packet = data;
182 }); 182 });
183 183
184 // setup a program map table 184 // setup a program map table
185 parseStream.programMapTable = { 185 transportParseStream.programMapTable = {
186 0x0010: videojs.mp2t.H264_STREAM_TYPE 186 0x0010: videojs.mp2t.H264_STREAM_TYPE
187 }; 187 };
188 188
189 parseStream.push(new Uint8Array([ 189 transportParseStream.push(new Uint8Array([
190 0x47, // sync byte 190 0x47, // sync byte
191 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0010 tsc:01 afc:01 cc:11 padding:00 191 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0010 tsc:01 afc:01 cc:11 padding:00
192 0x40, 0x02, 0x5c 192 0x40, 0x02, 0x5c
...@@ -196,16 +196,16 @@ test('parses a PES packet', function() { ...@@ -196,16 +196,16 @@ test('parses a PES packet', function() {
196 196
197 test('parses packets with variable length adaptation fields and a payload', function() { 197 test('parses packets with variable length adaptation fields and a payload', function() {
198 var packet; 198 var packet;
199 parseStream.on('data', function(data) { 199 transportParseStream.on('data', function(data) {
200 packet = data; 200 packet = data;
201 }); 201 });
202 202
203 // setup a program map table 203 // setup a program map table
204 parseStream.programMapTable = { 204 transportParseStream.programMapTable = {
205 0x0010: videojs.mp2t.H264_STREAM_TYPE 205 0x0010: videojs.mp2t.H264_STREAM_TYPE
206 }; 206 };
207 207
208 parseStream.push(new Uint8Array([ 208 transportParseStream.push(new Uint8Array([
209 0x47, // sync byte 209 0x47, // sync byte
210 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0010 tsc:01 afc:11 cc:11 afl:00 0000 11 stuffing:00 0000 0000 00 pscp:00 0001 210 // tei:0 pusi:1 tp:0 pid:0 0000 0000 0010 tsc:01 afc:11 cc:11 afl:00 0000 11 stuffing:00 0000 0000 00 pscp:00 0001
211 0x40, 0x02, 0x7c, 0x0c, 0x00, 0x01 211 0x40, 0x02, 0x7c, 0x0c, 0x00, 0x01
...@@ -254,13 +254,13 @@ PAT = [ ...@@ -254,13 +254,13 @@ PAT = [
254 254
255 test('parses the program map table pid from the program association table (PAT)', function() { 255 test('parses the program map table pid from the program association table (PAT)', function() {
256 var packet; 256 var packet;
257 parseStream.on('data', function(data) { 257 transportParseStream.on('data', function(data) {
258 packet = data; 258 packet = data;
259 }); 259 });
260 260
261 parseStream.push(new Uint8Array(PAT)); 261 transportParseStream.push(new Uint8Array(PAT));
262 ok(packet, 'parsed a packet'); 262 ok(packet, 'parsed a packet');
263 strictEqual(0x0010, parseStream.pmtPid, 'parsed PMT pid'); 263 strictEqual(0x0010, transportParseStream.pmtPid, 'parsed PMT pid');
264 }); 264 });
265 265
266 PMT = [ 266 PMT = [
...@@ -295,32 +295,32 @@ PMT = [ ...@@ -295,32 +295,32 @@ PMT = [
295 295
296 test('parse the elementary streams from a program map table', function() { 296 test('parse the elementary streams from a program map table', function() {
297 var packet; 297 var packet;
298 parseStream.on('data', function(data) { 298 transportParseStream.on('data', function(data) {
299 packet = data; 299 packet = data;
300 }); 300 });
301 parseStream.pmtPid = 0x0010; 301 transportParseStream.pmtPid = 0x0010;
302 302
303 parseStream.push(new Uint8Array(PMT.concat(0, 0, 0, 0, 0))); 303 transportParseStream.push(new Uint8Array(PMT.concat(0, 0, 0, 0, 0)));
304 304
305 ok(packet, 'parsed a packet'); 305 ok(packet, 'parsed a packet');
306 ok(parseStream.programMapTable, 'parsed a program map'); 306 ok(transportParseStream.programMapTable, 'parsed a program map');
307 strictEqual(0x1b, parseStream.programMapTable[0x11], 'associated h264 with pid 0x11'); 307 strictEqual(0x1b, transportParseStream.programMapTable[0x11], 'associated h264 with pid 0x11');
308 strictEqual(0x0f, parseStream.programMapTable[0x12], 'associated adts with pid 0x12'); 308 strictEqual(0x0f, transportParseStream.programMapTable[0x12], 'associated adts with pid 0x12');
309 strictEqual(parseStream.programMapTable[0], undefined, 'ignored trailing stuffing bytes'); 309 strictEqual(transportParseStream.programMapTable[0], undefined, 'ignored trailing stuffing bytes');
310 deepEqual(parseStream.programMapTable, packet.programMapTable, 'recorded the PMT'); 310 deepEqual(transportParseStream.programMapTable, packet.programMapTable, 'recorded the PMT');
311 }); 311 });
312 312
313 test('parses an elementary stream packet with just a pts', function() { 313 test('parses an elementary stream packet with just a pts', function() {
314 var packet; 314 var packet;
315 parseStream.on('data', function(data) { 315 transportParseStream.on('data', function(data) {
316 packet = data; 316 packet = data;
317 }); 317 });
318 318
319 parseStream.programMapTable = { 319 transportParseStream.programMapTable = {
320 0x11: 0x1b // pid 0x11 is h264 data 320 0x11: 0x1b // pid 0x11 is h264 data
321 }; 321 };
322 322
323 parseStream.push(new Uint8Array([ 323 transportParseStream.push(new Uint8Array([
324 0x47, // sync byte 324 0x47, // sync byte
325 // tei:0 pusi:1 tp:0 pid:0 0000 0001 0001 325 // tei:0 pusi:1 tp:0 pid:0 0000 0001 0001
326 0x40, 0x11, 326 0x40, 0x11,
...@@ -352,15 +352,15 @@ test('parses an elementary stream packet with just a pts', function() { ...@@ -352,15 +352,15 @@ test('parses an elementary stream packet with just a pts', function() {
352 352
353 test('parses an elementary stream packet with a pts and dts', function() { 353 test('parses an elementary stream packet with a pts and dts', function() {
354 var packet; 354 var packet;
355 parseStream.on('data', function(data) { 355 transportParseStream.on('data', function(data) {
356 packet = data; 356 packet = data;
357 }); 357 });
358 358
359 parseStream.programMapTable = { 359 transportParseStream.programMapTable = {
360 0x11: 0x1b // pid 0x11 is h264 data 360 0x11: 0x1b // pid 0x11 is h264 data
361 }; 361 };
362 362
363 parseStream.push(new Uint8Array([ 363 transportParseStream.push(new Uint8Array([
364 0x47, // sync byte 364 0x47, // sync byte
365 // tei:0 pusi:1 tp:0 pid:0 0000 0001 0001 365 // tei:0 pusi:1 tp:0 pid:0 0000 0001 0001
366 0x40, 0x11, 366 0x40, 0x11,
...@@ -446,16 +446,16 @@ standalonePes = videoPes([0xaf, 0x01], true); ...@@ -446,16 +446,16 @@ standalonePes = videoPes([0xaf, 0x01], true);
446 test('parses an elementary stream packet without a pts or dts', function() { 446 test('parses an elementary stream packet without a pts or dts', function() {
447 447
448 var packet; 448 var packet;
449 parseStream.on('data', function(data) { 449 transportParseStream.on('data', function(data) {
450 packet = data; 450 packet = data;
451 }); 451 });
452 452
453 // pid 0x11 is h264 data 453 // pid 0x11 is h264 data
454 parseStream.programMapTable = { 454 transportParseStream.programMapTable = {
455 0x11: H264_STREAM_TYPE 455 0x11: H264_STREAM_TYPE
456 }; 456 };
457 457
458 parseStream.push(new Uint8Array(standalonePes)); 458 transportParseStream.push(new Uint8Array(standalonePes));
459 459
460 ok(packet, 'parsed a packet'); 460 ok(packet, 'parsed a packet');
461 equal('pes', packet.type, 'recognized a PES packet'); 461 equal('pes', packet.type, 'recognized a PES packet');
...@@ -467,9 +467,9 @@ test('parses an elementary stream packet without a pts or dts', function() { ...@@ -467,9 +467,9 @@ test('parses an elementary stream packet without a pts or dts', function() {
467 ok(!packet.dts, 'did not parse a dts'); 467 ok(!packet.dts, 'did not parse a dts');
468 }); 468 });
469 469
470 module('MP2T ProgramStream', { 470 module('MP2T ElementaryStream', {
471 setup: function() { 471 setup: function() {
472 programStream = new ProgramStream(); 472 elementaryStream = new ElementaryStream();
473 } 473 }
474 }); 474 });
475 475
...@@ -486,16 +486,16 @@ test('parses metadata events from PSI packets', function() { ...@@ -486,16 +486,16 @@ test('parses metadata events from PSI packets', function() {
486 sortById = function(left, right) { 486 sortById = function(left, right) {
487 return left.id - right.id; 487 return left.id - right.id;
488 }; 488 };
489 programStream.on('data', function(data) { 489 elementaryStream.on('data', function(data) {
490 if (data.type === 'metadata') { 490 if (data.type === 'metadata') {
491 metadatas.push(data); 491 metadatas.push(data);
492 } 492 }
493 datas++; 493 datas++;
494 }); 494 });
495 programStream.push({ 495 elementaryStream.push({
496 type: 'pat' 496 type: 'pat'
497 }); 497 });
498 programStream.push({ 498 elementaryStream.push({
499 type: 'pmt', 499 type: 'pmt',
500 programMapTable: { 500 programMapTable: {
501 1: 0x1b, 501 1: 0x1b,
...@@ -519,14 +519,14 @@ test('parses metadata events from PSI packets', function() { ...@@ -519,14 +519,14 @@ test('parses metadata events from PSI packets', function() {
519 519
520 test('parses standalone program stream packets', function() { 520 test('parses standalone program stream packets', function() {
521 var packets = []; 521 var packets = [];
522 programStream.on('data', function(packet) { 522 elementaryStream.on('data', function(packet) {
523 packets.push(packet); 523 packets.push(packet);
524 }); 524 });
525 programStream.push({ 525 elementaryStream.push({
526 type: 'pes', 526 type: 'pes',
527 data: new Uint8Array(19) 527 data: new Uint8Array(19)
528 }); 528 });
529 programStream.end(); 529 elementaryStream.end();
530 530
531 equal(1, packets.length, 'built one packet'); 531 equal(1, packets.length, 'built one packet');
532 equal('audio', packets[0].type, 'identified audio data'); 532 equal('audio', packets[0].type, 'identified audio data');
...@@ -535,11 +535,11 @@ test('parses standalone program stream packets', function() { ...@@ -535,11 +535,11 @@ test('parses standalone program stream packets', function() {
535 535
536 test('aggregates program stream packets from the transport stream', function() { 536 test('aggregates program stream packets from the transport stream', function() {
537 var events = []; 537 var events = [];
538 programStream.on('data', function(event) { 538 elementaryStream.on('data', function(event) {
539 events.push(event); 539 events.push(event);
540 }); 540 });
541 541
542 programStream.push({ 542 elementaryStream.push({
543 type: 'pes', 543 type: 'pes',
544 streamType: H264_STREAM_TYPE, 544 streamType: H264_STREAM_TYPE,
545 payloadUnitStartIndicator: true, 545 payloadUnitStartIndicator: true,
...@@ -549,12 +549,12 @@ test('aggregates program stream packets from the transport stream', function() { ...@@ -549,12 +549,12 @@ test('aggregates program stream packets from the transport stream', function() {
549 }); 549 });
550 equal(0, events.length, 'buffers partial packets'); 550 equal(0, events.length, 'buffers partial packets');
551 551
552 programStream.push({ 552 elementaryStream.push({
553 type: 'pes', 553 type: 'pes',
554 streamType: H264_STREAM_TYPE, 554 streamType: H264_STREAM_TYPE,
555 data: new Uint8Array(13) 555 data: new Uint8Array(13)
556 }); 556 });
557 programStream.end(); 557 elementaryStream.end();
558 equal(1, events.length, 'built one packet'); 558 equal(1, events.length, 'built one packet');
559 equal('video', events[0].type, 'identified video data'); 559 equal('video', events[0].type, 'identified video data');
560 equal(events[0].pts, 7, 'passed along the pts'); 560 equal(events[0].pts, 7, 'passed along the pts');
...@@ -564,17 +564,17 @@ test('aggregates program stream packets from the transport stream', function() { ...@@ -564,17 +564,17 @@ test('aggregates program stream packets from the transport stream', function() {
564 564
565 test('buffers audio and video program streams individually', function() { 565 test('buffers audio and video program streams individually', function() {
566 var events = []; 566 var events = [];
567 programStream.on('data', function(event) { 567 elementaryStream.on('data', function(event) {
568 events.push(event); 568 events.push(event);
569 }); 569 });
570 570
571 programStream.push({ 571 elementaryStream.push({
572 type: 'pes', 572 type: 'pes',
573 payloadUnitStartIndicator: true, 573 payloadUnitStartIndicator: true,
574 streamType: H264_STREAM_TYPE, 574 streamType: H264_STREAM_TYPE,
575 data: new Uint8Array(1) 575 data: new Uint8Array(1)
576 }); 576 });
577 programStream.push({ 577 elementaryStream.push({
578 type: 'pes', 578 type: 'pes',
579 payloadUnitStartIndicator: true, 579 payloadUnitStartIndicator: true,
580 streamType: ADTS_STREAM_TYPE, 580 streamType: ADTS_STREAM_TYPE,
...@@ -582,17 +582,17 @@ test('buffers audio and video program streams individually', function() { ...@@ -582,17 +582,17 @@ test('buffers audio and video program streams individually', function() {
582 }); 582 });
583 equal(0, events.length, 'buffers partial packets'); 583 equal(0, events.length, 'buffers partial packets');
584 584
585 programStream.push({ 585 elementaryStream.push({
586 type: 'pes', 586 type: 'pes',
587 streamType: H264_STREAM_TYPE, 587 streamType: H264_STREAM_TYPE,
588 data: new Uint8Array(1) 588 data: new Uint8Array(1)
589 }); 589 });
590 programStream.push({ 590 elementaryStream.push({
591 type: 'pes', 591 type: 'pes',
592 streamType: ADTS_STREAM_TYPE, 592 streamType: ADTS_STREAM_TYPE,
593 data: new Uint8Array(1) 593 data: new Uint8Array(1)
594 }); 594 });
595 programStream.end(); 595 elementaryStream.end();
596 equal(2, events.length, 'parsed a complete packet'); 596 equal(2, events.length, 'parsed a complete packet');
597 equal('video', events[0].type, 'identified video data'); 597 equal('video', events[0].type, 'identified video data');
598 equal('audio', events[1].type, 'identified audio data'); 598 equal('audio', events[1].type, 'identified audio data');
...@@ -600,29 +600,29 @@ test('buffers audio and video program streams individually', function() { ...@@ -600,29 +600,29 @@ test('buffers audio and video program streams individually', function() {
600 600
601 test('flushes the buffered packets when a new one of that type is started', function() { 601 test('flushes the buffered packets when a new one of that type is started', function() {
602 var packets = []; 602 var packets = [];
603 programStream.on('data', function(packet) { 603 elementaryStream.on('data', function(packet) {
604 packets.push(packet); 604 packets.push(packet);
605 }); 605 });
606 programStream.push({ 606 elementaryStream.push({
607 type: 'pes', 607 type: 'pes',
608 payloadUnitStartIndicator: true, 608 payloadUnitStartIndicator: true,
609 streamType: H264_STREAM_TYPE, 609 streamType: H264_STREAM_TYPE,
610 data: new Uint8Array(1) 610 data: new Uint8Array(1)
611 }); 611 });
612 programStream.push({ 612 elementaryStream.push({
613 type: 'pes', 613 type: 'pes',
614 payloadUnitStartIndicator: true, 614 payloadUnitStartIndicator: true,
615 streamType: ADTS_STREAM_TYPE, 615 streamType: ADTS_STREAM_TYPE,
616 data: new Uint8Array(7) 616 data: new Uint8Array(7)
617 }); 617 });
618 programStream.push({ 618 elementaryStream.push({
619 type: 'pes', 619 type: 'pes',
620 streamType: H264_STREAM_TYPE, 620 streamType: H264_STREAM_TYPE,
621 data: new Uint8Array(1) 621 data: new Uint8Array(1)
622 }); 622 });
623 equal(0, packets.length, 'buffers packets by type'); 623 equal(0, packets.length, 'buffers packets by type');
624 624
625 programStream.push({ 625 elementaryStream.push({
626 type: 'pes', 626 type: 'pes',
627 payloadUnitStartIndicator: true, 627 payloadUnitStartIndicator: true,
628 streamType: H264_STREAM_TYPE, 628 streamType: H264_STREAM_TYPE,
...@@ -632,7 +632,7 @@ test('flushes the buffered packets when a new one of that type is started', func ...@@ -632,7 +632,7 @@ test('flushes the buffered packets when a new one of that type is started', func
632 equal('video', packets[0].type, 'identified video data'); 632 equal('video', packets[0].type, 'identified video data');
633 equal(2, packets[0].data.byteLength, 'concatenated packets'); 633 equal(2, packets[0].data.byteLength, 'concatenated packets');
634 634
635 programStream.end(); 635 elementaryStream.end();
636 equal(3, packets.length, 'built tow more packets'); 636 equal(3, packets.length, 'built tow more packets');
637 equal('video', packets[1].type, 'identified video data'); 637 equal('video', packets[1].type, 'identified video data');
638 equal(1, packets[1].data.byteLength, 'parsed the video payload'); 638 equal(1, packets[1].data.byteLength, 'parsed the video payload');
......