|
|
|
@ -48,22 +48,52 @@ func (s streamProtocol) String() string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type program struct { |
|
|
|
type program struct { |
|
|
|
protocols map[streamProtocol]struct{} |
|
|
|
protocols map[streamProtocol]struct{} |
|
|
|
rtspPort int |
|
|
|
rtspPort int |
|
|
|
rtpPort int |
|
|
|
rtpPort int |
|
|
|
rtcpPort int |
|
|
|
rtcpPort int |
|
|
|
publishKey string |
|
|
|
publishUser string |
|
|
|
preScript string |
|
|
|
publishPass string |
|
|
|
postScript string |
|
|
|
preScript string |
|
|
|
mutex sync.RWMutex |
|
|
|
postScript string |
|
|
|
rtspl *serverTcpListener |
|
|
|
mutex sync.RWMutex |
|
|
|
rtpl *serverUdpListener |
|
|
|
rtspl *serverTcpListener |
|
|
|
rtcpl *serverUdpListener |
|
|
|
rtpl *serverUdpListener |
|
|
|
clients map[*client]struct{} |
|
|
|
rtcpl *serverUdpListener |
|
|
|
publishers map[string]*client |
|
|
|
clients map[*client]struct{} |
|
|
|
|
|
|
|
publishers map[string]*client |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newProgram(protocolsStr string, rtspPort int, rtpPort int, rtcpPort int, publishKey string, preScript string, postScript string) (*program, error) { |
|
|
|
func newProgram() (*program, error) { |
|
|
|
|
|
|
|
kingpin.CommandLine.Help = "rtsp-simple-server " + Version + "\n\n" + |
|
|
|
|
|
|
|
"RTSP server." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
argVersion := kingpin.Flag("version", "print rtsp-simple-server version").Bool() |
|
|
|
|
|
|
|
argProtocolsStr := kingpin.Flag("protocols", "supported protocols").Default("udp,tcp").String() |
|
|
|
|
|
|
|
argRtspPort := kingpin.Flag("rtsp-port", "port of the RTSP TCP listener").Default("8554").Int() |
|
|
|
|
|
|
|
argRtpPort := kingpin.Flag("rtp-port", "port of the RTP UDP listener").Default("8000").Int() |
|
|
|
|
|
|
|
argRtcpPort := kingpin.Flag("rtcp-port", "port of the RTCP UDP listener").Default("8001").Int() |
|
|
|
|
|
|
|
argPublishUser := kingpin.Flag("publish-user", "optional username required to publish").Default("").String() |
|
|
|
|
|
|
|
argPublishPass := kingpin.Flag("publish-pass", "optional password required to publish").Default("").String() |
|
|
|
|
|
|
|
argPreScript := kingpin.Flag("pre-script", "optional script to run on client connect").Default("").String() |
|
|
|
|
|
|
|
argPostScript := kingpin.Flag("post-script", "optional script to run on client disconnect").Default("").String() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kingpin.Parse() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
version := *argVersion |
|
|
|
|
|
|
|
protocolsStr := *argProtocolsStr |
|
|
|
|
|
|
|
rtspPort := *argRtspPort |
|
|
|
|
|
|
|
rtpPort := *argRtpPort |
|
|
|
|
|
|
|
rtcpPort := *argRtcpPort |
|
|
|
|
|
|
|
publishUser := *argPublishUser |
|
|
|
|
|
|
|
publishPass := *argPublishPass |
|
|
|
|
|
|
|
preScript := *argPreScript |
|
|
|
|
|
|
|
postScript := *argPostScript |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if version == true { |
|
|
|
|
|
|
|
fmt.Println("rtsp-simple-server " + Version) |
|
|
|
|
|
|
|
os.Exit(0) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if rtspPort == 0 { |
|
|
|
if rtspPort == 0 { |
|
|
|
return nil, fmt.Errorf("rtsp port not provided") |
|
|
|
return nil, fmt.Errorf("rtsp port not provided") |
|
|
|
@ -102,24 +132,35 @@ func newProgram(protocolsStr string, rtspPort int, rtpPort int, rtcpPort int, pu |
|
|
|
return nil, fmt.Errorf("no protocols provided") |
|
|
|
return nil, fmt.Errorf("no protocols provided") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if publishKey != "" { |
|
|
|
if publishUser != "" { |
|
|
|
if !regexp.MustCompile("^[a-zA-Z0-9]+$").MatchString(publishKey) { |
|
|
|
if !regexp.MustCompile("^[a-zA-Z0-9]+$").MatchString(publishUser) { |
|
|
|
return nil, fmt.Errorf("publish key must be alphanumeric") |
|
|
|
return nil, fmt.Errorf("publish username must be alphanumeric") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if publishPass != "" { |
|
|
|
|
|
|
|
if !regexp.MustCompile("^[a-zA-Z0-9]+$").MatchString(publishPass) { |
|
|
|
|
|
|
|
return nil, fmt.Errorf("publish password must be alphanumeric") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if publishUser != "" && publishPass == "" || publishUser == "" && publishPass != "" { |
|
|
|
|
|
|
|
return nil, fmt.Errorf("publish username and password must be both filled") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.Printf("rtsp-simple-server %s", Version) |
|
|
|
log.Printf("rtsp-simple-server %s", Version) |
|
|
|
|
|
|
|
|
|
|
|
p := &program{ |
|
|
|
p := &program{ |
|
|
|
protocols: protocols, |
|
|
|
protocols: protocols, |
|
|
|
rtspPort: rtspPort, |
|
|
|
rtspPort: rtspPort, |
|
|
|
rtpPort: rtpPort, |
|
|
|
rtpPort: rtpPort, |
|
|
|
rtcpPort: rtcpPort, |
|
|
|
rtcpPort: rtcpPort, |
|
|
|
publishKey: publishKey, |
|
|
|
publishUser: publishUser, |
|
|
|
preScript: preScript, |
|
|
|
publishPass: publishPass, |
|
|
|
postScript: postScript, |
|
|
|
preScript: preScript, |
|
|
|
clients: make(map[*client]struct{}), |
|
|
|
postScript: postScript, |
|
|
|
publishers: make(map[string]*client), |
|
|
|
clients: make(map[*client]struct{}), |
|
|
|
|
|
|
|
publishers: make(map[string]*client), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
var err error |
|
|
|
@ -184,26 +225,7 @@ func (p *program) forwardTrack(path string, id int, flow trackFlow, frame []byte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
kingpin.CommandLine.Help = "rtsp-simple-server " + Version + "\n\n" + |
|
|
|
p, err := newProgram() |
|
|
|
"RTSP server." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
version := kingpin.Flag("version", "print rtsp-simple-server version").Bool() |
|
|
|
|
|
|
|
protocols := kingpin.Flag("protocols", "supported protocols").Default("udp,tcp").String() |
|
|
|
|
|
|
|
rtspPort := kingpin.Flag("rtsp-port", "port of the RTSP TCP listener").Default("8554").Int() |
|
|
|
|
|
|
|
rtpPort := kingpin.Flag("rtp-port", "port of the RTP UDP listener").Default("8000").Int() |
|
|
|
|
|
|
|
rtcpPort := kingpin.Flag("rtcp-port", "port of the RTCP UDP listener").Default("8001").Int() |
|
|
|
|
|
|
|
publishKey := kingpin.Flag("publish-key", "optional authentication key required to publish").Default("").String() |
|
|
|
|
|
|
|
preScript := kingpin.Flag("pre-script", "optional script to run on client connect").Default("").String() |
|
|
|
|
|
|
|
postScript := kingpin.Flag("post-script", "optional script to run on client disconnect").Default("").String() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kingpin.Parse() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if *version == true { |
|
|
|
|
|
|
|
fmt.Println("rtsp-simple-server " + Version) |
|
|
|
|
|
|
|
os.Exit(0) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p, err := newProgram(*protocols, *rtspPort, *rtpPort, *rtcpPort, *publishKey, *preScript, *postScript) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal("ERR: ", err) |
|
|
|
log.Fatal("ERR: ", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|