tor-browser

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

mediasource-webcodecs-appendencodedchunks-play.html (1950B)


      1 <!DOCTYPE html>
      2 <html>
      3  <title>Test basic encoded chunk buffering and playback with MediaSource</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="media-source-webcodecs-util.js"></script>
      7 <script>
      8 setup(() => {
      9  assert_implements(
     10      SourceBuffer.prototype.hasOwnProperty('appendEncodedChunks'),
     11      'SourceBuffer prototype hasOwnProperty "appendEncodedChunks", used ' +
     12          'here to feature detect MSE-for-WebCodecs implementation.');
     13 });
     14 
     15 promise_test(async t => {
     16  let buffer = await vp9.buffer();
     17  let [ videoElement, mediaSource ] = await getOpenMediaSource(t);
     18  videoElement.controls = true;  // Makes early prototype demo playback easier to control manually.
     19  let sourceBuffer = mediaSource.addSourceBuffer({ videoConfig: { codec: vp9.codec } });
     20  let next_timestamp = 0;
     21  let frame_duration = 100 * 1000;  // 100 milliseconds
     22  // forEach with async callbacks makes it too easy to have uncaught rejections
     23  // that don't fail this promise_test or even emit harness error.
     24  // Iterating explicitly instead.
     25  for (i = 0; i < vp9.frames.length; i++, next_timestamp += frame_duration) {
     26    let frame_metadata = vp9.frames[i];
     27    await sourceBuffer.appendEncodedChunks(new EncodedVideoChunk( {
     28      type: frame_metadata.type,
     29      timestamp: next_timestamp,
     30      duration: frame_duration,
     31      data: new Uint8Array(buffer, frame_metadata.offset, frame_metadata.size)
     32    }));
     33  }
     34 
     35  mediaSource.endOfStream();
     36 
     37  return new Promise( (resolve, reject) => {
     38    videoElement.onended = resolve;
     39    videoElement.onerror = reject;
     40    videoElement.play();
     41  });
     42 
     43 }, "Buffer EncodedVideoChunks (VP9) one-by-one and play them with MSE");
     44 
     45 // TODO(crbug.com/1144908): More exhaustive tests (multiple sourcebuffers,
     46 // varying append patterns, invalid append patterns; eventually more codecs,
     47 // out-of-order DTS, durations, etc.)
     48 
     49 </script>
     50 </html>