ws-cleanup: merge ws/cleanup-types (type annotations)
This commit is contained in:
commit
5d7c223ab8
115 files changed
+583
-515
No files matched your search
@@ -51,7 +51,7 @@ function Video.simpleDecoder(decodeOne: (data: buffer, packet: Types.Packet) ->
|
||||
if q then
|
||||
return q[1], q[2], q[3]
|
||||
end
|
||||
return nil
|
||||
return nil, nil, nil
|
||||
end
|
||||
function self.flush(_: any) end
|
||||
function self.reset(_: any)
|
||||
@@ -95,7 +95,7 @@ local function rawPlanar(data: buffer, pf: string, bits: number, w: number, h: n
|
||||
if pf == "gray" then
|
||||
u, v = 128, 128
|
||||
elseif pf == "yuv420p" then
|
||||
u, v = sample(uo + i * bps), sample(vo + i * bps)
|
||||
u, v = sample(uo + i * bps), sample(vo + i * bps) :: number
|
||||
elseif pf == "yuv422p" then
|
||||
local y0, y1 = cy * 2, math.min(cy * 2 + 1, h - 1)
|
||||
u = (sample(uo + (y0 * scw + cx) * bps) + sample(uo + (y1 * scw + cx) * bps) + 1) // 2
|
||||
@@ -155,18 +155,18 @@ local function rawDecoder(track: Types.Track, _opts: any?): (Types.VideoCodecDec
|
||||
if pf == "yuv420p" and bits == 8 then
|
||||
local img = Types.Image.new(w, h, "yuv420p")
|
||||
buffer.copy(img.pixels, 0, data, 0, need)
|
||||
return img
|
||||
return img, nil
|
||||
elseif pf == "yv12" then
|
||||
local img = Types.Image.new(w, h, "yuv420p")
|
||||
buffer.copy(img.pixels, 0, data, 0, w * h)
|
||||
buffer.copy(img.pixels, w * h, data, w * h + cw * ch, cw * ch)
|
||||
buffer.copy(img.pixels, w * h + cw * ch, data, w * h, cw * ch)
|
||||
return img
|
||||
return img, nil
|
||||
end
|
||||
return rawPlanar(data, pf, bits, w, h)
|
||||
return rawPlanar(data, pf, bits, w, h), nil
|
||||
end
|
||||
local bpp = if pf == "bgra" or pf == "rgba" then 4 else 3
|
||||
local stride = if track.stride then track.stride else w * bpp
|
||||
local stride: number = track.stride or w * bpp
|
||||
if n < stride * (h - 1) + w * bpp then
|
||||
return nil, Err.new(Err.TRUNCATED, "raw frame too short")
|
||||
end
|
||||
@@ -185,8 +185,8 @@ local function rawDecoder(track: Types.Track, _opts: any?): (Types.VideoCodecDec
|
||||
buffer.writeu32(px, o + x * 4, a + b * 256 + c * 65536 + 0xff000000)
|
||||
end
|
||||
end
|
||||
return img
|
||||
end)
|
||||
return img, nil
|
||||
end), nil
|
||||
end
|
||||
|
||||
local function vp8Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?)
|
||||
@@ -210,21 +210,21 @@ local function vp8Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecDec
|
||||
else
|
||||
dec = Vp8.newDecoder()
|
||||
end
|
||||
end)
|
||||
end), nil
|
||||
end
|
||||
|
||||
-- Motion JPEG: every packet one JPEG (or two fields), yuv420p straight from the planes (full range) when the layout
|
||||
-- allows, else rgba8
|
||||
local function mjpegDecoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?)
|
||||
local Jpeg = require("@formats/codecs/Jpeg")
|
||||
local o = { yuv = true, maxPixels = opts and opts.maxPixels }
|
||||
local o: Jpeg.DecodeOptions = { yuv = true, maxPixels = opts and opts.maxPixels }
|
||||
return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?)
|
||||
local img, err = Jpeg.decode(data, 0, buffer.len(data), o)
|
||||
if img and img.format == "yuv420p" then
|
||||
img.meta.yuv = { range = "full", matrix = "bt601" }
|
||||
end
|
||||
return img, err
|
||||
end)
|
||||
end), nil
|
||||
end
|
||||
|
||||
-- the MJPEG encoder (writers): JPEG is full-range, so limited-range yuv420p frames are remapped first
|
||||
@@ -269,7 +269,7 @@ local function mpeg1Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecD
|
||||
if q then
|
||||
return q[1], q[2], q[3]
|
||||
end
|
||||
return nil
|
||||
return nil, nil, nil
|
||||
end
|
||||
function self.flush(_: any)
|
||||
for _ = 1, 4 do
|
||||
@@ -331,7 +331,7 @@ function Video.register(entry: Entry): (boolean, Err.Err?)
|
||||
for _, m in entry.matroska or {} do
|
||||
byMatroska[m] = entry.id
|
||||
end
|
||||
return true
|
||||
return true, nil
|
||||
end
|
||||
for _, e in BUILTIN do
|
||||
Video.register(e)
|
||||
@@ -451,7 +451,7 @@ function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDec
|
||||
end
|
||||
local index, flushed, skipUntil = 0, false, -math.huge
|
||||
local tid = if track then track.id else -1
|
||||
local scale = if track and track.timescale and track.timescale > 0 then track.timescale else 1000
|
||||
local scale: number = if track and track.timescale and track.timescale > 0 then track.timescale else 1000
|
||||
local start = demuxer.startTime or 0
|
||||
v.startTime = start
|
||||
local defaultDur = if v.frameRate > 0 then 1 / v.frameRate else 0
|
||||
@@ -468,8 +468,8 @@ function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDec
|
||||
if t + 1e-9 >= skipUntil then
|
||||
index += 1
|
||||
local d = defaultDur
|
||||
if lastPts and t > lastPts and defaultDur == 0 then
|
||||
d = t - lastPts
|
||||
if lastPts and t > (lastPts :: number) and defaultDur == 0 then
|
||||
d = t - (lastPts :: number)
|
||||
end
|
||||
lastPts = t
|
||||
if o.rgba then
|
||||
|
||||
Reference in new issue
Block a user