H.264: Cabac / Cavlc resolved once per process (upvalue), not per slice; AAC: SBR / PS required with the first SBR element (AacSbr chunk: an AAC-LC open compiles 55 KB, not 203 KB); m4a: Alac required for an ALAC track; chunked build: Vp8 / Vp8L and the Opus CELT encoder in chunks of their own; load check: AAC-LC and HE-AACv2 m4a opens

This commit is contained in:
4DBug committed 2026-11-03 02:51:47 -06:00
1 parent 05a44e1193
commit 3f0a0df9c7
12 files changed
+4057 -3950

No files matched your search

+26 -13
View File
@@ -20855,7 +20855,11 @@ local Pcm = __include("codecs/audio/Pcm")
local Stream = __include("codecs/audio/Stream")
local IsoBmff = __include("containers/IsoBmff")
local Aac = __include("codecs/audio/Aac")
local Alac = __include("codecs/audio/Alac")
-- codecs/audio/Alac, required for an ALAC track
local function alac(): any
return __include("codecs/audio/Alac")
end
-- ------------------------------------------------------------------------------------------------ contract
local M4a = {
@@ -20915,11 +20919,11 @@ local function packetDecoder(t: IsoBmff.Track, buf: buffer, sbr: boolean?): (Pac
return nil, Err.new(Err.CORRUPT, "track " .. t.id .. " (" .. t.codec .. ") has no codec configuration")
end
if t.codec == "alac" then
local cfg, err = Alac.config(t.config :: buffer)
local cfg, err = alac().config(t.config :: buffer)
if not cfg then
return nil, err
end
local dec = Alac.decoder(cfg)
local dec = alac().decoder(cfg)
local pcm = table.create(cfg.frameLength * cfg.channels, 0)
local scale = 1 / 2 ^ (cfg.bitDepth - 1)
local pd: PacketDecoder = {
@@ -21086,11 +21090,11 @@ function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
end
local sr, ch = value.sampleRate, value.channels
local enc, eerr = Alac.encoder({ sampleRate = sr, channels = ch, bitDepth = o.bitDepth or 16, frameLength = o.frameLength })
local enc, eerr = alac().encoder({ sampleRate = sr, channels = ch, bitDepth = o.bitDepth or 16, frameLength = o.frameLength })
if not enc then
return nil, eerr
end
local e = enc :: Alac.Encoder
local e: any = enc
local depth = e.config.bitDepth
local fl = e.config.frameLength
local peak = 2 ^ (depth - 1)
@@ -21169,7 +21173,7 @@ function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
sampleRate = sr,
channels = ch,
bitsPerSample = depth,
config = Alac.cookie(e.config),
config = alac().cookie(e.config),
},
},
tags = tags,
@@ -27268,7 +27272,6 @@ __FILES["codecs/audio/Aac"] = function()
local Err = __include("core/Err")
local Bits = __include("core/Bits")
local Decode = __include("codecs/audio/Aac/Decode")
local Sbr = __include("codecs/audio/Aac/Sbr")
local Aac = {}
@@ -27538,7 +27541,7 @@ local function reset(self: Decoder)
c.prevShape = 0
end
for _, e in self.state.sbrElems do
Sbr.restart(e)
__include("codecs/audio/Aac/Sbr").restart(e)
end
end
@@ -27674,7 +27677,7 @@ __FILES["codecs/audio/Aac/Decode"] = function()
-- Written from the standard; no third-party code. PNS uses FFmpeg's LCG so the noise matches it.
local Mdct = __include("codecs/audio/Mdct")
local Tables = __include("codecs/audio/Aac/Tables")
local Sbr = __include("codecs/audio/Aac/Sbr")
local Sbr: any = nil -- codecs/audio/Aac/Sbr (and Ps), required with the first SBR element
local readu32, byteswap, lshift, rshift, band = buffer.readu32, bit32.byteswap, bit32.lshift, bit32.rshift, bit32.band
local floor, sqrt, abs = math.floor, math.sqrt, math.abs
@@ -28412,6 +28415,9 @@ end
local function sbrElement(st: State, i: number, nch: number): any
local e = st.sbrElems[i]
if not e or e.nch ~= nch then
if Sbr == nil then
Sbr = __include("codecs/audio/Aac/Sbr")
end
e = Sbr.element(nch, st.sbrRate, st.psOut and nch == 1)
st.sbrElems[i] = e
end
@@ -28575,7 +28581,8 @@ function Decode.frame(st: State, buf: buffer, off: number, len: number): (number
if kind == 13 or kind == 14 then -- EXT_SBR_DATA / EXT_SBR_DATA_CRC
st.sbr = true
if st.sbrOn and nElem > 0 and lastElement ~= 3 then
Sbr.extension(sbrElement(st, nElem, if lastElement == 1 then 2 else 1), B, start + 4, count * 8 - 4, kind == 14)
local e = sbrElement(st, nElem, if lastElement == 1 then 2 else 1)
Sbr.extension(e, B, start + 4, count * 8 - 4, kind == 14)
end
end
st.extensions += 1
@@ -110887,6 +110894,7 @@ local Deblock = __include("codecs/video/H264/Deblock")
local Inter = __include("codecs/video/H264/Inter")
local Pool = __include("codecs/video/Video/Pool")
local Types = __include("Types")
local Cabac: any, Cavlc: any = nil, nil -- the entropy decoder a stream uses, required on its first slice
local PAD, PADC = Inter.PAD, Inter.PADC
local CHROMA_QP = Tables.CHROMA_QP
@@ -111806,11 +111814,16 @@ local function decodeSlice(self: any, sh: any, r: Bitstream.Reader)
local before = 0
local st = S.sliceTab
local ok, err
-- the entropy decoder the stream uses, required on its first slice
if pps.cabac then
ok, err = __include("codecs/video/H264/Cabac").slice(S, self.M, r)
if Cabac == nil then
Cabac = __include("codecs/video/H264/Cabac")
end
ok, err = Cabac.slice(S, self.M, r)
else
ok, err = __include("codecs/video/H264/Cavlc").slice(S, self.M, r)
if Cavlc == nil then
Cavlc = __include("codecs/video/H264/Cavlc")
end
ok, err = Cavlc.slice(S, self.M, r)
end
for i = 1, #st do
if st[i] ~= 0 then