track

package
v4.15.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 20 Imported by: 22

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 IPuber, stuff ...any) (aac *AAC)

func (*AAC) CompleteRTP added in v4.10.0

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

func (*AAC) WriteADTS added in v4.11.0

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

func (*AAC) WriteAVCC

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

func (*AAC) WriteRTPFrame added in v4.10.0

func (aac *AAC) WriteRTPFrame(rtpItem *util.ListItem[RTPFrame])

https://datatracker.ietf.org/doc/html/rfc3640#section-3.2.1

func (*AAC) WriteSequenceHead added in v4.11.0

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

type AV1 added in v4.14.3

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

func NewAV1 added in v4.14.3

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

func (*AV1) CompleteAVCC added in v4.14.3

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

func (*AV1) CompleteRTP added in v4.14.3

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

RTP格式补完

func (*AV1) WriteRTPFrame added in v4.14.3

func (vt *AV1) WriteRTPFrame(rtpItem *util.ListItem[RTPFrame])

func (*AV1) WriteSequenceHead added in v4.14.3

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

type AVRingReader added in v4.11.0

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 added in v4.12.8

func NewAVRingReader(t *Media) *AVRingReader

func (*AVRingReader) DecConfChanged added in v4.11.0

func (r *AVRingReader) DecConfChanged() bool

func (*AVRingReader) GetDTS32 added in v4.11.17

func (r *AVRingReader) GetDTS32() uint32

func (*AVRingReader) GetPTS32 added in v4.11.17

func (r *AVRingReader) GetPTS32() uint32

func (*AVRingReader) ReadFrame added in v4.11.0

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

func (*AVRingReader) ResetAbsTime added in v4.11.9

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 added in v4.10.0

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

func (*Audio) CompleteRTP added in v4.10.0

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

func (*Audio) Detach

func (a *Audio) Detach()

func (*Audio) Flush

func (av *Audio) Flush()

func (*Audio) GetCodec added in v4.15.0

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

func (*Audio) GetName

func (a *Audio) GetName() string

func (*Audio) Narrow added in v4.11.0

func (a *Audio) Narrow()

func (*Audio) WriteADTS

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

func (*Audio) WriteAVCC added in v4.7.3

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

func (*Audio) WriteRawBytes added in v4.13.0

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

func (*Audio) WriteSequenceHead added in v4.14.3

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 added in v4.0.1

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

func (*Base[T, F]) Dispose added in v4.15.0

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

func (*Base[T, F]) GetBPS added in v4.15.0

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

func (*Base[T, F]) GetDrops added in v4.15.0

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

func (*Base[T, F]) GetFPS added in v4.15.0

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

func (*Base[T, F]) GetName

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

func (*Base[T, F]) GetPublisher added in v4.15.0

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

func (*Base[T, F]) GetRBSize added in v4.15.0

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

GetRBSize 获取缓冲区大小

func (*Base[T, F]) SetStuff added in v4.15.0

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

func (*Base[T, F]) SnapForJson added in v4.15.0

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

type BytesData added in v4.13.3

type BytesData struct {
	RecycleData[*util.ListItem[util.Buffer]]
	Pool util.BytesPool
}

func NewBytesDataTrack added in v4.13.3

func NewBytesDataTrack(name string) (dt *BytesData)

type Channel added in v4.14.7

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

func (*Channel[T]) AddListener added in v4.14.7

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

func (*Channel[T]) CreateReader added in v4.14.7

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

func (*Channel[T]) Write added in v4.14.7

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

type Data

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

func NewDataTrack added in v4.12.9

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

func (*Data[T]) Attach added in v4.11.5

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

func (*Data[T]) Init added in v4.13.5

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(*DataFrame[T]) error) (err error)

func (*Data[T]) Push

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

type DataReader added in v4.13.3

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

type G711

type G711 struct {
	Audio
}

func NewG711

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

func (*G711) CompleteRTP added in v4.13.8

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

func (*G711) WriteAVCC

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

func (*G711) WriteRTPFrame added in v4.10.0

func (g711 *G711) WriteRTPFrame(rtpItem *util.ListItem[RTPFrame])

type H264

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

func NewH264

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

func (*H264) CompleteRTP added in v4.10.0

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

RTP格式补完

func (*H264) GetNALU_SEI added in v4.13.4

func (vt *H264) GetNALU_SEI() (item *util.ListItem[util.Buffer])

func (*H264) WriteRTPFrame added in v4.10.0

func (vt *H264) WriteRTPFrame(rtpItem *util.ListItem[RTPFrame])

func (*H264) WriteSequenceHead added in v4.14.3

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

func (*H264) WriteSliceBytes added in v4.10.0

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

type H265

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

func NewH265

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

func (*H265) CompleteAVCC added in v4.14.3

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

func (*H265) CompleteRTP added in v4.10.0

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

RTP格式补完

func (*H265) GetNALU_SEI added in v4.13.4

func (vt *H265) GetNALU_SEI() (item *util.ListItem[util.Buffer])

func (*H265) WriteRTPFrame added in v4.10.0

func (vt *H265) WriteRTPFrame(rtpItem *util.ListItem[RTPFrame])

func (*H265) WriteSequenceHead added in v4.14.3

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

func (*H265) WriteSliceBytes added in v4.10.0

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

type IDRingList added in v4.11.0

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

func (*IDRingList) AddIDR added in v4.11.0

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

func (*IDRingList) ShiftIDR added in v4.11.0

func (p *IDRingList) ShiftIDR()

type Media

type Media struct {
	Base[any, *AVFrame]
	BufferTime      time.Duration //发布者配置中的缓冲时间(时光回溯)
	PayloadType     byte
	IDRingList      `json:"-" yaml:"-"` //最近的关键帧位置,首屏渲染
	SSRC            uint32
	SampleRate      uint32
	BytesPool       util.BytesPool      `json:"-" yaml:"-"`
	RtpPool         util.Pool[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 added in v4.11.0

func (av *Media) AddIDR()

func (*Media) AppendAuBytes added in v4.11.0

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

func (*Media) CurrentFrame

func (av *Media) CurrentFrame() *AVFrame

func (*Media) Flush

func (av *Media) Flush()

func (*Media) GetFromPool added in v4.13.0

func (av *Media) GetFromPool(b util.IBytes) (item *util.ListItem[util.Buffer])

func (*Media) GetRTPFromPool added in v4.11.10

func (av *Media) GetRTPFromPool() (result *util.ListItem[RTPFrame])

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() *AVFrame

func (*Media) SetSpeedLimit added in v4.8.6

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

func (*Media) SetStuff added in v4.9.5

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

func (*Media) SnapForJson added in v4.11.0

func (av *Media) SnapForJson()

为json序列化而计算的数据

func (*Media) WriteRTP added in v4.9.5

func (av *Media) WriteRTP(raw *util.ListItem[RTPFrame])

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

func (*Media) WriteRTPPack added in v4.9.5

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

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

func (*Media) WriteSequenceHead added in v4.11.0

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

type Opus added in v4.14.3

type Opus struct {
	Audio
}

func NewOpus added in v4.14.3

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

func (*Opus) CompleteRTP added in v4.14.3

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

func (*Opus) WriteAVCC added in v4.14.3

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

func (*Opus) WriteRTPFrame added in v4.14.3

func (opus *Opus) WriteRTPFrame(rtpItem *util.ListItem[RTPFrame])

type RTPDemuxer added in v4.8.2

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

type RecycleData added in v4.13.3

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

func NewRecycleDataTrack added in v4.13.3

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

func (*RecycleData[T]) Push added in v4.13.3

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

type RingReader added in v4.13.5

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

func (*RingReader[T, F]) Read added in v4.13.5

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

func (*RingReader[T, F]) ReadNext added in v4.13.5

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

func (*RingReader[T, F]) StartRead added in v4.13.5

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

func (*RingReader[T, F]) TryRead added in v4.13.5

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

type SpesificTrack added in v4.10.0

type SpesificTrack interface {
	CompleteRTP(*AVFrame)
	CompleteAVCC(*AVFrame)
	WriteSliceBytes([]byte)
	WriteRTPFrame(*util.ListItem[RTPFrame])

	WriteSequenceHead([]byte) error

	GetNALU_SEI() *util.ListItem[util.Buffer]
	Flush()
	// contains filtered or unexported methods
}

type Video

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

	codec.SPSInfo
	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 added in v4.10.0

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

func (*Video) Detach

func (v *Video) Detach()

func (*Video) Flush

func (vt *Video) Flush()

func (*Video) GetCodec added in v4.15.0

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

func (*Video) GetName

func (vt *Video) GetName() string

func (*Video) SetLostFlag added in v4.8.6

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 added in v4.11.14

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

func (*Video) WriteSequenceHead added in v4.11.0

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

func (*Video) WriteSliceByte added in v4.10.0

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

Jump to

Keyboard shortcuts

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