How to use createVideoDecoder method in wpt

Best JavaScript code snippet using wpt

videoDecoder-codec-specific.https.any.js

Source:videoDecoder-codec-specific.https.any.js Github

copy

Full Screen

...94 ]95};96// Allows mutating `callbacks` after constructing the VideoDecoder, wraps calls97// in t.step().98function createVideoDecoder(t, callbacks) {99 return new VideoDecoder({100 output(frame) {101 if (callbacks && callbacks.output) {102 t.step(() => callbacks.output(frame));103 } else {104 t.unreached_func('unexpected output()');105 }106 },107 error(e) {108 if (callbacks && callbacks.error) {109 t.step(() => callbacks.error(e));110 } else {111 t.unreached_func('unexpected error()');112 }113 }114 });115}116function createCorruptChunk(index) {117 let bad_data = CHUNK_DATA[index];118 for (var i = 0; i < bad_data.byteLength; i += 4)119 bad_data[i] = 0xFF;120 return new EncodedVideoChunk(121 {type: 'delta', timestamp: index, data: bad_data});122}123// Create a view of an ArrayBuffer.124function view(buffer, {offset, size}) {125 return new Uint8Array(buffer, offset, size);126}127let CONFIG = null;128let CHUNK_DATA = null;129let CHUNKS = null;130promise_setup(async () => {131 const data = {132 '?av1': AV1_DATA,133 '?vp8': VP8_DATA,134 '?vp9': VP9_DATA,135 '?h264_avc': H264_AVC_DATA,136 '?h264_annexb': H264_ANNEXB_DATA137 }[location.search];138 // Don't run any tests if the codec is not supported.139 let supported = false;140 try {141 // TODO(sandersd): To properly support H.264 in AVC format, this should142 // include the `description`. For now this test assumes that H.264 Annex B143 // support is the same as H.264 AVC support.144 const support =145 await VideoDecoder.isConfigSupported({codec: data.config.codec});146 supported = support.supported;147 } catch (e) {148 }149 assert_implements_optional(supported, data.config.codec + ' unsupported');150 // Fetch the media data and prepare buffers.151 const response = await fetch(data.src);152 const buf = await response.arrayBuffer();153 CONFIG = {...data.config};154 if (data.config.description) {155 CONFIG.description = view(buf, data.config.description);156 }157 CHUNK_DATA = data.chunks.map((chunk, i) => view(buf, chunk));158 CHUNKS = CHUNK_DATA.map(159 (data, i) => new EncodedVideoChunk(160 {type: i == 0 ? 'key' : 'delta', timestamp: i, duration: 1, data}));161});162promise_test(async t => {163 const support = await VideoDecoder.isConfigSupported(CONFIG);164 assert_true(support.supported, 'supported');165}, 'Test isConfigSupported()');166promise_test(async t => {167 // TODO(sandersd): Create a 1080p `description` for H.264 in AVC format.168 // This version is testing only the H.264 Annex B path.169 const config = {170 codec: CONFIG.codec,171 codedWidth: 1920,172 codedHeight: 1088,173 displayAspectWidth: 1920,174 displayAspectHeight: 1080,175 };176 const support = await VideoDecoder.isConfigSupported(config);177 assert_true(support.supported, 'supported');178}, 'Test isConfigSupported() with 1080p crop');179promise_test(async t => {180 // Define a valid config that includes a hypothetical `futureConfigFeature`,181 // which is not yet recognized by the User Agent.182 const config = {183 ...CONFIG,184 colorSpace: {primaries: 'bt709'},185 futureConfigFeature: 'foo',186 };187 // The UA will evaluate validConfig as being "valid", ignoring the188 // `futureConfigFeature` it doesn't recognize.189 const support = await VideoDecoder.isConfigSupported(config);190 assert_true(support.supported, 'supported');191 assert_equals(support.config.codec, config.codec, 'codec');192 assert_equals(support.config.codedWidth, config.codedWidth, 'codedWidth');193 assert_equals(support.config.codedHeight, config.codedHeight, 'codedHeight');194 assert_equals(support.config.displayAspectWidth, config.displayAspectWidth, 'displayAspectWidth');195 assert_equals(support.config.displayAspectHeight, config.displayAspectHeight, 'displayAspectHeight');196 assert_equals(support.config.colorSpace.primaries, config.colorSpace.primaries, 'color primaries');197 assert_equals(support.config.colorSpace.transfer, undefined, 'color transfer');198 assert_equals(support.config.colorSpace.matrix, undefined, 'color matrix');199 assert_equals(support.config.colorSpace.fullRange, undefined, 'color range');200 assert_false(support.config.hasOwnProperty('futureConfigFeature'), 'futureConfigFeature');201 if (config.description) {202 // The description must be copied.203 assert_false(204 support.config.description === config.description,205 'description is unique');206 assert_array_equals(207 new Uint8Array(support.config.description, 0),208 new Uint8Array(config.description, 0), 'description');209 } else {210 assert_false(support.config.hasOwnProperty('description'), 'description');211 }212}, 'Test that isConfigSupported() returns a parsed configuration');213promise_test(async t => {214 async function test(t, config, description) {215 await promise_rejects_js(216 t, TypeError, VideoDecoder.isConfigSupported(config), description);217 const decoder = createVideoDecoder(t);218 assert_throws_js(TypeError, () => decoder.configure(config), description);219 assert_equals(decoder.state, 'unconfigured', 'state');220 }221 await test(t, {...CONFIG, codedWidth: 0}, 'invalid codedWidth');222 await test(t, {...CONFIG, displayAspectWidth: 0}, 'invalid displayAspectWidth');223}, 'Test invalid configs');224promise_test(async t => {225 const decoder = createVideoDecoder(t);226 decoder.configure(CONFIG);227 assert_equals(decoder.state, 'configured', 'state');228}, 'Test configure()');229promise_test(async t => {230 const callbacks = {};231 const decoder = createVideoDecoder(t, callbacks);232 decoder.configure(CONFIG);233 decoder.decode(CHUNKS[0]);234 let outputs = 0;235 callbacks.output = frame => {236 outputs++;237 assert_equals(frame.timestamp, CHUNKS[0].timestamp, 'timestamp');238 frame.close();239 };240 await decoder.flush();241 assert_equals(outputs, 1, 'outputs');242}, 'Decode a key frame');243promise_test(async t => {244 const callbacks = {};245 const decoder = createVideoDecoder(t, callbacks);246 decoder.configure(CONFIG);247 // Ensure type value is verified.248 assert_equals(CHUNKS[1].type, 'delta');249 assert_throws_dom('DataError', () => decoder.decode(CHUNKS[1], 'decode'));250}, 'Decode a non key frame first fails');251promise_test(async t => {252 const callbacks = {};253 const decoder = createVideoDecoder(t, callbacks);254 decoder.configure(CONFIG);255 for (let i = 0; i < 16; i++) {256 decoder.decode(new EncodedVideoChunk(257 {type: 'key', timestamp: 0, data: CHUNK_DATA[0]}));258 }259 assert_greater_than(decoder.decodeQueueSize, 0);260 // Wait for the first output, then reset the decoder.261 let outputs = 0;262 await new Promise(resolve => {263 callbacks.output = frame => {264 outputs++;265 assert_equals(outputs, 1, 'outputs');266 assert_equals(frame.timestamp, 0, 'timestamp');267 frame.close();268 decoder.reset();269 assert_equals(decoder.decodeQueueSize, 0, 'decodeQueueSize');270 resolve();271 };272 });273 decoder.configure(CONFIG);274 for (let i = 0; i < 4; i++) {275 decoder.decode(new EncodedVideoChunk(276 {type: 'key', timestamp: 1, data: CHUNK_DATA[0]}));277 }278 // Expect future outputs to come from after the reset.279 callbacks.output = frame => {280 outputs++;281 assert_equals(frame.timestamp, 1, 'timestamp');282 frame.close();283 };284 await decoder.flush();285 assert_equals(outputs, 5);286 assert_equals(decoder.decodeQueueSize, 0);287}, 'Verify reset() suppresses outputs');288promise_test(async t => {289 const decoder = createVideoDecoder(t);290 assert_equals(decoder.state, 'unconfigured');291 decoder.reset();292 assert_equals(decoder.state, 'unconfigured');293 assert_throws_dom(294 'InvalidStateError', () => decoder.decode(CHUNKS[0]), 'decode');295 await promise_rejects_dom(t, 'InvalidStateError', decoder.flush(), 'flush');296}, 'Test unconfigured VideoDecoder operations');297promise_test(async t => {298 const decoder = createVideoDecoder(t);299 decoder.close();300 assert_equals(decoder.state, 'closed');301 assert_throws_dom(302 'InvalidStateError', () => decoder.configure(CONFIG), 'configure');303 assert_throws_dom('InvalidStateError', () => decoder.reset(), 'reset');304 assert_throws_dom('InvalidStateError', () => decoder.close(), 'close');305 assert_throws_dom(306 'InvalidStateError', () => decoder.decode(CHUNKS[0]), 'decode');307 await promise_rejects_dom(t, 'InvalidStateError', decoder.flush(), 'flush');308}, 'Test closed VideoDecoder operations');309promise_test(async t => {310 const callbacks = {};311 let errors = 0;312 callbacks.error = e => errors++;313 const decoder = createVideoDecoder(t, callbacks);314 decoder.configure(CONFIG);315 decoder.decode(CHUNKS[0]); // Decode keyframe first.316 decoder.decode(new EncodedVideoChunk(317 {type: 'key', timestamp: 1, data: new ArrayBuffer(0)}));318 await promise_rejects_dom(t, 'AbortError', decoder.flush());319 assert_equals(errors, 1, 'errors');320 assert_equals(decoder.state, 'closed', 'state');321}, 'Decode empty frame');322promise_test(async t => {323 const callbacks = {};324 let errors = 0;325 callbacks.error = e => errors++;326 let outputs = 0;327 callbacks.output = frame => {328 outputs++;329 frame.close();330 };331 const decoder = createVideoDecoder(t, callbacks);332 decoder.configure(CONFIG);333 decoder.decode(CHUNKS[0]); // Decode keyframe first.334 decoder.decode(createCorruptChunk(2));335 await promise_rejects_dom(t, 'AbortError', decoder.flush());336 assert_less_than_equal(outputs, 1);337 assert_equals(errors, 1, 'errors');338 assert_equals(decoder.state, 'closed', 'state');339}, 'Decode corrupt frame');340promise_test(async t => {341 const decoder = createVideoDecoder(t);342 decoder.configure(CONFIG);343 decoder.decode(CHUNKS[0]); // Decode keyframe first.344 decoder.decode(createCorruptChunk(1));345 let flushDone = decoder.flush();346 decoder.close();347 // Flush should have been synchronously rejected, with no output() or error()348 // callbacks.349 await promise_rejects_dom(t, 'AbortError', flushDone);350}, 'Close while decoding corrupt frame');351promise_test(async t => {352 const callbacks = {};353 const decoder = createVideoDecoder(t, callbacks);354 decoder.configure(CONFIG);355 decoder.decode(CHUNKS[0]);356 let outputs = 0;357 callbacks.output = frame => {358 outputs++;359 frame.close();360 };361 await decoder.flush();362 assert_equals(outputs, 1, 'outputs');363 decoder.decode(CHUNKS[0]);364 await decoder.flush();365 assert_equals(outputs, 2, 'outputs');366}, 'Test decoding after flush');367promise_test(async t => {368 const callbacks = {};369 const decoder = createVideoDecoder(t, callbacks);370 decoder.configure(CONFIG);371 decoder.decode(new EncodedVideoChunk(372 {type: 'key', timestamp: -42, data: CHUNK_DATA[0]}));373 let outputs = 0;374 callbacks.output = frame => {375 outputs++;376 assert_equals(frame.timestamp, -42, 'timestamp');377 frame.close();378 };379 await decoder.flush();380 assert_equals(outputs, 1, 'outputs');381}, 'Test decoding a with negative timestamp');382promise_test(async t => {383 const callbacks = {};384 const decoder = createVideoDecoder(t, callbacks);385 decoder.configure(CONFIG);386 decoder.decode(CHUNKS[0]);387 decoder.decode(CHUNKS[1]);388 const flushDone = decoder.flush();389 // Wait for the first output, then reset.390 let outputs = 0;391 await new Promise(resolve => {392 callbacks.output = frame => {393 outputs++;394 assert_equals(outputs, 1, 'outputs');395 decoder.reset();396 frame.close();397 resolve();398 };399 });400 // Flush should have been synchronously rejected.401 await promise_rejects_dom(t, 'AbortError', flushDone);402 assert_equals(outputs, 1, 'outputs');403}, 'Test reset during flush');404promise_test(async t => {405 const callbacks = {};406 const decoder = createVideoDecoder(t, callbacks);407 decoder.configure({...CONFIG, optimizeForLatency: true});408 decoder.decode(CHUNKS[0]);409 // The frame should be output without flushing.410 await new Promise(resolve => {411 callbacks.output = frame => {412 frame.close();413 resolve();414 };415 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function createVideoDecoder() {2 let decoder = new VideoDecoder({3 output: (frame, metadata) => {4 console.log(frame);5 }6 });7 return decoder;8}9function createVideoEncoder() {10 let encoder = new VideoEncoder({11 output: (chunk, metadata) => {12 console.log(chunk);13 }14 });15 return encoder;16}17function createImageBitmap() {18 let img = new Image();19 img.src = 'test.png';20 img.onload = () => {21 let bitmap = createImageBitmap(img);22 console.log(bitmap);23 };24}25async function createImageBitmap() {26 let img = new Image();27 img.src = 'test.png';28 img.onload = async () => {29 let bitmap = await createImageBitmap(img);30 console.log(bitmap);31 };32}33function createImageBitmap() {34 let img = new Image();35 img.src = 'test.png';36 img.onload = () => {37 let bitmap = createImageBitmap(img, 0, 0, 100, 100);38 console.log(bitmap);39 };40}41async function createImageBitmap() {42 let img = new Image();43 img.src = 'test.png';44 img.onload = async () => {45 let bitmap = await createImageBitmap(img, 0, 0, 100, 100);46 console.log(bitmap);47 };48}49function createImageBitmap() {50 let img = new Image();51 img.src = 'test.png';52 img.onload = () => {53 let bitmap = createImageBitmap(img, 0, 0, 100, 100, {resizeWidth: 100, resizeHeight: 100});54 console.log(bitmap);55 };56}57async function createImageBitmap() {58 let img = new Image();59 img.src = 'test.png';60 img.onload = async () => {61 let bitmap = await createImageBitmap(img, 0, 0, 100, 100, {resizeWidth: 100

Full Screen

Using AI Code Generation

copy

Full Screen

1var videoDecoder = createVideoDecoder();2videoDecoder.configure({codec: "vp9"});3videoDecoder.decode();4var videoEncoder = createVideoEncoder();5videoEncoder.configure({codec: "vp9"});6videoEncoder.encode();7var videoFrame = createVideoFrame();8videoFrame.close();9var videoFrameBuffer = createVideoFrameBuffer();10videoFrameBuffer.close();11var videoTrackReader = createVideoTrackReader();12videoTrackReader.read();13var videoTrackWriter = createVideoTrackWriter();14videoTrackWriter.write();15var videoTrack = createVideoTrackFromStream();16videoTrack.stop();17var audioTrack = createAudioTrackFromStream();18audioTrack.stop();19var videoTrack = createVideoTrackFromMediaStreamTrack();20videoTrack.stop();21var audioTrack = createAudioTrackFromMediaStreamTrack();22audioTrack.stop();23var videoTrack = createVideoTrackFromMediaStreamTrack();24videoTrack.stop();25var audioTrack = createAudioTrackFromMediaStreamTrack();26audioTrack.stop();27var audioWorkletNode = createAudioWorkletNode();28audioWorkletNode.port.close();29var audioWorkletProcessor = createAudioWorkletProcessor();30audioWorkletProcessor.port.close();31var mediaStreamAudioSourceNode = createMediaStreamAudioSourceNode();32mediaStreamAudioSourceNode.stop();33var mediaStreamAudioDestinationNode = createMediaStreamAudioDestinationNode();

Full Screen

Using AI Code Generation

copy

Full Screen

1var decoder = createVideoDecoder({codec: "vp8"});2decoder.configure({codec: "vp8", codedWidth: 1920, codedHeight: 1080, alpha: false});3decoder.flush();4decoder.close();5decoder = null;6I have also tried to run the same code in the chromium browser but it is giving me error as "Uncaught (in promise) DOMException: Failed to execute 'configure' on 'VideoDecoder': The VideoDecoder is not in a state that supports configuration."

Full Screen

Using AI Code Generation

copy

Full Screen

1var video = document.createElement('video');2var videoDecoder = await createVideoDecoder({codec: 'h264'});3var config = {codec: 'h264', codedWidth: 320, codedHeight: 240, displayWidth: 320, displayHeight: 240};4var input = new VideoDecoderInput({config: config});5var output = new VideoDecoderOutput();6var decodePromise = videoDecoder.decode(input, output);7var chunk = {type: 'key', timestamp: 0, data: new Uint8Array()};8await decodePromise;9await videoDecoder.flush(output);10await videoDecoder.close();11function testCreateVideoDecoder(t, testFunction) {12 promise_test(async (t) => {13 const video = document.createElement('video');14 const videoDecoder = await createVideoDecoder({codec: 'h264'});15 const config = {codec: 'h264', codedWidth: 320, codedHeight: 240, displayWidth: 320, displayHeight: 240};16 const input = new VideoDecoderInput({config: config});17 const output = new VideoDecoderOutput();18 await testFunction(t, video, videoDecoder, input, output);19 }, 'Test createVideoDecoder');20}21function createVideoDecoder(config) {22 return new Promise((resolve, reject) => {23 const videoDecoder = new VideoDecoder(config);24 videoDecoder.onerror = reject;25 videoDecoder.onunhandledrejection = reject;26 videoDecoder.onmessage = () => {27 resolve(videoDecoder);28 };29 });30}31class VideoDecoder {32 constructor(config) {33 this._config = config;34 this._input = null;35 this._output = null;36 this._pendingInput = null;37 this._pendingOutput = null;38 this._messageHandler = null;39 this._unhandledRejectionHandler = null;40 this._errorHandler = null;41 this._isClosed = false;42 this._isFlushing = false;43 this._isDecoding = false;44 this._isFinished = false;45 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var videoDecoder = new VideoDecoder({2 output: (frame, metadata) => {3 },4 error: (error) => {5 }6});7videoDecoder.configure({8}).then(() => {9 videoDecoder.decode({ buffer: frameBuffer });10});11var videoEncoder = new VideoEncoder({12 output: (encodedFrame, metadata) => {13 },14 error: (error) => {15 }16});17videoEncoder.configure({18}).then(() => {19 videoEncoder.encode({ input: frame });20});21const image = await createImageBitmap(imageBitmapSource);22const image = await createImageBitmap(imageBitmapSource, sx, sy, sw, sh, options);23const image = await createImageBitmap(imageBitmapSource, options);24const image = await createImageBitmap(blob);25const image = await createImageBitmap(imageBitmap);26const image = await createImageBitmap(offscreenCanvas);

Full Screen

Using AI Code Generation

copy

Full Screen

1var decoder = createVideoDecoder();2decoder.configure({codec: 'vp8'});3decoder.decode({input: new Uint8Array([0, 1, 2])});4decoder.flush();5decoder.close();6decoder.reset();7var decoder = createVideoDecoder();8decoder.configure({codec: 'vp9'});9decoder.decode({input: new Uint8Array([0, 1, 2])});10decoder.flush();11decoder.close();12decoder.reset();13var decoder = createVideoDecoder();14decoder.configure({codec: 'h264'});15decoder.decode({input: new Uint8Array([0, 1, 2])});16decoder.flush();17decoder.close();18decoder.reset();19var decoder = createVideoDecoder();20decoder.configure({codec: 'av1'});21decoder.decode({input: new Uint8Array([0, 1, 2])});22decoder.flush();23decoder.close();24decoder.reset();25var decoder = createVideoDecoder();26decoder.configure({codec: 'vp8'});27decoder.decode({input: new Uint8Array([0, 1, 2])});28decoder.flush();29decoder.close();30decoder.reset();31var decoder = createVideoDecoder();32decoder.configure({codec: 'vp9'});33decoder.decode({input: new Uint8Array([0, 1, 2])});34decoder.flush();35decoder.close();36decoder.reset();37var decoder = createVideoDecoder();38decoder.configure({codec: 'h264'});39decoder.decode({input: new Uint8Array([0, 1, 2])});40decoder.flush();41decoder.close();42decoder.reset();43var decoder = createVideoDecoder();44decoder.configure({codec: 'av1'});45decoder.decode({input: new Uint8Array([0, 1, 2])});46decoder.flush();47decoder.close();48decoder.reset();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful