track

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: 20 Imported by: 0

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

func (*AAC) CompleteRTP

func (aac *AAC) CompleteRTP(value *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) WriteRTPFrame

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

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

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(stream IStream, stuff ...any) (vt *AV1)

func (*AV1) CompleteAVCC

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

func (*AV1) CompleteRTP

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

RTP格式补完

func (*AV1) WriteRTPFrame

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

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

func (*Audio) CompleteRTP

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

func (*Audio) Detach

func (a *Audio) Detach()

func (*Audio) Flush

func (av *Audio) Flush()

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 BytesData

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

func NewBytesDataTrack

func NewBytesDataTrack(name string) (dt *BytesData)

type Data

type Data[T any] struct {
	Base[T, *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 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(*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(stream IStream, alaw bool, stuff ...any) (g711 *G711)

func (*G711) CompleteRTP

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

func (*G711) WriteAVCC

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

func (*G711) WriteRTPFrame

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

type H264

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

func NewH264

func NewH264(stream IStream, stuff ...any) (vt *H264)

func (*H264) CompleteRTP

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

RTP格式补完

func (*H264) GetNALU_SEI

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

func (*H264) WriteRTPFrame

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

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(stream IStream, stuff ...any) (vt *H265)

func (*H265) CompleteAVCC

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

func (*H265) CompleteRTP

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

RTP格式补完

func (*H265) GetNALU_SEI

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

func (*H265) WriteRTPFrame

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

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[*AVFrame]]
	IDRing      *util.Ring[*AVFrame]
	HistoryRing *util.Ring[*AVFrame]
}

func (*IDRingList) AddIDR

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

func (*IDRingList) ShiftIDR

func (p *IDRingList) ShiftIDR()

type Media

type Media struct {
	Base[any, *AVFrame]
	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

func (av *Media) AddIDR()

func (*Media) AppendAuBytes

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

func (*Media) CurrentFrame

func (av *Media) CurrentFrame() *AVFrame

func (*Media) Flush

func (av *Media) Flush()

func (*Media) GetFromPool

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

func (*Media) GetRTPFromPool

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

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 *util.ListItem[RTPFrame])

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(stream IStream, stuff ...any) (opus *Opus)

func (*Opus) CompleteRTP

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

func (*Opus) WriteAVCC

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

func (*Opus) WriteRTPFrame

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

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 common.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(*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:"-"`
	SEIReader     *DataReader[[]byte] `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func (*Video) Attach

func (v *Video) Attach()

func (*Video) CompleteAVCC

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

func (*Video) Detach

func (v *Video) Detach()

func (*Video) Flush

func (vt *Video) Flush()

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