@yume-chan/scrcpy 0.0.13 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.json +45 -0
  2. package/CHANGELOG.md +25 -1
  3. package/LICENSE +21 -21
  4. package/README.md +90 -89
  5. package/bin/scrcpy-server +0 -0
  6. package/bin/version.d.ts +1 -1
  7. package/bin/version.js +1 -1
  8. package/esm/client.d.ts +14 -2
  9. package/esm/client.d.ts.map +1 -1
  10. package/esm/client.js +275 -143
  11. package/esm/client.js.map +1 -1
  12. package/esm/connection.d.ts.map +1 -1
  13. package/esm/connection.js +74 -86
  14. package/esm/connection.js.map +1 -1
  15. package/esm/decoder/tinyh264/index.js +48 -48
  16. package/esm/decoder/tinyh264/index.js.map +1 -1
  17. package/esm/decoder/tinyh264/wrapper.js +3 -2
  18. package/esm/decoder/tinyh264/wrapper.js.map +1 -1
  19. package/esm/decoder/web-codecs/index.js +26 -21
  20. package/esm/decoder/web-codecs/index.js.map +1 -1
  21. package/esm/message.d.ts +13 -8
  22. package/esm/message.d.ts.map +1 -1
  23. package/esm/message.js +14 -8
  24. package/esm/message.js.map +1 -1
  25. package/esm/options/1_16/index.d.ts +8 -4
  26. package/esm/options/1_16/index.d.ts.map +1 -1
  27. package/esm/options/1_16/index.js +44 -18
  28. package/esm/options/1_16/index.js.map +1 -1
  29. package/esm/options/1_16/sps.js +3 -2
  30. package/esm/options/1_16/sps.js.map +1 -1
  31. package/esm/options/1_18.d.ts +3 -2
  32. package/esm/options/1_18.d.ts.map +1 -1
  33. package/esm/options/1_18.js +24 -1
  34. package/esm/options/1_18.js.map +1 -1
  35. package/esm/options/1_21.js +4 -1
  36. package/esm/options/1_21.js.map +1 -1
  37. package/esm/options/1_22.d.ts +3 -3
  38. package/esm/options/1_22.d.ts.map +1 -1
  39. package/esm/options/1_22.js +9 -6
  40. package/esm/options/1_22.js.map +1 -1
  41. package/esm/options/1_23.js +4 -1
  42. package/esm/options/1_23.js.map +1 -1
  43. package/esm/options/1_24.d.ts +9 -0
  44. package/esm/options/1_24.d.ts.map +1 -0
  45. package/esm/options/1_24.js +13 -0
  46. package/esm/options/1_24.js.map +1 -0
  47. package/esm/options/common.d.ts +2 -0
  48. package/esm/options/common.d.ts.map +1 -1
  49. package/esm/options/common.js.map +1 -1
  50. package/esm/options/index.d.ts +1 -0
  51. package/esm/options/index.d.ts.map +1 -1
  52. package/esm/options/index.js +1 -0
  53. package/esm/options/index.js.map +1 -1
  54. package/esm/push-server.js +5 -10
  55. package/esm/push-server.js.map +1 -1
  56. package/package.json +8 -8
  57. package/scrcpy.LICENSE +203 -203
  58. package/scripts/fetch-server.cjs +28 -28
  59. package/src/client.ts +435 -275
  60. package/src/codec.ts +35 -35
  61. package/src/connection.ts +148 -145
  62. package/src/decoder/index.ts +3 -3
  63. package/src/decoder/tinyh264/index.ts +112 -112
  64. package/src/decoder/tinyh264/types.d.ts +137 -137
  65. package/src/decoder/tinyh264/worker.ts +2 -2
  66. package/src/decoder/tinyh264/wrapper.ts +89 -89
  67. package/src/decoder/types.ts +35 -35
  68. package/src/decoder/web-codecs/index.ts +99 -99
  69. package/src/index.ts +8 -8
  70. package/src/message.ts +113 -105
  71. package/src/options/1_16/index.ts +345 -315
  72. package/src/options/1_16/sps.ts +300 -300
  73. package/src/options/1_18.ts +61 -41
  74. package/src/options/1_21.ts +34 -34
  75. package/src/options/1_22.ts +78 -80
  76. package/src/options/1_24.ts +18 -0
  77. package/src/options/common.ts +66 -63
  78. package/src/options/index.ts +7 -6
  79. package/src/push-server.ts +24 -24
  80. package/src/utils.ts +5 -5
@@ -1,300 +1,300 @@
1
- // cspell: ignore golomb
2
- // cspell: ignore qpprime
3
-
4
- class BitReader {
5
- private buffer: Uint8Array;
6
-
7
- private bytePosition = 0;
8
-
9
- private bitPosition = 0;
10
-
11
- public constructor(buffer: Uint8Array) {
12
- this.buffer = buffer;
13
- }
14
-
15
- public read(length: number): number {
16
- let result = 0;
17
- for (let i = 0; i < length; i += 1) {
18
- result = (result << 1) | this.next();
19
- }
20
- return result;
21
- }
22
-
23
- public next(): number {
24
- const value = (this.buffer[this.bytePosition]! >> (7 - this.bitPosition)) & 1;
25
- this.bitPosition += 1;
26
- if (this.bitPosition === 8) {
27
- this.bytePosition += 1;
28
- this.bitPosition = 0;
29
- }
30
- return value;
31
- }
32
-
33
- public decodeExponentialGolombNumber(): number {
34
- let length = 0;
35
- while (this.next() === 0) {
36
- length += 1;
37
- }
38
- if (length === 0) {
39
- return 0;
40
- }
41
- return (1 << length | this.read(length)) - 1;
42
- }
43
- }
44
-
45
- function* iterateNalu(buffer: Uint8Array): Generator<Uint8Array> {
46
- // -1 means we haven't found the first start code
47
- let start = -1;
48
- let writeIndex = 0;
49
-
50
- // How many `0x00`s in a row we have counted
51
- let zeroCount = 0;
52
-
53
- let inEmulation = false;
54
-
55
- for (const byte of buffer) {
56
- buffer[writeIndex] = byte;
57
- writeIndex += 1;
58
-
59
- if (inEmulation) {
60
- if (byte > 0x03) {
61
- // `0x00000304` or larger are invalid
62
- throw new Error('Invalid data');
63
- }
64
-
65
- inEmulation = false;
66
- continue;
67
- }
68
-
69
- if (byte == 0x00) {
70
- zeroCount += 1;
71
- continue;
72
- }
73
-
74
- const lastZeroCount = zeroCount;
75
- zeroCount = 0;
76
-
77
- if (start === -1) {
78
- // 0x000001 is the start code
79
- // But it can be preceded by any number of zeros
80
- // So 2 is the minimal
81
- if (lastZeroCount >= 2 && byte === 0x01) {
82
- // Found start of first NAL unit
83
- writeIndex = 0;
84
- start = 0;
85
- continue;
86
- }
87
-
88
- // Not begin with start code
89
- throw new Error('Invalid data');
90
- }
91
-
92
- if (lastZeroCount < 2) {
93
- // zero or one `0x00`s are acceptable
94
- continue;
95
- }
96
-
97
- if (byte === 0x01) {
98
- // Remove all leading `0x00`s and this `0x01`
99
- writeIndex -= lastZeroCount + 1;
100
-
101
- // Found another NAL unit
102
- yield buffer.subarray(start, writeIndex);
103
-
104
- start = writeIndex;
105
- continue;
106
- }
107
-
108
- if (lastZeroCount > 2) {
109
- // Too much `0x00`s
110
- throw new Error('Invalid data');
111
- }
112
-
113
- switch (byte) {
114
- case 0x02:
115
- // Didn't find why, but 7.4.1 NAL unit semantics forbids `0x000002` appearing in NAL units
116
- throw new Error('Invalid data');
117
- case 0x03:
118
- // `0x000003` is the "emulation_prevention_three_byte"
119
- // `0x00000300`, `0x00000301`, `0x00000302` and `0x00000303` represent
120
- // `0x000000`, `0x000001`, `0x000002` and `0x000003` respectively
121
-
122
- // Remove current byte
123
- writeIndex -= 1;
124
-
125
- inEmulation = true;
126
- break;
127
- default:
128
- // `0x000004` or larger are ok
129
- break;
130
- }
131
- }
132
-
133
- if (inEmulation || zeroCount !== 0) {
134
- throw new Error('Invalid data');
135
- }
136
-
137
- yield buffer.subarray(start, writeIndex);
138
- }
139
-
140
- // 7.3.2.1.1 Sequence parameter set data syntax
141
- export function parse_sequence_parameter_set(buffer: ArrayBuffer) {
142
- for (const nalu of iterateNalu(new Uint8Array(buffer))) {
143
- const reader = new BitReader(nalu);
144
- if (reader.next() !== 0) {
145
- throw new Error('Invalid data');
146
- }
147
-
148
- const nal_ref_idc = reader.read(2);
149
- const nal_unit_type = reader.read(5);
150
-
151
- if (nal_unit_type !== 7) {
152
- continue;
153
- }
154
-
155
- if (nal_ref_idc === 0) {
156
- throw new Error('Invalid data');
157
- }
158
-
159
- const profile_idc = reader.read(8);
160
- const constraint_set = reader.read(8);
161
-
162
- const constraint_set_reader = new BitReader(new Uint8Array([constraint_set]));
163
- const constraint_set0_flag = !!constraint_set_reader.next();
164
- const constraint_set1_flag = !!constraint_set_reader.next();
165
- const constraint_set2_flag = !!constraint_set_reader.next();
166
- const constraint_set3_flag = !!constraint_set_reader.next();
167
- const constraint_set4_flag = !!constraint_set_reader.next();
168
- const constraint_set5_flag = !!constraint_set_reader.next();
169
-
170
- // reserved_zero_2bits
171
- if (constraint_set_reader.read(2) !== 0) {
172
- throw new Error('Invalid data');
173
- }
174
-
175
- const level_idc = reader.read(8);
176
- const seq_parameter_set_id = reader.decodeExponentialGolombNumber();
177
-
178
- if (profile_idc === 100 || profile_idc === 110 ||
179
- profile_idc === 122 || profile_idc === 244 || profile_idc === 44 ||
180
- profile_idc === 83 || profile_idc === 86 || profile_idc === 118 ||
181
- profile_idc === 128 || profile_idc === 138 || profile_idc === 139 ||
182
- profile_idc === 134) {
183
- const chroma_format_idc = reader.decodeExponentialGolombNumber();
184
- if (chroma_format_idc === 3) {
185
- // separate_colour_plane_flag
186
- reader.next();
187
- }
188
-
189
- // bit_depth_luma_minus8
190
- reader.decodeExponentialGolombNumber();
191
- // bit_depth_chroma_minus8
192
- reader.decodeExponentialGolombNumber();
193
-
194
- // qpprime_y_zero_transform_bypass_flag
195
- reader.next();
196
-
197
- const seq_scaling_matrix_present_flag = !!reader.next();
198
- if (seq_scaling_matrix_present_flag) {
199
- const seq_scaling_list_present_flag: boolean[] = [];
200
- for (let i = 0; i < ((chroma_format_idc !== 3) ? 8 : 12); i++) {
201
- seq_scaling_list_present_flag[i] = !!reader.next();
202
- if (seq_scaling_list_present_flag[i])
203
- if (i < 6) {
204
- // TODO
205
- // scaling_list( ScalingList4x4[ i ], 16,
206
- // UseDefaultScalingMatrix4x4Flag[ i ])
207
- } else {
208
- // TODO
209
- // scaling_list( ScalingList8x8[ i − 6 ], 64,
210
- // UseDefaultScalingMatrix8x8Flag[ i − 6 ] )
211
- }
212
- }
213
- }
214
- }
215
-
216
- // log2_max_frame_num_minus4
217
- reader.decodeExponentialGolombNumber();
218
- const pic_order_cnt_type = reader.decodeExponentialGolombNumber();
219
- if (pic_order_cnt_type === 0) {
220
- // log2_max_pic_order_cnt_lsb_minus4
221
- reader.decodeExponentialGolombNumber();
222
- } else if (pic_order_cnt_type === 1) {
223
- // delta_pic_order_always_zero_flag
224
- reader.next();
225
- // offset_for_non_ref_pic
226
- reader.decodeExponentialGolombNumber();
227
- // offset_for_top_to_bottom_field
228
- reader.decodeExponentialGolombNumber();
229
- const num_ref_frames_in_pic_order_cnt_cycle = reader.decodeExponentialGolombNumber();
230
- const offset_for_ref_frame: number[] = [];
231
- for (let i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
232
- offset_for_ref_frame[i] = reader.decodeExponentialGolombNumber();
233
- }
234
- }
235
-
236
- // max_num_ref_frames
237
- reader.decodeExponentialGolombNumber();
238
- // gaps_in_frame_num_value_allowed_flag
239
- reader.next();
240
- const pic_width_in_mbs_minus1 = reader.decodeExponentialGolombNumber();
241
- const pic_height_in_map_units_minus1 = reader.decodeExponentialGolombNumber();
242
-
243
- const frame_mbs_only_flag = reader.next();
244
- if (!frame_mbs_only_flag) {
245
- // mb_adaptive_frame_field_flag
246
- reader.next();
247
- }
248
-
249
- // direct_8x8_inference_flag
250
- reader.next();
251
-
252
- const frame_cropping_flag = !!reader.next();
253
- let frame_crop_left_offset: number;
254
- let frame_crop_right_offset: number;
255
- let frame_crop_top_offset: number;
256
- let frame_crop_bottom_offset: number;
257
- if (frame_cropping_flag) {
258
- frame_crop_left_offset = reader.decodeExponentialGolombNumber();
259
- frame_crop_right_offset = reader.decodeExponentialGolombNumber();
260
- frame_crop_top_offset = reader.decodeExponentialGolombNumber();
261
- frame_crop_bottom_offset = reader.decodeExponentialGolombNumber();
262
- } else {
263
- frame_crop_left_offset = 0;
264
- frame_crop_right_offset = 0;
265
- frame_crop_top_offset = 0;
266
- frame_crop_bottom_offset = 0;
267
- }
268
-
269
- const vui_parameters_present_flag = !!reader.next();
270
- if (vui_parameters_present_flag) {
271
- // TODO
272
- // vui_parameters( )
273
- }
274
-
275
- return {
276
- profile_idc,
277
- constraint_set,
278
- constraint_set0_flag,
279
- constraint_set1_flag,
280
- constraint_set2_flag,
281
- constraint_set3_flag,
282
- constraint_set4_flag,
283
- constraint_set5_flag,
284
- level_idc,
285
- seq_parameter_set_id,
286
- pic_width_in_mbs_minus1,
287
- pic_height_in_map_units_minus1,
288
- frame_mbs_only_flag,
289
- frame_cropping_flag,
290
- frame_crop_left_offset,
291
- frame_crop_right_offset,
292
- frame_crop_top_offset,
293
- frame_crop_bottom_offset,
294
- };
295
- }
296
-
297
- throw new Error('Invalid data');
298
- }
299
-
300
- export type SequenceParameterSet = ReturnType<typeof parse_sequence_parameter_set>;
1
+ // cspell: ignore golomb
2
+ // cspell: ignore qpprime
3
+
4
+ class BitReader {
5
+ private buffer: Uint8Array;
6
+
7
+ private bytePosition = 0;
8
+
9
+ private bitPosition = 0;
10
+
11
+ public constructor(buffer: Uint8Array) {
12
+ this.buffer = buffer;
13
+ }
14
+
15
+ public read(length: number): number {
16
+ let result = 0;
17
+ for (let i = 0; i < length; i += 1) {
18
+ result = (result << 1) | this.next();
19
+ }
20
+ return result;
21
+ }
22
+
23
+ public next(): number {
24
+ const value = (this.buffer[this.bytePosition]! >> (7 - this.bitPosition)) & 1;
25
+ this.bitPosition += 1;
26
+ if (this.bitPosition === 8) {
27
+ this.bytePosition += 1;
28
+ this.bitPosition = 0;
29
+ }
30
+ return value;
31
+ }
32
+
33
+ public decodeExponentialGolombNumber(): number {
34
+ let length = 0;
35
+ while (this.next() === 0) {
36
+ length += 1;
37
+ }
38
+ if (length === 0) {
39
+ return 0;
40
+ }
41
+ return (1 << length | this.read(length)) - 1;
42
+ }
43
+ }
44
+
45
+ function* iterateNalu(buffer: Uint8Array): Generator<Uint8Array> {
46
+ // -1 means we haven't found the first start code
47
+ let start = -1;
48
+ let writeIndex = 0;
49
+
50
+ // How many `0x00`s in a row we have counted
51
+ let zeroCount = 0;
52
+
53
+ let inEmulation = false;
54
+
55
+ for (const byte of buffer) {
56
+ buffer[writeIndex] = byte;
57
+ writeIndex += 1;
58
+
59
+ if (inEmulation) {
60
+ if (byte > 0x03) {
61
+ // `0x00000304` or larger are invalid
62
+ throw new Error('Invalid data');
63
+ }
64
+
65
+ inEmulation = false;
66
+ continue;
67
+ }
68
+
69
+ if (byte == 0x00) {
70
+ zeroCount += 1;
71
+ continue;
72
+ }
73
+
74
+ const lastZeroCount = zeroCount;
75
+ zeroCount = 0;
76
+
77
+ if (start === -1) {
78
+ // 0x000001 is the start code
79
+ // But it can be preceded by any number of zeros
80
+ // So 2 is the minimal
81
+ if (lastZeroCount >= 2 && byte === 0x01) {
82
+ // Found start of first NAL unit
83
+ writeIndex = 0;
84
+ start = 0;
85
+ continue;
86
+ }
87
+
88
+ // Not begin with start code
89
+ throw new Error('Invalid data');
90
+ }
91
+
92
+ if (lastZeroCount < 2) {
93
+ // zero or one `0x00`s are acceptable
94
+ continue;
95
+ }
96
+
97
+ if (byte === 0x01) {
98
+ // Remove all leading `0x00`s and this `0x01`
99
+ writeIndex -= lastZeroCount + 1;
100
+
101
+ // Found another NAL unit
102
+ yield buffer.subarray(start, writeIndex);
103
+
104
+ start = writeIndex;
105
+ continue;
106
+ }
107
+
108
+ if (lastZeroCount > 2) {
109
+ // Too much `0x00`s
110
+ throw new Error('Invalid data');
111
+ }
112
+
113
+ switch (byte) {
114
+ case 0x02:
115
+ // Didn't find why, but 7.4.1 NAL unit semantics forbids `0x000002` appearing in NAL units
116
+ throw new Error('Invalid data');
117
+ case 0x03:
118
+ // `0x000003` is the "emulation_prevention_three_byte"
119
+ // `0x00000300`, `0x00000301`, `0x00000302` and `0x00000303` represent
120
+ // `0x000000`, `0x000001`, `0x000002` and `0x000003` respectively
121
+
122
+ // Remove current byte
123
+ writeIndex -= 1;
124
+
125
+ inEmulation = true;
126
+ break;
127
+ default:
128
+ // `0x000004` or larger are ok
129
+ break;
130
+ }
131
+ }
132
+
133
+ if (inEmulation || zeroCount !== 0) {
134
+ throw new Error('Invalid data');
135
+ }
136
+
137
+ yield buffer.subarray(start, writeIndex);
138
+ }
139
+
140
+ // 7.3.2.1.1 Sequence parameter set data syntax
141
+ export function parse_sequence_parameter_set(buffer: ArrayBuffer) {
142
+ for (const nalu of iterateNalu(new Uint8Array(buffer))) {
143
+ const reader = new BitReader(nalu);
144
+ if (reader.next() !== 0) {
145
+ throw new Error('Invalid data');
146
+ }
147
+
148
+ const nal_ref_idc = reader.read(2);
149
+ const nal_unit_type = reader.read(5);
150
+
151
+ if (nal_unit_type !== 7) {
152
+ continue;
153
+ }
154
+
155
+ if (nal_ref_idc === 0) {
156
+ throw new Error('Invalid data');
157
+ }
158
+
159
+ const profile_idc = reader.read(8);
160
+ const constraint_set = reader.read(8);
161
+
162
+ const constraint_set_reader = new BitReader(new Uint8Array([constraint_set]));
163
+ const constraint_set0_flag = !!constraint_set_reader.next();
164
+ const constraint_set1_flag = !!constraint_set_reader.next();
165
+ const constraint_set2_flag = !!constraint_set_reader.next();
166
+ const constraint_set3_flag = !!constraint_set_reader.next();
167
+ const constraint_set4_flag = !!constraint_set_reader.next();
168
+ const constraint_set5_flag = !!constraint_set_reader.next();
169
+
170
+ // reserved_zero_2bits
171
+ if (constraint_set_reader.read(2) !== 0) {
172
+ throw new Error('Invalid data');
173
+ }
174
+
175
+ const level_idc = reader.read(8);
176
+ const seq_parameter_set_id = reader.decodeExponentialGolombNumber();
177
+
178
+ if (profile_idc === 100 || profile_idc === 110 ||
179
+ profile_idc === 122 || profile_idc === 244 || profile_idc === 44 ||
180
+ profile_idc === 83 || profile_idc === 86 || profile_idc === 118 ||
181
+ profile_idc === 128 || profile_idc === 138 || profile_idc === 139 ||
182
+ profile_idc === 134) {
183
+ const chroma_format_idc = reader.decodeExponentialGolombNumber();
184
+ if (chroma_format_idc === 3) {
185
+ // separate_colour_plane_flag
186
+ reader.next();
187
+ }
188
+
189
+ // bit_depth_luma_minus8
190
+ reader.decodeExponentialGolombNumber();
191
+ // bit_depth_chroma_minus8
192
+ reader.decodeExponentialGolombNumber();
193
+
194
+ // qpprime_y_zero_transform_bypass_flag
195
+ reader.next();
196
+
197
+ const seq_scaling_matrix_present_flag = !!reader.next();
198
+ if (seq_scaling_matrix_present_flag) {
199
+ const seq_scaling_list_present_flag: boolean[] = [];
200
+ for (let i = 0; i < ((chroma_format_idc !== 3) ? 8 : 12); i++) {
201
+ seq_scaling_list_present_flag[i] = !!reader.next();
202
+ if (seq_scaling_list_present_flag[i])
203
+ if (i < 6) {
204
+ // TODO
205
+ // scaling_list( ScalingList4x4[ i ], 16,
206
+ // UseDefaultScalingMatrix4x4Flag[ i ])
207
+ } else {
208
+ // TODO
209
+ // scaling_list( ScalingList8x8[ i − 6 ], 64,
210
+ // UseDefaultScalingMatrix8x8Flag[ i − 6 ] )
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+ // log2_max_frame_num_minus4
217
+ reader.decodeExponentialGolombNumber();
218
+ const pic_order_cnt_type = reader.decodeExponentialGolombNumber();
219
+ if (pic_order_cnt_type === 0) {
220
+ // log2_max_pic_order_cnt_lsb_minus4
221
+ reader.decodeExponentialGolombNumber();
222
+ } else if (pic_order_cnt_type === 1) {
223
+ // delta_pic_order_always_zero_flag
224
+ reader.next();
225
+ // offset_for_non_ref_pic
226
+ reader.decodeExponentialGolombNumber();
227
+ // offset_for_top_to_bottom_field
228
+ reader.decodeExponentialGolombNumber();
229
+ const num_ref_frames_in_pic_order_cnt_cycle = reader.decodeExponentialGolombNumber();
230
+ const offset_for_ref_frame: number[] = [];
231
+ for (let i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
232
+ offset_for_ref_frame[i] = reader.decodeExponentialGolombNumber();
233
+ }
234
+ }
235
+
236
+ // max_num_ref_frames
237
+ reader.decodeExponentialGolombNumber();
238
+ // gaps_in_frame_num_value_allowed_flag
239
+ reader.next();
240
+ const pic_width_in_mbs_minus1 = reader.decodeExponentialGolombNumber();
241
+ const pic_height_in_map_units_minus1 = reader.decodeExponentialGolombNumber();
242
+
243
+ const frame_mbs_only_flag = reader.next();
244
+ if (!frame_mbs_only_flag) {
245
+ // mb_adaptive_frame_field_flag
246
+ reader.next();
247
+ }
248
+
249
+ // direct_8x8_inference_flag
250
+ reader.next();
251
+
252
+ const frame_cropping_flag = !!reader.next();
253
+ let frame_crop_left_offset: number;
254
+ let frame_crop_right_offset: number;
255
+ let frame_crop_top_offset: number;
256
+ let frame_crop_bottom_offset: number;
257
+ if (frame_cropping_flag) {
258
+ frame_crop_left_offset = reader.decodeExponentialGolombNumber();
259
+ frame_crop_right_offset = reader.decodeExponentialGolombNumber();
260
+ frame_crop_top_offset = reader.decodeExponentialGolombNumber();
261
+ frame_crop_bottom_offset = reader.decodeExponentialGolombNumber();
262
+ } else {
263
+ frame_crop_left_offset = 0;
264
+ frame_crop_right_offset = 0;
265
+ frame_crop_top_offset = 0;
266
+ frame_crop_bottom_offset = 0;
267
+ }
268
+
269
+ const vui_parameters_present_flag = !!reader.next();
270
+ if (vui_parameters_present_flag) {
271
+ // TODO
272
+ // vui_parameters( )
273
+ }
274
+
275
+ return {
276
+ profile_idc,
277
+ constraint_set,
278
+ constraint_set0_flag,
279
+ constraint_set1_flag,
280
+ constraint_set2_flag,
281
+ constraint_set3_flag,
282
+ constraint_set4_flag,
283
+ constraint_set5_flag,
284
+ level_idc,
285
+ seq_parameter_set_id,
286
+ pic_width_in_mbs_minus1,
287
+ pic_height_in_map_units_minus1,
288
+ frame_mbs_only_flag,
289
+ frame_cropping_flag,
290
+ frame_crop_left_offset,
291
+ frame_crop_right_offset,
292
+ frame_crop_top_offset,
293
+ frame_crop_bottom_offset,
294
+ };
295
+ }
296
+
297
+ throw new Error('Invalid data');
298
+ }
299
+
300
+ export type SequenceParameterSet = ReturnType<typeof parse_sequence_parameter_set>;