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:
1 parent
15e0dfcc86
commit
0b2d8774b9
10 files changed
+463
-27
No files matched your search
@@ -7,6 +7,7 @@ local Err = require("@rosetta/core/Err")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Decode = require("@rosetta/codecs/image/Vp8/Decode")
|
||||
local Yuv = require("@rosetta/codecs/image/Vp8/Yuv")
|
||||
local Pool = require("@rosetta/codecs/video/Video/Pool")
|
||||
|
||||
local Vp8 = {}
|
||||
|
||||
@@ -52,10 +53,10 @@ end
|
||||
local DecoderMeta = {}
|
||||
DecoderMeta.__index = DecoderMeta
|
||||
|
||||
export type Decoder = typeof(setmetatable({} :: { state: Decode.State }, DecoderMeta))
|
||||
export type Decoder = typeof(setmetatable({} :: { state: Decode.State, images: Pool.Pool }, DecoderMeta))
|
||||
|
||||
function Vp8.newDecoder(): Decoder
|
||||
return setmetatable({ state = Decode.new() }, DecoderMeta)
|
||||
return setmetatable({ state = Decode.new(), images = Pool.new() }, DecoderMeta)
|
||||
end
|
||||
|
||||
function DecoderMeta.decodeFrame(self: Decoder, buf: buffer, off: number?, len: number?, opts: Options?): (Types.Image?, Err.Err?)
|
||||
@@ -69,7 +70,7 @@ function DecoderMeta.decodeFrame(self: Decoder, buf: buffer, off: number?, len:
|
||||
elseif f.skipped then
|
||||
return nil, nil
|
||||
end
|
||||
local img = Types.Image.new(f.width, f.height, "yuv420p")
|
||||
local img = self.images:take(f.width, f.height, "yuv420p")
|
||||
local ny = f.width * f.height
|
||||
local nc = ((f.width + 1) // 2) * ((f.height + 1) // 2)
|
||||
Decode.cropTo(f, img.pixels, 0, img.pixels, ny, img.pixels, ny + nc)
|
||||
@@ -78,6 +79,11 @@ function DecoderMeta.decodeFrame(self: Decoder, buf: buffer, off: number?, len:
|
||||
return img, nil
|
||||
end
|
||||
|
||||
-- hands a decoded Image back for reuse by a later frame (the caller is done with it); false if it was not this decoder's
|
||||
function DecoderMeta.release(self: Decoder, image: Types.Image): boolean
|
||||
return self.images:give(image)
|
||||
end
|
||||
|
||||
function DecoderMeta.reset(self: Decoder)
|
||||
Decode.reset(self.state)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user