diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/webrtc-encoded-transform/script-late-transform.https.html | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.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/webrtc-encoded-transform/script-late-transform.https.html')
-rw-r--r-- | testing/web-platform/tests/webrtc-encoded-transform/script-late-transform.https.html | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webrtc-encoded-transform/script-late-transform.https.html b/testing/web-platform/tests/webrtc-encoded-transform/script-late-transform.https.html new file mode 100644 index 0000000000..726852bad9 --- /dev/null +++ b/testing/web-platform/tests/webrtc-encoded-transform/script-late-transform.https.html @@ -0,0 +1,94 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> +<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 src='../mediacapture-streams/permission-helper.js'></script> + </head> + <body> + <video controls id="video" autoplay></video> + <canvas id="canvas" width="640" height="480"></canvas> + <script src ="routines.js"></script> + <script> +function grabFrameData(x, y, w, h) +{ + canvas.width = video.videoWidth; + canvas.height = video.videoHeight; + + canvas.getContext('2d').drawImage(video, x, y, w, h, x, y, w, h); + return canvas.getContext('2d').getImageData(x, y, w, h).data; +} + +function getCircleImageData() +{ + return grabFrameData(450, 100, 150, 100); +} + +async function checkVideoIsUpdated(test, shouldBeUpdated, count, referenceData) +{ + if (count === undefined) + count = 0; + else if (count >= 20) + return Promise.reject("checkVideoIsUpdated timed out :" + shouldBeUpdated + " " + count); + + if (referenceData === undefined) + referenceData = getCircleImageData(); + + await waitFor(test, 200); + const newData = getCircleImageData(); + + if (shouldBeUpdated === (JSON.stringify(referenceData) !== JSON.stringify(newData))) + return; + + await checkVideoIsUpdated(test, shouldBeUpdated, ++count, newData); +} + +promise_test(async (test) => { + await setMediaPermission("granted", ["camera"]); + const localStream = await navigator.mediaDevices.getUserMedia({video: true}); + const senderTransform = new SFrameTransform({ compatibilityMode: "H264" }); + const receiverTransform = new SFrameTransform({ compatibilityMode: "H264" }); + await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]).then(key => { + senderTransform.setEncryptionKey(key); + receiverTransform.setEncryptionKey(key); + }); + + let sender, receiver; + const stream = await new Promise((resolve, reject) => { + createConnections(test, (firstConnection) => { + pc1 = firstConnection; + sender = firstConnection.addTrack(localStream.getVideoTracks()[0], localStream); + sender.transform = senderTransform; + }, (secondConnection) => { + pc2 = secondConnection; + secondConnection.ontrack = (trackEvent) => { + receiver = trackEvent.receiver; + // we do not set the receiver transform here; + resolve(trackEvent.streams[0]); + }; + }, { + observeOffer : (offer) => { + const lines = offer.sdp.split('\r\n'); + const h264Lines = lines.filter(line => line.indexOf("a=fmtp") === 0 && line.indexOf("42e01f") !== -1); + const baselineNumber = h264Lines[0].substring(6).split(' ')[0]; + offer.sdp = lines.filter(line => { + return (line.indexOf('a=fmtp') === -1 && line.indexOf('a=rtcp-fb') === -1 && line.indexOf('a=rtpmap') === -1) || line.indexOf(baselineNumber) !== -1; + }).join('\r\n'); + } + }); + test.step_timeout(() => reject("Test timed out"), 5000); + }); + + video.srcObject = stream; + video.play(); + + // We set the receiver transform here so that the decoder probably tried to decode sframe content. + test.step_timeout(() => receiver.transform = receiverTransform, 50); + await checkVideoIsUpdated(test, true); +}, "video exchange with late receiver transform"); + </script> + </body> +</html> |