pyrowave

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	HeaderWords = 2
	// MaxRecordWords is what the 12-bit payload_words field can say.
	MaxRecordWords = 1<<12 - 1
)

Record sizes in 32-bit words.

View Source
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.

View Source
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
)
View Source
const (
	Levels = 5

	MaxDimension = 1 << 14
	BlockSize    = 32
)

Variables

View Source
var (
	ErrTruncated = errors.New("pyrowave: record runs past its chunk")
	ErrBadRecord = errors.New("pyrowave: malformed record")
)
View Source
var ErrNoHeader = errors.New("pyrowave: no sequence header in the frame")

ErrNoHeader means no chunk of the frame arrived with a sequence header.

View Source
var ErrTooLarge = errors.New("pyrowave: frame needs more than 16 slices of 255 chunks")

Functions

func Block8x8Scale

func Block8x8Scale(code uint8) float32

Block8x8Scale decodes the high nibble of an 8x8 block's QScale byte.

func Block32x32Scale

func Block32x32Scale(code uint8) float32

Block32x32Scale decodes a block header's quant_code: 3-bit mantissa, 5-bit exponent, a value in (0, 16).

func EncodeQuant

func EncodeQuant(scale float32) uint8

EncodeQuant is the quant_code whose Block32x32Scale is at most scale and shares its exponent: the inverse of Block32x32Scale for the encoder.

func QuantCode8x8

func QuantCode8x8(maxAbs float32) (uint8, float32)

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

func QuantResolution(level, component, kind int) float32

QuantResolution is the factor band coefficients are scaled by before truncation to integers, rounded to what quant_code can signal.

func RDOScale

func RDOScale(level, component, kind int, chroma420 bool) float32

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

func SubblockPlanes(cw uint16, qs uint8, s int) int

SubblockPlanes is the number of magnitude planes of subblock s of an 8x8 block with code word cw and QScale byte qs.

func Unswizzle8x8

func Unswizzle8x8(i int) (x, y int)

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.

func (Band) Blocks

func (b Band) Blocks() int

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 NewLayout

func NewLayout(width, height int, chroma420 bool) (*Layout, error)

NewLayout builds the layout of a width x height picture.

func (*Layout) BandOf

func (l *Layout) BandOf(block int) int

BandOf returns the index into Bands of the band holding block, or -1.

func (*Layout) FirstLevel

func (l *Layout) FirstLevel(c int) int

FirstLevel is the finest decomposition level of component c: chroma starts at level 1 under 4:2:0, where its plane is half size.

func (*Layout) PlaneSize

func (l *Layout) PlaneSize(c int) (int, int)

PlaneSize is the size of component c's full-resolution plane.

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 NewPacker

func NewPacker(l *Layout, chunkLen int) (*Packer, error)

func (*Packer) MaxFrameLen

func (p *Packer) MaxFrameLen() int

MaxFrameLen is the largest packed frame.

func (*Packer) Overhead

func (p *Packer) Overhead() float64

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).

func (*Packer) Pack

func (p *Packer) Pack(dst []byte, seq SequenceHeader, payload []byte) (Packed, error)

Pack writes the frame's chunks to dst (grown if needed). payload holds block records in any order, as the GPU wrote them; seq is the frame's sequence header. The returned SliceEnds alias the packer and are valid until the next Pack.

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 NewParser

func NewParser(l *Layout, chunkLen int) *Parser

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)

Directories

Path Synopsis
Package ref is a CPU PyroWave encoder and decoder in float32, the reference the GPU kernels are tested against.
Package ref is a CPU PyroWave encoder and decoder in float32, the reference the GPU kernels are tested against.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL