mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-27 17:21:23 +08:00
接口不使用“I”开头, 实现类不使用"impl"结尾
This commit is contained in:
@@ -9,22 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// Session 负责除连接和断开以外的所有RTMP生命周期处理
|
||||
type Session interface {
|
||||
Input(conn net.Conn, data []byte) error //接受网络数据包再交由Stack处理
|
||||
|
||||
Close()
|
||||
}
|
||||
|
||||
func NewSession(conn net.Conn) Session {
|
||||
impl := &sessionImpl{}
|
||||
|
||||
stack := librtmp.NewStack(impl)
|
||||
impl.stack = stack
|
||||
impl.conn = conn
|
||||
return impl
|
||||
}
|
||||
|
||||
type sessionImpl struct {
|
||||
type Session struct {
|
||||
//解析rtmp协议栈
|
||||
stack *librtmp.Stack
|
||||
//Publisher/sink, 在publish或play成功后赋值
|
||||
@@ -34,7 +19,7 @@ type sessionImpl struct {
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
func (s *sessionImpl) generateSourceId(app, stream_ string) string {
|
||||
func (s *Session) generateSourceId(app, stream_ string) string {
|
||||
if len(app) == 0 {
|
||||
return stream_
|
||||
} else if len(stream_) == 0 {
|
||||
@@ -44,7 +29,7 @@ func (s *sessionImpl) generateSourceId(app, stream_ string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sessionImpl) OnPublish(app, stream_ string, response chan utils.HookState) {
|
||||
func (s *Session) OnPublish(app, stream_ string, response chan utils.HookState) {
|
||||
log.Sugar.Infof("rtmp onpublish app:%s stream:%s conn:%s", app, stream_, s.conn.RemoteAddr().String())
|
||||
|
||||
sourceId := s.generateSourceId(app, stream_)
|
||||
@@ -66,7 +51,7 @@ func (s *sessionImpl) OnPublish(app, stream_ string, response chan utils.HookSta
|
||||
})
|
||||
}
|
||||
|
||||
func (s *sessionImpl) OnPlay(app, stream_ string, response chan utils.HookState) {
|
||||
func (s *Session) OnPlay(app, stream_ string, response chan utils.HookState) {
|
||||
sourceId := s.generateSourceId(app, stream_)
|
||||
//拉流事件Sink统一处理
|
||||
sink := NewSink(stream.GenerateSinkId(s.conn.RemoteAddr()), sourceId, s.conn)
|
||||
@@ -81,7 +66,7 @@ func (s *sessionImpl) OnPlay(app, stream_ string, response chan utils.HookState)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *sessionImpl) Input(conn net.Conn, data []byte) error {
|
||||
func (s *Session) Input(conn net.Conn, data []byte) error {
|
||||
//如果是推流,并且握手成功,后续收到的包,都将发送给LoopEvent处理
|
||||
if s.isPublisher {
|
||||
s.handle.(*Publisher).AddEvent(stream.SourceEventInput, data)
|
||||
@@ -91,7 +76,7 @@ func (s *sessionImpl) Input(conn net.Conn, data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sessionImpl) Close() {
|
||||
func (s *Session) Close() {
|
||||
log.Sugar.Debugf("释放rtmp session conn:%s", s.conn.RemoteAddr().String())
|
||||
|
||||
//释放协议栈
|
||||
@@ -110,7 +95,16 @@ func (s *sessionImpl) Close() {
|
||||
s.handle.(*Publisher).AddEvent(stream.SourceEventClose, nil)
|
||||
}
|
||||
} else {
|
||||
sink := s.handle.(stream.ISink)
|
||||
sink := s.handle.(stream.Sink)
|
||||
sink.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func NewSession(conn net.Conn) *Session {
|
||||
session := &Session{}
|
||||
|
||||
stack := librtmp.NewStack(session)
|
||||
session.stack = stack
|
||||
session.conn = conn
|
||||
return session
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user