Documentation
¶
Overview ¶
Package pyrowave is a Go port of PyroWave, Hans-Kristian Arntzen's intra-only wavelet video codec for local game streaming (https://github.com/Themaister/pyrowave, MIT, bitstream v1 at a32b05e0). The shader math in shaders/ is ported from the upstream MIT shaders; see LICENSE.pyrowave for the upstream notice.
Every frame stands alone: a 5-level CDF 9/7 wavelet per component, 32x32 coefficient blocks coded as raw bit-planes, and exact single-pass rate control. The host encodes with Direct3D 11 compute shaders on the capture GPU; clients decode with Metal (macOS) or Direct3D 11 (Windows) compute shaders straight into a presentable texture. Package ref holds a CPU encoder and decoder used as the reference in tests.
Transport framing (chunk.go): a frame is a run of chunks of the session's shard size, each holding whole 32-bit records. A missing chunk decodes as zero coefficients for its blocks, so loss blurs a region instead of freezing the stream. The codec is meant for LAN links only.
Index ¶
- Constants
- Variables
- func Block8x8Scale(code uint8) float32
- func Block32x32Scale(code uint8) float32
- func EncodeQuant(scale float32) uint8
- func QuantCode8x8(maxAbs float32) (uint8, float32)
- func QuantResolution(level, component, kind int) float32
- func RDOScale(level, component, kind int, chroma420 bool) float32
- func SubblockPlanes(cw uint16, qs uint8, s int) int
- func Unswizzle8x8(i int) (x, y int)
- type Band
- type BlockHeader
- type Layout
- type Packed
- type Packer
- type Parser
- type Rec
- type RecordKind
- type SequenceHeader
Constants ¶
const ( HeaderWords = 2 // MaxRecordWords is what the 12-bit payload_words field can say. MaxRecordWords = 1<<12 - 1 )
Record sizes in 32-bit words.
const ( ChromaRes420 = 0 ChromaRes444 = 1 PrimariesSRGB = 0 PrimariesBT2020 = 1 TransferSRGB = 0 TransferPQ = 1 MatrixBT709 = 0 MatrixBT2020 = 1 RangeFull = 0 RangeLimited = 1 SitingCenter = 0 SitingLeft = 1 )
Sequence header values.
const ( // MinChunkLen leaves room for the header and the largest 8x8 block. MinChunkLen = 256 // MaxSliceChunks is the data shard count per slice the packer aims for, // leaving room for parity under the 255-shard Reed-Solomon limit. MaxSliceChunks = 192 )
const ( Levels = 5 MaxDimension = 1 << 14 BlockSize = 32 )
Variables ¶
var ( ErrTruncated = errors.New("pyrowave: record runs past its chunk") ErrBadRecord = errors.New("pyrowave: malformed record") )
var ErrNoHeader = errors.New("pyrowave: no sequence header in the frame")
ErrNoHeader means no chunk of the frame arrived with a sequence header.
var ErrTooLarge = errors.New("pyrowave: frame needs more than 16 slices of 255 chunks")
Functions ¶
func Block8x8Scale ¶
Block8x8Scale decodes the high nibble of an 8x8 block's QScale byte.
func Block32x32Scale ¶
Block32x32Scale decodes a block header's quant_code: 3-bit mantissa, 5-bit exponent, a value in (0, 16).
func EncodeQuant ¶
EncodeQuant is the quant_code whose Block32x32Scale is at most scale and shares its exponent: the inverse of Block32x32Scale for the encoder.
func QuantCode8x8 ¶
QuantCode8x8 picks an 8x8 block's scale code from the magnitude of its largest quantized coefficient, so that magnitude lands just below a power of two, and returns the code and the factor to multiply coefficients by.
func QuantResolution ¶
QuantResolution is the factor band coefficients are scaled by before truncation to integers, rounded to what quant_code can signal.
func RDOScale ¶
RDOScale weights a band's squared coefficient error by a contrast sensitivity model (96 DPI, viewing distance of one screen height), so rate control spends bits where the eye sees them.
func SubblockPlanes ¶
SubblockPlanes is the number of magnitude planes of subblock s of an 8x8 block with code word cw and QScale byte qs.
func Unswizzle8x8 ¶
Unswizzle8x8 maps a coefficient's index inside an 8x8 block (subblock*8 + pixel) to its position.
Types ¶
type Band ¶
type Band struct {
Level, Component, Kind int // Kind: 0 LL, 1 HL, 2 LH, 3 HH
Width, Height int
BlocksX, BlocksY int
// FirstBlock is the block_index of the band's top-left 32x32 block.
FirstBlock int
}
Band is one coded sub-band of one component.
type BlockHeader ¶
type BlockHeader struct {
Ballot uint16
PayloadWords int
Sequence uint8
QuantCode uint8
BlockIndex int
}
BlockHeader is the 8-byte header of a 32x32 block record.
func ParseBlockHeader ¶
func ParseBlockHeader(b []byte) BlockHeader
func (BlockHeader) Put ¶
func (h BlockHeader) Put(b []byte)
type Layout ¶
type Layout struct {
Width, Height int
AlignedWidth, AlignedHeight int
Chroma420 bool
// Bands are in block_index order (level 4 to 0, Y Cb Cr, LL HL LH HH).
Bands []Band
TotalBlocks int
// CriticalBlocks is the number of leading blocks (levels 4 and 3) whose
// loss is visible as more than local blur.
CriticalBlocks int
}
Layout is the coefficient geometry of one picture size and chroma mode.
func (*Layout) FirstLevel ¶
FirstLevel is the finest decomposition level of component c: chroma starts at level 1 under 4:2:0, where its plane is half size.
type Packed ¶
type Packed struct {
Data []byte
// SliceEnds are the end offsets in Data of each slice; every slice is
// whole chunks.
SliceEnds []int
// Critical is the number of leading slices that hold levels 4 and 3.
Critical int
Chunks int
}
Packed is one packed frame.
type Packer ¶
type Packer struct {
// contains filtered or unexported fields
}
Packer arranges an encoder's block records into chunks. Not safe for concurrent use; it allocates only in NewPacker.
func (*Packer) MaxFrameLen ¶
MaxFrameLen is the largest packed frame.
func (*Packer) Overhead ¶
Overhead is the share of chunk bytes that do not carry block data, for budgeting: the per-chunk header and tail, plus split record headers and padding (about 2% measured at 1080p).
type Parser ¶
type Parser struct {
Recs []Rec
// Rejected counts records dropped as malformed, conflicting or stale.
Rejected int
// contains filtered or unexported fields
}
Parser validates the records of a received frame and gathers them, word aligned, for the GPU. Not safe for concurrent use.
func (*Parser) Parse ¶
func (p *Parser) Parse(au, upload []byte) (SequenceHeader, int, error)
Parse walks the chunks of au, copies every valid block record to upload and fills Recs. upload must hold len(au) bytes. Missing chunks are zero and skipped. It returns the frame's sequence header and the bytes used in upload.
type Rec ¶
type Rec struct {
// Word is the record's offset in the upload buffer, in 32-bit words.
Word int32
Words int32
Block int32
// Band indexes Layout.Bands.
Band int32
}
Rec is one validated block record copied to the decoder's upload buffer.
type RecordKind ¶
type RecordKind uint8
RecordKind says what a record in a word stream is.
const ( RecordEnd RecordKind = iota // a zero word: the rest of the chunk is empty RecordBlock RecordSequence RecordPadding )
func NextRecord ¶
func NextRecord(b []byte) (RecordKind, int, error)
NextRecord reads the record at the start of b (word aligned, little endian) and returns its kind and length in bytes.
type SequenceHeader ¶
type SequenceHeader struct {
Width, Height int
Sequence uint8
TotalBlocks int
Chroma uint8
Primaries uint8
Transfer uint8
Matrix uint8
Range uint8
Siting uint8
}
SequenceHeader is the start-of-frame record (extended = 1, code = 0).
func ParseSequenceHeader ¶
func ParseSequenceHeader(b []byte) (SequenceHeader, bool)
func (SequenceHeader) Put ¶
func (s SequenceHeader) Put(b []byte)