tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

video-decoder-no-size-in-configure.https.any.js (2391B)


      1 // META: global=window,dedicatedworker
      2 // META: script=/webcodecs/video-encoder-utils.js
      3 // META: variant=?av1
      4 // META: variant=?vp8
      5 // META: variant=?vp9_p0
      6 // META: variant=?h264_avc
      7 // META: variant=?h264_annexb
      8 
      9 var CODEC = null;
     10 promise_setup(async () => {
     11  CODEC = {
     12    '?av1': { codec: 'av01.0.04M.08' },
     13    '?vp8': { codec: 'vp8' },
     14    '?vp9_p0': { codec: 'vp09.00.10.08' },
     15    '?h264_avc': { codec: 'avc1.42001E', avc: { format: 'avc' } },
     16    '?h264_annexb': { codec: 'avc1.42001E', avc: { format: 'annexb' } },
     17  }[location.search];
     18 });
     19 
     20 promise_test(async t => {
     21  let encoderConfig = {
     22    ...CODEC,
     23    width: 320,
     24    height: 240,
     25  };
     26 
     27  const encoderSupport = await VideoEncoder.isConfigSupported(encoderConfig);
     28  assert_implements_optional(encoderSupport.supported,  `${encoderConfig.codec} encoder is unsupported`);
     29 
     30  let encodedResult;
     31  const encoder = new VideoEncoder({
     32    output: (chunk, metadata) => {
     33      encodedResult = { chunk, metadata };
     34    },
     35    error: e => {
     36      t.unreached_func('Unexpected encoding error: ' + e);
     37    },
     38  });
     39 
     40  encoderConfig.framerate = 30;
     41  encoderConfig.bitrate = 3000000;
     42  encoder.configure(encoderConfig);
     43 
     44  let frame = createFrame(encoderConfig.width, encoderConfig.height, 0);
     45  encoder.encode(frame);
     46  frame.close();
     47 
     48  await encoder.flush();
     49  encoder.close();
     50 
     51  let decoderConfig = encodedResult.metadata.decoderConfig;
     52  delete decoderConfig.codedWidth;
     53  delete decoderConfig.codedHeight;
     54  delete decoderConfig.displayAspectWidth;
     55  delete decoderConfig.displayAspectHeight;
     56 
     57  const decoderSupport = await VideoDecoder.isConfigSupported(decoderConfig);
     58  assert_implements_optional(decoderSupport.supported,  `${decoderConfig.codec} decoder is unsupported`);
     59 
     60  let decodedResult;
     61  const decoder = new VideoDecoder({
     62    output: frame => {
     63      decodedResult = frame;
     64    },
     65    error: e => {
     66      t.unreached_func('Unexpected decoding error: ' + e);
     67    },
     68  });
     69 
     70 
     71  decoder.configure(decoderConfig);
     72  decoder.decode(encodedResult.chunk);
     73  await decoder.flush();
     74 
     75  // Note: Coded size may vary based on decoder requirements.
     76  assert_equals(
     77      decodedResult.visibleRect.width, encoderConfig.width,
     78      'decoded frame width');
     79  assert_equals(
     80      decodedResult.visibleRect.height, encoderConfig.height,
     81      'decoded frame height');
     82 }, 'Test configure() without setting width and height');