mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-05 15:16:49 +08:00
fix: rtmp推拉流频繁创建内存问题
This commit is contained in:
@@ -65,11 +65,7 @@ func (s *server) OnPacket(conn net.Conn, data []byte) []byte {
|
|||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.isPublisher {
|
return session.receiveBuffer
|
||||||
return stream.TCPReceiveBufferPool.Get().([]byte)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() Server {
|
func NewServer() Server {
|
||||||
|
@@ -14,6 +14,7 @@ type Session struct {
|
|||||||
stack *rtmp.ServerStack // rtmp协议栈, 解析message
|
stack *rtmp.ServerStack // rtmp协议栈, 解析message
|
||||||
handle interface{} // 持有具体会话句柄(推流端/拉流端), 在@see OnPublish @see OnPlay回调中赋值
|
handle interface{} // 持有具体会话句柄(推流端/拉流端), 在@see OnPublish @see OnPlay回调中赋值
|
||||||
isPublisher bool // 是否是推流会话
|
isPublisher bool // 是否是推流会话
|
||||||
|
receiveBuffer []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) generateSourceID(app, stream string) string {
|
func (s *Session) generateSourceID(app, stream string) string {
|
||||||
@@ -95,6 +96,11 @@ func (s *Session) Close() {
|
|||||||
s.stack.Close()
|
s.stack.Close()
|
||||||
s.stack = nil
|
s.stack = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.receiveBuffer != nil {
|
||||||
|
stream.TCPReceiveBufferPool.Put(s.receiveBuffer[:cap(s.receiveBuffer)])
|
||||||
|
s.receiveBuffer = nil
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 还未确定会话类型, 无需处理
|
// 还未确定会话类型, 无需处理
|
||||||
@@ -118,7 +124,9 @@ func (s *Session) Close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewSession(conn net.Conn) *Session {
|
func NewSession(conn net.Conn) *Session {
|
||||||
session := &Session{}
|
session := &Session{
|
||||||
|
receiveBuffer: stream.TCPReceiveBufferPool.Get().([]byte),
|
||||||
|
}
|
||||||
|
|
||||||
stackServer := rtmp.NewStackServer(false)
|
stackServer := rtmp.NewStackServer(false)
|
||||||
stackServer.SetOnStreamHandler(session)
|
stackServer.SetOnStreamHandler(session)
|
||||||
|
Reference in New Issue
Block a user