fbb6a663 by David LaPalomento

Use 4-byte ecmascriptarray terminator to match acstionscript. Fix writeBytes.

The actionscript segment parser uses a 4-byte terminator for "ecmascriptarray" objects in script tags. This doesn't match my reading of the spec but we'll go with it for now to get these things binary-compatible. The writeBytes method on FlvTag defaults the length argument to zero but in that case, the entire bytes argument should be written out instead of nothing.
1 parent 5351582b
...@@ -42,7 +42,7 @@ hls.FlvTag = function(type, extraData) { ...@@ -42,7 +42,7 @@ hls.FlvTag = function(type, extraData) {
42 // ByteArray#writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0) 42 // ByteArray#writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0)
43 this.writeBytes = function(bytes, offset, length) { 43 this.writeBytes = function(bytes, offset, length) {
44 offset = offset || 0; 44 offset = offset || 0;
45 length = length || 0; 45 length = length || bytes.byteLength;
46 46
47 try { 47 try {
48 this.bytes.set(bytes.subarray(offset, offset + length), this.position); 48 this.bytes.set(bytes.subarray(offset, offset + length), this.position);
...@@ -198,10 +198,10 @@ hls.FlvTag = function(type, extraData) { ...@@ -198,10 +198,10 @@ hls.FlvTag = function(type, extraData) {
198 this.position++; 198 this.position++;
199 this.view.setUint32(this.position, adHoc); 199 this.view.setUint32(this.position, adHoc);
200 this.position = this.length; 200 this.position = this.length;
201 this.bytes.set([0, 0, 9], this.position); 201 // this.bytes.set([0, 0, 9], this.position);
202 this.position += 3; 202 // this.position += 3;
203 // this.view.setUint32(this.position, 0x09); // End Data Tag 203 this.view.setUint32(this.position, 0x09); // End Data Tag
204 // this.position += 4; 204 this.position += 4;
205 this.length = this.position; 205 this.length = this.position;
206 break; 206 break;
207 } 207 }
......
...@@ -146,9 +146,14 @@ ...@@ -146,9 +146,14 @@
146 tag.pts = pts; 146 tag.pts = pts;
147 expGolomb = new ExpGolomb(this.getSps0Rbsp()); 147 expGolomb = new ExpGolomb(this.getSps0Rbsp());
148 148
149 profile_idc = expGolomb.readUnsignedByte(); // :int = expGolomb.readUnsignedByte(); // profile_idc u(8) 149 // :int = expGolomb.readUnsignedByte(); // profile_idc u(8)
150 expGolomb.skipBits(16);// constraint_set[0-5]_flag, u(1), reserved_zero_2bits u(2), level_idc u(8) 150 profile_idc = expGolomb.readUnsignedByte();
151 expGolomb.skipUnsignedExpGolomb(); // seq_parameter_set_id 151
152 // constraint_set[0-5]_flag, u(1), reserved_zero_2bits u(2), level_idc u(8)
153 expGolomb.skipBits(16);
154
155 // seq_parameter_set_id
156 expGolomb.skipUnsignedExpGolomb();
152 157
153 if (profile_idc === 100 || 158 if (profile_idc === 100 ||
154 profile_idc === 110 || 159 profile_idc === 110 ||
...@@ -230,7 +235,7 @@ ...@@ -230,7 +235,7 @@
230 this.extraDataTag = function(pts) { 235 this.extraDataTag = function(pts) {
231 var 236 var
232 i, 237 i,
233 tag = new FlvTag(FlvTag.VIDEO_TAG,true); 238 tag = new FlvTag(FlvTag.VIDEO_TAG, true);
234 239
235 tag.dts = pts; 240 tag.dts = pts;
236 tag.pts = pts; 241 tag.pts = pts;
......
1 (function(window) {
2 /*
3 ======== A Handy Little QUnit Reference ========
4 http://api.qunitjs.com/
5
6 Test methods:
7 module(name, {[setup][ ,teardown]})
8 test(name, callback)
9 expect(numberOfAssertions)
10 stop(increment)
11 start(decrement)
12 Test assertions:
13 ok(value, [message])
14 equal(actual, expected, [message])
15 notEqual(actual, expected, [message])
16 deepEqual(actual, expected, [message])
17 notDeepEqual(actual, expected, [message])
18 strictEqual(actual, expected, [message])
19 notStrictEqual(actual, expected, [message])
20 throws(block, [expected], [message])
21 */
22 var FlvTag = window.videojs.hls.FlvTag;
23
24 module('FLV tag');
25
26 test('writeBytes with zero length writes the entire array', function() {
27 var
28 tag = new FlvTag(FlvTag.VIDEO_TAG),
29 headerLength = tag.length;
30
31 tag.writeBytes(new Uint8Array([0x1, 0x2, 0x3]));
32
33 equal(3 + headerLength, tag.length, '3 payload bytes are written');
34 });
35
36 })(this);
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
52 52
53 <script src="video-js-hls_test.js"></script> 53 <script src="video-js-hls_test.js"></script>
54 <script src="exp-golomb_test.js"></script> 54 <script src="exp-golomb_test.js"></script>
55 <script src="flv-tag_test.js"></script>
55 </head> 56 </head>
56 <body> 57 <body>
57 <div id="qunit"></div> 58 <div id="qunit"></div>
......