Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(media-server): name the tag or time base that differs when a recording fails its packet proof

Richie McIlroy70b5a3d82a7f
diff --git a/apps/media-server/src/__tests__/lib/recording-verification.integration.test.ts b/apps/media-server/src/__tests__/lib/recording-verification.integration.test.ts
index afc319988..9a7eda1f6 100644
--- a/apps/media-server/src/__tests__/lib/recording-verification.integration.test.ts
+++ b/apps/media-server/src/__tests__/lib/recording-verification.integration.test.ts
@@ -15,6 +15,7 @@ import { Readable } from "node:stream";
import { EncodedPacketSink, FilePathSource, Input, MP4 } from "mediabunny";
import { muxMediaTracksToMp4 } from "../../lib/media-video";
import {
+ describeTrackDifference,
proveRecordingPackets,
readRecordingAudioTail,
} from "../../lib/recording-packet-proof";
@@ -746,6 +747,32 @@ describe("encoded recording preservation", () => {
/audio does not preserve the source \(.*first difference at packet 0: pts -?[\d.]+ vs [\d.]+, dts/,
);
+ const retagged = join(directory, "proof-explained-tags.mp4");
+ await run([
+ "ffmpeg",
+ "-v",
+ "error",
+ "-i",
+ silent,
+ "-map",
+ "0",
+ "-c",
+ "copy",
+ "-metadata:s:v:0",
+ "handler_name=Retagged",
+ retagged,
+ ]);
+ await expect(
+ proveRecordingPackets(
+ silent,
+ silent,
+ retagged,
+ AbortSignal.timeout(5000),
+ ),
+ ).rejects.toThrow(
+ /video does not preserve the source \(tags\.handler_name "[^"]*" vs "Retagged"/,
+ );
+
const changed = join(directory, "proof-explained-data.mp4");
const bytes = await readFile(silent);
const mdat = bytes.indexOf(Buffer.from("mdat"));
@@ -758,6 +785,21 @@ describe("encoded recording preservation", () => {
/does not preserve the source \(first difference at packet \d+: data differs\)/,
);
});
+ test("shows both time bases when packet timing differs", () => {
+ const summary = (packets: string) => ({
+ configuration: { codec_type: "video" as const, start: "0/1" },
+ count: 2,
+ packets,
+ startTime: 0,
+ tail: undefined,
+ });
+ expect(
+ describeTrackDifference(
+ { summary: summary("a"), log: undefined, timeBase: "1/15000" },
+ { summary: summary("b"), log: undefined, timeBase: "1/90000" },
+ ),
+ ).toBe("time base 1/15000 vs 1/90000");
+ });
test("does not start cancelled packet verification", async () => {
const controller = new AbortController();
controller.abort();
diff --git a/apps/media-server/src/lib/recording-packet-proof.ts b/apps/media-server/src/lib/recording-packet-proof.ts
index a316aacca..233de879c 100644
--- a/apps/media-server/src/lib/recording-packet-proof.ts
+++ b/apps/media-server/src/lib/recording-packet-proof.ts
@@ -311,21 +311,51 @@ async function explainTrackMismatch(
}
}
-function describeTrackDifference(
- source: Awaited<ReturnType<typeof readTrack>>,
- output: Awaited<ReturnType<typeof readTrack>>,
-): string {
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return typeof value === "object" && value !== null && !Array.isArray(value);
+}
+
+function configurationDifferences(
+ left: Record<string, unknown>,
+ right: Record<string, unknown>,
+ path = "",
+): string[] {
const parts: string[] = [];
- const left = source.summary.configuration as Record<string, unknown>;
- const right = output.summary.configuration as Record<string, unknown>;
+ const value = (raw: unknown) => {
+ const text = JSON.stringify(raw) ?? "none";
+ return text.length > 40 ? `${text.slice(0, 37)}...` : text;
+ };
for (const key of new Set([...Object.keys(left), ...Object.keys(right)])) {
if (JSON.stringify(left[key]) === JSON.stringify(right[key])) continue;
- const value = (raw: unknown) => {
- const text = JSON.stringify(raw) ?? "none";
- return text.length > 40 ? "(differs)" : text;
- };
- parts.push(`${key} ${value(left[key])} vs ${value(right[key])}`);
+ const [a, b] = [left[key], right[key]];
+ // Name the tag or disposition that changed instead of printing two long objects.
+ if (!path && (isRecord(a) || isRecord(b)))
+ parts.push(
+ ...configurationDifferences(
+ isRecord(a) ? a : {},
+ isRecord(b) ? b : {},
+ `${key}.`,
+ ),
+ );
+ else parts.push(`${path}${key} ${value(a)} vs ${value(b)}`);
}
+ return parts;
+}
+
+export function describeTrackDifference(
+ source: Pick<
+ Awaited<ReturnType<typeof readTrack>>,
+ "summary" | "log" | "timeBase"
+ >,
+ output: Pick<
+ Awaited<ReturnType<typeof readTrack>>,
+ "summary" | "log" | "timeBase"
+ >,
+): string {
+ const parts = configurationDifferences(
+ source.summary.configuration as Record<string, unknown>,
+ output.summary.configuration as Record<string, unknown>,
+ );
if (source.summary.count !== output.summary.count)
parts.push(`packets ${source.summary.count} vs ${output.summary.count}`);
if (source.summary.startTime !== output.summary.startTime)
@@ -338,6 +368,8 @@ function describeTrackDifference(
output.log
)
parts.push(firstPacketDifference(source.log, output.log));
+ if (source.timeBase !== output.timeBase)
+ parts.push(`time base ${source.timeBase} vs ${output.timeBase}`);
return parts.join("; ").slice(0, 400) || "track summaries differ";
}
@@ -522,6 +554,7 @@ async function readTrack(
tail,
},
log,
+ timeBase: base,
};
}