function make_audio_data(timestamp, channels, sampleRate, frames) {
let data = new Float32Array(frames*channels);
// This generates samples in a planar format. for (var channel = 0; channel < channels; channel++) {
let hz = 100 + channel * 50; // sound frequency
let base_index = channel * frames; for (var i = 0; i < frames; i++) {
let t = (i / sampleRate) * hz * (Math.PI * 2);
data[base_index + i] = Math.sin(t);
}
}
function makeOffscreenCanvas(width, height, options) {
let canvas = new OffscreenCanvas(width, height);
let ctx = canvas.getContext('2d', options);
ctx.fillStyle = 'rgba(50, 100, 150, 255)';
ctx.fillRect(0, 0, width, height); return canvas;
}
function makeImageBitmap(width, height) { return makeOffscreenCanvas(width, height).transferToImageBitmap();
}
// Gives a chance to pending output and error callbacks to complete before // resolving. function endAfterEventLoopTurn() { returnnew Promise(resolve => step_timeout(resolve, 0));
}
// Returns a codec initialization with callbacks that expected to not be called. function getDefaultCodecInit(test) { return {
output: test.unreached_func("unexpected output"),
error: test.unreached_func("unexpected error"),
}
}
// Checks that codec can be configured, reset, reconfigured, and that incomplete // or invalid configs throw errors immediately. function testConfigurations(codec, validConfig, unsupportedCodecsList) {
assert_equals(codec.state, "unconfigured");
const requiredConfigPairs = validConfig;
let incrementalConfig = {};
for (let key in requiredConfigPairs) { // Configure should fail while required keys are missing.
assert_throws_js(TypeError, () => { codec.configure(incrementalConfig); });
incrementalConfig[key] = requiredConfigPairs[key];
assert_equals(codec.state, "unconfigured");
}
// Configure should pass once incrementalConfig meets all requirements.
codec.configure(incrementalConfig);
assert_equals(codec.state, "configured");
// We should be able to reconfigure the codec.
codec.configure(incrementalConfig);
assert_equals(codec.state, "configured");
// Performs an encode or decode with the provided input, depending on whether // the passed codec is an encoder or a decoder. function encodeOrDecodeShouldThrow(codec, input) { // We are testing encode/decode on codecs in invalid states.
assert_not_equals(codec.state, "configured");
if (codec.decode) {
assert_throws_dom("InvalidStateError",
() => codec.decode(input), "decode");
} elseif (codec.encode) { // Encoders consume frames, so clone it to be safe.
assert_throws_dom("InvalidStateError",
() => codec.encode(input.clone()), "encode");
} else {
assert_unreached("Codec should have encode or decode function");
}
}
// Makes sure that we cannot close, configure, reset, flush, decode or encode a // closed codec. function testClosedCodec(test, codec, validconfig, codecInput) {
assert_equals(codec.state, "unconfigured");
// Makes sure we cannot flush, encode or decode with an unconfigured coded, and // that reset is a valid no-op. function testUnconfiguredCodec(test, codec, codecInput) {
assert_equals(codec.state, "unconfigured");
// Configure() and Close() are valid operations that would transition us into // a different state.
// Resetting an unconfigured encoder is a no-op.
codec.reset();
assert_equals(codec.state, "unconfigured");
function testCanvas(ctx, width, height, expected_pixel, imageSetting, assert_compares) { // The dup getImageData is to workaournd crbug.com/1100233
let imageData = ctx.getImageData(0, 0, width, height, imageSetting);
let colorData = ctx.getImageData(0, 0, width, height, imageSetting).data; const kMaxPixelToCheck = 128 * 96;
let step = width * height / kMaxPixelToCheck;
step = Math.round(step);
step = (step < 1) ? 1 : step; for (let i = 0; i < 4 * width * height; i += (4 * step)) {
assert_compares(colorData[i], expected_pixel[0]);
assert_compares(colorData[i + 1], expected_pixel[1]);
assert_compares(colorData[i + 2], expected_pixel[2]);
assert_compares(colorData[i + 3], expected_pixel[3]);
}
}
function makeDetachedArrayBuffer() { const buffer = new ArrayBuffer(10); const view = new Uint8Array(buffer); new MessageChannel().port1.postMessage(buffer, [buffer]); return view;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.