common

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 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
	AVCC   net.Buffers `json:"-"` // 打包好的AVCC格式
	RTP    []*RTPFrame `json:"-"`
	Raw    []T         `json:"-"` // 裸数据
	// 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]) 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格式的数据
	WriteRTP([]byte)
	WriteRTPPack(*rtp.Packet)
	Flush()
}

type AnnexBFrame

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

type AudioSlice

type AudioSlice []byte

type AudioTrack

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

type Base added in v4.1.0

type Base struct {
	Name   string
	Stream IStream `json:"-"`

	BPS     int
	FPS     int
	RawPart []int               // 裸数据片段用于UI上显示
	RawSize int                 // 裸数据长度
	BPSs    []TimelineData[int] // 10s码率统计
	FPSs    []TimelineData[int] // 10s帧率统计
	// contains filtered or unexported fields
}

Base 基础Track类

func (*Base) ComputeBPS added in v4.1.0

func (bt *Base) ComputeBPS(bytes int)

func (*Base) Flush added in v4.1.0

func (bt *Base) Flush(bf *BaseFrame)

func (*Base) GetBase added in v4.1.0

func (bt *Base) GetBase() *Base

func (*Base) SnapForJson added in v4.5.1

func (bt *Base) SnapForJson()

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
	Seq         int //收到第几个序列帧,用于变码率时让订阅者发送序列帧
}
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 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
}

func (*RTPFrame) H264Type

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

func (*RTPFrame) H265Type

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

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] `json:"-"`
	Size          int
	MoveCount     uint32
	LastValue     *T
}

func (*RingBuffer[T]) Init

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

func (*RingBuffer[T]) MoveNext

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

type TimelineData added in v4.5.6

type TimelineData[T any] struct {
	Timestamp time.Time
	Value     T
}

type Track

type Track interface {
	GetBase() *Base
	LastWriteTime() time.Time
	SnapForJson()
}

type VideoTrack

type VideoTrack interface {
	AVTrack
	GetDecoderConfiguration() DecoderConfiguration[NALUSlice]
	CurrentFrame() *AVFrame[NALUSlice]
	PreFrame() *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