Skip to content

Commit 8cf9f28

Browse files
committed
Convert src/demux/exp-golomb.js to typescript.
1 parent 11e7f74 commit 8cf9f28

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414

15-
src/remux/mp4-generator.js and src/demux/exp-golomb.js implementation in this project
15+
src/remux/mp4-generator.js and src/demux/exp-golomb.ts implementation in this project
1616
are derived from the HLS library for video.js (https://github.com/videojs/videojs-contrib-hls)
1717

1818
That work is also covered by the Apache 2 License, following copyright:

src/demux/exp-golomb.js renamed to src/demux/exp-golomb.ts

+26-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import { logger } from '../utils/logger';
66

77
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) {
914
this.data = data;
1015
// the number of bytes left to examine in this.data
1116
this.bytesAvailable = data.byteLength;
@@ -16,7 +21,7 @@ class ExpGolomb {
1621
}
1722

1823
// ():void
19-
loadWord() {
24+
loadWord(): void {
2025
const data = this.data;
2126
const bytesAvailable = this.bytesAvailable;
2227
const position = data.byteLength - bytesAvailable;
@@ -34,7 +39,7 @@ class ExpGolomb {
3439
}
3540

3641
// (count:int):void
37-
skipBits(count) {
42+
skipBits(count: number): void {
3843
let skipBytes; // :int
3944
if (this.bitsAvailable > count) {
4045
this.word <<= count;
@@ -51,7 +56,7 @@ class ExpGolomb {
5156
}
5257

5358
// (size:int):uint
54-
readBits(size) {
59+
readBits(size: number): number {
5560
let bits = Math.min(this.bitsAvailable, size); // :uint
5661
const valu = this.word >>> (32 - bits); // :uint
5762
if (size > 32) {
@@ -74,7 +79,7 @@ class ExpGolomb {
7479
}
7580

7681
// ():uint
77-
skipLZ() {
82+
skipLZ(): number {
7883
let leadingZeroCount; // :uint
7984
for (
8085
leadingZeroCount = 0;
@@ -94,23 +99,23 @@ class ExpGolomb {
9499
}
95100

96101
// ():void
97-
skipUEG() {
102+
skipUEG(): void {
98103
this.skipBits(1 + this.skipLZ());
99104
}
100105

101106
// ():void
102-
skipEG() {
107+
skipEG(): void {
103108
this.skipBits(1 + this.skipLZ());
104109
}
105110

106111
// ():uint
107-
readUEG() {
112+
readUEG(): number {
108113
const clz = this.skipLZ(); // :uint
109114
return this.readBits(clz + 1) - 1;
110115
}
111116

112117
// ():int
113-
readEG() {
118+
readEG(): number {
114119
const valu = this.readUEG(); // :int
115120
if (0x01 & valu) {
116121
// the number is odd if the low order bit is set
@@ -122,33 +127,33 @@ class ExpGolomb {
122127

123128
// Some convenience functions
124129
// :Boolean
125-
readBoolean() {
130+
readBoolean(): boolean {
126131
return this.readBits(1) === 1;
127132
}
128133

129134
// ():int
130-
readUByte() {
135+
readUByte(): number {
131136
return this.readBits(8);
132137
}
133138

134139
// ():int
135-
readUShort() {
140+
readUShort(): number {
136141
return this.readBits(16);
137142
}
138143

139144
// ():int
140-
readUInt() {
145+
readUInt(): number {
141146
return this.readBits(32);
142147
}
143148

144149
/**
145150
* Advance the ExpGolomb decoder past a scaling list. The scaling
146151
* list is optionally transmitted as part of a sequence parameter
147152
* 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
149154
* @see Recommendation ITU-T H.264, Section 7.3.2.1.1.1
150155
*/
151-
skipScalingList(count) {
156+
skipScalingList(count: number): void {
152157
let lastScale = 8;
153158
let nextScale = 8;
154159
let deltaScale;
@@ -170,7 +175,11 @@ class ExpGolomb {
170175
* sequence parameter set, including the dimensions of the
171176
* associated video frames.
172177
*/
173-
readSPS() {
178+
readSPS(): {
179+
width: number;
180+
height: number;
181+
pixelRatio: [number, number];
182+
} {
174183
let frameCropLeftOffset = 0;
175184
let frameCropRightOffset = 0;
176185
let frameCropTopOffset = 0;
@@ -258,7 +267,7 @@ class ExpGolomb {
258267
frameCropTopOffset = readUEG();
259268
frameCropBottomOffset = readUEG();
260269
}
261-
let pixelRatio = [1, 1];
270+
let pixelRatio: [number, number] = [1, 1];
262271
if (readBoolean()) {
263272
// vui_parameters_present_flag
264273
if (readBoolean()) {

0 commit comments

Comments
 (0)