优化网络IO使用buffer读取

This commit is contained in:
yangjiechina
2024-06-15 19:31:17 +08:00
parent 17973b3e9e
commit 89de34bd98
22 changed files with 355 additions and 288 deletions

View File

@@ -16,7 +16,8 @@ type Session struct {
handle interface{}
isPublisher bool
conn net.Conn
conn net.Conn
receiveBuffer *stream.ReceiveBuffer
}
func (s *Session) generateSourceId(app, stream_ string) string {
@@ -37,6 +38,9 @@ func (s *Session) OnPublish(app, stream_ string, response chan utils.HookState)
//设置推流的音视频回调
s.stack.SetOnPublishHandler(source)
//初始化放在add source前面, 以防add-init空窗期, 拉流队列空指针.
source.Init(source.Input, source.Close, stream.ReceiveBufferTCPBlockCount)
//推流事件Source统一处理, 是否已经存在, Hook回调....
_, state := stream.PreparePublishSource(source, true)
if utils.HookStateOK != state {
@@ -44,8 +48,8 @@ func (s *Session) OnPublish(app, stream_ string, response chan utils.HookState)
} else {
s.handle = source
s.isPublisher = true
s.receiveBuffer = stream.NewTCPReceiveBuffer()
source.Init(source.Input, source.Close)
go source.LoopEvent()
}