Skip to main content

TSMPCodec

Namespace: K13A.TSMP

Base type for codec handlers.

A codec handler tells the encoder how to write payload bytes into pixels and tells the decoder which material/options should be used to recover payload bytes.

Public fields

FieldTypeUse
codecIdushortStable codec ID written into the frame header.
displayNamestringEditor-facing name.
codecOptionBytesbyte[]Decoder-side option bytes copied from the frame header.
selectedDecodeMaterialMaterialMaterial used for byte decode.
payloadStartRowintFirst payload row for decode.
payloadBlockCountintNumber of payload blocks to decode.
byteCountintRequested payload byte count.

Runtime encoder query result fields are public for Udon event bridge use. They are assigned by OnTSMPEncoderQuery() and OnTSMPEncoderWritePayload().

Runtime encode methods

MethodUse
GetEncoderSymbolMode()Return symbol mode for frame header.
GetEncoderPayloadStartRow(width, blockSize)Return first payload row.
GetEncoderPayloadCapacityBytes(width, height, blockSize)Return payload byte capacity.
GetEncoderCodecOptionByteCount()Return option byte count, max 5.
GetEncoderCodecOptionByte(index)Return one option byte.
WriteEncoderPayload(...)Write payload bytes into encoder pixels.
ApplyDecodeOptions()Apply decoder state from header/options.

These methods must be UdonSharp-compatible if the codec should run inside VRChat.

Helper methods

MethodUse
ReadCodecOptionByte(index, fallback)Read one codec option with fallback.
ReadCodecOptionFlag(index, fallback)Read one option as a boolean.
GetEncoderActiveWidthBlocks(width, blockSize)Calculate writable block width.
GetEncoderActiveHeightBlocks(height, blockSize)Calculate writable block height.
WriteEncoderColorBlockAtIndex(...)Fill one encoded block with a color.
ReadEncoderBits(...)Read arbitrary bits from payload bytes.

Editor/native methods

Available outside COMPILER_UDONSHARP:

MethodUse
SymbolModeNative symbol mode property.
TryWriteFrame(...)Write complete frame into a Texture2D.
GetCodecOptionBytes()Native codec option byte array.
DecodeMaterialCountNumber of decode materials.
GetDecodeMaterial(index)Decode material lookup.
DebugMaterialCountNumber of debug materials.
GetDebugMaterial(index)Debug material lookup.
ConfigureMaterials(context)Configure decode/debug materials.

Udon event bridge

TSMPCodec exposes public event methods used by the encoder:

MethodPurpose
OnTSMPEncoderQuery()Populates encoder query result fields.
OnTSMPEncoderWritePayload()Calls WriteEncoderPayload and stores the result.

The encoder uses this bridge so optional codec packages can be called without hard-coding codec classes.