56e2bde3 by David LaPalomento

Add a real-work ExpGolomb test

Make sure that a reasonable sequence parameter set can be decoded.
1 parent 422ac236
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 */ 21 */
22 var 22 var
23 buffer, 23 buffer,
24 ExpGolomb = window.videojs.hls.ExpGolomb,
24 expGolomb; 25 expGolomb;
25 26
26 module('Exponential Golomb coding'); 27 module('Exponential Golomb coding');
...@@ -44,32 +45,62 @@ test('small numbers are coded correctly', function() { ...@@ -44,32 +45,62 @@ test('small numbers are coded correctly', function() {
44 45
45 while (i--) { 46 while (i--) {
46 buffer = new Uint8Array([expected[i][0]]); 47 buffer = new Uint8Array([expected[i][0]]);
47 expGolomb = new window.videojs.hls.ExpGolomb(buffer); 48 expGolomb = new ExpGolomb(buffer);
48 result = expGolomb.readUnsignedExpGolomb(); 49 result = expGolomb.readUnsignedExpGolomb();
49 equal(expected[i][1], result, expected[i][0] + ' is decoded to ' + expected[i][1]); 50 equal(expected[i][1], result, expected[i][0] + ' is decoded to ' + expected[i][1]);
50 } 51 }
51 }); 52 });
52 53
53 test('drops working data as it is parsed', function() { 54 test('drops working data as it is parsed', function() {
54 var expGolomb = new window.videojs.hls.ExpGolomb(new Uint8Array([0x00, 0xFF])); 55 var expGolomb = new ExpGolomb(new Uint8Array([0x00, 0xFF]));
55 expGolomb.skipBits(8); 56 expGolomb.skipBits(8);
56 equal(8, expGolomb.bitsAvailable(), '8 bits remain'); 57 equal(8, expGolomb.bitsAvailable(), '8 bits remain');
57 equal(0xFF, expGolomb.readBits(8), 'the second byte is read'); 58 equal(0xFF, expGolomb.readBits(8), 'the second byte is read');
58 }); 59 });
59 60
60 test('drops working data when skipping leading zeros', function() { 61 test('drops working data when skipping leading zeros', function() {
61 var expGolomb = new window.videojs.hls.ExpGolomb(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0xFF])); 62 var expGolomb = new ExpGolomb(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0xFF]));
62 equal(32, expGolomb.skipLeadingZeros(), '32 leading zeros are dropped'); 63 equal(32, expGolomb.skipLeadingZeros(), '32 leading zeros are dropped');
63 equal(8, expGolomb.bitsAvailable(), '8 bits remain'); 64 equal(8, expGolomb.bitsAvailable(), '8 bits remain');
64 equal(0xFF, expGolomb.readBits(8), 'the second byte is read'); 65 equal(0xFF, expGolomb.readBits(8), 'the second byte is read');
65 }); 66 });
66 67
67 test('drops working data when skipping leading zeros', function() { 68 test('drops working data when skipping leading zeros', function() {
68 var expGolomb = new window.videojs.hls.ExpGolomb(new Uint8Array([0x15, 0xab, 0x40, 0xc8, 0xFF])); 69 var expGolomb = new ExpGolomb(new Uint8Array([0x15, 0xab, 0x40, 0xc8, 0xFF]));
69 equal(3, expGolomb.skipLeadingZeros(), '3 leading zeros are dropped'); 70 equal(3, expGolomb.skipLeadingZeros(), '3 leading zeros are dropped');
70 equal((8 * 4) + 5, expGolomb.bitsAvailable(), '37 bits remain'); 71 equal((8 * 4) + 5, expGolomb.bitsAvailable(), '37 bits remain');
71 expGolomb.skipBits(1); 72 expGolomb.skipBits(1);
72 equal(0x5a, expGolomb.readBits(8), 'the next bits are read'); 73 equal(0x5a, expGolomb.readBits(8), 'the next bits are read');
73 }); 74 });
74 75
75 })(this); 76 test('parses a sequence parameter set', function() {
77 var
78 sps = new Uint8Array([
79 0x27, 0x42, 0xe0, 0x0b,
80 0xa9, 0x18, 0x60, 0x9d,
81 0x80, 0x35, 0x06, 0x01,
82 0x06, 0xb6, 0xc2, 0xb5,
83 0xef, 0x7c, 0x04
84 ]),
85 expGolomb = new ExpGolomb(sps);
86
87 strictEqual(expGolomb.readBits(8), 0x27, 'the NAL type specifies an SPS');
88 strictEqual(expGolomb.readBits(8), 66, 'profile_idc is 66');
89 strictEqual(expGolomb.readBits(4), 0x0E, 'constraints 0-3 are correct');
90
91 expGolomb.skipBits(4);
92 strictEqual(expGolomb.readBits(8), 11, 'level_idc is 11');
93 strictEqual(expGolomb.readUnsignedExpGolomb(), 0, 'seq_parameter_set_id is 0');
94 strictEqual(expGolomb.readUnsignedExpGolomb(), 1, 'log2_max_frame_num_minus4 is 1');
95 strictEqual(expGolomb.readUnsignedExpGolomb(), 0, 'pic_order_cnt_type is 0');
96 strictEqual(expGolomb.readUnsignedExpGolomb(), 3, 'log2_max_pic_order_cnt_lsb_minus4 is 3');
97 strictEqual(expGolomb.readUnsignedExpGolomb(), 2, 'max_num_ref_frames is 2');
98 strictEqual(expGolomb.readBits(1), 0, 'gaps_in_frame_num_value_allowed_flag is false');
99 strictEqual(expGolomb.readUnsignedExpGolomb(), 11, 'pic_width_in_mbs_minus1 is 11');
100 strictEqual(expGolomb.readUnsignedExpGolomb(), 8, 'pic_height_in_map_units_minus1 is 8');
101 strictEqual(expGolomb.readBits(1), 1, 'frame_mbs_only_flag is true');
102 strictEqual(expGolomb.readBits(1), 1, 'direct_8x8_inference_flag is true');
103 strictEqual(expGolomb.readBits(1), 0, 'frame_cropping_flag is false');
104 });
105
106 })(this);
......