tor-browser

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

video-encoder-h264.https.any.js (2535B)


      1 // META: global=window,dedicatedworker
      2 // META: script=/common/media.js
      3 // META: script=/webcodecs/utils.js
      4 // META: script=/webcodecs/video-encoder-utils.js
      5 // META: variant=?baseline
      6 // META: variant=?main
      7 // META: variant=?high
      8 // META: variant=?high-6.2
      9 
     10 promise_test(async t => {
     11  const codecString = {
     12    '?baseline': 'avc1.42001e',
     13    '?main': 'avc1.4d001e',
     14    '?high': 'avc1.64001e',
     15    '?high-6.2': 'avc1.64003e',
     16  }[location.search];
     17 
     18  var encoderConfig;
     19  if (location.search != "?high-6.2") {
     20    encoderConfig = {
     21      codec: codecString,
     22      width: 640,
     23      height: 480,
     24      displayWidth: 800,
     25      displayHeight: 600,
     26      avc: {format: 'avc'},  // AVC makes it easy to check the profile.
     27    };
     28  } else {
     29    // high profile + level 6.2
     30    encoderConfig = {
     31      codec: codecString,
     32      width: 7680,
     33      height: 4320,
     34      displayWidth: 7680,
     35      displayHeight: 4320,
     36      avc: {format: 'avc'},  // AVC makes it easy to check the profile.
     37    };
     38  }
     39 
     40  let supported = false;
     41  try {
     42    const support = await VideoEncoder.isConfigSupported(encoderConfig);
     43    supported = support.supported;
     44  } catch (e) {
     45  }
     46  assert_implements_optional(
     47      supported, `H264 ${location.search.substring(1)} profile unsupported`);
     48 
     49  let description = null;
     50  let codecInit = {
     51    error: t.unreached_func('Unexpected encoding error'),
     52    output: (_, metadata) => {
     53      assert_not_equals(metadata, null);
     54      if (metadata.decoderConfig)
     55        description = metadata.decoderConfig.description;
     56    },
     57  };
     58 
     59  let encoder = new VideoEncoder(codecInit);
     60  encoder.configure(encoderConfig);
     61 
     62  let frame1 = createFrame(encoderConfig.width, encoderConfig.height, 0);
     63  let frame2 = createFrame(encoderConfig.width, encoderConfig.height, 33333);
     64  t.add_cleanup(() => {
     65    frame1.close();
     66    frame2.close();
     67  });
     68 
     69  encoder.encode(frame1);
     70  encoder.encode(frame2);
     71 
     72  await encoder.flush();
     73 
     74  assert_not_equals(description, null);
     75  assert_not_equals(description.length, 0);
     76 
     77  // Profile is a hex code at xx in a codec string of form "avc1.xxyyzz".
     78  let expectedProfileIndication = parseInt(codecString.substring(5, 7), 16);
     79 
     80  // See AVCDecoderConfigurationRecord in ISO/IEC 14496-15 for details.
     81  // https://www.w3.org/TR/webcodecs-avc-codec-registration/#dom-avcbitstreamformat-avc
     82  let profileIndication = new Uint8Array(description)[1];
     83  assert_equals(profileIndication, expectedProfileIndication);
     84 }, 'Test that encoding with a specific H264 profile actually produces that profile.');