mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(studio-server): a video with a codec nobody listed gets a playable preview copy (#7356)
* fix(studio-server): a video with a codec nobody listed gets a playable preview copy * refactor(studio-server): drop a comment the codec names already carry
This commit is contained in:
@@ -269,24 +269,43 @@ describe("shouldPrewarmProxy", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
// `shouldPrewarmProxy` alone cannot catch a missing `Object.hasOwn` guard —
|
||||
// `.prewarm === true` is already strict against `Object.prototype.constructor`.
|
||||
// The input that misbehaves goes through `codecFactsFor`, which would report
|
||||
// an ordinary asset as browser-hostile.
|
||||
it("does not treat a codec named after an Object.prototype key as hostile", async () => {
|
||||
it("treats a codec nobody listed as browser-hostile, so its file gets a playable copy", async () => {
|
||||
const project = tmpProject();
|
||||
const videoPath = join(project, "clip.mp4");
|
||||
writeFileSync(videoPath, "fake video bytes");
|
||||
|
||||
const facts = await probeAssetCodec(videoPath, makeRunner({ [videoPath]: "wmv3" }));
|
||||
|
||||
expect(facts).toEqual({
|
||||
codecName: "wmv3",
|
||||
browserHostile: true,
|
||||
representativeMime: null,
|
||||
hasAlpha: false,
|
||||
});
|
||||
expect(shouldPrewarmProxy(facts!)).toBe(true);
|
||||
expect(decideMediaProxyEligibility(facts)).toEqual({ eligible: true });
|
||||
});
|
||||
|
||||
it.each(["h264", "vp8", "vp9", "av1"])("does not pre-warm %s", async (codecName) => {
|
||||
const project = tmpProject();
|
||||
const videoPath = join(project, "clip.mp4");
|
||||
writeFileSync(videoPath, "fake video bytes");
|
||||
|
||||
const facts = await probeAssetCodec(videoPath, makeRunner({ [videoPath]: codecName }));
|
||||
|
||||
expect(shouldPrewarmProxy(facts!)).toBe(false);
|
||||
});
|
||||
|
||||
// A codec named after an Object.prototype key must not resolve against it: it is an unlisted codec like any other.
|
||||
it("reads a codec named after an Object.prototype key as an unlisted codec", async () => {
|
||||
const project = tmpProject();
|
||||
const videoPath = join(project, "clip.mp4");
|
||||
writeFileSync(videoPath, "fake video bytes");
|
||||
|
||||
const facts = await probeAssetCodec(videoPath, makeRunner({ [videoPath]: "constructor" }));
|
||||
|
||||
expect(facts).toEqual({
|
||||
codecName: "constructor",
|
||||
browserHostile: false,
|
||||
representativeMime: null,
|
||||
hasAlpha: false,
|
||||
});
|
||||
expect(shouldPrewarmProxy(facts!)).toBe(false);
|
||||
expect(facts?.browserHostile).toBe(true);
|
||||
expect(facts?.representativeMime).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ export interface BrowserHostileCodec {
|
||||
}
|
||||
|
||||
/**
|
||||
* Browser-hostile codec table v1. One exported constant so extending it is a
|
||||
* one-line change. `ffprobe` cannot emit exact RFC 6381 codec strings, so
|
||||
* Browser-hostile codec table v1: the codecs with a known answer; one not here and not in
|
||||
* `BROWSER_PLAYABLE_CODECS` is hostile too. `ffprobe` cannot emit exact RFC 6381 codec strings, so
|
||||
* these `representativeMime` values are deliberately coarse (a false
|
||||
* positive costs one proxy transcode, never correctness; a false negative is
|
||||
* rescued by the runtime's reactive zero-videoWidth swap).
|
||||
@@ -78,12 +78,15 @@ export const BROWSER_HOSTILE_CODECS: Record<string, BrowserHostileCodec> = {
|
||||
vp9: { representativeMime: 'video/webm; codecs="vp09.00.10.08"', prewarm: false },
|
||||
};
|
||||
|
||||
const BROWSER_PLAYABLE_CODECS: ReadonlySet<string> = new Set(["h264", "vp8"]);
|
||||
|
||||
const UNLISTED_HOSTILE: BrowserHostileCodec = { representativeMime: null, prewarm: true };
|
||||
|
||||
/** `Object.hasOwn` rather than a bare index: a codec named `constructor` or
|
||||
* `toString` would otherwise resolve against `Object.prototype`. */
|
||||
function hostileCodecEntry(codecName: string): BrowserHostileCodec | undefined {
|
||||
return Object.hasOwn(BROWSER_HOSTILE_CODECS, codecName)
|
||||
? BROWSER_HOSTILE_CODECS[codecName]
|
||||
: undefined;
|
||||
if (Object.hasOwn(BROWSER_HOSTILE_CODECS, codecName)) return BROWSER_HOSTILE_CODECS[codecName];
|
||||
return BROWSER_PLAYABLE_CODECS.has(codecName) ? undefined : UNLISTED_HOSTILE;
|
||||
}
|
||||
|
||||
/** The pre-warm gate: true only for codecs with no cross-platform browser
|
||||
|
||||
Reference in New Issue
Block a user