Documentation
¶
Index ¶
- Constants
- Variables
- func AddHook(name string, callback interface{})
- func AddHookConditional(name string, callback interface{}, goon func() bool)
- func AddHooks(hooks map[string]interface{})
- 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) NextRead() (item *AVItem, value interface{})
- 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) Write(value interface{})
- type AVTrack
- type AudioPack
- type AudioTrack
- type BaseTrack
- type DataItem
- type DataTrack
- type LockItem
- type RTPAudio
- type RTPNalu
- type RTPPublisher
- 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{})
- func (rb *RingBuffer) ReadLoopConditional(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) AddOnClose(onClose func())
- 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(codec 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) Update()
- func (r *Stream) WaitAudioTrack(names ...string) *AudioTrack
- func (r *Stream) WaitDataTrack(names ...string) *DataTrack
- func (r *Stream) WaitVideoTrack(names ...string) *VideoTrack
- type StreamCollection
- 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 Hooks = make(map[string]*RingBuffer)
Functions ¶
func AddHookConditional ¶
func TriggerHook ¶
func TriggerHook(name string, payload ...interface{})
Types ¶
type AVPack ¶
func (*AVPack) Bytes2Payload ¶
func (pack *AVPack) Bytes2Payload()
type AVRing ¶
type AVRing struct { RingBuffer // contains filtered or unexported fields }
func (*AVRing) CurrentValue ¶
func (r *AVRing) CurrentValue() interface{}
type AVTrack ¶
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 ¶
func (at *AudioTrack) Play(onAudio func(uint32, *AudioPack), exit1, exit2 <-chan struct{})
func (*AudioTrack) SetASC ¶
func (at *AudioTrack) SetASC(asc []byte)
type DataTrack ¶
type DataTrack struct { RingBuffer BaseTrack *LockItem sync.Locker // 写入锁,可选,单一写入可以不加锁 }
type RTPAudio ¶
type RTPAudio struct { RTPPublisher *AudioTrack }
type RTPPublisher ¶
func (*RTPPublisher) Push ¶
func (p *RTPPublisher) Push(payload []byte)
type RTPVideo ¶
type RTPVideo struct { RTPPublisher *VideoTrack // contains filtered or unexported fields }
type RingBuffer ¶
func (RingBuffer) Clone ¶
func (rb RingBuffer) Clone() *RingBuffer
func (*RingBuffer) Current ¶
func (rb *RingBuffer) Current() *LockItem
func (*RingBuffer) CurrentValue ¶
func (rb *RingBuffer) CurrentValue() interface{}
func (*RingBuffer) Dispose ¶
func (rb *RingBuffer) Dispose()
func (*RingBuffer) GetNext ¶
func (rb *RingBuffer) GetNext() *LockItem
func (*RingBuffer) Init ¶
func (rb *RingBuffer) Init(ctx context.Context, n int) *RingBuffer
func (*RingBuffer) MoveNext ¶
func (rb *RingBuffer) MoveNext()
func (*RingBuffer) NextValue ¶
func (rb *RingBuffer) NextValue() interface{}
func (*RingBuffer) Read ¶
func (rb *RingBuffer) Read() interface{}
func (*RingBuffer) ReadLoop ¶
func (rb *RingBuffer) ReadLoop(handler interface{})
ReadLoop 循环读取,采用了反射机制,不适用高性能场景 handler入参可以传入回调函数或者channel
func (*RingBuffer) ReadLoopConditional ¶
func (rb *RingBuffer) ReadLoopConditional(handler interface{}, goon func() bool)
goon判断函数用来判断是否继续读取,返回false将终止循环
func (*RingBuffer) Step ¶
func (rb *RingBuffer) Step()
func (RingBuffer) SubRing ¶
func (rb RingBuffer) SubRing(rr *ring.Ring) *RingBuffer
func (*RingBuffer) Write ¶
func (rb *RingBuffer) Write(value interface{})
type Stream ¶
type Stream struct { context.Context `json:"-"` StreamPath string Type string //流类型,来自发布者 StartTime time.Time //流的创建时间 Subscribers []*Subscriber // 订阅者 VideoTracks Tracks AudioTracks Tracks DataTracks Tracks AutoUnPublish bool // 当无人订阅时自动停止发布 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) 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 ¶
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 ¶
func (sc *StreamCollection) Range(f func(*Stream))
func (*StreamCollection) ToList ¶
func (sc *StreamCollection) ToList() (r []*Stream)
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 ¶
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 ¶
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.