Browse Source

cleanup

pull/31/head
aler9 6 years ago
parent
commit
53e7d36411
  1. 10
      main.go
  2. 10
      server-client.go
  3. 2
      server-udpl.go
  4. 6
      streamer.go
  5. 14
      utils.go

10
main.go

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

10
server-client.go

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

2
server-udpl.go

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

6
streamer.go

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

14
utils.go

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

Loading…
Cancel
Save