A quick translation of h264-stream
Map over H264Stream from action script and get it passing JSLint. There are still plenty of pieces which are definitely busted. Stub ExpGolomb out for now.
Showing
2 changed files
with
141 additions
and
0 deletions
src/exp-golomb.js
0 → 100644
1 | (function() { | ||
2 | |||
3 | window.videojs.hls.ExpGolomb = function() {}; | ||
4 | |||
5 | /* | ||
6 | public class ExpGolomb | ||
7 | { | ||
8 | private var workingData:ByteArray; | ||
9 | private var workingWord:uint; | ||
10 | private var workingbBitsAvailable:uint; | ||
11 | |||
12 | public function ExpGolomb(pData:ByteArray) | ||
13 | { | ||
14 | workingData = pData; | ||
15 | workingData.position = 0; | ||
16 | loadWord(); | ||
17 | } | ||
18 | |||
19 | public function length():uint | ||
20 | { | ||
21 | return ( 8 * workingData.length ); | ||
22 | } | ||
23 | |||
24 | public function bitsAvailable():uint | ||
25 | { | ||
26 | return ( 8 * workingData.bytesAvailable ) + workingbBitsAvailable; | ||
27 | } | ||
28 | |||
29 | private function loadWord():void | ||
30 | { | ||
31 | workingWord = 0; workingbBitsAvailable = 0; | ||
32 | switch( workingData.bytesAvailable ) | ||
33 | { | ||
34 | case 0: workingbBitsAvailable = 0; break; | ||
35 | default: // not 0, but greater than 4 | ||
36 | case 4: workingWord = workingData.readUnsignedByte(); workingbBitsAvailable = 8; | ||
37 | case 3: workingWord = ( workingWord << 8 ) | workingData.readUnsignedByte(); workingbBitsAvailable += 8; | ||
38 | case 2: workingWord = ( workingWord << 8 ) | workingData.readUnsignedByte(); workingbBitsAvailable += 8; | ||
39 | case 1: workingWord = ( workingWord << 8 ) | workingData.readUnsignedByte(); workingbBitsAvailable += 8; | ||
40 | } | ||
41 | |||
42 | workingWord <<= (32 - workingbBitsAvailable); | ||
43 | } | ||
44 | |||
45 | public function skipBits(size:int):void | ||
46 | { | ||
47 | if ( workingbBitsAvailable > size ) | ||
48 | { | ||
49 | workingWord <<= size; | ||
50 | workingbBitsAvailable -= size; | ||
51 | } | ||
52 | else | ||
53 | { | ||
54 | size -= workingbBitsAvailable; | ||
55 | var skipBytes:int = size / 8; | ||
56 | |||
57 | size -= ( skipBytes * 8 ); | ||
58 | workingData.position += skipBytes; | ||
59 | |||
60 | loadWord(); | ||
61 | |||
62 | workingWord <<= size; | ||
63 | workingbBitsAvailable -= size; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public function readBits(size:int):uint | ||
68 | { | ||
69 | // if ( 32 < size ) | ||
70 | // throw new Error("Can not read more than 32 bits at a time"); | ||
71 | |||
72 | var bits:uint = ( workingbBitsAvailable < size ? workingbBitsAvailable : size); | ||
73 | var valu:uint = workingWord >>> (32 - bits); | ||
74 | |||
75 | workingbBitsAvailable -= bits; | ||
76 | if ( 0 < workingbBitsAvailable ) | ||
77 | workingWord <<= bits; | ||
78 | else | ||
79 | loadWord(); | ||
80 | |||
81 | bits = size - bits; | ||
82 | if ( 0 < bits ) | ||
83 | return valu << bits | readBits( bits ); | ||
84 | else | ||
85 | return valu; | ||
86 | } | ||
87 | |||
88 | private function skipLeadingZeros():uint | ||
89 | { | ||
90 | for( var clz:uint = 0 ; clz < workingbBitsAvailable ; ++clz ) | ||
91 | { | ||
92 | if( 0 != ( workingWord & ( 0x80000000 >>> clz ) ) ) | ||
93 | { | ||
94 | workingWord <<= clz; | ||
95 | workingbBitsAvailable -= clz; | ||
96 | return clz; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | loadWord(); // we exhausted workingWord and still have not found a 1 | ||
101 | return clz + skipLeadingZeros(); | ||
102 | } | ||
103 | |||
104 | public function skipUnsignedExpGolomb():void | ||
105 | { | ||
106 | skipBits(1 + skipLeadingZeros() ); | ||
107 | } | ||
108 | |||
109 | public function skipExpGolomb():void | ||
110 | { | ||
111 | skipBits(1 + skipLeadingZeros() ); | ||
112 | } | ||
113 | |||
114 | public function readUnsignedExpGolomb():uint | ||
115 | { | ||
116 | var clz:uint = skipLeadingZeros(); | ||
117 | return readBits(clz+1) - 1; | ||
118 | } | ||
119 | |||
120 | public function readExpGolomb():int | ||
121 | { | ||
122 | var valu:int = readUnsignedExpGolomb(); | ||
123 | if ( 0x01 & valu ) // the number is odd if the low order bit is set | ||
124 | return (1 + valu) >>> 1; // add 1 to make it even, and devide by 2 | ||
125 | else | ||
126 | return -1 * (valu >>> 1); // devide by two then make it negative | ||
127 | } | ||
128 | |||
129 | // Some convenience functions | ||
130 | public function readBoolean():Boolean | ||
131 | { | ||
132 | return 1 == readBits(1); | ||
133 | } | ||
134 | |||
135 | public function readUnsignedByte():int | ||
136 | { | ||
137 | return readBits(8); | ||
138 | } | ||
139 | } | ||
140 | */ | ||
141 | })(); |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment