Use common H.264 check in tests

Avoid duplicating this logic in multiple places.
This commit is contained in:
Pierre Ossman 2024-11-20 12:49:36 +01:00
parent 43326eb67b
commit 89e0591aab
1 changed files with 5 additions and 30 deletions

View File

@ -4,6 +4,7 @@ import Display from '../core/display.js';
import { H264Parser } from '../core/decoders/h264.js';
import H264Decoder from '../core/decoders/h264.js';
import Base64 from '../core/base64.js';
import { supportsWebCodecsH264Decode } from '../core/util/browser.js';
import FakeWebSocket from './fake.websocket.js';
@ -29,32 +30,6 @@ const redGreenBlue16x16Video = new Uint8Array(Base64.decode(
'4AA5DRJMnkycJk4TPwAAAAFBiIga8RigADVVHAAGaGOAANtuAAAAAUGIkBr///wRRQABVf8c' +
'AAcho4AAiD4='));
let _haveH264Decode = null;
async function haveH264Decode() {
if (_haveH264Decode !== null) {
return _haveH264Decode;
}
if (!('VideoDecoder' in window)) {
_haveH264Decode = false;
return false;
}
// We'll need to make do with some placeholders here
const config = {
codec: 'avc1.42401f',
codedWidth: 1920,
codedHeight: 1080,
optimizeForLatency: true,
};
let support = await VideoDecoder.isConfigSupported(config);
_haveH264Decode = support.supported;
return _haveH264Decode;
}
function createSolidColorFrameBuffer(color, width, height) {
const r = (color >> 24) & 0xff;
const g = (color >> 16) & 0xff;
@ -158,8 +133,8 @@ describe('H.264 Parser', function () {
describe('H.264 Decoder Unit Test', function () {
let decoder;
beforeEach(async function () {
if (!await haveH264Decode()) {
beforeEach(function () {
if (!supportsWebCodecsH264Decode) {
this.skip();
return;
}
@ -213,8 +188,8 @@ describe('H.264 Decoder Functional Test', function () {
before(FakeWebSocket.replace);
after(FakeWebSocket.restore);
beforeEach(async function () {
if (!await haveH264Decode()) {
beforeEach(function () {
if (!supportsWebCodecsH264Decode) {
this.skip();
return;
}