Skip to content

Commit cab9fe5

Browse files
committed
test(media): cover playback demuxer mappings
1 parent 8744d25 commit cab9fe5

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

‎src/media/playback-transcode.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,68 @@ describe("playback transcode policy", () => {
171171
},
172172
);
173173

174+
it.each([
175+
["audio/m4a", "audio", "mov"],
176+
["audio/mpeg", "audio", "mp3"],
177+
["audio/mp4", "audio", "mov"],
178+
["audio/wav", "audio", "wav"],
179+
["audio/wave", "audio", "wav"],
180+
["audio/x-m4a", "audio", "mov"],
181+
["audio/x-wav", "audio", "wav"],
182+
["audio/aac", "audio", "aac"],
183+
["audio/aiff", "audio", "aiff"],
184+
["audio/amr", "audio", "amr"],
185+
["audio/amr-wb", "audio", "amr"],
186+
["audio/flac", "audio", "flac"],
187+
["audio/ogg", "audio", "ogg"],
188+
["audio/opus", "audio", "ogg"],
189+
["audio/vorbis", "audio", "ogg"],
190+
["audio/webm", "audio", "matroska,webm"],
191+
["audio/x-aiff", "audio", "aiff"],
192+
["audio/x-caf", "audio", "caf"],
193+
["audio/x-ms-wma", "audio", "asf"],
194+
["video/mp4", "video", "mov"],
195+
["video/avi", "video", "avi"],
196+
["video/flv", "video", "flv"],
197+
["video/matroska", "video", "matroska,webm"],
198+
["video/quicktime", "video", "mov"],
199+
["video/webm", "video", "matroska,webm"],
200+
["video/x-flv", "video", "flv"],
201+
["video/x-matroska", "video", "matroska,webm"],
202+
["video/x-ms-asf", "video", "asf"],
203+
["video/x-ms-wmv", "video", "asf"],
204+
["video/x-msvideo", "video", "avi"],
205+
] as const)(
206+
"uses the $2 demuxer for accepted $0 conversion",
207+
async (mimeType, kind, inputFormat) => {
208+
const source = await createSource(`demux-${mimeType.replaceAll("/", "-")}`);
209+
const probe =
210+
kind === "audio"
211+
? { durationMs: 1000, audioCodec: "opus", audioStreamIndex: 0 }
212+
: { durationMs: 1000, videoCodec: "hevc", videoStreamIndex: 0 };
213+
runFfmpeg.mockImplementationOnce(async (args: string[]) => {
214+
await fs.writeFile(args.at(-1) ?? "", `normalized-${kind}`);
215+
return "";
216+
});
217+
218+
await expect(
219+
playback.resolvePlaybackTranscode({ ...source, mimeType, kind, probe }),
220+
).resolves.toEqual({ kind: "preparing" });
221+
await waitForPlaybackTranscodeJobsForTest("all");
222+
223+
const ffmpegArgs = runFfmpeg.mock.calls[0]?.[0] as string[];
224+
const inputFormatIndex = ffmpegArgs.indexOf("-f");
225+
expect(ffmpegArgs[inputFormatIndex + 1]).toBe(inputFormat);
226+
await expect(
227+
playback.resolvePlaybackTranscode({ ...source, mimeType, kind, probe }),
228+
).resolves.toMatchObject(
229+
kind === "audio"
230+
? { kind: "transcoded", contentType: "audio/mp4", extension: ".m4a" }
231+
: { kind: "transcoded", contentType: "video/mp4", extension: ".mp4" },
232+
);
233+
},
234+
);
235+
174236
it("derives a stable cache key from path, size, and modification time", () => {
175237
const source = {
176238
path: "/media/clip.mkv",

0 commit comments

Comments
 (0)