Documentation
¶
Overview ¶
Package hevc parses the HEVC syntax a hardware decoder that takes parsed parameters (VA-API) needs from an Annex B stream: NAL units, the sequence and picture parameter sets, slice segment headers, reference picture sets and picture order counts (ITU-T H.265, 7.3 and 8.3); and writes the parameter sets and slice headers of a low-delay stream, for a hardware encoder that takes them packed (VA-API).
It covers the Main and Main 10 profiles: 4:2:0, no range or screen content extensions.
Index ¶
- Constants
- Variables
- func IsIDR(t int) bool
- func IsIRAP(t int) bool
- func NALType(nal []byte) int
- func NALUnits(au []byte) [][]byte
- func ParseSliceHeader(nal []byte, sps map[uint32]*SPS, pps map[uint32]*PPS, prev *SliceHeader) (*SliceHeader, *SPS, *PPS, error)
- type Colour
- type POC
- type PPS
- type SPS
- type ScalingList
- type ShortTermRPS
- type Slice
- type SliceHeader
- type Stream
Constants ¶
const ( NalTrailN = 0 NalRASLR = 9 NalBLAWLP = 16 NalIDRWRADL = 19 NalIDRNLP = 20 NalCRA = 21 NalRsvIRAP23 = 23 NalVPS = 32 NalSPS = 33 NalPPS = 34 NalAUD = 35 )
NAL unit types (Table 7-1).
const ( SliceB = 0 SliceP = 1 SliceI = 2 )
Slice types.
Variables ¶
var ErrSyntax = errors.New("hevc: malformed syntax")
ErrSyntax is the error of a parameter set or slice header that ends early or holds a value out of range.
Functions ¶
func NALUnits ¶
NALUnits returns the NAL units of an Annex B access unit, without their start codes or trailing zero bytes.
func ParseSliceHeader ¶
func ParseSliceHeader(nal []byte, sps map[uint32]*SPS, pps map[uint32]*PPS, prev *SliceHeader) (*SliceHeader, *SPS, *PPS, error)
ParseSliceHeader parses the header of a slice segment NAL unit, header included. pps and sps are the parameter sets by id; prev is the picture's previous independent segment, whose fields a dependent one takes.
Types ¶
type Colour ¶
type Colour struct {
Primaries, Transfer, Matrix uint8
}
Colour is the VUI colour description, as ITU-T H.273 code points.
type POC ¶
type POC struct {
// contains filtered or unexported fields
}
POC derives picture order counts (8.3.1) across a stream.
type PPS ¶
type PPS struct {
ID, SPSID uint32
DependentSliceSegments bool
OutputFlagPresent bool
NumExtraSliceHeaderBits uint32
SignDataHiding, CabacInitPresent bool
NumRefIdxL0DefaultMinus1 uint32
NumRefIdxL1DefaultMinus1 uint32
InitQPMinus26 int32
ConstrainedIntraPred, TransformSkip bool
CuQPDeltaEnabled bool
DiffCuQPDeltaDepth uint32
CbQPOffset, CrQPOffset int32
SliceChromaQPOffsetsPresent bool
WeightedPred, WeightedBipred bool
TransquantBypass bool
Tiles, EntropyCodingSync bool
NumTileColumnsMinus1, NumTileRowsMinus1 uint32
UniformSpacing bool
ColumnWidthMinus1 []uint32
RowHeightMinus1 []uint32
LoopFilterAcrossTiles bool
LoopFilterAcrossSlices bool
DeblockingOverrideEnabled bool
DeblockingDisabled bool
BetaOffsetDiv2, TcOffsetDiv2 int32
ScalingListPresent bool
ScalingList ScalingList
ListsModificationPresent bool
Log2ParallelMergeLevelMinus2 uint32
SliceSegmentHeaderExtensionPresent bool
}
PPS is a picture parameter set, the fields a decoder needs.
type SPS ¶
type SPS struct {
ID uint32
MaxSubLayersMinus1 uint32
ChromaFormatIdc uint32
SeparateColourPlane bool
Width, Height uint32
ConfLeft, ConfRight, ConfTop, ConfBot uint32
BitDepthLuma, BitDepthChroma uint32 // minus 8
Log2MaxPocLsb uint32 // log2_max_pic_order_cnt_lsb_minus4 + 4
MaxDecPicBufferingMinus1 uint32 // of the highest sub-layer
MaxNumReorder uint32
Log2MinCbMinus3, Log2DiffMaxMinCb uint32
Log2MinTbMinus2, Log2DiffMaxMinTb uint32
MaxTHDepthInter, MaxTHDepthIntra uint32
ScalingListEnabled bool
ScalingList ScalingList
AMP, SAO bool
PCM bool
PCMBitDepthLuma, PCMBitDepthChroma uint32 // minus 1
Log2MinPCMMinus3, Log2DiffMaxMinPCM uint32
PCMLoopFilterDisabled bool
ShortTermRPS []ShortTermRPS
LongTermRefsPresent bool
LtRefPicPocLsb []uint32
LtUsedByCurr []bool
TemporalMVP bool
StrongIntraSmoothing bool
}
SPS is a sequence parameter set, the fields a decoder needs.
func (*SPS) VisibleSize ¶
VisibleSize is the picture's size inside its conformance window.
type ScalingList ¶
type ScalingList struct {
List4 [6][16]uint8
List8 [6][64]uint8
List16 [6][64]uint8
List32 [6][64]uint8 // matrixId 0 and 3 are used
DC16 [6]uint8
DC32 [6]uint8
}
ScalingList holds scaling factors in coded (up-right diagonal) order, ScalingList[sizeId][matrixId][i] of 7.4.5, and the DC factors of the 16x16 and 32x32 lists.
func DefaultScalingList ¶
func DefaultScalingList() ScalingList
DefaultScalingList is Table 7-5 and 7-6, in coded order.
type ShortTermRPS ¶
type ShortTermRPS struct {
NumNegative, NumPositive int
DeltaPocS0, DeltaPocS1 [16]int32
UsedS0, UsedS1 [16]bool
}
ShortTermRPS is a short-term reference picture set (7.4.8): the POC deltas before and after the current picture, and which the current picture uses.
type Slice ¶
type Slice struct {
IDR bool
Type int // SliceI, SliceP or SliceB
// Address is the slice's first CTB in raster order; 0 starts the
// picture.
Address uint32
PocLsb uint32
QPDelta int32
// SAOLuma and SAOChroma, when the stream has SAO.
SAOLuma, SAOChroma bool
TemporalMVP bool
}
Slice is one slice segment of a picture.
type SliceHeader ¶
type SliceHeader struct {
NalType int
TemporalID int
FirstSliceSegmentInPic bool
NoOutputOfPriorPics bool
PPSID uint32
Dependent bool
SegmentAddress uint32
Type int
PicOutput bool
ColourPlaneID uint32
PocLsb uint32
ShortTermInSPS bool
ShortTermIdx int
// ShortTerm is the short-term RPS the slice uses, its own or the
// SPS's; ShortTermBits the bits of the slice's own.
ShortTerm ShortTermRPS
ShortTermBits int
// Long-term pictures: POC LSBs, the MSB cycle when present, used by
// the current picture or not.
NumLongTerm int
LtPoc [32]int32
LtMSBPresent [32]bool
LtMSBCycle [32]int32 // DeltaPocMsbCycleLt
LtUsedByCurr [32]bool
TemporalMVP bool
SAOLuma bool
SAOChroma bool
NumRefIdxL0 int // active, not minus 1
NumRefIdxL1 int
ListModL0 bool
ListModL1 bool
ListEntryL0 [16]uint32
ListEntryL1 [16]uint32
MvdL1Zero bool
CabacInit bool
CollocFromL0 bool
CollocRefIdx uint32
FiveMinusMaxMergeCand uint32
LumaLog2WeightDenom uint32
ChromaLog2WeightDenom int32 // the delta
LumaWeightL0 [16]int32 // delta_luma_weight, 0 when absent
LumaOffsetL0 [16]int32
ChromaWeightL0 [16][2]int32 // delta_chroma_weight
ChromaOffsetL0 [16][2]int32 // ChromaOffsetL0, derived
LumaWeightL1 [16]int32
LumaOffsetL1 [16]int32
ChromaWeightL1 [16][2]int32
ChromaOffsetL1 [16][2]int32
QPDelta int32
CbQPOffset, CrQPOffset int32
DeblockingDisabled bool
BetaOffsetDiv2 int32
TcOffsetDiv2 int32
LoopFilterAcrossSlices bool
NumEntryPointOffsets uint32
// DataOffset is where the slice data starts, in bytes of the NAL unit
// as it is, emulation prevention bytes included; EPBInHeader counts
// those before it.
DataOffset int
EPBInHeader int
}
SliceHeader is a slice segment header (7.3.6.1), with what a decoder derives from it.
func (*SliceHeader) NumPicTotalCurr ¶
func (h *SliceHeader) NumPicTotalCurr() int
NumPicTotalCurr is the pictures the current one may reference (7-55).
type Stream ¶
type Stream struct {
ProfileIdc uint32 // 1 Main, 2 Main 10
LevelIdc uint32 // 30 times the level
// Width and Height are the coded size, a multiple of the minimum
// coding block; the conformance window crops it to VisibleWidth and
// VisibleHeight.
Width, Height uint32
VisibleWidth, VisibleHeight uint32
BitDepthMinus8 uint32
Log2MaxPocLsb uint32 // 4 to 16
Log2MinCbMinus3, Log2DiffMaxMinCb uint32
Log2MinTbMinus2, Log2DiffMaxMinTb uint32
MaxTHDepthInter, MaxTHDepthIntra uint32
AMP, SAO, TemporalMVP bool
StrongIntraSmoothing bool
InitQPMinus26 int32
SignDataHiding bool
ConstrainedIntraPred bool
TransformSkip bool
CuQPDelta bool
LoopFilterAcrossSlices bool
FiveMinusMaxMergeCand uint32
Colour *Colour
MaxDecPicBufferingMinus1 uint32
}
Stream is what an encoder fixes for a whole stream: what its VPS, SPS and PPS say, and what each slice header takes from them. It describes a low-delay stream of one temporal layer: IDR pictures and pictures predicted from the one before, 4:2:0, no scaling lists, PCM, tiles, long-term references or weighted prediction.
func (*Stream) SliceHeader ¶
SliceHeader is the slice segment NAL unit of h with no slice data: its header up to the byte alignment, as a VA-API packed slice header. Pictures after an IDR reference the one before them alone.