common

package
v0.0.0-...-92b04c0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyLocker emptyLocker

Functions

func SplitAnnexB

func SplitAnnexB[T ~[]byte](frame T, process func(T), delimiter []byte)

Types

type AVFrame

type AVFrame struct {
	DataFrame[any]
	IFrame    bool
	PTS       time.Duration
	DTS       time.Duration
	Timestamp time.Duration               // 绝对时间戳
	ADTS      *util.ListItem[util.Buffer] `json:"-" yaml:"-"` // ADTS头
	AVCC      util.BLL                    `json:"-" yaml:"-"` // 打包好的AVCC格式(MPEG-4格式、Byte-Stream Format)
	RTP       util.List[RTPFrame]         `json:"-" yaml:"-"`
	AUList    util.BLLs                   `json:"-" yaml:"-"` // 裸数据
}

func NewAVFrame

func NewAVFrame() *AVFrame

func (*AVFrame) Reset

func (av *AVFrame) Reset()

Reset 重置数据,复用内存

func (*AVFrame) WriteAVCC

func (av *AVFrame) WriteAVCC(ts uint32, frame *util.BLL)

type AVTrack

type AVTrack interface {
	Track
	PreFrame() *AVFrame
	CurrentFrame() *AVFrame
	Attach()
	Detach()
	WriteAVCC(ts uint32, frame *util.BLL) error //写入AVCC格式的数据
	WriteRTP(*util.ListItem[RTPFrame])
	WriteRTPPack(*rtp.Packet)
	WriteSequenceHead(sh []byte) error
	Flush()
	SetSpeedLimit(time.Duration)
	GetRTPFromPool() *util.ListItem[RTPFrame]
	GetFromPool(util.IBytes) *util.ListItem[util.Buffer]
}

type AudioTrack

type AudioTrack interface {
	AVTrack
	WriteADTS(uint32, util.IBytes)
	WriteRawBytes(uint32, util.IBytes)
}

type Base

type Base[T any, F IDataFrame[T]] struct {
	RingWriter[T, F]
	Name     string
	log.Zap  `json:"-" yaml:"-"`
	Stream   IStream     `json:"-" yaml:"-"`
	Attached atomic.Bool `json:"-" yaml:"-"`
	State    TrackState

	DropCount int `json:"-" yaml:"-"` //丢帧数
	BPS       int
	FPS       int
	Drops     int   // 丢帧率
	RawSize   int   // 裸数据长度
	RawPart   []int // 裸数据片段用于UI上显示
	// contains filtered or unexported fields
}

Base 基础Track类

func (*Base[T, F]) ComputeBPS

func (bt *Base[T, F]) ComputeBPS(bytes int)

func (*Base[T, F]) Dispose

func (bt *Base[T, F]) Dispose()

func (*Base[T, F]) GetBPS

func (bt *Base[T, F]) GetBPS() int

func (*Base[T, F]) GetDrops

func (bt *Base[T, F]) GetDrops() int

func (*Base[T, F]) GetFPS

func (bt *Base[T, F]) GetFPS() int

func (*Base[T, F]) GetName

func (bt *Base[T, F]) GetName() string

func (*Base[T, F]) GetRBSize

func (bt *Base[T, F]) GetRBSize() int

GetRBSize 获取缓冲区大小

func (*Base[T, F]) SetStuff

func (bt *Base[T, F]) SetStuff(stuff ...any)

func (*Base[T, F]) SnapForJson

func (bt *Base[T, F]) SnapForJson()

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) Clone

func (d *DTSEstimator) Clone() *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 {
	DeltaTime uint32    // 相对上一帧时间戳,毫秒
	WriteTime time.Time // 写入时间,可用于比较两个帧的先后
	Sequence  uint32    // 在一个Track中的序号
	BytesIn   int       // 输入字节数用于计算BPS
	CanRead   bool      `json:"-" yaml:"-"` // 是否可读取

	Data      T `json:"-" yaml:"-"`
	sync.Cond `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func NewDataFrame

func NewDataFrame[T any]() *DataFrame[T]

func (*DataFrame[T]) Discard

func (df *DataFrame[T]) Discard() int32

func (*DataFrame[T]) GetSequence

func (df *DataFrame[T]) GetSequence() uint32

func (*DataFrame[T]) Init

func (df *DataFrame[T]) Init()

func (*DataFrame[T]) IsDiscarded

func (df *DataFrame[T]) IsDiscarded() bool

func (*DataFrame[T]) IsWriting

func (df *DataFrame[T]) IsWriting() bool

func (*DataFrame[T]) ReaderCount

func (df *DataFrame[T]) ReaderCount() int32

func (*DataFrame[T]) ReaderEnter

func (df *DataFrame[T]) ReaderEnter() int32

func (*DataFrame[T]) ReaderLeave

func (df *DataFrame[T]) ReaderLeave() int32

func (*DataFrame[T]) Ready

func (df *DataFrame[T]) Ready()

func (*DataFrame[T]) Reset

func (df *DataFrame[T]) Reset()

func (*DataFrame[T]) SetSequence

func (df *DataFrame[T]) SetSequence(sequence uint32)

func (*DataFrame[T]) StartWrite

func (df *DataFrame[T]) StartWrite() bool

type IDataFrame

type IDataFrame[T any] interface {
	Init()               // 初始化
	Reset()              // 重置数据,复用内存
	Ready()              // 标记为可读取
	ReaderEnter() int32  // 读取者数量+1
	ReaderLeave() int32  // 读取者数量-1
	StartWrite() bool    // 开始写入
	SetSequence(uint32)  // 设置序号
	GetSequence() uint32 // 获取序号
	ReaderCount() int32  // 读取者数量
	Discard() int32      // 如果写入时还有读取者没有离开则废弃该帧,剥离RingBuffer,防止并发读写
	IsDiscarded() bool   // 是否已废弃
	IsWriting() bool     // 是否正在写入
	Wait()               // 阻塞等待可读取
	Broadcast()          // 广播可读取
}

type IStream

type IStream interface {
	AddTrack(Track) *util.Promise[Track]
	RemoveTrack(Track)
	Close()
	IsClosed() bool
	SSRC() uint32
	log.Zap
	Receive(any) bool
	SetIDR(Track)
	GetPublisherConfig() *config.Publish
	GetStartTime() time.Time
	GetType() string
}

type ParamaterSets

type ParamaterSets [][]byte

func (ParamaterSets) GetAnnexB

func (v ParamaterSets) GetAnnexB() (r net.Buffers)

func (ParamaterSets) WriteAnnexBTo

func (v ParamaterSets) WriteAnnexBTo(w io.Writer) (n int, err error)

type RTPFrame

type RTPFrame struct {
	*rtp.Packet
	Raw []byte
}

func (*RTPFrame) H264Type

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

func (*RTPFrame) H265Type

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

func (*RTPFrame) Unmarshal

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

type RingWriter

type RingWriter[T any, F IDataFrame[T]] struct {
	*util.Ring[F] `json:"-" yaml:"-"`
	ReaderCount   atomic.Int32 `json:"-" yaml:"-"`

	Size      int
	LastValue F
	// contains filtered or unexported fields
}

func (*RingWriter[T, F]) GetReaderCount

func (rb *RingWriter[T, F]) GetReaderCount() int32

func (*RingWriter[T, F]) Glow

func (rb *RingWriter[T, F]) Glow(size int) (newItem *util.Ring[F])

func (*RingWriter[T, F]) Init

func (rb *RingWriter[T, F]) Init(n int, constructor func() F) *RingWriter[T, F]

func (*RingWriter[T, F]) Recycle

func (rb *RingWriter[T, F]) Recycle(r *util.Ring[F])

func (*RingWriter[T, F]) Reduce

func (rb *RingWriter[T, F]) Reduce(size int)

func (*RingWriter[T, F]) Step

func (rb *RingWriter[T, F]) Step() (normal bool)

type TimelineData

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

type Track

type Track interface {
	GetReaderCount() int32
	GetName() string
	GetBPS() int
	GetFPS() int
	GetDrops() int
	LastWriteTime() time.Time
	SnapForJson()
	SetStuff(stuff ...any)
	GetRBSize() int
	Dispose()
}

type TrackState

type TrackState byte
const (
	TrackStateOnline  TrackState = iota // 上线
	TrackStateOffline                   // 下线
)

type VideoTrack

type VideoTrack interface {
	AVTrack
	WriteSliceBytes(slice []byte)
	WriteNalu(uint32, uint32, []byte)
	WriteAnnexB(uint32, uint32, []byte)
	SetLostFlag()
}

Jump to

Keyboard shortcuts

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