refbuf

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: BSD-2-Clause Imports: 0 Imported by: 1 module, 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 refbuf manages VP9 reference frame buffers (spec §8.9.1).

VP9 maintains 8 named reference frame slots (indices 0..7). Each frame header carries a refresh_frame_flags bitmask that tells the decoder which slots to overwrite with the just-decoded frame. Three of the 8 slots have special names used during prediction:

LAST_FRAME   = slot pointed to by ref_frame_idx[0]
GOLDEN_FRAME = slot pointed to by ref_frame_idx[1]
ALTREF_FRAME = slot pointed to by ref_frame_idx[2]

The three per-frame indices are decoded from the frame header; this package stores them in Refs and exposes accessor methods.

Frame layout

Each Frame stores one luma (Y) plane and two chroma (U, V) planes. All planes have an BORDER-pixel border on every side (VP9 requires ≥ 8 pixels; we use 8). The pixel at position (row, col) of an N-wide plane is at:

buf[BORDER*stride + BORDER + row*stride + col]

where stride = width + 2*BORDER.

Index

Constants

View Source
const BORDER = 96

BORDER is the number of pixels added on every side of each plane for sub-pixel filter access. The 8-tap filter needs ±3..+4, but inter motion vectors point past the frame edge, and the MC reads the reference's border there. libvpx's decoder carries a 32-pixel border and falls back to an on-demand edge-replicating copy (extend_and_predict) for reads beyond it. We instead carry a wide border (replicating the frame edge, identical result to extend_and_predict) so any MV within BORDER pixels of the edge is exact.

Variables

This section is empty.

Functions

func ExtendBorders

func ExtendBorders(f *Frame)

ExtendBorders replicates the edge pixels of each plane into the border region so that sub-pixel filters always have valid data to read.

func ExtendBorders16 added in v0.2.0

func ExtendBorders16(f *Frame16)

ExtendBorders16 replicates each visible edge into the border (see Frame).

Types

type Buffer

type Buffer struct {

	// Refs[0..2] are the slot indices for LAST, GOLDEN, ALTREF respectively.
	// Values are in [0,7]; default to 0 before any frame is decoded.
	Refs [3]int
	// contains filtered or unexported fields
}

Buffer holds VP9's 8 named reference frame slots. Slot indices 0..7 correspond to the hardware frame buffer pool. The three active reference frames are identified by Refs[0..2].

func (*Buffer) AltRef

func (b *Buffer) AltRef() *Frame

AltRef returns the ALTREF_FRAME reference (slot Refs[2]).

func (*Buffer) Get

func (b *Buffer) Get(slot int) *Frame

Get returns the frame currently stored in the given slot index (0..7). Returns nil if the slot has not been filled yet.

func (*Buffer) Golden

func (b *Buffer) Golden() *Frame

Golden returns the GOLDEN_FRAME reference (slot Refs[1]).

func (*Buffer) Last

func (b *Buffer) Last() *Frame

Last returns the LAST_FRAME reference (slot Refs[0]).

func (*Buffer) SetRef

func (b *Buffer) SetRef(idx, slotIndex int)

SetRef updates one of the three active reference indices (idx=0 for LAST, 1 for GOLDEN, 2 for ALTREF) to point to slotIndex.

func (*Buffer) Update

func (b *Buffer) Update(frame *Frame, refreshMask uint8)

Update stores frame f into each slot whose bit is set in refreshMask (refreshMask bit k → slot k, per VP9 spec §8.9.1). After the update it also applies ExtendBorders to keep each refreshed frame's border consistent.

type Buffer16 added in v0.2.0

type Buffer16 struct {
	Refs [3]int
	// contains filtered or unexported fields
}

Buffer16 holds VP9's 8 reference-frame slots for 16-bit frames.

func (*Buffer16) AltRef added in v0.2.0

func (b *Buffer16) AltRef() *Frame16

func (*Buffer16) Get added in v0.2.0

func (b *Buffer16) Get(slot int) *Frame16

func (*Buffer16) Golden added in v0.2.0

func (b *Buffer16) Golden() *Frame16

func (*Buffer16) Last added in v0.2.0

func (b *Buffer16) Last() *Frame16

func (*Buffer16) SetRef added in v0.2.0

func (b *Buffer16) SetRef(idx, slotIndex int)

func (*Buffer16) Update added in v0.2.0

func (b *Buffer16) Update(frame *Frame16, refreshMask uint8)

type Frame

type Frame struct {
	// Y, U, V are the luma and chroma planes including their borders.
	Y, U, V []byte

	// Stride is the row stride (in bytes) of each plane.
	// For Y:   stride = width  + 2*BORDER
	// For U/V: stride = width/2 + 2*BORDER  (4:2:0)
	YStride, UVStride int

	// Width and height of the visible picture in pixels.
	Width, Height int
}

Frame is one decoded reference frame (4:2:0 planar, 8-bit).

func NewFrame

func NewFrame(width, height int) *Frame

NewFrame allocates a zero-initialised Frame for a 4:2:0 picture.

func (*Frame) UBase

func (f *Frame) UBase() int

UBase returns the linear index of pixel (0,0) in the U plane.

func (*Frame) VBase

func (f *Frame) VBase() int

VBase returns the linear index of pixel (0,0) in the V plane.

func (*Frame) YBase

func (f *Frame) YBase() int

YBase returns the linear index of pixel (0,0) in the Y plane.

type Frame16 added in v0.2.0

type Frame16 struct {
	Y, U, V           []uint16
	YStride, UVStride int
	Width, Height     int
	BitDepth          int // 10 or 12
}

Frame16 is one decoded reference frame with 16-bit samples (VP9 profile 2/3, 10/12-bit). It mirrors Frame but stores []uint16 planes; the 8-bit Frame is left untouched so its bit-exact pipeline is unaffected.

func NewFrame16 added in v0.2.0

func NewFrame16(width, height, bitDepth int) *Frame16

NewFrame16 allocates a zero-initialised 16-bit 4:2:0 frame.

func (*Frame16) UBase added in v0.2.0

func (f *Frame16) UBase() int

func (*Frame16) VBase added in v0.2.0

func (f *Frame16) VBase() int

func (*Frame16) YBase added in v0.2.0

func (f *Frame16) YBase() int

Jump to

Keyboard shortcuts

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