video: frame reuse (opts.reuse, v:release, decoder:release) and the control tests

- codecs/video/Video/Pool: Images a decoder made, handed back and reused (only its own; fresh meta)
- H264 / Vp8 / Mpeg2 output Images come from a Pool; H264 / Vp8 decoder:release, VideoCodecDecoder.release
- Video.open: opts.reuse recycles the previous frame's Image at the next nextFrame; v:release(frame); the yuv Image
  under an rgba / scaled frame (never seen by the caller) goes back to the codec at once
- tests/video/control.luau: yield hook (identical frames, H.264 / VP8 / MPEG-1, conversions), disposable packets in
  every container, skipDisposable bit-exact at the right index, reuse identical and recycled, fuzz
- docs/guide/video.md: Skipping and reusing frames; docs/API.md
This commit is contained in:
4DBug committed 2026-11-02 21:46:59 -06:00
1 parent 15e0dfcc86
commit 0b2d8774b9
10 files changed
+463 -27

No files matched your search

+15 -8
View File
@@ -12,6 +12,7 @@ local Cavlc = require("@rosetta/codecs/video/H264/Cavlc")
local Cabac = require("@rosetta/codecs/video/H264/Cabac")
local Deblock = require("@rosetta/codecs/video/H264/Deblock")
local Inter = require("@rosetta/codecs/video/H264/Inter")
local Pool = require("@rosetta/codecs/video/Video/Pool")
local Types = require("@rosetta/Types")
local PAD, PADC = Inter.PAD, Inter.PADC
@@ -54,6 +55,7 @@ function Decoder.new(opts: Options?): any
prevFrameNum = 0,
maxLongTermIdx = -1,
pool = {},
images = Pool.new(), -- output Images given back (H264 decoder:release)
gray = nil,
frames = 0,
errors = 0,
@@ -153,15 +155,11 @@ local function grayPicture(self: any, sps: any): any
return g
end
local function emit(self: any, p: any)
p.waiting = false
if p.skipped then
table.insert(self.out, { image = nil, skipped = true, pts = p.pts, duration = 0, poc = p.poc, keyframe = false })
return
end
-- the cropped output copy of a decoded picture
local function toImage(self: any, p: any): Types.Image
local sps = p.sps
local W, H = sps.width, sps.height
local img = Types.Image.new(W, H, "yuv420p")
local img = self.images:take(W, H, "yuv420p")
local px = img.pixels
local cx, cy = sps.cropX, sps.cropY
for y = 0, H - 1 do
@@ -178,7 +176,16 @@ local function emit(self: any, p: any)
img.meta.sar = { sps.sarW, sps.sarH }
end
img.meta.yuv = { range = if sps.fullRange then "full" else "limited", matrix = if sps.matrix == 1 then "bt709" else "bt601" }
table.insert(self.out, { image = img, pts = p.pts, duration = 0, poc = p.poc, keyframe = p.idr })
return img
end
local function emit(self: any, p: any)
p.waiting = false
if p.skipped then
table.insert(self.out, { image = nil, skipped = true, pts = p.pts, duration = 0, poc = p.poc, keyframe = false })
return
end
table.insert(self.out, { image = toImage(self, p), pts = p.pts, duration = 0, poc = p.poc, keyframe = p.idr })
release(self, p)
end