Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: publish validated quiet audio corrections

Richie McIlroy7390d1340a92
diff --git a/apps/web/__tests__/unit/audio-level-publication.test.ts b/apps/web/__tests__/unit/audio-level-publication.test.ts
index c44d7a02d..a7de7c099 100644
--- a/apps/web/__tests__/unit/audio-level-publication.test.ts
+++ b/apps/web/__tests__/unit/audio-level-publication.test.ts
@@ -161,6 +161,28 @@ async function prepare(overrides: Record<string, unknown> = {}) {
}
describe("audio derivative publication", () => {
+ it.each([
+ { inputLufs: -50.48, outputLufs: -22.49, truePeak: -3.04 },
+ { inputLufs: -55, outputLufs: -27, truePeak: -10 },
+ { inputLufs: -35, outputLufs: -22, truePeak: -3 },
+ ])(
+ "selects a validated quiet correction for playback: %j",
+ async (levels) => {
+ const prepared = await prepare();
+ expect(
+ await handleAudioLevelPublication({
+ ...result,
+ ...levels,
+ token: prepared.token,
+ }),
+ ).toEqual({ status: "published" });
+ expect(writes).toHaveLength(1);
+ expect(resolveRecordingObjectKey(current, "owner/video/result.mp4")).toBe(
+ current.source.audioLevelOutputKey,
+ );
+ expect(getPublishedRecordingOutputKey(current)).toBe(sourceKey);
+ },
+ );
it.each(["desktopMP4", "webMP4"] as const)(
"publishes %s with the original retained",
async (type) => {
@@ -229,6 +251,10 @@ describe("audio derivative publication", () => {
{ token: `${prepared.token}0` },
{ truePeak: 0 },
{ outputLufs: -30 },
+ { inputLufs: -55.01, outputLufs: -27.01 },
+ { inputLufs: -50.48, outputLufs: -21.48 },
+ { inputLufs: -35, outputLufs: -21 },
+ { inputLufs: -30, outputLufs: -17 },
{ outputSize: 1024 * 1024 },
]) {
expect(
diff --git a/apps/web/lib/audio-level-publication.ts b/apps/web/lib/audio-level-publication.ts
index ec927b6d9..eb6b8aa0c 100644
--- a/apps/web/lib/audio-level-publication.ts
+++ b/apps/web/lib/audio-level-publication.ts
@@ -54,7 +54,7 @@ const publishSchema = z.object({
.int()
.positive()
.max(512 * 1024 * 1024),
- inputLufs: z.number().finite().min(-50).max(-18),
+ inputLufs: z.number().finite().min(-55).max(-18),
outputLufs: z.number().finite().max(-14),
truePeak: z.number().finite().max(-1),
});
@@ -193,9 +193,14 @@ export async function handleAudioLevelPublication(payload: unknown) {
const parsed = publishSchema.safeParse(payload);
if (!parsed.success) return unchanged("invalid-request");
const result = parsed.data;
+ const maximumGain = Math.min(
+ 28,
+ Math.max(12, -22 - result.inputLufs),
+ -16 - result.inputLufs,
+ );
if (
result.outputLufs < result.inputLufs + 0.5 ||
- result.outputLufs > result.inputLufs + 12.75
+ result.outputLufs > result.inputLufs + maximumGain + 0.75
)
return unchanged("invalid-levels");
const context = decodeToken(result.token, secret);