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