支持保存推流数据包到文件. 打印拉流url

This commit is contained in:
yangjiechina
2024-07-04 22:35:55 +08:00
parent 4b1200d9ad
commit dfda276583
17 changed files with 280 additions and 81 deletions

42
stream/stream_server.go Normal file
View File

@@ -0,0 +1,42 @@
package stream
import (
"github.com/yangjiechina/avformat/transport"
"github.com/yangjiechina/lkm/log"
"net"
)
type SessionHandler[T any] interface {
OnNewSession(conn net.Conn) T
OnCloseSession(session T)
}
type StreamServer[T any] struct {
SourceType SourceType
Handler SessionHandler[T]
}
func (s *StreamServer[T]) OnConnected(conn net.Conn) []byte {
log.Sugar.Debugf("%s连接 conn:%s", s.SourceType.ToString(), conn.RemoteAddr().String())
conn.(*transport.Conn).Data = s.Handler.OnNewSession(conn)
return nil
}
func (s *StreamServer[T]) OnPacket(conn net.Conn, data []byte) []byte {
if AppConfig.Debug {
DumpStream2File(s.SourceType, conn, data)
}
return nil
}
func (s *StreamServer[T]) OnDisConnected(conn net.Conn, err error) {
log.Sugar.Debugf("%s断开连接 conn:%s", s.SourceType.ToString(), conn.RemoteAddr().String())
t := conn.(*transport.Conn)
if t.Data != nil {
s.Handler.OnCloseSession(t.Data.(T))
t.Data = nil
}
}