mirror of
https://github.com/aler9/gortsplib
synced 2025-10-08 16:40:09 +08:00
add ServerConn.Tracks
This commit is contained in:
@@ -55,7 +55,8 @@ func (s ServerConnState) String() string {
|
||||
return "uknown"
|
||||
}
|
||||
|
||||
type serverConnTrack struct {
|
||||
// ServerConnTrack is a track of a ServerConn.
|
||||
type ServerConnTrack struct {
|
||||
rtpPort int
|
||||
rtcpPort int
|
||||
}
|
||||
@@ -131,7 +132,7 @@ type ServerConn struct {
|
||||
br *bufio.Reader
|
||||
bw *bufio.Writer
|
||||
state ServerConnState
|
||||
tracks map[int]serverConnTrack
|
||||
tracks map[int]ServerConnTrack
|
||||
tracksProtocol *StreamProtocol
|
||||
writeMutex sync.Mutex
|
||||
readHandlers ServerConnReadHandlers
|
||||
@@ -156,7 +157,7 @@ func newServerConn(conf ServerConf, nconn net.Conn) *ServerConn {
|
||||
nconn: nconn,
|
||||
br: bufio.NewReaderSize(conn, serverReadBufferSize),
|
||||
bw: bufio.NewWriterSize(conn, serverWriteBufferSize),
|
||||
tracks: make(map[int]serverConnTrack),
|
||||
tracks: make(map[int]ServerConnTrack),
|
||||
terminate: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
@@ -189,6 +190,11 @@ func (sc *ServerConn) HasTrack(trackID int) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// Tracks returns the setupped tracks.
|
||||
func (sc *ServerConn) Tracks() map[int]ServerConnTrack {
|
||||
return sc.tracks
|
||||
}
|
||||
|
||||
func (sc *ServerConn) checkState(allowed map[ServerConnState]struct{}) error {
|
||||
if _, ok := allowed[sc.state]; ok {
|
||||
return nil
|
||||
@@ -476,7 +482,7 @@ func (sc *ServerConn) handleRequest(req *base.Request) (*base.Response, error) {
|
||||
sc.tracksProtocol = &th.Protocol
|
||||
|
||||
if th.Protocol == StreamProtocolUDP {
|
||||
sc.tracks[trackID] = serverConnTrack{
|
||||
sc.tracks[trackID] = ServerConnTrack{
|
||||
rtpPort: th.ClientPorts[0],
|
||||
rtcpPort: th.ClientPorts[1],
|
||||
}
|
||||
@@ -492,7 +498,7 @@ func (sc *ServerConn) handleRequest(req *base.Request) (*base.Response, error) {
|
||||
}.Write()
|
||||
|
||||
} else {
|
||||
sc.tracks[trackID] = serverConnTrack{}
|
||||
sc.tracks[trackID] = ServerConnTrack{}
|
||||
|
||||
res.Header["Transport"] = headers.Transport{
|
||||
Protocol: StreamProtocolTCP,
|
||||
|
Reference in New Issue
Block a user