This commit is contained in:
aler9 2020-07-11 10:24:42 +02:00
parent 3a72c6ef1c
commit 53e7d36411
5 changed files with 21 additions and 21 deletions

10
main.go
View File

@ -394,12 +394,12 @@ func newProgram(sargs []string, stdin io.Reader) (*program, error) {
http.DefaultServeMux = http.NewServeMux()
}
p.udplRtp, err = newServerUdpListener(p, conf.RtpPort, _TRACK_FLOW_RTP)
p.udplRtp, err = newServerUdpListener(p, conf.RtpPort, _TRACK_FLOW_TYPE_RTP)
if err != nil {
return nil, err
}
p.udplRtcp, err = newServerUdpListener(p, conf.RtcpPort, _TRACK_FLOW_RTCP)
p.udplRtcp, err = newServerUdpListener(p, conf.RtcpPort, _TRACK_FLOW_TYPE_RTCP)
if err != nil {
return nil, err
}
@ -570,7 +570,7 @@ outer:
}
for i, t := range cl.streamTracks {
if evt.trackFlowType == _TRACK_FLOW_RTP {
if evt.trackFlowType == _TRACK_FLOW_TYPE_RTP {
if t.rtpPort == evt.addr.Port {
return cl, i
}
@ -676,7 +676,7 @@ func (p *program) forwardTrack(path string, id int, trackFlowType trackFlowType,
for c := range p.clients {
if c.path == path && c.state == _CLIENT_STATE_PLAY {
if c.streamProtocol == _STREAM_PROTOCOL_UDP {
if trackFlowType == _TRACK_FLOW_RTP {
if trackFlowType == _TRACK_FLOW_TYPE_RTP {
p.udplRtp.write(&net.UDPAddr{
IP: c.ip(),
Zone: c.zone(),
@ -692,7 +692,7 @@ func (p *program) forwardTrack(path string, id int, trackFlowType trackFlowType,
}
} else {
c.writeFrame(trackToInterleavedChannel(id, trackFlowType), frame)
c.writeFrame(trackFlowTypeToInterleavedChannel(id, trackFlowType), frame)
}
}
}

View File

@ -18,10 +18,10 @@ const (
_UDP_STREAM_DEAD_AFTER = 10 * time.Second
)
type clientState int
type serverClientState int
const (
_CLIENT_STATE_STARTING clientState = iota
_CLIENT_STATE_STARTING serverClientState = iota
_CLIENT_STATE_ANNOUNCE
_CLIENT_STATE_PRE_PLAY
_CLIENT_STATE_PLAY
@ -29,7 +29,7 @@ const (
_CLIENT_STATE_RECORD
)
func (cs clientState) String() string {
func (cs serverClientState) String() string {
switch cs {
case _CLIENT_STATE_STARTING:
return "STARTING"
@ -55,7 +55,7 @@ func (cs clientState) String() string {
type serverClient struct {
p *program
conn *gortsplib.ConnServer
state clientState
state serverClientState
path string
authUser string
authPass string
@ -887,7 +887,7 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
switch recvt := recv.(type) {
case *gortsplib.InterleavedFrame:
trackId, trackFlowType := interleavedChannelToTrack(frame.Channel)
trackId, trackFlowType := interleavedChannelToTrackFlowType(frame.Channel)
if trackId >= len(c.streamTracks) {
c.log("ERR: invalid track id '%d'", trackId)

View File

@ -51,7 +51,7 @@ func newServerUdpListener(p *program, port int, trackFlowType trackFlowType) (*s
func (l *serverUdpListener) log(format string, args ...interface{}) {
var label string
if l.trackFlowType == _TRACK_FLOW_RTP {
if l.trackFlowType == _TRACK_FLOW_TYPE_RTP {
label = "RTP"
} else {
label = "RTCP"

View File

@ -272,13 +272,13 @@ func (s *streamer) runUdp(conn *gortsplib.ConnClient) bool {
var err error
udplRtp, err = newStreamerUdpListener(s.p, rtpPort, s, i,
_TRACK_FLOW_RTP, publisherIp)
_TRACK_FLOW_TYPE_RTP, publisherIp)
if err != nil {
continue
}
udplRtcp, err = newStreamerUdpListener(s.p, rtcpPort, s, i,
_TRACK_FLOW_RTCP, publisherIp)
_TRACK_FLOW_TYPE_RTCP, publisherIp)
if err != nil {
udplRtp.close()
continue
@ -606,7 +606,7 @@ outer:
break
}
trackId, trackFlowType := interleavedChannelToTrack(frame.Channel)
trackId, trackFlowType := interleavedChannelToTrackFlowType(frame.Channel)
s.p.events <- programEventStreamerFrame{s, trackId, trackFlowType, frame.Content}
}

View File

@ -32,19 +32,19 @@ func parseIpCidrList(in []string) ([]interface{}, error) {
type trackFlowType int
const (
_TRACK_FLOW_RTP trackFlowType = iota
_TRACK_FLOW_RTCP
_TRACK_FLOW_TYPE_RTP trackFlowType = iota
_TRACK_FLOW_TYPE_RTCP
)
func interleavedChannelToTrack(channel uint8) (int, trackFlowType) {
func interleavedChannelToTrackFlowType(channel uint8) (int, trackFlowType) {
if (channel % 2) == 0 {
return int(channel / 2), _TRACK_FLOW_RTP
return int(channel / 2), _TRACK_FLOW_TYPE_RTP
}
return int((channel - 1) / 2), _TRACK_FLOW_RTCP
return int((channel - 1) / 2), _TRACK_FLOW_TYPE_RTCP
}
func trackToInterleavedChannel(id int, trackFlowType trackFlowType) uint8 {
if trackFlowType == _TRACK_FLOW_RTP {
func trackFlowTypeToInterleavedChannel(id int, trackFlowType trackFlowType) uint8 {
if trackFlowType == _TRACK_FLOW_TYPE_RTP {
return uint8(id * 2)
}
return uint8((id * 2) + 1)