summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html')
-rw-r--r--testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html69
1 files changed, 69 insertions, 0 deletions
diff --git a/testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html b/testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html
new file mode 100644
index 0000000000..7b4f88e944
--- /dev/null
+++ b/testing/web-platform/tests/mediacapture-insertable-streams/MediaStreamTrackProcessor-backpressure.https.html
@@ -0,0 +1,69 @@
+<!doctype html>
+<html>
+<head>
+ <title>MediaStreamTrackProcessor backpressure</title>
+ <link rel="help" href="https://w3c.github.io/mediacapture-insertable-streams">
+</head>
+<body>
+ <h1 class="instructions">Description</h1>
+<p class="instructions">This test checks that MediaStreamTrackProcessor handles backpressure from a WHATWG stream pipeline.</p>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=/resources/testdriver.js></script>
+<script src=/resources/testdriver-vendor.js></script>
+<script>
+
+ const height = 240;
+ const width = 320;
+
+ const inputCanvas = new OffscreenCanvas(width, height);
+ const inputCtx = inputCanvas.getContext('2d', {alpha: false});
+ inputCtx.fillStyle = 'black';
+ inputCtx.fillRect(0, 0, width, height);
+
+ const frameDuration = 40;
+
+ function makeUniformVideoFrame(timestamp) {
+ return new VideoFrame(inputCanvas, {timestamp, alpha: 'discard'});
+ }
+
+ promise_test(async t => {
+ // TODO: use "new VideoTrackGenerator"
+ const generator = new MediaStreamTrackGenerator({kind: 'video'});
+ t.add_cleanup(() => generator.stop());
+
+ // Write frames for the duration of the test.
+ const writer = generator.writable.getWriter();
+ let timestamp = 0;
+ const intervalId = setInterval(
+ t.step_func(async () => {
+ if (generator.readyState === 'live') {
+ timestamp++;
+ await writer.write(makeUniformVideoFrame(timestamp));
+ }
+ }),
+ frameDuration);
+ t.add_cleanup(() => clearInterval(intervalId));
+ t.step_timeout(function() {
+ clearInterval(intervalId);
+ generator.stop();
+ }, 2000);
+ const processor = new MediaStreamTrackProcessor({track: generator});
+ let ts = 1;
+ await processor.readable.pipeTo(new WritableStream({
+ async write(frame) {
+ if (ts === 1) {
+ assert_equals(frame.timestamp, ts, "Timestamp mismatch");
+ } else {
+ assert_greater_than_equal(frame.timestamp, ts, "Backpressure should have resulted in skipping at least 3 frames");
+ }
+ frame.close();
+ ts+=3;
+ // Wait the equivalent of 3 frames
+ return new Promise((res) => t.step_timeout(res, 3*frameDuration));
+ }
+ }));
+ }, "Tests that backpressure forces MediaStreamTrackProcess to skip frames");
+</script>
+</body>
+</html>