track

package
v4.15.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	READSTATE_INIT = iota
	READSTATE_FIRST
	READSTATE_NORMAL
)
View Source
const (
	SUBMODE_REAL = iota
	SUBMODE_NOJUMP
	SUBMODE_BUFFER
)
View Source
const RTPMTU = 1400

Variables

View Source
var ErrDiscard = errors.New("discard")

Functions

This section is empty.

Types

type AAC

type AAC struct {
	Audio

	Mode int // 1为lbr,2为hbr
	// contains filtered or unexported fields
}

func NewAAC

func NewAAC(puber common.IPuber, stuff ...any) (aac *AAC)

func (*AAC) CompleteRTP

func (aac *AAC) CompleteRTP(value *common.AVFrame)

func (*AAC) WriteADTS

func (aac *AAC) WriteADTS(ts uint32, b util.IBytes)

func (*AAC) WriteAVCC

func (aac *AAC) WriteAVCC(ts uint32, frame *util.BLL) error

func (*AAC) WriteSequenceHead

func (aac *AAC) WriteSequenceHead(sh []byte) error

type AV1

type AV1 struct {
	Video
	// contains filtered or unexported fields
}

func NewAV1

func NewAV1(puber common.IPuber, stuff ...any) (vt *AV1)

func (*AV1) CompleteAVCC

func (vt *AV1) CompleteAVCC(rv *common.AVFrame)

func (*AV1) CompleteRTP

func (vt *AV1) CompleteRTP(value *common.AVFrame)

RTP格式补完

func (*AV1) WriteRTPFrame

func (vt *AV1) WriteRTPFrame(rtpItem *common.LIRTP)

func (*AV1) WriteSequenceHead

func (vt *AV1) WriteSequenceHead(head []byte) (err error)

type AVRingReader

type AVRingReader struct {
	RingReader[any, *common.AVFrame]

	Track    *Media
	State    byte
	FirstSeq uint32
	StartTs  time.Duration
	FirstTs  time.Duration
	SkipTs   time.Duration //ms

	ConfSeq int

	AbsTime uint32
	Delay   uint32
	*log.Logger
	// contains filtered or unexported fields
}

func NewAVRingReader

func NewAVRingReader(t *Media) *AVRingReader

func (*AVRingReader) DecConfChanged

func (r *AVRingReader) DecConfChanged() bool

func (*AVRingReader) GetDTS32

func (r *AVRingReader) GetDTS32() uint32

func (*AVRingReader) GetPTS32

func (r *AVRingReader) GetPTS32() uint32

func (*AVRingReader) ReadFrame

func (r *AVRingReader) ReadFrame(mode int) (err error)

func (*AVRingReader) ResetAbsTime

func (r *AVRingReader) ResetAbsTime()

type Audio

type Audio struct {
	Media
	CodecID          codec.AudioCodecID
	Channels         byte
	SampleSize       byte
	SizeLength       int // 通常为13
	IndexLength      int
	IndexDeltaLength int
	AVCCHead         []byte // 音频包在AVCC格式中,AAC会有两个字节,其他的只有一个字节
	codec.AudioSpecificConfig
}

func (*Audio) Attach

func (a *Audio) Attach()

func (*Audio) CompleteAVCC

func (a *Audio) CompleteAVCC(value *common.AVFrame)

func (*Audio) CompleteRTP

func (a *Audio) CompleteRTP(value *common.AVFrame)

func (*Audio) Detach

func (a *Audio) Detach()

func (*Audio) Flush

func (av *Audio) Flush()

func (*Audio) GetCodec

func (a *Audio) GetCodec() codec.AudioCodecID

func (*Audio) GetName

func (a *Audio) GetName() string

func (*Audio) Narrow

func (a *Audio) Narrow()

func (*Audio) WriteADTS

func (av *Audio) WriteADTS(pts uint32, adts util.IBytes)

func (*Audio) WriteAVCC

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

func (*Audio) WriteRawBytes

func (av *Audio) WriteRawBytes(pts uint32, raw util.IBytes)

func (*Audio) WriteSequenceHead

func (av *Audio) WriteSequenceHead(sh []byte) error

type Base

type Base[T any, F util.IDataFrame[T]] struct {
	util.RingWriter[T, F]
	Name      string
	log.Zap   `json:"-" yaml:"-"`
	Publisher common.IPuber `json:"-" yaml:"-"` //所属发布者
	State     common.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]) GetPublisher

func (bt *Base[T, F]) GetPublisher() common.IPuber

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 BytesData

type BytesData struct {
	RecycleData[util.LIBP]
	Pool util.BytesPool
}

func NewBytesDataTrack

func NewBytesDataTrack(name string) (dt *BytesData)

type Channel

type Channel[T any] struct {
	// contains filtered or unexported fields
}

func (*Channel[T]) AddListener

func (r *Channel[T]) AddListener(c chan T)

func (*Channel[T]) CreateReader

func (r *Channel[T]) CreateReader(l int) chan T

func (*Channel[T]) Write

func (r *Channel[T]) Write(data T)

type Data

type Data[T any] struct {
	Base[T, *common.DataFrame[T]]
	sync.Locker `json:"-" yaml:"-"` // 写入锁,可选,单一协程写入可以不加锁
}

func NewDataTrack

func NewDataTrack[T any](name string) (dt *Data[T])

func (*Data[T]) Attach

func (d *Data[T]) Attach(s common.IStream)

func (*Data[T]) Init

func (dt *Data[T]) Init(n int)

func (*Data[T]) LastWriteTime

func (d *Data[T]) LastWriteTime() time.Time

func (*Data[T]) Play

func (d *Data[T]) Play(ctx context.Context, onData func(*common.DataFrame[T]) error) (err error)

func (*Data[T]) Push

func (dt *Data[T]) Push(data T)

type DataReader

type DataReader[T any] struct {
	RingReader[T, *common.DataFrame[T]]
}

type G711

type G711 struct {
	Audio
}

func NewG711

func NewG711(puber common.IPuber, alaw bool, stuff ...any) (g711 *G711)

func (*G711) CompleteRTP

func (g711 *G711) CompleteRTP(value *common.AVFrame)

func (*G711) WriteAVCC

func (g711 *G711) WriteAVCC(ts uint32, frame *util.BLL) error

func (*G711) WriteRTPFrame

func (g711 *G711) WriteRTPFrame(rtpItem *common.LIRTP)

type H264

type H264 struct {
	Video
	// contains filtered or unexported fields
}

func NewH264

func NewH264(puber common.IPuber, stuff ...any) (vt *H264)

func (*H264) CompleteRTP

func (vt *H264) CompleteRTP(value *common.AVFrame)

RTP格式补完

func (*H264) GetNALU_SEI

func (vt *H264) GetNALU_SEI() (item util.LIBP)

func (*H264) WriteRTPFrame

func (vt *H264) WriteRTPFrame(rtpItem *common.LIRTP)

func (*H264) WriteSequenceHead

func (vt *H264) WriteSequenceHead(head []byte) (err error)

func (*H264) WriteSliceBytes

func (vt *H264) WriteSliceBytes(slice []byte)

type H265

type H265 struct {
	Video
	VPS []byte `json:"-" yaml:"-"`
}

func NewH265

func NewH265(puber common.IPuber, stuff ...any) (vt *H265)

func (*H265) CompleteAVCC

func (vt *H265) CompleteAVCC(rv *common.AVFrame)

func (*H265) CompleteRTP

func (vt *H265) CompleteRTP(value *common.AVFrame)

RTP格式补完

func (*H265) GetNALU_SEI

func (vt *H265) GetNALU_SEI() (item util.LIBP)

func (*H265) WriteRTPFrame

func (vt *H265) WriteRTPFrame(rtpItem *common.LIRTP)

func (*H265) WriteSequenceHead

func (vt *H265) WriteSequenceHead(head []byte) (err error)

func (*H265) WriteSliceBytes

func (vt *H265) WriteSliceBytes(slice []byte)

type IDRingList

type IDRingList struct {
	IDRList     util.List[*util.Ring[*common.AVFrame]]
	IDRing      *util.Ring[*common.AVFrame]
	HistoryRing *util.Ring[*common.AVFrame]
}

func (*IDRingList) AddIDR

func (p *IDRingList) AddIDR(IDRing *util.Ring[*common.AVFrame])

func (*IDRingList) ShiftIDR

func (p *IDRingList) ShiftIDR()

type Media

type Media struct {
	Base[any, *common.AVFrame]
	BufferTime      time.Duration //发布者配置中的缓冲时间(时光回溯)
	PayloadType     byte
	IDRingList      `json:"-" yaml:"-"` //最近的关键帧位置,首屏渲染
	SSRC            uint32
	SampleRate      uint32
	BytesPool       util.BytesPool             `json:"-" yaml:"-"`
	RtpPool         util.Pool[common.RTPFrame] `json:"-" yaml:"-"`
	SequenceHead    []byte                     `json:"-" yaml:"-"` //H264(SPS、PPS) H265(VPS、SPS、PPS) AAC(config)
	SequenceHeadSeq int
	RTPDemuxer
	SpesificTrack `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

Media 基础媒体Track类

func (*Media) AddIDR

func (av *Media) AddIDR()

func (*Media) AppendAuBytes

func (av *Media) AppendAuBytes(b ...[]byte)

func (*Media) CurrentFrame

func (av *Media) CurrentFrame() *common.AVFrame

func (*Media) Flush

func (av *Media) Flush()

func (*Media) GetFromPool

func (av *Media) GetFromPool(b util.IBytes) (item util.LIBP)

func (*Media) GetRTPFromPool

func (av *Media) GetRTPFromPool() (result *common.LIRTP)

func (*Media) LastWriteTime

func (av *Media) LastWriteTime() time.Time

func (*Media) PacketizeRTP

func (av *Media) PacketizeRTP(payloads ...[][]byte)

https://www.cnblogs.com/moonwalk/p/15903760.html Packetize packetizes the payload of an RTP packet and returns one or more RTP packets

func (*Media) PreFrame

func (av *Media) PreFrame() *common.AVFrame

func (*Media) SetSpeedLimit

func (av *Media) SetSpeedLimit(value time.Duration)

func (*Media) SetStuff

func (av *Media) SetStuff(stuff ...any)

func (*Media) SnapForJson

func (av *Media) SnapForJson()

为json序列化而计算的数据

func (*Media) WriteRTP

func (av *Media) WriteRTP(raw *common.LIRTP)

WriteRTPFrame 写入未反序列化的RTP包, 未排序的

func (*Media) WriteRTPPack

func (av *Media) WriteRTPPack(p *rtp.Packet)

WriteRTPPack 写入已反序列化的RTP包,已经排序过了的

func (*Media) WriteSequenceHead

func (av *Media) WriteSequenceHead(sh []byte)

type Opus

type Opus struct {
	Audio
}

func NewOpus

func NewOpus(puber common.IPuber, stuff ...any) (opus *Opus)

func (*Opus) CompleteRTP

func (opus *Opus) CompleteRTP(value *common.AVFrame)

func (*Opus) WriteAVCC

func (opus *Opus) WriteAVCC(ts uint32, frame *util.BLL) error

func (*Opus) WriteRTPFrame

func (opus *Opus) WriteRTPFrame(rtpItem *common.LIRTP)

type RTPDemuxer

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

type RecycleData

type RecycleData[T util.Recyclable] struct {
	Data[T]
}

func NewRecycleDataTrack

func NewRecycleDataTrack[T util.Recyclable](name string) (dt *RecycleData[T])

func (*RecycleData[T]) Push

func (dt *RecycleData[T]) Push(data T)

type RingReader

type RingReader[T any, F util.IDataFrame[T]] struct {
	*util.Ring[F]
	Count int // 读取的帧数
}

func (*RingReader[T, F]) Read

func (r *RingReader[T, F]) Read(ring *util.Ring[F]) (err error)

func (*RingReader[T, F]) ReadNext

func (r *RingReader[T, F]) ReadNext() (err error)

func (*RingReader[T, F]) StartRead

func (r *RingReader[T, F]) StartRead(ring *util.Ring[F]) (err error)

func (*RingReader[T, F]) TryRead

func (r *RingReader[T, F]) TryRead() (f F, err error)

type SpesificTrack

type SpesificTrack interface {
	CompleteRTP(*common.AVFrame)
	CompleteAVCC(*common.AVFrame)
	WriteSliceBytes([]byte)
	WriteRTPFrame(*common.LIRTP)

	WriteSequenceHead([]byte) error

	GetNALU_SEI() util.LIBP
	Flush()
	// contains filtered or unexported methods
}

type Video

type Video struct {
	Media
	CodecID codec.VideoCodecID
	GOP     int //关键帧间隔

	codec.SPSInfo
	common.ParamaterSets `json:"-" yaml:"-"`
	SPS                  []byte `json:"-" yaml:"-"`
	PPS                  []byte `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func (*Video) Attach

func (v *Video) Attach()

func (*Video) CompleteAVCC

func (vt *Video) CompleteAVCC(rv *common.AVFrame)

func (*Video) Detach

func (v *Video) Detach()

func (*Video) Flush

func (vt *Video) Flush()

func (*Video) GetCodec

func (vt *Video) GetCodec() codec.VideoCodecID

func (*Video) GetName

func (vt *Video) GetName() string

func (*Video) SetLostFlag

func (vt *Video) SetLostFlag()

func (*Video) WriteAVCC

func (vt *Video) WriteAVCC(ts uint32, frame *util.BLL) (err error)

func (*Video) WriteAnnexB

func (vt *Video) WriteAnnexB(pts uint32, dts uint32, frame []byte)

func (*Video) WriteNalu

func (vt *Video) WriteNalu(pts uint32, dts uint32, nalu []byte)

func (*Video) WriteSequenceHead

func (vt *Video) WriteSequenceHead(sh []byte)

func (*Video) WriteSliceByte

func (vt *Video) WriteSliceByte(b ...byte)

Jump to

Keyboard shortcuts

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