Documentation
¶
Index ¶
- Constants
- Variables
- func AddHook(name string, callback interface{})
- func AddHookConditional(name string, callback interface{}, goon func() bool)
- func AddHookGo(name string, callback interface{})
- func AddHooks(hooks map[string]interface{})
- func InstallPlugin(opt *PluginConfig)
- func Run(ctx context.Context, configFile string) (err error)
- func TriggerHook(name string, payload ...interface{})
- type AVItem
- type AVPack
- type AVRing
- func (r AVRing) Clone() *AVRing
- func (r *AVRing) Current() *AVItem
- func (r *AVRing) CurrentValue() interface{}
- func (r *AVRing) GetNext() *AVItem
- func (r *AVRing) Init(ctx context.Context, n int) *AVRing
- func (r *AVRing) NextValue() interface{}
- func (r *AVRing) PreItem() *AVItem
- func (r *AVRing) Read() (item *AVItem, value interface{})
- func (r *AVRing) Step()
- func (r AVRing) SubRing(rr *ring.Ring) *AVRing
- func (r *AVRing) TryRead() (item *AVItem, value interface{})
- func (r *AVRing) Write(value interface{})
- type AVTrack
- type AudioPack
- type AudioTrack
- type B
- type BaseTrack
- type DTSEstimator
- type DataItem
- type DataTrack
- type LockItem
- type PluginConfig
- type RTPAudio
- type RTPDemuxer
- type RTPNalu
- type RTPVideo
- type RingBuffer
- func (rb RingBuffer) Clone() *RingBuffer
- func (rb *RingBuffer) Current() *LockItem
- func (rb *RingBuffer) CurrentValue() interface{}
- func (rb *RingBuffer) Dispose()
- func (rb *RingBuffer) GetNext() *LockItem
- func (rb *RingBuffer) Init(ctx context.Context, n int) *RingBuffer
- func (rb *RingBuffer) MoveNext()
- func (rb *RingBuffer) NextValue() interface{}
- func (rb *RingBuffer) Read() interface{}
- func (rb *RingBuffer) ReadLoop(handler interface{}, async bool)
- func (rb *RingBuffer) ReadLoopConditional(handler interface{}, goon func() bool)
- func (r *RingBuffer) ReadLoopConditionalGo(handler interface{}, goon func() bool)
- func (rb *RingBuffer) Step()
- func (rb RingBuffer) SubRing(rr *ring.Ring) *RingBuffer
- func (rb *RingBuffer) Write(value interface{})
- type Stream
- func (r *Stream) Close()
- func (s *Stream) NewAudioTrack(codec byte) (at *AudioTrack)
- func (s *Stream) NewDataTrack(l sync.Locker) (dt *DataTrack)
- func (s *Stream) NewRTPAudio(codec byte) (r *RTPAudio)
- func (s *Stream) NewRTPVideo(codecID byte) (r *RTPVideo)
- func (s *Stream) NewVideoTrack(codec byte) (vt *VideoTrack)
- func (r *Stream) Publish() bool
- func (r *Stream) Subscribe(s *Subscriber)
- func (r *Stream) UnSubscribe(s *Subscriber)
- func (r *Stream) WaitAudioTrack(names ...string) *AudioTrack
- func (r *Stream) WaitDataTrack(names ...string) *DataTrack
- func (r *Stream) WaitVideoTrack(names ...string) *VideoTrack
- type StreamCollection
- type StreamContext
- type Subscriber
- type TSSlice
- type Track
- type Tracks
- type TransCodeReq
- type VideoPack
- type VideoTrack
Constants ¶
View Source
const ( HOOK_SUBSCRIBE = "Subscribe" HOOK_UNSUBSCRIBE = "UnSubscibe" HOOK_STREAMCLOSE = "StreamClose" HOOK_PUBLISH = "Publish" HOOK_REQUEST_TRANSAUDIO = "RequestTransAudio" )
Variables ¶
View Source
var ( // ConfigRaw 配置信息的原始数据 ConfigRaw []byte StartTime time.Time //启动时间 Plugins = make(map[string]*PluginConfig) // Plugins 所有的插件配置 HasTranscoder bool Ctx context.Context )
View Source
var Hooks = make(map[string]*RingBuffer)
View Source
var StreamTimeoutError = errors.New("timeout")
View Source
var Version = "3.2.2"
Functions ¶
func AddHookConditional ¶ added in v3.1.8
func TriggerHook ¶
func TriggerHook(name string, payload ...interface{})
Types ¶
type AVItem ¶ added in v3.2.5
type AVItem struct {
DataItem
// contains filtered or unexported fields
}
type AVPack ¶ added in v3.1.0
func (*AVPack) Bytes2Payload ¶ added in v3.3.1
func (pack *AVPack) Bytes2Payload()
type AVRing ¶ added in v3.2.5
type AVRing struct {
RingBuffer
// contains filtered or unexported fields
}
func (*AVRing) CurrentValue ¶ added in v3.2.5
func (r *AVRing) CurrentValue() interface{}
type AVTrack ¶ added in v3.3.1
type AudioTrack ¶
type AudioTrack struct {
AVTrack
SoundRate int //2bit
SoundSize byte //1bit
Channels byte //1bit
ExtraData []byte `json:"-"` //rtmp协议需要先发这个帧
PushByteStream func(ts uint32, payload []byte) `json:"-"`
PushRaw func(ts uint32, payload []byte) `json:"-"`
*AudioPack `json:"-"` // 当前正在写入的音频对象
// contains filtered or unexported fields
}
func (*AudioTrack) Play ¶ added in v3.1.3
func (at *AudioTrack) Play(onAudio func(uint32, *AudioPack), exit1, exit2 <-chan struct{})
func (*AudioTrack) SetASC ¶
func (at *AudioTrack) SetASC(asc []byte)
type DTSEstimator ¶ added in v3.3.12
type DTSEstimator struct {
// contains filtered or unexported fields
}
DTSEstimator is a DTS estimator.
func NewDTSEstimator ¶ added in v3.3.12
func NewDTSEstimator() *DTSEstimator
NewDTSEstimator allocates a DTSEstimator.
func (*DTSEstimator) Feed ¶ added in v3.3.12
func (d *DTSEstimator) Feed(pts uint32) uint32
Feed provides PTS to the estimator, and returns the estimated DTS.
type DataTrack ¶ added in v3.3.1
type DataTrack struct {
RingBuffer
BaseTrack
*LockItem
sync.Locker // 写入锁,可选,单一写入可以不加锁
}
type PluginConfig ¶
type PluginConfig struct {
Name string //插件名称
Config interface{} //插件配置
Version string //插件版本
Dir string //插件代码路径
Run func() //插件启动函数
HotConfig map[string]func(interface{}) //热修改配置
}
PluginConfig 插件配置定义
func (*PluginConfig) Install ¶ added in v3.4.0
func (opt *PluginConfig) Install(run func())
func (*PluginConfig) Save ¶ added in v3.4.0
func (opt *PluginConfig) Save() error
type RTPAudio ¶
type RTPAudio struct {
RTPDemuxer `json:"-"`
*AudioTrack
}
type RTPDemuxer ¶ added in v3.3.12
type RTPDemuxer struct {
rtp.Packet
PTS uint32 // 修复后的时间戳(毫秒)
OnDemux func(uint32, []byte)
// contains filtered or unexported fields
}
对rtp包进行解封装,并修复时间戳,包括时间戳跳跃
func (*RTPDemuxer) Push ¶ added in v3.3.12
func (r *RTPDemuxer) Push(rtpRaw []byte)
type RTPVideo ¶
type RTPVideo struct {
RTPDemuxer `json:"-"`
*VideoTrack
// contains filtered or unexported fields
}
type RingBuffer ¶ added in v3.1.0
func (RingBuffer) Clone ¶ added in v3.1.0
func (rb RingBuffer) Clone() *RingBuffer
func (*RingBuffer) Current ¶ added in v3.1.0
func (rb *RingBuffer) Current() *LockItem
func (*RingBuffer) CurrentValue ¶ added in v3.1.0
func (rb *RingBuffer) CurrentValue() interface{}
func (*RingBuffer) Dispose ¶ added in v3.2.5
func (rb *RingBuffer) Dispose()
func (*RingBuffer) GetNext ¶ added in v3.1.0
func (rb *RingBuffer) GetNext() *LockItem
func (*RingBuffer) Init ¶ added in v3.1.0
func (rb *RingBuffer) Init(ctx context.Context, n int) *RingBuffer
func (*RingBuffer) MoveNext ¶ added in v3.1.0
func (rb *RingBuffer) MoveNext()
func (*RingBuffer) NextValue ¶ added in v3.1.0
func (rb *RingBuffer) NextValue() interface{}
func (*RingBuffer) Read ¶ added in v3.1.0
func (rb *RingBuffer) Read() interface{}
func (*RingBuffer) ReadLoop ¶ added in v3.1.7
func (rb *RingBuffer) ReadLoop(handler interface{}, async bool)
ReadLoop 循环读取,采用了反射机制,不适用高性能场景 handler入参可以传入回调函数或者channel
func (*RingBuffer) ReadLoopConditional ¶ added in v3.1.8
func (rb *RingBuffer) ReadLoopConditional(handler interface{}, goon func() bool)
goon判断函数用来判断是否继续读取,返回false将终止循环
func (*RingBuffer) ReadLoopConditionalGo ¶ added in v3.3.14
func (r *RingBuffer) ReadLoopConditionalGo(handler interface{}, goon func() bool)
goon判断函数用来判断是否继续读取,返回false将终止循环
func (*RingBuffer) Step ¶ added in v3.3.1
func (rb *RingBuffer) Step()
func (RingBuffer) SubRing ¶ added in v3.1.0
func (rb RingBuffer) SubRing(rr *ring.Ring) *RingBuffer
func (*RingBuffer) Write ¶ added in v3.1.0
func (rb *RingBuffer) Write(value interface{})
type Stream ¶
type Stream struct {
URL string //远程地址,仅远程拉流有值
StreamContext `json:"-"`
StreamPath string
Type string //流类型,来自发布者
StartTime time.Time //流的创建时间
Subscribers []*Subscriber // 订阅者
VideoTracks Tracks
AudioTracks Tracks
DataTracks Tracks
AutoCloseAfter *int //当无人订阅时延迟N秒后自动停止发布
Transcoding map[string]string //转码配置,key:目标编码,value:发布者提供的编码
OnClose func() `json:"-"`
ExtraProp interface{} //额外的属性,用于实现子类化,减少map的使用
// contains filtered or unexported fields
}
Stream 流定义
func (*Stream) NewAudioTrack ¶
func (s *Stream) NewAudioTrack(codec byte) (at *AudioTrack)
func (*Stream) NewDataTrack ¶ added in v3.3.1
func (*Stream) NewRTPAudio ¶
func (*Stream) NewRTPVideo ¶
func (*Stream) NewVideoTrack ¶
func (s *Stream) NewVideoTrack(codec byte) (vt *VideoTrack)
func (*Stream) WaitAudioTrack ¶
func (r *Stream) WaitAudioTrack(names ...string) *AudioTrack
TODO: 触发转码逻辑
func (*Stream) WaitDataTrack ¶ added in v3.3.1
func (*Stream) WaitVideoTrack ¶
func (r *Stream) WaitVideoTrack(names ...string) *VideoTrack
type StreamCollection ¶
var Streams StreamCollection
Streams 所有的流集合
func (*StreamCollection) Delete ¶
func (sc *StreamCollection) Delete(streamPath string)
func (*StreamCollection) GetStream ¶
func (sc *StreamCollection) GetStream(streamPath string) *Stream
func (*StreamCollection) Range ¶ added in v3.2.4
func (sc *StreamCollection) Range(f func(*Stream))
func (*StreamCollection) ToList ¶
func (sc *StreamCollection) ToList() (r []*Stream)
type StreamContext ¶ added in v3.3.7
type StreamContext struct {
context.Context
IsTimeout bool
// contains filtered or unexported fields
}
func (*StreamContext) Err ¶ added in v3.3.7
func (r *StreamContext) Err() error
func (*StreamContext) Update ¶ added in v3.3.7
func (r *StreamContext) Update()
type Subscriber ¶
type Subscriber struct {
context.Context `json:"-"`
Ctx2 context.Context `json:"-"`
*Stream `json:"-"`
ID string
TotalDrop int //总丢帧
TotalPacket int
Type string
BufferLength int
Delay uint32
SubscribeTime time.Time
SubscribeArgs url.Values
OnAudio func(uint32, *AudioPack) `json:"-"`
OnVideo func(uint32, *VideoPack) `json:"-"`
// contains filtered or unexported fields
}
Subscriber 订阅者实体定义
func DeleteSliceItem_Subscriber ¶
func DeleteSliceItem_Subscriber(slice []*Subscriber, item *Subscriber) ([]*Subscriber, bool)
func (*Subscriber) PlayAudio ¶
func (s *Subscriber) PlayAudio(at *AudioTrack)
func (*Subscriber) PlayVideo ¶
func (s *Subscriber) PlayVideo(vt *VideoTrack)
func (*Subscriber) Subscribe ¶
func (s *Subscriber) Subscribe(streamPath string) error
Subscribe 开始订阅 将Subscriber与Stream关联
type Tracks ¶
type Tracks struct {
RingBuffer
context.Context
sync.RWMutex
// contains filtered or unexported fields
}
func (*Tracks) MarshalJSON ¶
type TransCodeReq ¶
type TransCodeReq struct {
*Subscriber
RequestCodec string
}
type VideoPack ¶
func (*VideoPack) ResetNALUs ¶ added in v3.3.1
func (v *VideoPack) ResetNALUs()
type VideoTrack ¶
type VideoTrack struct {
IDRing *ring.Ring `json:"-"` //最近的关键帧位置,首屏渲染
AVTrack
SPSInfo codec.SPSInfo
GOP int //关键帧间隔
ExtraData *VideoPack `json:"-"` //H264(SPS、PPS) H265(VPS、SPS、PPS)
WaitIDR chan struct{} `json:"-"`
PushNalu func(ts uint32, cts uint32, nalus ...[]byte) `json:"-"`
UsingDonlField bool
*VideoPack `json:"-"` //当前写入的视频数据
// contains filtered or unexported fields
}
func (*VideoTrack) Play ¶ added in v3.1.3
func (vt *VideoTrack) Play(onVideo func(uint32, *VideoPack), exit1, exit2 <-chan struct{})
func (*VideoTrack) PushAnnexB ¶
func (vt *VideoTrack) PushAnnexB(ts uint32, cts uint32, payload []byte)
func (*VideoTrack) PushByteStream ¶
func (vt *VideoTrack) PushByteStream(ts uint32, payload []byte)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.