mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Update web-platform-tests to revision e51f414776c4e7efa7cfa5fe63a3a8b3969e06ac
This commit is contained in:
parent
ed392ab3be
commit
db4f300c7c
7956 changed files with 92483 additions and 78520 deletions
|
@ -582,7 +582,7 @@ const trackFactories = {
|
|||
return dst.stream.getAudioTracks()[0];
|
||||
},
|
||||
|
||||
video({width = 640, height = 480} = {}) {
|
||||
video({width = 640, height = 480, signal = null} = {}) {
|
||||
const canvas = Object.assign(
|
||||
document.createElement("canvas"), {width, height}
|
||||
);
|
||||
|
@ -593,8 +593,13 @@ const trackFactories = {
|
|||
setInterval(() => {
|
||||
ctx.fillStyle = `rgb(${count%255}, ${count*count%255}, ${count%255})`;
|
||||
count += 1;
|
||||
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
// If signal is set, add a constant-color box to the video frame.
|
||||
if (signal !== null) {
|
||||
ctx.fillStyle = `rgb(${signal}, ${signal}, ${signal})`;
|
||||
ctx.fillRect(10, 10, 20, 20);
|
||||
let pixel = ctx.getImageData(15, 15, 1, 1);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
if (document.body) {
|
||||
|
@ -609,13 +614,40 @@ const trackFactories = {
|
|||
}
|
||||
};
|
||||
|
||||
// Get the signal from a video element inserted by createNoiseStream
|
||||
function getVideoSignal(v) {
|
||||
if (v.videoWidth < 21 || v.videoHeight < 21) {
|
||||
return null;
|
||||
}
|
||||
const canvas = new OffscreenCanvas(v.videoWidth, v.videoHeight);
|
||||
let context = canvas.getContext('2d');
|
||||
context.drawImage(v, 0, 0, v.videoWidth, v.videoHeight);
|
||||
// Extract pixel value at position 20, 20
|
||||
let pixel = context.getImageData(20, 20, 1, 1);
|
||||
return (pixel.data[0] + pixel.data[1] + pixel.data[2]) / 3;
|
||||
}
|
||||
|
||||
function detectSignal(t, v, value) {
|
||||
return new Promise((resolve) => {
|
||||
let check = () => {
|
||||
const signal = getVideoSignal(v);
|
||||
if (signal !== null && signal < value + 1 && signal > value - 1) {
|
||||
resolve();
|
||||
} else {
|
||||
t.step_timeout(check, 100);
|
||||
}
|
||||
}
|
||||
check();
|
||||
});
|
||||
}
|
||||
|
||||
// Generate a MediaStream bearing the specified tracks.
|
||||
//
|
||||
// @param {object} [caps]
|
||||
// @param {boolean} [caps.audio] - flag indicating whether the generated stream
|
||||
// should include an audio track
|
||||
// @param {boolean} [caps.video] - flag indicating whether the generated stream
|
||||
// should include a video track
|
||||
// should include a video track, or parameters for video
|
||||
async function getNoiseStream(caps = {}) {
|
||||
if (!trackFactories.canCreate(caps)) {
|
||||
return navigator.mediaDevices.getUserMedia(caps);
|
||||
|
@ -627,7 +659,7 @@ async function getNoiseStream(caps = {}) {
|
|||
}
|
||||
|
||||
if (caps.video) {
|
||||
tracks.push(trackFactories.video());
|
||||
tracks.push(trackFactories.video(caps.video));
|
||||
}
|
||||
|
||||
return new MediaStream(tracks);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue