video_decoder removed; fix video regression and updated to no-zstd

This commit is contained in:
minjaesong
2026-05-10 05:56:56 +09:00
parent b27ef0dbf9
commit 2cdd731c3b
63 changed files with 127 additions and 31850 deletions

View File

@@ -275,6 +275,7 @@ class AudioJSR223Delegate(private val vm: VM) {
// while the following code does work, it was decided that MP3 is "too new" for tsvm and thus removed.
/*
js-mp3
https://github.com/soundbus-technologies/js-mp3

View File

@@ -5433,6 +5433,18 @@ class GraphicsJSR223Delegate(private val vm: VM) {
private val TAV_QLUT = intArrayOf(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,256,264,272,280,288,296,304,312,320,328,336,344,352,360,368,376,384,392,400,408,416,424,432,440,448,456,464,472,480,488,496,504,512,528,544,560,576,592,608,624,640,656,672,688,704,720,736,752,768,784,800,816,832,848,864,880,896,912,928,944,960,976,992,1008,1024,1056,1088,1120,1152,1184,1216,1248,1280,1312,1344,1376,1408,1440,1472,1504,1536,1568,1600,1632,1664,1696,1728,1760,1792,1824,1856,1888,1920,1952,1984,2016,2048,2112,2176,2240,2304,2368,2432,2496,2560,2624,2688,2752,2816,2880,2944,3008,3072,3136,3200,3264,3328,3392,3456,3520,3584,3648,3712,3776,3840,3904,3968,4032,4096)
// Zstd magic = 0x28 0xB5 0x2F 0xFD (little-endian frame magic).
// Newer TAV files default to no Zstd (Video Flags bit 4); detecting the magic
// lets the decoder accept both compressed and raw payloads transparently.
private fun tavDecompressIfZstd(data: ByteArray): ByteArray {
if (data.size >= 4 &&
data[0] == 0x28.toByte() && data[1] == 0xB5.toByte() &&
data[2] == 0x2F.toByte() && data[3] == 0xFD.toByte()) {
return ZstdInputStream(ByteArrayInputStream(data)).use { it.readBytes() }
}
return data
}
// New tavDecode function that accepts compressed data and decompresses internally
fun tavDecodeCompressed(compressedDataPtr: Long, compressedSize: Int, currentRGBAddr: Long, prevRGBAddr: Long,
width: Int, height: Int, qIndex: Int, qYGlobal: Int, qCoGlobal: Int, qCgGlobal: Int, channelLayout: Int,
@@ -5445,12 +5457,9 @@ class GraphicsJSR223Delegate(private val vm: VM) {
}
return try {
// Decompress using Zstd
val bais = ByteArrayInputStream(compressedData)
val zis = ZstdInputStream(bais)
val decompressedData = zis.readBytes()
zis.close()
bais.close()
// Decompress with Zstd if the payload starts with the Zstd frame magic;
// otherwise pass through (TAV files written without --zstd-level).
val decompressedData = tavDecompressIfZstd(compressedData)
// Allocate buffer for decompressed data
val decompressedBuffer = vm.malloc(decompressedData.size)
@@ -6725,9 +6734,9 @@ class GraphicsJSR223Delegate(private val vm: VM) {
)
val decompressedData = try {
ZstdInputStream(java.io.ByteArrayInputStream(compressedData)).use { zstd ->
zstd.readBytes()
}
// Decompress with Zstd if the payload starts with the Zstd frame magic;
// otherwise pass through (TAV files written without --zstd-level).
tavDecompressIfZstd(compressedData)
} catch (e: Exception) {
println("ERROR: Zstd decompression failed: ${e.message}")
return arrayOf(0, dbgOut)

View File

@@ -911,24 +911,32 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) {
((tadInputBin[offset++].toUint()) shl 8)
)
val maxIndex = tadInputBin[offset++].toUint()
val payloadSize = (
val payloadSizeField = (
(tadInputBin[offset++].toUint()) or
((tadInputBin[offset++].toUint()) shl 8) or
((tadInputBin[offset++].toUint()) shl 16) or
((tadInputBin[offset++].toUint()) shl 24)
)
// Decompress payload
// MSB of payload size = 1 means the payload is stored uncompressed (no Zstd).
val payloadIsRaw = (payloadSizeField and 0x80000000.toInt()) != 0
val payloadSize = payloadSizeField and 0x7FFFFFFF
// Read payload bytes
val compressed = ByteArray(payloadSize)
UnsafeHelper.memcpyRaw(null, tadInputBin.ptr + offset, compressed, UnsafeHelper.getArrayOffset(compressed), payloadSize.toLong())
val payload: ByteArray = try {
ZstdInputStream(ByteArrayInputStream(compressed)).use { zstd ->
zstd.readBytes()
val payload: ByteArray = if (payloadIsRaw) {
compressed
} else {
try {
ZstdInputStream(ByteArrayInputStream(compressed)).use { zstd ->
zstd.readBytes()
}
} catch (e: Exception) {
println("ERROR: Zstd decompression failed: ${e.message}")
return
}
} catch (e: Exception) {
println("ERROR: Zstd decompression failed: ${e.message}")
return
}
// Decode using binary tree EZBC - FIXED!

View File

@@ -12,5 +12,7 @@
<orderEntry type="library" name="jetbrains.kotlin.reflect" level="project" />
<orderEntry type="library" name="jetbrains.kotlin.test" level="project" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="badlogicgames.gdx" level="project" />
<orderEntry type="library" name="badlogicgames.gdx.backend.lwjgl3" level="project" />
</component>
</module>