|
7 | 7 | timeline, |
8 | 8 | } from "@/lib/ads/video/compose"; |
9 | 9 | import type { VideoDesignSnapshot } from "@/lib/ads/video/snapshot"; |
10 | | -import { GOP_FRAMES, hlsArgs, mp4Args, multivariantPlaylist, posterArgs } from "@/lib/ads/video/encode"; |
| 10 | +import { AAC_LC_CODEC, avcCodecString, GOP_FRAMES, hlsArgs, mp4Args, multivariantPlaylist, posterArgs } from "@/lib/ads/video/encode"; |
11 | 11 | import { |
12 | 12 | evaluateProbe, |
13 | 13 | parseRational, |
@@ -195,6 +195,32 @@ describe("encoder arguments carry the media contract", () => { |
195 | 195 | expect(poster[poster.indexOf("-ss") + 1]).toBe("2"); |
196 | 196 | }); |
197 | 197 |
|
| 198 | +it("derives the avc1 codec string from what was actually encoded", () => { |
| 199 | + // Shipped renditions probe as High @ 3.1. The hardcoded string said level |
| 200 | + // 4.0 (0x28), which is a promise about the bitstream it does not keep. |
| 201 | + expect(avcCodecString("High", 31)).toBe("avc1.64001F"); |
| 202 | + expect(avcCodecString("High", 40)).toBe("avc1.640028"); |
| 203 | + expect(avcCodecString("Main", 31)).toBe("avc1.4D001F"); |
| 204 | + expect(avcCodecString("Constrained Baseline", 30)).toBe("avc1.42001E"); |
| 205 | + // Unknown input falls back to High @ 3.1 rather than emitting nonsense. |
| 206 | + expect(avcCodecString(undefined, undefined)).toBe("avc1.64001F"); |
| 207 | + }); |
| 208 | + |
| 209 | + it("never advertises audio for a silent rendition", () => { |
| 210 | + // A player reads CODECS before fetching a segment, so an audio codec named |
| 211 | + // here is an audio track it will wait for. Every ad is silent today. |
| 212 | + const silent = multivariantPlaylist([ |
| 213 | + { name: "720p", width: 1280, height: 720, bandwidth: 700000, codecs: avcCodecString("High", 31) }, |
| 214 | + ]); |
| 215 | + expect(silent).toContain('CODECS="avc1.64001F"'); |
| 216 | + expect(silent).not.toContain(AAC_LC_CODEC); |
| 217 | + |
| 218 | + const narrated = multivariantPlaylist([ |
| 219 | + { name: "720p", width: 1280, height: 720, bandwidth: 700000, codecs: `${avcCodecString("High", 31)},${AAC_LC_CODEC}` }, |
| 220 | + ]); |
| 221 | + expect(narrated).toContain(AAC_LC_CODEC); |
| 222 | + }); |
| 223 | + |
198 | 224 | it("does not claim independent segments in the multivariant playlist", () => { |
199 | 225 | const m = multivariantPlaylist([ |
200 | 226 | { name: "720p", width: 1280, height: 720, bandwidth: 2_400_000, codecs: "avc1.640028" }, |
|
0 commit comments