common

package
v4.0.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 10 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AVCCFrame

type AVCCFrame []byte // 一帧AVCC格式的数据

func (AVCCFrame) AudioCodecID

func (avcc AVCCFrame) AudioCodecID() codec.AudioCodecID

func (AVCCFrame) CTS

func (avcc AVCCFrame) CTS() uint32

func (AVCCFrame) IsIDR

func (avcc AVCCFrame) IsIDR() bool

func (AVCCFrame) IsSequence

func (avcc AVCCFrame) IsSequence() bool

func (AVCCFrame) VideoCodecID

func (avcc AVCCFrame) VideoCodecID() codec.VideoCodecID

type AVFrame

type AVFrame[T RawSlice] struct {
	BaseFrame
	IFrame bool
	PTS    uint32
	DTS    uint32
	FLV    net.Buffers // 打包好的FLV Tag
	AVCC   net.Buffers // 打包好的AVCC格式
	RTP    []*RTPFrame
	Raw    []T //裸数据
	// contains filtered or unexported fields
}

func (*AVFrame[T]) AppendAVCC

func (av *AVFrame[T]) AppendAVCC(avcc ...[]byte)

func (*AVFrame[T]) AppendRTP

func (av *AVFrame[T]) AppendRTP(rtp ...*RTPFrame)

func (*AVFrame[T]) AppendRaw

func (av *AVFrame[T]) AppendRaw(raw ...T)

func (*AVFrame[T]) FillFLV

func (av *AVFrame[T]) FillFLV(t byte, ts uint32)

func (*AVFrame[T]) Reset

func (av *AVFrame[T]) Reset()

type AVRing

type AVRing[T RawSlice] struct {
	RingBuffer[AVFrame[T]]
	Poll time.Duration
}

func (*AVRing[T]) Read

func (r *AVRing[T]) Read(ctx context.Context) (item *AVFrame[T])

func (*AVRing[T]) Step

func (r *AVRing[T]) Step() *AVFrame[T]

func (*AVRing[T]) TryRead

func (r *AVRing[T]) TryRead() (item *AVFrame[T])

type AVTrack

type AVTrack interface {
	Track
	Attach()
	Detach()
	WriteAVCC(ts uint32, frame AVCCFrame) //写入AVCC格式的数据
	Flush()
}

type AnnexBFrame

type AnnexBFrame []byte // 一帧AnnexB格式数据

type AudioSlice

type AudioSlice []byte

type AudioTrack

type AudioTrack interface {
	AVTrack
	GetDecoderConfiguration() DecoderConfiguration[AudioSlice]
	CurrentFrame() *AVFrame[AudioSlice]
	WriteSlice(AudioSlice)
	WriteADTS([]byte)
}

type BPS

type BPS struct {
	BPS int
	// contains filtered or unexported fields
}

func (*BPS) ComputeBPS

func (bps *BPS) ComputeBPS(bytes int)

type BaseFrame

type BaseFrame struct {
	DeltaTime uint32    // 相对上一帧时间戳,毫秒
	AbsTime   uint32    // 绝对时间戳,毫秒
	Timestamp time.Time // 写入时间,可用于比较两个帧的先后
	Sequence  uint32    // 在一个Track中的序号
	BytesIn   int       // 输入字节数用于计算BPS
}

type DTSEstimator

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

DTSEstimator is a DTS estimator.

func NewDTSEstimator

func NewDTSEstimator() *DTSEstimator

NewDTSEstimator allocates a DTSEstimator.

func (*DTSEstimator) Feed

func (d *DTSEstimator) Feed(pts uint32) uint32

Feed provides PTS to the estimator, and returns the estimated DTS.

type DataFrame

type DataFrame[T any] struct {
	BaseFrame
	Value T
}

type DecoderConfiguration

type DecoderConfiguration[T RawSlice] struct {
	PayloadType byte
	AVCC        net.Buffers
	Raw         T
	FLV         net.Buffers
}
func (annexb AnnexBFrame) ToSlices() (ret []NALUSlice) {
	for len(annexb) > 0 {
		before, after, found := bytes.Cut(annexb, codec.NALU_Delimiter1)
		if !found {
			return append(ret, NALUSlice{annexb})
		}
		if len(before) > 0 {
			ret = append(ret, NALUSlice{before})
		}
		annexb = after
	}
	return
}
func (annexb AnnexBFrame) ToNALUs() (ret [][]NALUSlice) {
	for len(annexb) > 0 {
		before, after, found := bytes.Cut(annexb, codec.NALU_Delimiter1)
		if !found {
			return append(ret, annexb.ToSlices())
		}
		if len(before) > 0 {
			ret = append(ret, AnnexBFrame(before).ToSlices())
		}
		annexb = after
	}
	return
}

type IStream

type IStream interface {
	AddTrack(Track)
	RemoveTrack(Track)
	IsClosed() bool
	SSRC() uint32
	log.Zap
	Receive(any) bool
}

type LockFrame

type LockFrame[T any] struct {
	DataFrame[T]
	sync.RWMutex
}

type LockRing

type LockRing[T any] struct {
	RingBuffer[LockFrame[T]]
	Flag *int32
}

func (*LockRing[T]) Dispose

func (rb *LockRing[T]) Dispose()

func (*LockRing[T]) Init

func (lr *LockRing[T]) Init(n int) *LockRing[T]

func (*LockRing[T]) Read

func (rb *LockRing[T]) Read() *DataFrame[T]

func (*LockRing[T]) Step

func (rb *LockRing[T]) Step()

func (*LockRing[T]) Write

func (rb *LockRing[T]) Write(value T)

type MediaFrame

type MediaFrame interface {
	GetFLV() net.Buffers
	GetAVCC() net.Buffers
	GetRTP() []*RTPFrame
}

type NALUSlice

type NALUSlice net.Buffers

func (*NALUSlice) Append

func (nalu *NALUSlice) Append(b ...[]byte)

func (NALUSlice) Bytes

func (nalu NALUSlice) Bytes() (b []byte)

func (NALUSlice) H264Type

func (nalu NALUSlice) H264Type() (naluType codec.H264NALUType)
func (nalu *H264NALU) Append(slice ...NALUSlice) {
	*nalu = append(*nalu, slice...)
}

func (NALUSlice) H265Type

func (nalu NALUSlice) H265Type() (naluType codec.H265NALUType)

func (NALUSlice) RefIdc

func (nalu NALUSlice) RefIdc() byte

func (*NALUSlice) Reset

func (nalu *NALUSlice) Reset() *NALUSlice

type RTPFrame

type RTPFrame struct {
	rtp.Packet
	Raw []byte // 序列化后的数据,避免反复序列化
}

func (*RTPFrame) H264Type

func (rtp *RTPFrame) H264Type() (naluType codec.H264NALUType)

func (*RTPFrame) H265Type

func (rtp *RTPFrame) H265Type() (naluType codec.H265NALUType)

func (*RTPFrame) Marshal

func (rtp *RTPFrame) Marshal() *RTPFrame

func (*RTPFrame) Unmarshal

func (rtp *RTPFrame) Unmarshal(raw []byte) *RTPFrame

type RawSlice

type RawSlice interface {
	~[][]byte | ~[]byte
}

裸数据片段

type RingBuffer

type RingBuffer[T any] struct {
	*util.Ring[T]
	Size      int
	MoveCount uint32
}

func (*RingBuffer[T]) Init

func (rb *RingBuffer[T]) Init(n int) *RingBuffer[T]

func (*RingBuffer[T]) MoveNext

func (rb *RingBuffer[T]) MoveNext() *T

func (*RingBuffer[T]) PreValue

func (rb *RingBuffer[T]) PreValue() *T

func (RingBuffer[T]) SubRing

func (rb RingBuffer[T]) SubRing(rr *util.Ring[T]) *RingBuffer[T]

type Track

type Track interface {
	GetName() string
	LastWriteTime() time.Time
}

type VideoTrack

type VideoTrack interface {
	AVTrack
	GetDecoderConfiguration() DecoderConfiguration[NALUSlice]
	CurrentFrame() *AVFrame[NALUSlice]
	WriteSlice(NALUSlice)
	WriteAnnexB(uint32, uint32, AnnexBFrame)
}

Jump to

Keyboard shortcuts

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