-- codecs/video/Legacy tests: Cinepak, MS Video 1, QuickTime RLE and SMC: every frame equals ffmpeg's (CRC-32 of rgba). -- Fixtures: tools/fixtures/legacy.py. local T = require("@tests/T") local F = require("@rosetta") local Crc32 = require("@rosetta/core/Crc32") local Video = require("@rosetta/codecs/video/Video") local Legacy = require("@rosetta/codecs/video/Legacy") local Fx = require("@tests/gen/legacy_cases") local t = T.suite("legacy") t:eq(Video.fromFourcc("cvid"), "cinepak", "cvid") t:eq(Video.fromFourcc("CRAM"), "msvideo1", "CRAM") t:eq(Video.fromFourcc("msvc"), "msvideo1", "msvc") t:eq(Video.fromFourcc("rle "), "qtrle", "rle ") t:eq(Video.fromFourcc("smc "), "smc", "smc ") for _, id in Legacy.CODECS do t:check(Video.canDecode(id), id .. ": decodable") end local samples: { [string]: { any } } = {} for _, c in Fx do local label = c.name local v, err = F.video.open(c.data) t:check(v ~= nil, label .. ": open: " .. tostring(err)) if v then t:eq(v.codec, c.codec, label .. ": codec") t:eq(v.width, c.width, label .. ": width") local n, bad, first = 0, 0, nil while true do local f, ferr = v:nextFrame() if not f then t:check(ferr == nil, label .. ": decode error " .. tostring(ferr)) break end n += 1 local img = f.image if img.format ~= "rgba8" or img.width ~= c.width or Crc32.of(img.pixels) ~= c.frames[n] then bad += 1 first = first or n end end t:check(n == #c.frames and bad == 0, string.format("%s: %d of %d frames equal ffmpeg's (%d differ, first %s)", label, n - bad, #c.frames, bad, tostring(first))) -- seeking: back to the start, the first frame again v:seek(0) local f = v:nextFrame() t:check(f ~= nil and Crc32.of(f.image.pixels) == c.frames[1], label .. ": seek(0)") local dmx = v.demuxer local tr = dmx:track("video") if not samples[c.codec] then local list = {} for k = 1, math.min(3, dmx:count(tr.id)) do table.insert(list, dmx:get(tr.id, k).data) end samples[c.codec] = { track = tr, packets = list } end end end -- the fuzz pass on the native packet decoders (no pcall in between) local P = Legacy.Picture local raw: { [string]: (tr: any) -> (buffer) -> any } = { cinepak = function(tr) return function(b) local pic = P.new(tr.width, tr.height, tr.bitsPerPixel == 8, 4, 4, tr.palette) return Legacy.Cinepak.decode(pic, b, Legacy.Cinepak.state(), false) end end, msvideo1 = function(tr) return function(b) local bits = if tr.bitsPerPixel == 8 then 8 else 16 return Legacy.Msvideo1.decode(P.new(tr.width, tr.height, bits == 8, 4, 4), b, bits) end end, qtrle = function(tr) return function(b) local d = tr.bitsPerPixel or 24 for _, depth in { d, 1, 2, 4, 8, 16, 32 } do Legacy.QtRle.decode(P.new(tr.width, tr.height, Legacy.QtRle.palettised(depth), Legacy.QtRle.pad(depth), 1), b, depth) end return true end end, smc = function(tr) return function(b) return Legacy.Smc.decode(P.new(tr.width, tr.height, true, 4, 4), b, Legacy.Smc.tables()) end end, } for id, s in samples do local fn = raw[id] if fn then t:fuzz(id .. " packets", fn(s.track), s.packets, { mutations = 24, garbage = 60 }) end end t:fuzz("open", function(b: buffer) local v = F.video.open(b) if v then for _ = 1, 3 do if not v:nextFrame() then break end end end return v end, { Fx[1].data, Fx[#Fx].data }, { mutations = 8, garbage = 20 }) t:done()