|
|
@ -1,6 +1,7 @@ |
|
|
|
package core |
|
|
|
package core |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"encoding/hex" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"net" |
|
|
|
"net" |
|
|
@ -9,6 +10,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"github.com/aler9/gortsplib" |
|
|
|
"github.com/aler9/gortsplib" |
|
|
|
"github.com/aler9/gortsplib/pkg/base" |
|
|
|
"github.com/aler9/gortsplib/pkg/base" |
|
|
|
|
|
|
|
"github.com/google/uuid" |
|
|
|
"github.com/pion/rtp" |
|
|
|
"github.com/pion/rtp" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/conf" |
|
|
|
"github.com/aler9/rtsp-simple-server/internal/conf" |
|
|
@ -32,13 +34,13 @@ type rtspSessionParent interface { |
|
|
|
type rtspSession struct { |
|
|
|
type rtspSession struct { |
|
|
|
isTLS bool |
|
|
|
isTLS bool |
|
|
|
protocols map[conf.Protocol]struct{} |
|
|
|
protocols map[conf.Protocol]struct{} |
|
|
|
id string |
|
|
|
|
|
|
|
ss *gortsplib.ServerSession |
|
|
|
ss *gortsplib.ServerSession |
|
|
|
author *gortsplib.ServerConn |
|
|
|
author *gortsplib.ServerConn |
|
|
|
externalCmdPool *externalcmd.Pool |
|
|
|
externalCmdPool *externalcmd.Pool |
|
|
|
pathManager rtspSessionPathManager |
|
|
|
pathManager rtspSessionPathManager |
|
|
|
parent rtspSessionParent |
|
|
|
parent rtspSessionParent |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uuid uuid.UUID |
|
|
|
created time.Time |
|
|
|
created time.Time |
|
|
|
path *path |
|
|
|
path *path |
|
|
|
stream *stream |
|
|
|
stream *stream |
|
|
@ -50,7 +52,6 @@ type rtspSession struct { |
|
|
|
func newRTSPSession( |
|
|
|
func newRTSPSession( |
|
|
|
isTLS bool, |
|
|
|
isTLS bool, |
|
|
|
protocols map[conf.Protocol]struct{}, |
|
|
|
protocols map[conf.Protocol]struct{}, |
|
|
|
id string, |
|
|
|
|
|
|
|
ss *gortsplib.ServerSession, |
|
|
|
ss *gortsplib.ServerSession, |
|
|
|
sc *gortsplib.ServerConn, |
|
|
|
sc *gortsplib.ServerConn, |
|
|
|
externalCmdPool *externalcmd.Pool, |
|
|
|
externalCmdPool *externalcmd.Pool, |
|
|
@ -60,12 +61,12 @@ func newRTSPSession( |
|
|
|
s := &rtspSession{ |
|
|
|
s := &rtspSession{ |
|
|
|
isTLS: isTLS, |
|
|
|
isTLS: isTLS, |
|
|
|
protocols: protocols, |
|
|
|
protocols: protocols, |
|
|
|
id: id, |
|
|
|
|
|
|
|
ss: ss, |
|
|
|
ss: ss, |
|
|
|
author: sc, |
|
|
|
author: sc, |
|
|
|
externalCmdPool: externalCmdPool, |
|
|
|
externalCmdPool: externalCmdPool, |
|
|
|
pathManager: pathManager, |
|
|
|
pathManager: pathManager, |
|
|
|
parent: parent, |
|
|
|
parent: parent, |
|
|
|
|
|
|
|
uuid: uuid.New(), |
|
|
|
created: time.Now(), |
|
|
|
created: time.Now(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -93,7 +94,8 @@ func (s *rtspSession) remoteAddr() net.Addr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *rtspSession) log(level logger.Level, format string, args ...interface{}) { |
|
|
|
func (s *rtspSession) log(level logger.Level, format string, args ...interface{}) { |
|
|
|
s.parent.log(level, "[session %s] "+format, append([]interface{}{s.id}, args...)...) |
|
|
|
id := hex.EncodeToString(s.uuid[:4]) |
|
|
|
|
|
|
|
s.parent.log(level, "[session %s] "+format, append([]interface{}{id}, args...)...) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// onClose is called by rtspServer.
|
|
|
|
// onClose is called by rtspServer.
|
|
|
@ -357,7 +359,7 @@ func (s *rtspSession) apiReaderDescribe() interface{} { |
|
|
|
return struct { |
|
|
|
return struct { |
|
|
|
Type string `json:"type"` |
|
|
|
Type string `json:"type"` |
|
|
|
ID string `json:"id"` |
|
|
|
ID string `json:"id"` |
|
|
|
}{typ, s.id} |
|
|
|
}{typ, s.uuid.String()} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// apiSourceDescribe implements source.
|
|
|
|
// apiSourceDescribe implements source.
|
|
|
@ -372,7 +374,7 @@ func (s *rtspSession) apiSourceDescribe() interface{} { |
|
|
|
return struct { |
|
|
|
return struct { |
|
|
|
Type string `json:"type"` |
|
|
|
Type string `json:"type"` |
|
|
|
ID string `json:"id"` |
|
|
|
ID string `json:"id"` |
|
|
|
}{typ, s.id} |
|
|
|
}{typ, s.uuid.String()} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// onPacketRTP is called by rtspServer.
|
|
|
|
// onPacketRTP is called by rtspServer.
|
|
|
|