mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-08 08:30:15 +08:00
完善rtmp server
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package rtmp
|
||||
|
||||
import (
|
||||
"github.com/yangjiechina/avformat"
|
||||
"github.com/yangjiechina/avformat/librtmp"
|
||||
"github.com/yangjiechina/avformat/utils"
|
||||
"github.com/yangjiechina/live-server/stream"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Session 负责除RTMP连接和断开以外的所有生命周期处理
|
||||
@@ -15,43 +14,49 @@ type Session interface {
|
||||
Close()
|
||||
}
|
||||
|
||||
func NewSession() *sessionImpl {
|
||||
func NewSession(conn net.Conn) Session {
|
||||
impl := &sessionImpl{}
|
||||
stack := librtmp.NewStack(impl)
|
||||
impl.stack = stack
|
||||
impl.conn = conn
|
||||
return impl
|
||||
}
|
||||
|
||||
type sessionImpl struct {
|
||||
stream.SessionImpl
|
||||
//解析rtmp协议栈
|
||||
stack *librtmp.Stack
|
||||
//publisher/sink
|
||||
handle interface{}
|
||||
conn net.Conn
|
||||
|
||||
streamId string
|
||||
}
|
||||
|
||||
func (s *sessionImpl) OnPublish(app, stream_ string, response chan avformat.HookState) {
|
||||
func (s *sessionImpl) OnPublish(app, stream_ string, response chan utils.HookState) {
|
||||
s.streamId = app + "/" + stream_
|
||||
publisher := NewPublisher(s.streamId)
|
||||
s.stack.SetOnPublishHandler(publisher)
|
||||
s.stack.SetOnTransDeMuxerHandler(publisher)
|
||||
//stream.SessionImpl统一处理, Source是否已经存在, Hook回调....
|
||||
s.SessionImpl.OnPublish(publisher, nil, func() {
|
||||
s.handle = publisher
|
||||
response <- http.StatusOK
|
||||
}, func(state avformat.HookState) {
|
||||
response <- utils.HookStateOK
|
||||
}, func(state utils.HookState) {
|
||||
response <- state
|
||||
})
|
||||
}
|
||||
|
||||
func (s *sessionImpl) OnPlay(app, stream string, response chan avformat.HookState) {
|
||||
s.streamId = app + "/" + stream
|
||||
//sink := &Sink{}
|
||||
//s.SessionImpl.OnPlay(sink, nil, func() {
|
||||
// s.handle = sink
|
||||
// response <- http.StatusOK
|
||||
//}, func(state avformat.HookState) {
|
||||
// response <- state
|
||||
//})
|
||||
func (s *sessionImpl) OnPlay(app, stream_ string, response chan utils.HookState) {
|
||||
s.streamId = app + "/" + stream_
|
||||
|
||||
sink := NewSink(stream.GenerateSinkId(s.conn), s.conn)
|
||||
s.SessionImpl.OnPlay(sink, nil, func() {
|
||||
s.handle = sink
|
||||
response <- utils.HookStateOK
|
||||
}, func(state utils.HookState) {
|
||||
response <- state
|
||||
})
|
||||
}
|
||||
|
||||
func (s *sessionImpl) Input(conn net.Conn, data []byte) error {
|
||||
|
Reference in New Issue
Block a user