h264

package
v0.0.0-...-945029b Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DonDiff

func DonDiff(don1 uint16, don2 uint16) (diff int)

DonDiff may not be needed as uint16 automatically wraps on under/overflow.

func EBSPToRaw

func EBSPToRaw(buf []byte) []byte

EBSPToRaw removes emulation prevention bytes from the buffer transforming Encapsulated Byte Sequence Payload (EBSP) into Raw Byte Sequence Payload (RBSP).

func RBSPToEncapsulated

func RBSPToEncapsulated(buf []byte) []byte

RBSPToEncapsulated adds emulation prevention bytes to the buffer transforming Raw Byte Sequence Payload (RBSP) into Encapsulated Byte Sequence Payload (EBSP).

func SplitAnnexB

func SplitAnnexB(buf []byte) [][]byte

SplitAnnexB attempts to recognize a sequence of NALUs separated by start codes in the buffer. Returns a list of raw/unparsed units with emulation bytes removed.

Types

type BitReader

type BitReader struct {
	// contains filtered or unexported fields
}

BitReader implements bit stream reading for H.264 network layer processing.

func NewBitReader

func NewBitReader(buf []byte) *BitReader

NewBitReader creates a bit stream reader from a slice of bytes.

func (*BitReader) Available

func (r *BitReader) Available() uint

Available returns number of unread bits in the bit stream buffer.

func (*BitReader) ReadBits

func (r *BitReader) ReadBits(n uint) (val uint32, err error)

ReadBits attempts to read requested number of bits from the bit stream. Returns an error if running into end of stream prematurely.

func (*BitReader) ReadByteBits

func (r *BitReader) ReadByteBits(n uint) (val byte, err error)

ReadByteBits attempts to read a single byte from the bit stream. Returns an error if running into end of stream prematurely. Useful to assign result directly to byte target.

func (*BitReader) ReadFlag

func (r *BitReader) ReadFlag() (val bool, err error)

ReadFlag attempts to read a single bit from the bit stream. Returns an error if running into end of stream prematurely. Useful to assign result directly to boolean target.

func (*BitReader) ReadPayloadParam

func (r *BitReader) ReadPayloadParam() (val uint32, err error)

ReadPayloadParam parses payload type and size of SEI message from bit reader.

func (*BitReader) ReadScalingList

func (r *BitReader) ReadScalingList(list []int32) (useDefault bool, err error)

ReadScalingList reads scaling list into a slice and returns either an indicator to use default matrix or an error. The length of the list to read is driven by the length of the slice.

func (*BitReader) ReadSignedGolomb

func (r *BitReader) ReadSignedGolomb() (val int32, err error)

ReadSignedGolomb reads and decodes exponential golomb encoded value from a bit stream. and interprets it as signed value. Returns an error if running into end of stream prematurely.

func (*BitReader) ReadUnsignedGolomb

func (r *BitReader) ReadUnsignedGolomb() (val uint32, err error)

ReadUnsignedGolomb reads and decodes exponential golomb encoded value from a bit stream. Returns an error if running into end of stream prematurely.

func (*BitReader) SkipBits

func (r *BitReader) SkipBits(n uint) (err error)

SkipBits attempts to skip requested number of bits in the bit stream. Returns an error if running into end of stream prematurely.

func (*BitReader) SkipGolomb

func (r *BitReader) SkipGolomb() (err error)

SkipGolomb decodes exponential golomb encoded value in the bit stream and skips it. Returns an error if running into end of stream prematurely.

func (*BitReader) SkipTrailingBits

func (r *BitReader) SkipTrailingBits() (err error)

SkipTrailingBits ensures that remaining bits in the buffer consist of stop bit and variable number of aligning zero-bits;

type NALFragment

type NALFragment struct {
	NALUnit
	Flags byte
}

NALFragment represents NAL unit fragment together with fragment specidfic flags (start, end). +---------------+ |0|1|2|3|4|5|6|7| +-+-+-+-+-+-+-+-+ |S|E|R| Type | +---------------+ Start flag, End flag, Reserved must be 0, NAL payload Type

func (NALFragment) IsEnd

func (f NALFragment) IsEnd() bool

IsEnd returns end flag of the NAL unit fragment.

func (NALFragment) IsStart

func (f NALFragment) IsStart() bool

IsStart returns start flag of the NAL unit fragment.

type NALSink

type NALSink struct {
	Units     []NALUnit
	Fragments []NALFragment
	Don       uint16 // Decoding Order Number
}

NALSink handles NAL unit aggreagates and fragments

func NewNALSink

func NewNALSink() *NALSink

NewNALSink creates a sink to handle NAL unit aggreagates and fragments. Sink combines fragments to emit a unit into the queue and resets unit queue on each subsequent RTP packet. Fragment queue is reset upon receiving first fragment in a series.

func (*NALSink) AddFragment

func (s *NALSink) AddFragment(indicator byte, header byte, don uint16, ts uint32, data []byte)

AddFragment pushes NAL unit fragment into the fragment queue, resetting queue before accepting first fragment in a series. Upon receiving last fragment in a series, all fragments are combined into a NAL unit and added to the unit queue.

func (*NALSink) Push

func (s *NALSink) Push(buf []byte, ts uint32) error

Push RTP payload parsing NAL units and handling aggregation and fragmenting.

type NALUnit

type NALUnit struct {
	Header byte
	Don    uint16 // Decoding Order Number
	TS     uint32 // Timestamp
	Data   []byte
}

NALUnit describes a single Network Access Layer Unit in video stream. +---------------+ |0|1|2|3|4|5|6|7| +-+-+-+-+-+-+-+-+ |F|NRI| Type | +---------------+ Forbidden Zero bit, must be 0; NAL Ref Idc; NAL Type.

func (*NALUnit) RefIdc

func (u *NALUnit) RefIdc() byte

RefIdc returns NAL unit reference flag and importance.

func (*NALUnit) Type

func (u *NALUnit) Type() byte

Type returns type of NAL unit.

func (*NALUnit) ZeroBit

func (u *NALUnit) ZeroBit() bool

ZeroBit returns forbidden zero bit value of NAL header.

type PPSInfo

type PPSInfo struct {
	PpsID                              uint32
	SpsID                              uint32
	EntropyCodingMode                  bool
	BottomFieldPicOorderInFramePresent bool
	NumSliceGroupsMinus1               uint32 // 0..7, i.e. up to 8 groups
	SliceGroupMapType                  uint32
	RunLengthMinus1                    [8]uint32
	TopLeft                            [8]uint32
	BottomRight                        [8]uint32
	SliceGroupChangeDirection          bool
	SliceGroupChangeRateMinus1         uint32
	PicSizeInMapUnitsMinus1            uint32
	SliceGroupID                       []byte
	NumRefIdxL0DefaultActiveMinus1     uint32
	NumRefIdxL1DefaultActiveMinus1     uint32
	WeightedPred                       bool
	WeightedBipredIdc                  byte
	PicInitQpMinus26                   int32
	PicInitQsMinus26                   int32
	ChromaQpIndexOffset                int32
	DeblockingFilterControlPresent     bool
	ConstrainedIntraPred               bool
	RedundantPicCntPresent             bool
	Transform8x8Mode                   bool
	ScalingMatrixPresent               bool
	ScalingListPresent                 uint32
	ScalingList                        [6*16 + 6*64]int32
	UseDefaultScalingMatrix            [12]bool
	SecondChromaQpIndexOffset          int32
}

PPSInfo holds Picture Parameter Set information referenced by slices.

type ParameterSets

type ParameterSets struct {
	// contains filtered or unexported fields
}

ParameterSets keep all current parsed and indexed parameter sets for quick access.

func NewParameterSets

func NewParameterSets() *ParameterSets

NewParameterSets create an representation of indexed storage for sequence and picture parameter sets.

func (*ParameterSets) GetPPS

func (s *ParameterSets) GetPPS(id uint32) (pps *PPSInfo, ok bool)

GetPPS looks up PPS by id among currently available parameter sets.

func (*ParameterSets) GetSPS

func (s *ParameterSets) GetSPS(id uint32) (sps *SPSInfo, ok bool)

GetSPS looks up SPS by id among currently available parameter sets.

func (*ParameterSets) ParsePPS

func (s *ParameterSets) ParsePPS(buf []byte) (err error)

ParsePPS parses Picture Parameter Set information from a given buffer and adds it to the indexed list of available sets. Buffer can be out-of-band, coming from sprop-parameter-sets property in SDP. It could also come in-band in a NAL with respective type.

func (*ParameterSets) ParseSPS

func (s *ParameterSets) ParseSPS(buf []byte) (err error)

ParseSPS parses Sequence Parameter Set information from a given buffer and adds it to the indexed list of available sets. Buffer can be out-of-band, coming from sprop-parameter-sets property in SDP. It could also come in-band in a NAL with respective type.

func (*ParameterSets) ParseSprop

func (s *ParameterSets) ParseSprop(buf []byte) (err error)

ParseSprop analyzes value from SDP sprop parameter sets where first byte is a NAL header. To simplify code we do not fully queue and process NAL.

type SPSInfo

type SPSInfo struct {
	ProfileIdc                     byte
	ConstraintSet                  byte
	LevelIdc                       byte
	SpsID                          uint32
	ChromaFormatIdc                uint32
	SeparateColorPlane             bool
	BitDepthLuma                   uint32
	BitDepthChroma                 uint32
	ZeroTransformBypass            bool
	ScalingMatrixPresent           bool
	ScalingListPresent             uint32
	ScalingList                    [6*16 + 6*64]int32
	UseDefaultScalingMatrix        [12]bool
	Log2MaxFrameNum                uint32
	PicOrderCntType                uint32
	Log2MaxPicOrderCnt             uint32
	DeltaPicOrderAlways0           bool
	OffsetForNonRefPic             int32
	OffsetForTopToBottomField      int32
	NumRefFramesInPicOrderCntCycle uint32
	MaxNumRefFrames                uint32
	GapsInFrameNumValueAllowed     bool
	PicWidthInMbsMinus1            uint32
	PicHeightInMapUnitsMinus1      uint32
	FrameMbsOnly                   uint32
	MbAdaptiveFrameField           bool
	Direct8x8Inference             bool
	FrameCropping                  bool
	FrameCropLeftOffset            uint32
	FrameCropRightOffset           uint32
	FrameCropTopOffset             uint32
	FrameCropBottomOffset          uint32
	VuiParametersPresent           bool
	Width                          uint32
	Height                         uint32
}

SPSInfo holds Sequence Parameter Set information parsed from out-of-band or in-band data in the stream. Most of the information here is unused but parsed anyway. VUI parameters are no parsed at all.

Jump to

Keyboard shortcuts

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