File: videoDecoder-codec-specific-setup.js

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (279 lines) | stat: -rw-r--r-- 8,353 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
const AV1_DATA = {
  src: 'av1.mp4',
  config: {
    codec: 'av01.0.04M.08',
    codedWidth: 320,
    codedHeight: 240,
    visibleRect: {x: 0, y: 0, width: 320, height: 240},
    displayWidth: 320,
    displayHeight: 240,
  },
  chunks: [
    {offset: 48, size: 1938}, {offset: 1986, size: 848},
    {offset: 2834, size: 3}, {offset: 2837, size: 47}, {offset: 2884, size: 3},
    {offset: 2887, size: 116}, {offset: 3003, size: 3},
    {offset: 3006, size: 51}, {offset: 3057, size: 25},
    {offset: 3082, size: 105}
  ]
};

const VP8_DATA = {
  src: 'vp8.webm',
  config: {
    codec: 'vp8',
    codedWidth: 320,
    codedHeight: 240,
    visibleRect: {x: 0, y: 0, width: 320, height: 240},
    displayWidth: 320,
    displayHeight: 240,
  },
  chunks: [
    {offset: 522, size: 4826}, {offset: 5355, size: 394},
    {offset: 5756, size: 621}, {offset: 6384, size: 424},
    {offset: 6815, size: 532}, {offset: 7354, size: 655},
    {offset: 8016, size: 670}, {offset: 8693, size: 2413},
    {offset: 11113, size: 402}, {offset: 11522, size: 686}
  ]
};

const VP9_DATA = {
  src: 'vp9.mp4',
  // TODO(sandersd): Verify that the file is actually level 1.
  config: {
    codec: 'vp09.00.10.08',
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 44, size: 3315}, {offset: 3359, size: 203},
    {offset: 3562, size: 245}, {offset: 3807, size: 172},
    {offset: 3979, size: 312}, {offset: 4291, size: 170},
    {offset: 4461, size: 195}, {offset: 4656, size: 181},
    {offset: 4837, size: 356}, {offset: 5193, size: 159}
  ]
};

const H264_AVC_DATA = {
  src: 'h264.mp4',
  config: {
    codec: 'avc1.64000b',
    description: {offset: 9490, size: 45},
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 48, size: 4140}, {offset: 4188, size: 604},
    {offset: 4792, size: 475}, {offset: 5267, size: 561},
    {offset: 5828, size: 587}, {offset: 6415, size: 519},
    {offset: 6934, size: 532}, {offset: 7466, size: 523},
    {offset: 7989, size: 454}, {offset: 8443, size: 528}
  ]
};

const H264_SEI_AVC_DATA = {
  src: 'h264_sei.mp4',
  config: {
    codec: 'avc1.64000b',
    description: {offset: 11989, size: 46},
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 48, size: 4229, key: true}, {offset: 4277, size: 1114},
    {offset: 5391, size: 320}, {offset: 5711, size: 188},
    {offset: 5899, size: 173}, {offset: 6072, size: 3694, key: true},
    {offset: 9766, size: 936}, {offset: 10702, size: 345},
    {offset: 11047, size: 213}, {offset: 11260, size: 210}
  ]
};

const H264_ANNEXB_DATA = {
  src: 'h264.annexb',
  config: {
    codec: 'avc1.64000b',
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 0, size: 4175}, {offset: 4175, size: 602},
    {offset: 4777, size: 473}, {offset: 5250, size: 559},
    {offset: 5809, size: 585}, {offset: 6394, size: 517},
    {offset: 6911, size: 530}, {offset: 7441, size: 521},
    {offset: 7962, size: 452}, {offset: 8414, size: 526}
  ]
};

const H264_SEI_ANNEXB_DATA = {
  src: 'h264_sei.annexb',
  config: {
    codec: 'avc1.64000b',
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 0, size: 4264, key: true}, {offset: 4264, size: 1112},
    {offset: 5376, size: 318}, {offset: 5694, size: 186},
    {offset: 5880, size: 171}, {offset: 6051, size: 3729, key: true},
    {offset: 9780, size: 934}, {offset: 10714, size: 343},
    {offset: 11057, size: 211}, {offset: 11268, size: 208}
  ]
};

const H265_HEVC_DATA = {
  src: 'h265.mp4',
  config: {
    codec: 'hev1.1.6.L60.90',
    description: {offset: 5821, size: 2406},
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 44, size: 2515}, {offset: 2559, size: 279},
    {offset: 2838, size: 327}, {offset: 3165, size: 329},
    {offset: 3494, size: 308}, {offset: 3802, size: 292},
    {offset: 4094, size: 352}, {offset: 4446, size: 296},
    {offset: 4742, size: 216}, {offset: 4958, size: 344}
  ]
};

const H265_ANNEXB_DATA = {
  src: 'h265.annexb',
  config: {
    codec: 'hev1.1.6.L60.90',
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 0, size: 4894}, {offset: 4894, size: 279},
    {offset: 5173, size: 327}, {offset: 5500, size: 329},
    {offset: 5829, size: 308}, {offset: 6137, size: 292},
    {offset: 6429, size: 352}, {offset: 6781, size: 296},
    {offset: 7077, size: 216}, {offset: 7293, size: 344}
  ]
};

// Note: We only test AVC format since with AnnexB there's not enough
// information ahead of the first decode() call to determine if the content is
// interlaced or not.
const H264_INTERLACED_AVC_DATA = {
  src: 'h264_interlaced.mp4',
  config: {
    codec: 'avc1.64000b',
    description: {offset: 7501, size: 47},
    codedWidth: 320,
    codedHeight: 240,
    displayAspectWidth: 320,
    displayAspectHeight: 240,
  },
  chunks: [
    {offset: 48, size: 4091}, {offset: 4139, size: 949},
    {offset: 5088, size: 260}, {offset: 5348, size: 134},
    {offset: 5482, size: 111}, {offset: 5593, size: 660},
    {offset: 6253, size: 197}, {offset: 6450, size: 96},
    {offset: 6546, size: 159}, {offset: 6705, size: 277}
  ]
};

// Allows mutating `callbacks` after constructing the VideoDecoder, wraps calls
// in t.step().
function createVideoDecoder(t, callbacks) {
  return new VideoDecoder({
    output(frame) {
      if (callbacks && callbacks.output) {
        t.step(() => callbacks.output(frame));
      } else {
        t.unreached_func('unexpected output()');
      }
    },
    error(e) {
      if (callbacks && callbacks.error) {
        t.step(() => callbacks.error(e));
      } else {
        t.unreached_func('unexpected error()');
      }
    }
  });
}

function createCorruptChunk(index) {
  let bad_data = CHUNK_DATA[index];
  // AV1 may require more extensive corruption to trigger decoding errors with
  // some software decoders (e.g., dav1d).
  let skip = CONFIG.codec.indexOf('av01') >= 0 ? 2 : 4;
  for (var i = 0; i < bad_data.byteLength; i += skip) {
    bad_data[i] = 0xFF;
  }
  return new EncodedVideoChunk(
      {type: 'delta', timestamp: index, data: bad_data});
}

// Create a view of an ArrayBuffer.
function view(buffer, {offset, size}) {
  return new Uint8Array(buffer, offset, size);
}

async function checkImplements() {
  // Don't run any tests if the codec is not supported.
  assert_equals('function', typeof VideoDecoder.isConfigSupported);
  let supported = false;
  try {
    // TODO(sandersd): To properly support H.264 in AVC format, this should
    // include the `description`. For now this test assumes that H.264 Annex B
    // support is the same as H.264 AVC support.
    const support = await VideoDecoder.isConfigSupported({codec: CONFIG.codec});
    supported = support.supported;
  } catch (e) {
  }
  assert_implements_optional(supported, CONFIG.codec + ' unsupported');
}

let CONFIG = null;
let CHUNK_DATA = null;
let CHUNKS = null;
promise_setup(async () => {
  const data = {
    '?av1': AV1_DATA,
    '?vp8': VP8_DATA,
    '?vp9': VP9_DATA,
    '?h264_avc': H264_AVC_DATA,
    '?h264_sei_avc': H264_SEI_AVC_DATA,
    '?h264_interlaced_avc': H264_INTERLACED_AVC_DATA,
    '?h264_annexb': H264_ANNEXB_DATA,
    '?h264_sei_annexb': H264_SEI_ANNEXB_DATA,
    '?h265_hevc': H265_HEVC_DATA,
    '?h265_annexb': H265_ANNEXB_DATA
  }[location.search];

  // Fetch the media data and prepare buffers.
  const response = await fetch(data.src);
  const buf = await response.arrayBuffer();

  CONFIG = {...data.config};
  if (data.config.description) {
    CONFIG.description = view(buf, data.config.description);
  }

  CHUNK_DATA = data.chunks.map((chunk, i) => view(buf, chunk));

  CHUNKS =
      CHUNK_DATA.map((encoded_data, i) => new EncodedVideoChunk({
                       type: (i == 0 || data.chunks[i].key) ? 'key' : 'delta',
                       timestamp: i,
                       duration: 1,
                       data: encoded_data
                     }));
});