5
5
import { logger } from '../utils/logger' ;
6
6
7
7
class ExpGolomb {
8
- constructor ( data ) {
8
+ private data : Uint8Array ;
9
+ public bytesAvailable : number ;
10
+ private word : number ;
11
+ private bitsAvailable : number ;
12
+
13
+ constructor ( data : Uint8Array ) {
9
14
this . data = data ;
10
15
// the number of bytes left to examine in this.data
11
16
this . bytesAvailable = data . byteLength ;
@@ -16,7 +21,7 @@ class ExpGolomb {
16
21
}
17
22
18
23
// ():void
19
- loadWord ( ) {
24
+ loadWord ( ) : void {
20
25
const data = this . data ;
21
26
const bytesAvailable = this . bytesAvailable ;
22
27
const position = data . byteLength - bytesAvailable ;
@@ -34,7 +39,7 @@ class ExpGolomb {
34
39
}
35
40
36
41
// (count:int):void
37
- skipBits ( count ) {
42
+ skipBits ( count : number ) : void {
38
43
let skipBytes ; // :int
39
44
if ( this . bitsAvailable > count ) {
40
45
this . word <<= count ;
@@ -51,7 +56,7 @@ class ExpGolomb {
51
56
}
52
57
53
58
// (size:int):uint
54
- readBits ( size ) {
59
+ readBits ( size : number ) : number {
55
60
let bits = Math . min ( this . bitsAvailable , size ) ; // :uint
56
61
const valu = this . word >>> ( 32 - bits ) ; // :uint
57
62
if ( size > 32 ) {
@@ -74,7 +79,7 @@ class ExpGolomb {
74
79
}
75
80
76
81
// ():uint
77
- skipLZ ( ) {
82
+ skipLZ ( ) : number {
78
83
let leadingZeroCount ; // :uint
79
84
for (
80
85
leadingZeroCount = 0 ;
@@ -94,23 +99,23 @@ class ExpGolomb {
94
99
}
95
100
96
101
// ():void
97
- skipUEG ( ) {
102
+ skipUEG ( ) : void {
98
103
this . skipBits ( 1 + this . skipLZ ( ) ) ;
99
104
}
100
105
101
106
// ():void
102
- skipEG ( ) {
107
+ skipEG ( ) : void {
103
108
this . skipBits ( 1 + this . skipLZ ( ) ) ;
104
109
}
105
110
106
111
// ():uint
107
- readUEG ( ) {
112
+ readUEG ( ) : number {
108
113
const clz = this . skipLZ ( ) ; // :uint
109
114
return this . readBits ( clz + 1 ) - 1 ;
110
115
}
111
116
112
117
// ():int
113
- readEG ( ) {
118
+ readEG ( ) : number {
114
119
const valu = this . readUEG ( ) ; // :int
115
120
if ( 0x01 & valu ) {
116
121
// the number is odd if the low order bit is set
@@ -122,33 +127,33 @@ class ExpGolomb {
122
127
123
128
// Some convenience functions
124
129
// :Boolean
125
- readBoolean ( ) {
130
+ readBoolean ( ) : boolean {
126
131
return this . readBits ( 1 ) === 1 ;
127
132
}
128
133
129
134
// ():int
130
- readUByte ( ) {
135
+ readUByte ( ) : number {
131
136
return this . readBits ( 8 ) ;
132
137
}
133
138
134
139
// ():int
135
- readUShort ( ) {
140
+ readUShort ( ) : number {
136
141
return this . readBits ( 16 ) ;
137
142
}
138
143
139
144
// ():int
140
- readUInt ( ) {
145
+ readUInt ( ) : number {
141
146
return this . readBits ( 32 ) ;
142
147
}
143
148
144
149
/**
145
150
* Advance the ExpGolomb decoder past a scaling list. The scaling
146
151
* list is optionally transmitted as part of a sequence parameter
147
152
* set and is not relevant to transmuxing.
148
- * @param count {number} the number of entries in this scaling list
153
+ * @param count the number of entries in this scaling list
149
154
* @see Recommendation ITU-T H.264, Section 7.3.2.1.1.1
150
155
*/
151
- skipScalingList ( count ) {
156
+ skipScalingList ( count : number ) : void {
152
157
let lastScale = 8 ;
153
158
let nextScale = 8 ;
154
159
let deltaScale ;
@@ -170,7 +175,11 @@ class ExpGolomb {
170
175
* sequence parameter set, including the dimensions of the
171
176
* associated video frames.
172
177
*/
173
- readSPS ( ) {
178
+ readSPS ( ) : {
179
+ width : number ;
180
+ height : number ;
181
+ pixelRatio : [ number , number ] ;
182
+ } {
174
183
let frameCropLeftOffset = 0 ;
175
184
let frameCropRightOffset = 0 ;
176
185
let frameCropTopOffset = 0 ;
@@ -258,7 +267,7 @@ class ExpGolomb {
258
267
frameCropTopOffset = readUEG ( ) ;
259
268
frameCropBottomOffset = readUEG ( ) ;
260
269
}
261
- let pixelRatio = [ 1 , 1 ] ;
270
+ let pixelRatio : [ number , number ] = [ 1 , 1 ] ;
262
271
if ( readBoolean ( ) ) {
263
272
// vui_parameters_present_flag
264
273
if ( readBoolean ( ) ) {
0 commit comments