chunked build: detect check (F.detect on common headers loads the Detect chunk only, Detect under 160 KB); sniff extraction skips table and type keys (Aac.adts no longer pulls core/Bits into Detect); guide: chunk layout
This commit is contained in:
1 parent
62fcfa7e93
commit
45f6cbc7a8
11 files changed
+1610
-1571
No files matched your search
@@ -3627,15 +3627,7 @@ end
|
||||
local P_codecs_audio_Aac: any = {}
|
||||
do -- codecs/audio/Aac: adts
|
||||
local Aac = {}
|
||||
local Bits = __include("core/Bits")
|
||||
Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }
|
||||
local function objectType(br: Bits.BitReader): number
|
||||
local t = br:read(5)
|
||||
if t == 31 then
|
||||
t = 32 + br:read(6)
|
||||
end
|
||||
return t
|
||||
end
|
||||
type Adts = {
|
||||
headerSize: number, -- 7, or 9 with a CRC
|
||||
frameSize: number,
|
||||
|
||||
+618
-618
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"Core": [[8, "src/Rosetta/init.luau"], [941, "src/Rosetta/Registry.luau"], [3558, "src/Rosetta/Types.luau"], [4675, "src/Rosetta/core/Bytes.luau"], [5202, "src/Rosetta/core/Err.luau"], [5284, "src/Rosetta/core/Input.luau"], [5360, "src/Rosetta/host/init.luau"]],
|
||||
"Detect": [[8, "src/Rosetta/Sniffs.luau"], [4247, "src/Rosetta/core/Bits.luau"], [4540, "src/Rosetta/core/Crc16.luau"], [4592, "src/Rosetta/core/Sniff.luau"]],
|
||||
"Detect": [[8, "src/Rosetta/Sniffs.luau"], [4239, "src/Rosetta/core/Crc16.luau"], [4291, "src/Rosetta/core/Sniff.luau"]],
|
||||
"Mpeg2": [[8, "src/Rosetta/codecs/video/Dsp.luau"], [846, "src/Rosetta/codecs/video/Mpeg1/init.luau"], [859, "src/Rosetta/codecs/video/Mpeg2/init.luau"], [1233, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], [2760, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], [2900, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"]],
|
||||
"H263": [[8, "src/Rosetta/codecs/video/H263/init.luau"], [165, "src/Rosetta/codecs/video/H263/Decoder.luau"], [1023, "src/Rosetta/codecs/video/H263/Tables.luau"]],
|
||||
"H264": [[8, "src/Rosetta/codecs/video/H264/init.luau"], [398, "src/Rosetta/codecs/video/H264/Bitstream.luau"], [673, "src/Rosetta/codecs/video/H264/Cabac.luau"], [1804, "src/Rosetta/codecs/video/H264/Cavlc.luau"], [2572, "src/Rosetta/codecs/video/H264/Deblock.luau"], [2834, "src/Rosetta/codecs/video/H264/Decoder.luau"], [3900, "src/Rosetta/codecs/video/H264/Inter.luau"], [4226, "src/Rosetta/codecs/video/H264/Intra.luau"], [4633, "src/Rosetta/codecs/video/H264/Mb.luau"], [5587, "src/Rosetta/codecs/video/H264/Params.luau"], [6035, "src/Rosetta/codecs/video/H264/Slice.luau"], [6287, "src/Rosetta/codecs/video/H264/Tables.luau"], [6329, "src/Rosetta/codecs/video/H264/Transform.luau"]],
|
||||
@@ -90,7 +90,7 @@
|
||||
"containers_MacFile": [[8, "src/Rosetta/containers/MacFile.luau"], [157, "src/Rosetta/containers/Ogg/init.luau"], [582, "src/Rosetta/containers/Ogg/Mux.luau"], [771, "src/Rosetta/containers/Ogg/Page.luau"]],
|
||||
"containers_Riff": [[8, "src/Rosetta/containers/Riff/init.luau"], [325, "src/Rosetta/containers/Tar.luau"]],
|
||||
"containers_Zip": [[8, "src/Rosetta/containers/Zip/init.luau"]],
|
||||
"core_Adler32": [[8, "src/Rosetta/core/Adler32.luau"], [68, "src/Rosetta/core/Base64.luau"], [296, "src/Rosetta/core/Crc32.luau"], [447, "src/Rosetta/core/Md5.luau"]],
|
||||
"core_Adler32": [[8, "src/Rosetta/core/Adler32.luau"], [68, "src/Rosetta/core/Base64.luau"], [296, "src/Rosetta/core/Bits.luau"], [589, "src/Rosetta/core/Crc32.luau"], [740, "src/Rosetta/core/Md5.luau"]],
|
||||
"data_cbor": [[8, "src/Rosetta/data/cbor/init.luau"], [107, "src/Rosetta/data/cbor/Codec.luau"], [676, "src/Rosetta/data/csv/init.luau"]],
|
||||
"data_ini": [[8, "src/Rosetta/data/ini/init.luau"], [254, "src/Rosetta/data/json/init.luau"], [346, "src/Rosetta/data/msgpack/init.luau"], [435, "src/Rosetta/data/msgpack/Codec.luau"], [877, "src/Rosetta/data/nbt/init.luau"]],
|
||||
"data_plist": [[8, "src/Rosetta/data/plist/init.luau"], [314, "src/Rosetta/data/plist/Binary.luau"], [581, "src/Rosetta/data/q3shader/init.luau"], [820, "src/Rosetta/data/q3skin/init.luau"], [916, "src/Rosetta/data/snbt/init.luau"]],
|
||||
|
||||
+296
-304
@@ -17,7 +17,6 @@ local __CHUNK = {
|
||||
["core/Input"] = "Core",
|
||||
["host"] = "Core",
|
||||
["Sniffs"] = "Detect",
|
||||
["core/Bits"] = "Detect",
|
||||
["core/Crc16"] = "Detect",
|
||||
["core/Sniff"] = "Detect",
|
||||
["codecs/video/Dsp"] = "Mpeg2",
|
||||
@@ -347,6 +346,7 @@ local __CHUNK = {
|
||||
["containers/Zip"] = "containers_Zip",
|
||||
["core/Adler32"] = "core_Adler32",
|
||||
["core/Base64"] = "core_Adler32",
|
||||
["core/Bits"] = "core_Adler32",
|
||||
["core/Crc32"] = "core_Adler32",
|
||||
["core/Md5"] = "core_Adler32",
|
||||
["data/cbor"] = "data_cbor",
|
||||
@@ -6095,7 +6095,7 @@ end
|
||||
<ProtectedString name="Source">--!optimize 2
|
||||
--!nocheck
|
||||
-- rosetta chunk Detect (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit.
|
||||
-- 4 modules (2 native: @native); the Rosetta root requires it when one of them is first included.
|
||||
-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included.
|
||||
-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where).
|
||||
return function(__FILES, __include)
|
||||
__FILES["Sniffs"] = function()
|
||||
@@ -6150,15 +6150,7 @@ end
|
||||
local P_codecs_audio_Aac: any = {}
|
||||
do -- codecs/audio/Aac: adts
|
||||
local Aac = {}
|
||||
local Bits = __include("core/Bits")
|
||||
Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }
|
||||
local function objectType(br: Bits.BitReader): number
|
||||
local t = br:read(5)
|
||||
if t == 31 then
|
||||
t = 32 + br:read(6)
|
||||
end
|
||||
return t
|
||||
end
|
||||
type Adts = {
|
||||
headerSize: number, -- 7, or 9 with a CRC
|
||||
frameSize: number,
|
||||
@@ -10337,299 +10329,6 @@ end
|
||||
|
||||
return S
|
||||
end
|
||||
__FILES["core/Bits"] = @native function()
|
||||
|
||||
|
||||
-- core/Bits: bit readers and writers, LSB-first (DEFLATE, GIF LZW, VP8L, ...) and MSB-first (JPEG entropy data
|
||||
-- without the 0xFF00 unstuffing, MPEG, H.264, FLAC, ...). Up to 32 bits per read / write.
|
||||
-- Plain arithmetic on an accumulator of at most 31 bits (no bit32 calls), exact on doubles, cheap on both runtimes.
|
||||
-- Never throws: reading past the end returns zero bits and sets the sticky `err` (Err.TRUNCATED).
|
||||
local Err = __include("core/Err")
|
||||
local Bytes = __include("core/Bytes")
|
||||
|
||||
local readu8, blen = buffer.readu8, buffer.len
|
||||
local floor = math.floor
|
||||
|
||||
local POW = table.create(33, 0)
|
||||
for i = 0, 32 do
|
||||
POW[i + 1] = 2 ^ i
|
||||
end
|
||||
|
||||
local Bits = {}
|
||||
Bits.POW = POW
|
||||
|
||||
type BitReader = {
|
||||
buf: buffer,
|
||||
pos: number, -- next byte to load
|
||||
limit: number,
|
||||
acc: number, -- loaded, unread bits
|
||||
cnt: number, -- how many
|
||||
err: Err.Err?,
|
||||
read: (BitReader, number) -> number,
|
||||
peek: (BitReader, number) -> number,
|
||||
skip: (BitReader, number) -> (),
|
||||
align: (BitReader) -> (),
|
||||
bytePos: (BitReader) -> number,
|
||||
bitsLeft: (BitReader) -> number,
|
||||
}
|
||||
|
||||
@native local function overrun(self: any)
|
||||
if not self.err then
|
||||
self.err = Err.new(Err.TRUNCATED, "bit stream ends early", self.limit)
|
||||
end
|
||||
end
|
||||
|
||||
-- LSB-first: the first bit of the stream is bit 0 of the first byte; a field's first bit is its least significant
|
||||
local Lsb = {}
|
||||
Lsb.__index = Lsb
|
||||
|
||||
@native local function lsbFill(self: any, n: number)
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do
|
||||
if pos < self.limit then
|
||||
acc += readu8(self.buf, pos) * POW[cnt + 1]
|
||||
pos += 1
|
||||
else
|
||||
overrun(self)
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
|
||||
@native function Lsb.read(self: any, n: number): number
|
||||
if n > 24 then
|
||||
local lo = Lsb.read(self, 16)
|
||||
return lo + Lsb.read(self, n - 16) * 65536
|
||||
end
|
||||
if self.cnt < n then
|
||||
lsbFill(self, n)
|
||||
end
|
||||
local m = POW[n + 1]
|
||||
local v = self.acc % m
|
||||
self.acc = (self.acc - v) / m
|
||||
self.cnt -= n
|
||||
return v
|
||||
end
|
||||
@native function Lsb.peek(self: any, n: number): number
|
||||
if self.cnt < n then
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do -- no error for peeking past the end: the bits are zeros
|
||||
if pos < self.limit then
|
||||
acc += readu8(self.buf, pos) * POW[cnt + 1]
|
||||
pos += 1
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
-- keep the loaded bytes only when they are all real (zero padding past the end is not data)
|
||||
if (pos - self.pos) * 8 == cnt - self.cnt then
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
return acc % POW[n + 1]
|
||||
end
|
||||
return self.acc % POW[n + 1]
|
||||
end
|
||||
@native function Lsb.skip(self: any, n: number)
|
||||
while n > 24 do
|
||||
Lsb.read(self, 24)
|
||||
n -= 24
|
||||
end
|
||||
Lsb.read(self, n)
|
||||
end
|
||||
@native function Lsb.align(self: any)
|
||||
local k = self.cnt % 8
|
||||
if k > 0 then
|
||||
Lsb.read(self, k)
|
||||
end
|
||||
end
|
||||
@native function Lsb.bytePos(self: any): number
|
||||
return self.pos - floor(self.cnt / 8)
|
||||
end
|
||||
@native function Lsb.bitsLeft(self: any): number
|
||||
return (self.limit - self.pos) * 8 + self.cnt
|
||||
end
|
||||
|
||||
-- MSB-first: the first bit of the stream is bit 7 of the first byte; a field's first bit is its most significant
|
||||
local Msb = {}
|
||||
Msb.__index = Msb
|
||||
|
||||
@native local function msbFill(self: any, n: number)
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do
|
||||
if pos < self.limit then
|
||||
acc = acc * 256 + readu8(self.buf, pos)
|
||||
pos += 1
|
||||
else
|
||||
acc *= 256
|
||||
overrun(self)
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
|
||||
@native function Msb.read(self: any, n: number): number
|
||||
if n > 24 then
|
||||
local hi = Msb.read(self, n - 16)
|
||||
return hi * 65536 + Msb.read(self, 16)
|
||||
end
|
||||
if self.cnt < n then
|
||||
msbFill(self, n)
|
||||
end
|
||||
local sh = POW[self.cnt - n + 1]
|
||||
local v = floor(self.acc / sh)
|
||||
self.acc -= v * sh
|
||||
self.cnt -= n
|
||||
return v
|
||||
end
|
||||
@native function Msb.peek(self: any, n: number): number
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do
|
||||
if pos < self.limit then
|
||||
acc = acc * 256 + readu8(self.buf, pos)
|
||||
pos += 1
|
||||
else
|
||||
acc *= 256
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
-- keep the loaded bytes only when they are all real (zero padding past the end is not data)
|
||||
if (pos - self.pos) * 8 == cnt - self.cnt then
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
return floor(acc / POW[cnt - n + 1])
|
||||
end
|
||||
@native function Msb.skip(self: any, n: number)
|
||||
while n > 24 do
|
||||
Msb.read(self, 24)
|
||||
n -= 24
|
||||
end
|
||||
Msb.read(self, n)
|
||||
end
|
||||
@native function Msb.align(self: any)
|
||||
local k = self.cnt % 8
|
||||
if k > 0 then
|
||||
Msb.read(self, k)
|
||||
end
|
||||
end
|
||||
Msb.bytePos = Lsb.bytePos
|
||||
Msb.bitsLeft = Lsb.bitsLeft
|
||||
|
||||
@native local function reader(meta: any, buf: buffer, offset: number?, length: number?): BitReader
|
||||
local n = blen(buf)
|
||||
local o = math.clamp(offset or 0, 0, n)
|
||||
local l = math.clamp(length or (n - o), 0, n - o)
|
||||
return setmetatable({ buf = buf, pos = o, limit = o + l, acc = 0, cnt = 0, err = nil }, meta) :: any
|
||||
end
|
||||
|
||||
@native function Bits.lsbReader(buf: buffer, offset: number?, length: number?): BitReader
|
||||
return reader(Lsb, buf, offset, length)
|
||||
end
|
||||
@native function Bits.msbReader(buf: buffer, offset: number?, length: number?): BitReader
|
||||
return reader(Msb, buf, offset, length)
|
||||
end
|
||||
|
||||
type BitWriter = {
|
||||
out: Bytes.Writer, -- the bytes so far (whole bytes only)
|
||||
acc: number,
|
||||
cnt: number,
|
||||
write: (BitWriter, number, number) -> (),
|
||||
align: (BitWriter) -> (),
|
||||
finish: (BitWriter) -> buffer,
|
||||
}
|
||||
|
||||
local LsbW = {}
|
||||
LsbW.__index = LsbW
|
||||
@native function LsbW.write(self: any, v: number, n: number)
|
||||
if n > 24 then
|
||||
local lo = v % 65536
|
||||
LsbW.write(self, lo, 16)
|
||||
LsbW.write(self, (v - lo) / 65536, n - 16)
|
||||
return
|
||||
end
|
||||
local acc = self.acc + (v % POW[n + 1]) * POW[self.cnt + 1]
|
||||
local cnt = self.cnt + n
|
||||
local out = self.out
|
||||
while cnt >= 8 do
|
||||
local byte = acc % 256
|
||||
out:u8(byte)
|
||||
acc = (acc - byte) / 256
|
||||
cnt -= 8
|
||||
end
|
||||
self.acc, self.cnt = acc, cnt
|
||||
end
|
||||
@native function LsbW.align(self: any)
|
||||
if self.cnt > 0 then
|
||||
self.out:u8(self.acc)
|
||||
self.acc, self.cnt = 0, 0
|
||||
end
|
||||
end
|
||||
@native function LsbW.finish(self: any): buffer
|
||||
LsbW.align(self)
|
||||
return self.out:finish()
|
||||
end
|
||||
|
||||
local MsbW = {}
|
||||
MsbW.__index = MsbW
|
||||
@native function MsbW.write(self: any, v: number, n: number)
|
||||
if n > 24 then
|
||||
local lo = v % 65536
|
||||
MsbW.write(self, (v - lo) / 65536, n - 16)
|
||||
MsbW.write(self, lo, 16)
|
||||
return
|
||||
end
|
||||
local acc = self.acc * POW[n + 1] + (v % POW[n + 1])
|
||||
local cnt = self.cnt + n
|
||||
local out = self.out
|
||||
while cnt >= 8 do
|
||||
local sh = POW[cnt - 8 + 1]
|
||||
local byte = floor(acc / sh)
|
||||
out:u8(byte)
|
||||
acc -= byte * sh
|
||||
cnt -= 8
|
||||
end
|
||||
self.acc, self.cnt = acc, cnt
|
||||
end
|
||||
@native function MsbW.align(self: any)
|
||||
if self.cnt > 0 then
|
||||
self.out:u8(self.acc * POW[8 - self.cnt + 1])
|
||||
self.acc, self.cnt = 0, 0
|
||||
end
|
||||
end
|
||||
@native function MsbW.finish(self: any): buffer
|
||||
MsbW.align(self)
|
||||
return self.out:finish()
|
||||
end
|
||||
|
||||
-- w = { buf, pos, acc, cnt }: no growth (the caller keeps buf large enough); acc holds cnt < 8 bits
|
||||
type RawWriter = { buf: buffer, pos: number, acc: number, cnt: number }
|
||||
@native function Bits.msbPut(w: RawWriter, v: number, n: number)
|
||||
if n == 0 then
|
||||
return
|
||||
end
|
||||
local acc = w.acc * POW[n + 1] + v
|
||||
local cnt = w.cnt + n
|
||||
local b, p = w.buf, w.pos
|
||||
while cnt >= 8 do
|
||||
cnt -= 8
|
||||
local m = POW[cnt + 1]
|
||||
local byte = floor(acc / m)
|
||||
buffer.writeu8(b, p, byte)
|
||||
p += 1
|
||||
acc -= byte * m
|
||||
end
|
||||
w.acc, w.cnt, w.pos = acc, cnt, p
|
||||
end
|
||||
|
||||
@native function Bits.lsbWriter(capacity: number?): BitWriter
|
||||
return setmetatable({ out = Bytes.writer(capacity), acc = 0, cnt = 0 }, LsbW) :: any
|
||||
end
|
||||
@native function Bits.msbWriter(capacity: number?): BitWriter
|
||||
return setmetatable({ out = Bytes.writer(capacity), acc = 0, cnt = 0 }, MsbW) :: any
|
||||
end
|
||||
|
||||
return Bits
|
||||
end
|
||||
__FILES["core/Crc16"] = @native function()
|
||||
|
||||
|
||||
@@ -136343,7 +136042,7 @@ end
|
||||
<ProtectedString name="Source">--!optimize 2
|
||||
--!nocheck
|
||||
-- rosetta chunk core_Adler32 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit.
|
||||
-- 4 modules (4 native: @native); the Rosetta root requires it when one of them is first included.
|
||||
-- 5 modules (5 native: @native); the Rosetta root requires it when one of them is first included.
|
||||
-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where).
|
||||
return function(__FILES, __include)
|
||||
__FILES["core/Adler32"] = @native function()
|
||||
@@ -136634,6 +136333,299 @@ end
|
||||
|
||||
return Base64
|
||||
end
|
||||
__FILES["core/Bits"] = @native function()
|
||||
|
||||
|
||||
-- core/Bits: bit readers and writers, LSB-first (DEFLATE, GIF LZW, VP8L, ...) and MSB-first (JPEG entropy data
|
||||
-- without the 0xFF00 unstuffing, MPEG, H.264, FLAC, ...). Up to 32 bits per read / write.
|
||||
-- Plain arithmetic on an accumulator of at most 31 bits (no bit32 calls), exact on doubles, cheap on both runtimes.
|
||||
-- Never throws: reading past the end returns zero bits and sets the sticky `err` (Err.TRUNCATED).
|
||||
local Err = __include("core/Err")
|
||||
local Bytes = __include("core/Bytes")
|
||||
|
||||
local readu8, blen = buffer.readu8, buffer.len
|
||||
local floor = math.floor
|
||||
|
||||
local POW = table.create(33, 0)
|
||||
for i = 0, 32 do
|
||||
POW[i + 1] = 2 ^ i
|
||||
end
|
||||
|
||||
local Bits = {}
|
||||
Bits.POW = POW
|
||||
|
||||
type BitReader = {
|
||||
buf: buffer,
|
||||
pos: number, -- next byte to load
|
||||
limit: number,
|
||||
acc: number, -- loaded, unread bits
|
||||
cnt: number, -- how many
|
||||
err: Err.Err?,
|
||||
read: (BitReader, number) -> number,
|
||||
peek: (BitReader, number) -> number,
|
||||
skip: (BitReader, number) -> (),
|
||||
align: (BitReader) -> (),
|
||||
bytePos: (BitReader) -> number,
|
||||
bitsLeft: (BitReader) -> number,
|
||||
}
|
||||
|
||||
@native local function overrun(self: any)
|
||||
if not self.err then
|
||||
self.err = Err.new(Err.TRUNCATED, "bit stream ends early", self.limit)
|
||||
end
|
||||
end
|
||||
|
||||
-- LSB-first: the first bit of the stream is bit 0 of the first byte; a field's first bit is its least significant
|
||||
local Lsb = {}
|
||||
Lsb.__index = Lsb
|
||||
|
||||
@native local function lsbFill(self: any, n: number)
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do
|
||||
if pos < self.limit then
|
||||
acc += readu8(self.buf, pos) * POW[cnt + 1]
|
||||
pos += 1
|
||||
else
|
||||
overrun(self)
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
|
||||
@native function Lsb.read(self: any, n: number): number
|
||||
if n > 24 then
|
||||
local lo = Lsb.read(self, 16)
|
||||
return lo + Lsb.read(self, n - 16) * 65536
|
||||
end
|
||||
if self.cnt < n then
|
||||
lsbFill(self, n)
|
||||
end
|
||||
local m = POW[n + 1]
|
||||
local v = self.acc % m
|
||||
self.acc = (self.acc - v) / m
|
||||
self.cnt -= n
|
||||
return v
|
||||
end
|
||||
@native function Lsb.peek(self: any, n: number): number
|
||||
if self.cnt < n then
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do -- no error for peeking past the end: the bits are zeros
|
||||
if pos < self.limit then
|
||||
acc += readu8(self.buf, pos) * POW[cnt + 1]
|
||||
pos += 1
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
-- keep the loaded bytes only when they are all real (zero padding past the end is not data)
|
||||
if (pos - self.pos) * 8 == cnt - self.cnt then
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
return acc % POW[n + 1]
|
||||
end
|
||||
return self.acc % POW[n + 1]
|
||||
end
|
||||
@native function Lsb.skip(self: any, n: number)
|
||||
while n > 24 do
|
||||
Lsb.read(self, 24)
|
||||
n -= 24
|
||||
end
|
||||
Lsb.read(self, n)
|
||||
end
|
||||
@native function Lsb.align(self: any)
|
||||
local k = self.cnt % 8
|
||||
if k > 0 then
|
||||
Lsb.read(self, k)
|
||||
end
|
||||
end
|
||||
@native function Lsb.bytePos(self: any): number
|
||||
return self.pos - floor(self.cnt / 8)
|
||||
end
|
||||
@native function Lsb.bitsLeft(self: any): number
|
||||
return (self.limit - self.pos) * 8 + self.cnt
|
||||
end
|
||||
|
||||
-- MSB-first: the first bit of the stream is bit 7 of the first byte; a field's first bit is its most significant
|
||||
local Msb = {}
|
||||
Msb.__index = Msb
|
||||
|
||||
@native local function msbFill(self: any, n: number)
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do
|
||||
if pos < self.limit then
|
||||
acc = acc * 256 + readu8(self.buf, pos)
|
||||
pos += 1
|
||||
else
|
||||
acc *= 256
|
||||
overrun(self)
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
|
||||
@native function Msb.read(self: any, n: number): number
|
||||
if n > 24 then
|
||||
local hi = Msb.read(self, n - 16)
|
||||
return hi * 65536 + Msb.read(self, 16)
|
||||
end
|
||||
if self.cnt < n then
|
||||
msbFill(self, n)
|
||||
end
|
||||
local sh = POW[self.cnt - n + 1]
|
||||
local v = floor(self.acc / sh)
|
||||
self.acc -= v * sh
|
||||
self.cnt -= n
|
||||
return v
|
||||
end
|
||||
@native function Msb.peek(self: any, n: number): number
|
||||
local acc, cnt, pos = self.acc, self.cnt, self.pos
|
||||
while cnt < n do
|
||||
if pos < self.limit then
|
||||
acc = acc * 256 + readu8(self.buf, pos)
|
||||
pos += 1
|
||||
else
|
||||
acc *= 256
|
||||
end
|
||||
cnt += 8
|
||||
end
|
||||
-- keep the loaded bytes only when they are all real (zero padding past the end is not data)
|
||||
if (pos - self.pos) * 8 == cnt - self.cnt then
|
||||
self.acc, self.cnt, self.pos = acc, cnt, pos
|
||||
end
|
||||
return floor(acc / POW[cnt - n + 1])
|
||||
end
|
||||
@native function Msb.skip(self: any, n: number)
|
||||
while n > 24 do
|
||||
Msb.read(self, 24)
|
||||
n -= 24
|
||||
end
|
||||
Msb.read(self, n)
|
||||
end
|
||||
@native function Msb.align(self: any)
|
||||
local k = self.cnt % 8
|
||||
if k > 0 then
|
||||
Msb.read(self, k)
|
||||
end
|
||||
end
|
||||
Msb.bytePos = Lsb.bytePos
|
||||
Msb.bitsLeft = Lsb.bitsLeft
|
||||
|
||||
@native local function reader(meta: any, buf: buffer, offset: number?, length: number?): BitReader
|
||||
local n = blen(buf)
|
||||
local o = math.clamp(offset or 0, 0, n)
|
||||
local l = math.clamp(length or (n - o), 0, n - o)
|
||||
return setmetatable({ buf = buf, pos = o, limit = o + l, acc = 0, cnt = 0, err = nil }, meta) :: any
|
||||
end
|
||||
|
||||
@native function Bits.lsbReader(buf: buffer, offset: number?, length: number?): BitReader
|
||||
return reader(Lsb, buf, offset, length)
|
||||
end
|
||||
@native function Bits.msbReader(buf: buffer, offset: number?, length: number?): BitReader
|
||||
return reader(Msb, buf, offset, length)
|
||||
end
|
||||
|
||||
type BitWriter = {
|
||||
out: Bytes.Writer, -- the bytes so far (whole bytes only)
|
||||
acc: number,
|
||||
cnt: number,
|
||||
write: (BitWriter, number, number) -> (),
|
||||
align: (BitWriter) -> (),
|
||||
finish: (BitWriter) -> buffer,
|
||||
}
|
||||
|
||||
local LsbW = {}
|
||||
LsbW.__index = LsbW
|
||||
@native function LsbW.write(self: any, v: number, n: number)
|
||||
if n > 24 then
|
||||
local lo = v % 65536
|
||||
LsbW.write(self, lo, 16)
|
||||
LsbW.write(self, (v - lo) / 65536, n - 16)
|
||||
return
|
||||
end
|
||||
local acc = self.acc + (v % POW[n + 1]) * POW[self.cnt + 1]
|
||||
local cnt = self.cnt + n
|
||||
local out = self.out
|
||||
while cnt >= 8 do
|
||||
local byte = acc % 256
|
||||
out:u8(byte)
|
||||
acc = (acc - byte) / 256
|
||||
cnt -= 8
|
||||
end
|
||||
self.acc, self.cnt = acc, cnt
|
||||
end
|
||||
@native function LsbW.align(self: any)
|
||||
if self.cnt > 0 then
|
||||
self.out:u8(self.acc)
|
||||
self.acc, self.cnt = 0, 0
|
||||
end
|
||||
end
|
||||
@native function LsbW.finish(self: any): buffer
|
||||
LsbW.align(self)
|
||||
return self.out:finish()
|
||||
end
|
||||
|
||||
local MsbW = {}
|
||||
MsbW.__index = MsbW
|
||||
@native function MsbW.write(self: any, v: number, n: number)
|
||||
if n > 24 then
|
||||
local lo = v % 65536
|
||||
MsbW.write(self, (v - lo) / 65536, n - 16)
|
||||
MsbW.write(self, lo, 16)
|
||||
return
|
||||
end
|
||||
local acc = self.acc * POW[n + 1] + (v % POW[n + 1])
|
||||
local cnt = self.cnt + n
|
||||
local out = self.out
|
||||
while cnt >= 8 do
|
||||
local sh = POW[cnt - 8 + 1]
|
||||
local byte = floor(acc / sh)
|
||||
out:u8(byte)
|
||||
acc -= byte * sh
|
||||
cnt -= 8
|
||||
end
|
||||
self.acc, self.cnt = acc, cnt
|
||||
end
|
||||
@native function MsbW.align(self: any)
|
||||
if self.cnt > 0 then
|
||||
self.out:u8(self.acc * POW[8 - self.cnt + 1])
|
||||
self.acc, self.cnt = 0, 0
|
||||
end
|
||||
end
|
||||
@native function MsbW.finish(self: any): buffer
|
||||
MsbW.align(self)
|
||||
return self.out:finish()
|
||||
end
|
||||
|
||||
-- w = { buf, pos, acc, cnt }: no growth (the caller keeps buf large enough); acc holds cnt < 8 bits
|
||||
type RawWriter = { buf: buffer, pos: number, acc: number, cnt: number }
|
||||
@native function Bits.msbPut(w: RawWriter, v: number, n: number)
|
||||
if n == 0 then
|
||||
return
|
||||
end
|
||||
local acc = w.acc * POW[n + 1] + v
|
||||
local cnt = w.cnt + n
|
||||
local b, p = w.buf, w.pos
|
||||
while cnt >= 8 do
|
||||
cnt -= 8
|
||||
local m = POW[cnt + 1]
|
||||
local byte = floor(acc / m)
|
||||
buffer.writeu8(b, p, byte)
|
||||
p += 1
|
||||
acc -= byte * m
|
||||
end
|
||||
w.acc, w.cnt, w.pos = acc, cnt, p
|
||||
end
|
||||
|
||||
@native function Bits.lsbWriter(capacity: number?): BitWriter
|
||||
return setmetatable({ out = Bytes.writer(capacity), acc = 0, cnt = 0 }, LsbW) :: any
|
||||
end
|
||||
@native function Bits.msbWriter(capacity: number?): BitWriter
|
||||
return setmetatable({ out = Bytes.writer(capacity), acc = 0, cnt = 0 }, MsbW) :: any
|
||||
end
|
||||
|
||||
return Bits
|
||||
end
|
||||
__FILES["core/Crc32"] = @native function()
|
||||
|
||||
|
||||
|
||||
@@ -4269,15 +4269,7 @@ end
|
||||
local P_codecs_audio_Aac= {}
|
||||
do -- codecs/audio/Aac: adts
|
||||
local Aac = {}
|
||||
local Bits = __include("core/Bits")
|
||||
Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }
|
||||
local function objectType(br)
|
||||
local t = br:read(5)
|
||||
if t == 31 then
|
||||
t = 32 + br:read(6)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
+618
-618
File diff suppressed because it is too large.
Load diff
@@ -44,9 +44,10 @@ as `F`, and its input files as variables such as `pngBytes` (a buffer) or `srtTe
|
||||
**Roblox.** Two builds, both committed (rebuilt by `python3 -I tools/build.py roblox`):
|
||||
|
||||
- [`build/Rosetta.rbxm`](../../build/Rosetta.rbxm), the native build: a ModuleScript `Rosetta` with child
|
||||
ModuleScripts, the chunks (Core, one per heavy codec such as Mpeg2, H264, Jpeg, Opus, and the rest by folder). A
|
||||
chunk is required the first time one of its modules is, so an Actor that only decodes MPEG-1 and JPEG loads only
|
||||
those chunks and Core. Roblox compiles native code per ModuleScript within a budget per module; each chunk stays
|
||||
ModuleScripts, the chunks (Core; Detect, the sniffs `F.detect` runs; one per heavy codec such as Mpeg2, H264, Jpeg,
|
||||
Opus; and one per format folder, codec or container, small neighbours packed together). A chunk is required the
|
||||
first time one of its modules is, so an Actor that only decodes MPEG-1 and JPEG loads only those chunks and Core,
|
||||
and `F.detect` compiles Detect alone. Roblox compiles native code per ModuleScript within a budget per module; each chunk stays
|
||||
well under it (tools/bundle.py checks it). Insert the file, or mount it with Rojo
|
||||
(`"Rosetta": { "$path": "rosetta/build/Rosetta.rbxm" }`; this repository's `default.project.json` does, so
|
||||
`rojo build -o Rosetta.rbxm` or `rojo serve` works from here). [`build/Rosetta.rbxmx`](../../build/Rosetta.rbxmx)
|
||||
|
||||
@@ -49,15 +49,7 @@ end
|
||||
local P_codecs_audio_Aac: any = {}
|
||||
do -- codecs/audio/Aac: adts
|
||||
local Aac = {}
|
||||
local Bits = require("@rosetta/core/Bits")
|
||||
Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }
|
||||
local function objectType(br: Bits.BitReader): number
|
||||
local t = br:read(5)
|
||||
if t == 31 then
|
||||
t = 32 + br:read(6)
|
||||
end
|
||||
return t
|
||||
end
|
||||
type Adts = {
|
||||
headerSize: number, -- 7, or 9 with a CRC
|
||||
frameSize: number,
|
||||
|
||||
+69
-1
@@ -252,7 +252,8 @@ def bundle_roblox():
|
||||
# Chunks: Core; Detect (DETECT: what F.detect runs, apart from Core); one per hot codec (HOT); then one per unit (a
|
||||
# format folder, a codec or container with its submodules), small neighbours of a family (top folder, or
|
||||
# codecs/<category>) packed up to UNIT_PACK bytes; a chunk is named after its first unit (image_png, containers_Riff).
|
||||
# So opening a format compiles its own modules and what they use, not its family.
|
||||
# So opening a format compiles its own modules and what they use, not its family; F.detect compiles Detect alone
|
||||
# (detect_check).
|
||||
# A --!native module's functions get @native (a chunk can mix native and non-native modules); a chunk with no native
|
||||
# module has none. Outputs: build/Rosetta.rbxm (LZ4, written by model/rbxm under the luau CLI), build/Rosetta.rbxmx,
|
||||
# build/Rosetta.rbxm.linemap.json ({chunk: [[first line, source file], ...]}).
|
||||
@@ -462,6 +463,7 @@ def bundle_chunked(mods, native, deps):
|
||||
if not text.startswith("--!optimize 2\n"):
|
||||
sys.exit("bundle: chunk %s does not start with --!optimize 2" % name)
|
||||
codegen_check([("Rosetta", root)] + sources, chunks, native)
|
||||
detect_check(root, sources)
|
||||
write_rbxm(root, sources)
|
||||
|
||||
|
||||
@@ -509,6 +511,72 @@ def codegen_check(sources, chunks, native):
|
||||
if bad:
|
||||
sys.exit("bundle: chunk budget:\n " + "\n ".join(bad))
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ detect check
|
||||
# F.detect on common inputs loads the Detect chunk only (DETECT_CASES: a header and a name), and Detect stays under
|
||||
# DETECT_MAX source bytes: requiring the root and a first F.detect compile Core + Detect, nothing else. Run under the
|
||||
# luau CLI on a copy of the chunked tree whose root records the chunks it requires.
|
||||
DETECT_MAX = 160 * 1024
|
||||
DETECT_CASES = [ # (format, header, file name)
|
||||
("mp4", "\\0\\0\\0\\32ftypisom\\0\\0\\2\\0isomiso2avc1mp41\\0\\0\\0\\8free", "x.mp4"),
|
||||
("png", "\\137PNG\\r\\n\\26\\n\\0\\0\\0\\13IHDR\\0\\0\\0\\1\\0\\0\\0\\1\\8\\6\\0\\0\\0", "x.png"),
|
||||
("jpeg", "\\255\\216\\255\\224\\0\\16JFIF\\0\\1\\1\\0\\0\\1\\0\\1\\0\\0", "x.jpg"),
|
||||
("wav", "RIFF\\36\\0\\0\\0WAVEfmt \\16\\0\\0\\0\\1\\0\\1\\0\\68\\172\\0\\0\\136\\88\\1\\0\\2\\0\\16\\0", "x.wav"),
|
||||
("mp3", "ID3\\3\\0\\0\\0\\0\\0\\0\\255\\251\\144\\100", "x.mp3"),
|
||||
("vorbis", "OggS\\0\\2\\0\\0\\0\\0\\0\\0\\0\\0\\1\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\1\\30\\1vorbis", "x.ogg"),
|
||||
("gltf", "glTF\\2\\0\\0\\0\\20\\0\\0\\0", "x.glb"),
|
||||
("gif", "GIF89a\\1\\0\\1\\0\\0\\0\\0", "x.gif"),
|
||||
("zip", "PK\\3\\4\\20\\0\\0\\0\\0\\0", "x.zip"),
|
||||
("flac", "fLaC\\0\\0\\0\\34", "x.flac"),
|
||||
]
|
||||
DETECT_CHECK = """local F = require("./Rosetta")
|
||||
local __ROSETTA_CHUNKS = F._chunksLoaded
|
||||
local out = {}
|
||||
for _, c in __CASES__ do
|
||||
local before = #__ROSETTA_CHUNKS
|
||||
local name = F.detect(buffer.fromstring(c[2]), { name = c[3] })
|
||||
local got = {}
|
||||
for i = before + 1, #__ROSETTA_CHUNKS do
|
||||
table.insert(got, __ROSETTA_CHUNKS[i])
|
||||
end
|
||||
table.insert(out, c[1] .. "\\t" .. tostring(name) .. "\\t" .. table.concat(got, " "))
|
||||
end
|
||||
print(table.concat(out, "\\n"))
|
||||
"""
|
||||
|
||||
|
||||
def detect_check(root, sources):
|
||||
d = os.path.join(MODULES, "chunked", "detect_check")
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
shutil.copytree(CHUNKED, os.path.join(d, "Rosetta"))
|
||||
hook = "\trequire(m)(__FILES, __include)\n"
|
||||
if hook not in root:
|
||||
sys.exit("bundle: detect check: the root's chunk require changed")
|
||||
with open(os.path.join(d, "Rosetta", "init.luau"), "w") as f:
|
||||
f.write(root.replace(hook, "\ttable.insert(__CHUNKS_LOADED, name)\n" + hook).replace(
|
||||
"local __FILES = {}", "local __CHUNKS_LOADED = {}\nlocal __FILES = {}", 1).replace(
|
||||
"\nreturn Rosetta\n", "\nRosetta._chunksLoaded = __CHUNKS_LOADED\nreturn Rosetta\n"))
|
||||
cases = "{ " + ", ".join('{ "%s", "%s", "%s" }' % c for c in DETECT_CASES) + " }"
|
||||
with open(os.path.join(d, "check.luau"), "w") as f:
|
||||
f.write(DETECT_CHECK.replace("__CASES__", cases))
|
||||
r = subprocess.run(tool("luau") + ["check.luau"], capture_output=True, text=True, cwd=d)
|
||||
if r.returncode != 0:
|
||||
sys.exit("bundle: detect check failed:\n" + (r.stdout + r.stderr)[-3000:])
|
||||
bad = []
|
||||
for line in r.stdout.strip().split("\n"):
|
||||
case, name, got = (line.split("\t") + [""])[:3]
|
||||
if name != case:
|
||||
bad.append("%s detected as %s" % (case, name))
|
||||
if [x for x in got.split() if x != "Detect"]:
|
||||
bad.append("detect %s loads chunks %s (only Detect: copy what its sniff reads, tools/sniff_extract.py)"
|
||||
% (case, got))
|
||||
size = len(dict(sources)["Detect"])
|
||||
if size > DETECT_MAX:
|
||||
bad.append("Detect: %d source bytes > %d" % (size, DETECT_MAX))
|
||||
if bad:
|
||||
sys.exit("bundle: detect check:\n " + "\n ".join(bad))
|
||||
print("bundle: Rosetta.rbxm detect loads Detect only (%s), %.0f KB" % (
|
||||
", ".join(c[0] for c in DETECT_CASES), size / 1024))
|
||||
|
||||
|
||||
def long_string(s):
|
||||
n = 0
|
||||
|
||||
@@ -85,7 +85,9 @@ def statements(text):
|
||||
|
||||
|
||||
def free_names(code):
|
||||
"""identifiers read by code that are not field / method names (an over-approximation: locals are included)"""
|
||||
"""identifiers read by code that are not field / method names or table / type keys ({ name = ..., name: T }; an
|
||||
over-approximation: locals are included)"""
|
||||
code = re.sub(r"([{,]\s*)" + NAME + r"(\s*(=(?!=)|:\s))", r"\1\2", code)
|
||||
return {m.group(1) for m in re.finditer(r"(?<![.:\w])\s*(" + NAME + r")", code)} - KEYWORDS
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user