decode

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 7 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 decode defines the hardware video decoder contract shared by the platform backends: Media Foundation on Direct3D 11 (Windows) and VideoToolbox (macOS). Decoded pictures stay on the GPU.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoFrame = errors.New("decode: no picture for this access unit")

ErrNoFrame means the access unit produced no picture yet (the decoder needs more input). It is not a failure.

View Source
var ErrUnsupported = errors.New("decode: unsupported by this decoder")

ErrUnsupported means no hardware decoder takes this codec or format.

Functions

func Register

func Register(b Backend)

Register makes b the decoder for its codec.

Types

type Backend

type Backend struct {
	Name  string
	Codec encode.Codec
	Open  func(t Target, cfg Config) (Decoder, error)
}

Backend opens a decoder for one codec on a Target.

type Config

type Config struct {
	Codec         encode.Codec
	Width, Height int
	FPS           int
	// Chroma and ChunkLen describe a PyroWave stream: its sampling and
	// depth, and the transport shard size its chunks are framed in.
	Chroma   encode.Chroma
	ChunkLen int
	// HDR10 says the pictures are BT.2020 PQ, for the sink that shows
	// them; decoders ignore it.
	HDR10 bool
}

Config is what the caller knows of the stream before the first access unit. Width and Height are hints; the bitstream's own size wins.

type Decoder

type Decoder interface {
	// Decode decodes one access unit (Annex B for HEVC, a temporal unit of
	// OBUs for AV1) and returns its picture.
	Decode(au []byte, pts int64) (Frame, error)
	// Release gives a picture back to the decoder's pool.
	Release(Frame)
	Close() error
}

Decoder turns access units into GPU pictures.

func Open

func Open(t Target, cfg Config) (Decoder, error)

Open opens the decoder registered for cfg.Codec on t.

type Finisher

type Finisher interface {
	Finish(f *Frame)
}

Finisher is a Decoder whose Decode returns before the GPU has written the picture, so that presenting it overlaps decoding. Finish blocks until the picture is written and sets f.Latency to the time from Decode's call, for callers that measure decoding.

type Frame

type Frame struct {
	// Surface is the picture: an ID3D11Texture2D* on Windows, an
	// IOSurfaceRef on macOS.
	Surface uintptr
	// Slice is the array slice of Surface that holds the picture; Windows
	// decoders write into texture arrays. 0 on macOS.
	Slice int
	// Format is NV12, P010 or BGRA8.
	Format capture.Format
	// Width and Height are the picture's visible size; the surface may be
	// larger (coded size, aligned).
	Width, Height int
	PTS           int64
	// Latency is the time from Decode's call to the picture being ready.
	Latency time.Duration
	// Ref is the backend's handle that keeps Surface alive (an IMFSample*,
	// a CVPixelBufferRef). Callers leave it alone.
	Ref uintptr
}

Frame is a decoded picture owned by the decoder until Release.

type Target

type Target struct {
	// Device is an ID3D11Device* on Windows, an id<MTLDevice> on macOS.
	Device uintptr
	// Queue is the surface's id<MTLCommandQueue> on macOS, shared so decode
	// and present run in order without a fence. 0 on Windows.
	Queue   uintptr
	Adapter gpu.Adapter
	// Accepts, on Linux, reports whether the presenting surface shows
	// DMA-BUFs of a DRM fourcc and modifier as they are. A decoder whose
	// pictures it does not accept (or with Accepts nil) copies them into
	// memory (capture.DMABuf.CPU).
	Accepts func(fourcc uint32, modifier uint64) bool
}

Target is the GPU a decoder writes its pictures on: the presenting surface's, so pictures never leave it.

Directories

Path Synopsis
Package d3d11 decodes HEVC and AV1 on the GPU of a Direct3D 11 device through a Media Foundation decoder transform made aware of the device (DXVA).
Package d3d11 decodes HEVC and AV1 on the GPU of a Direct3D 11 device through a Media Foundation decoder transform made aware of the device (DXVA).
internal
hostbuf
Package hostbuf keeps decoded Linux pictures in memory: NV12 or P010 planes in memfd-backed mappings, which a Wayland compositor maps as wl_shm buffers with no copy, described by capture.DMABuf with Memory set.
Package hostbuf keeps decoded Linux pictures in memory: NV12 or P010 planes in memfd-backed mappings, which a Wayland compositor maps as wl_shm buffers with no copy, described by capture.DMABuf with Memory set.
Package linuxdec picks a Linux hardware decoder: VA-API or NVDEC.
Package linuxdec picks a Linux hardware decoder: VA-API or NVDEC.
Package nvdec decodes HEVC and AV1 on NVIDIA GPUs under Linux with NVDEC, through libcuda.so.1 and libnvcuvid.so.1 loaded with purego (no cgo).
Package nvdec decodes HEVC and AV1 on NVIDIA GPUs under Linux with NVDEC, through libcuda.so.1 and libnvcuvid.so.1 loaded with purego (no cgo).
Package vaapi decodes HEVC on Linux with VA-API (Intel, AMD, and NVIDIA through nvidia-vaapi-driver), through libva.so.2 and libva-drm.so.2 loaded with purego (no cgo).
Package vaapi decodes HEVC on Linux with VA-API (Intel, AMD, and NVIDIA through nvidia-vaapi-driver), through libva.so.2 and libva-drm.so.2 loaded with purego (no cgo).
Package vt decodes HEVC and AV1 with Apple VideoToolbox through purego, with no cgo.
Package vt decodes HEVC and AV1 with Apple VideoToolbox through purego, with no cgo.

Jump to

Keyboard shortcuts

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