tor-browser

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

test_hw_video_decoding.html (3914B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title>Test video hardware decoding</title>
      5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7 <script type="application/javascript">
      8 
      9 /**
     10 * This test is used to check hardware video decoding on different platforms.
     11 */
     12 const FFVPX_HW = "media.ffvpx-hw.enabled";
     13 
     14 const PLATFORMS = {
     15  // TODO : add Linux and Android, media-gpu doesn't run on them yet
     16  WINNT: {
     17    process: "GPU",
     18    tests: [
     19      {
     20        files: ["gizmo.mp4"],
     21        decoder: "wmf H264 codec hardware video decoder",
     22      },
     23      {
     24        files: ["gizmo.webm"],
     25        decoder: "ffvpx video decoder",
     26      },
     27      {
     28        files: ["gizmo.webm"],
     29        disableFFVPXHW : true,
     30        decoder: "wmf VP9 codec hardware video decoder",
     31      },
     32      {
     33        files: [
     34          "gizmo_av1_8bit_420.webm",
     35          "gizmo_av1_10bit_420.webm",
     36          "av1-yuv420p.mp4",
     37        ],
     38        decoder: "ffvpx video decoder",
     39      },
     40      {
     41        files: [
     42          "gizmo_av1_8bit_420.webm",
     43          "gizmo_av1_10bit_420.webm"
     44        ],
     45        disableFFVPXHW : true,
     46        decoder: "wmf AV1 codec hardware video decoder",
     47      },
     48    ],
     49  },
     50  Darwin: {
     51    process: "RDD",
     52    tests: [
     53      {
     54        files: ["gizmo.mp4"], // H264
     55        decoder: "apple hardware VT decoder",
     56      },
     57      {
     58        files: ["gizmo_hevc_8bit_420.mp4"],  // HEVC
     59        decoder: "apple hardware VT decoder",
     60      },
     61      // TODO : enable VP9 for MacOS. The current machine on CI doesn't support
     62      // VP9 HW. See bug 1861741.
     63      // {
     64      //   file: "gizmo.webm",
     65      //   decoder: "apple hardware VT decoder",
     66      // },
     67    ],
     68  },
     69 };
     70 
     71 add_task(async function testHardwareVideoDecoding() {
     72  const platformName = SpecialPowers.Services.appinfo.OS;
     73  const platformTest = PLATFORMS[platformName];
     74  for (const test of platformTest.tests) {
     75    for (const file of test.files) {
     76      info(
     77        `Testing ${file} on ${platformName} : expect ${test.decoder} in ${platformTest.process}`
     78      );
     79      // Disable ffvpx hw if needed
     80      if (test.disableFFVPXHW !== undefined) {
     81        await SpecialPowers.pushPrefEnv({
     82          set: [[FFVPX_HW, false]],
     83        });
     84      }
     85      await createAndPlayVideo(file);
     86      await assertRunningProcessAndDecoderName({
     87        expectedProcess: platformTest.process,
     88        expectedDecoder: test.decoder,
     89      });
     90      // Reset ffvpx hw pref in order not to interfere next test case
     91      if (test.disableFFVPXHW !== undefined) {
     92        await SpecialPowers.pushPrefEnv({
     93          set: [[FFVPX_HW, true]],
     94        });
     95      }
     96    }
     97  }
     98 });
     99 
    100 // Following are helper functions
    101 async function createAndPlayVideo(fileUrl) {
    102  let video = document.querySelector("video");
    103  if (!video) {
    104    video = document.createElement("video");
    105    document.body.appendChild(video);
    106  }
    107  video.src = fileUrl;
    108  video.loop = true;
    109  ok(
    110    await video.play().then(
    111      () => true,
    112      () => false
    113    ),
    114    "video started playing"
    115  );
    116 }
    117 
    118 async function assertRunningProcessAndDecoderName(
    119  { expectedProcess, expectedDecoder } = {}
    120 ) {
    121  const video = document.querySelector("video");
    122  ok(!video.paused, "checking a playing video that should be hw decoding");
    123 
    124  const debugInfo = await SpecialPowers.wrap(video).mozRequestDebugInfo();
    125  const videoDecoderName = debugInfo.decoder.reader.videoDecoderName;
    126 
    127  const isExpectedDecoder =
    128    videoDecoderName.indexOf(`${expectedDecoder}`) == 0;
    129  ok(
    130    isExpectedDecoder,
    131    `Playback running by decoder '${videoDecoderName}', expected '${expectedDecoder}'`
    132  );
    133 
    134  const isExpectedProcess =
    135    videoDecoderName.indexOf(`(${expectedProcess} remote)`) > 0;
    136  ok(
    137    isExpectedProcess,
    138    `Playback running in process '${videoDecoderName}', expected '${expectedProcess}'`
    139  );
    140 }
    141 
    142 </script>
    143 </head>
    144 <body>
    145 </body>
    146 </html>