|
|
|
@ -6,6 +6,7 @@ import (
@@ -6,6 +6,7 @@ import (
|
|
|
|
|
"net" |
|
|
|
|
"os" |
|
|
|
|
"regexp" |
|
|
|
|
"strings" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"gopkg.in/alecthomas/kingpin.v2" |
|
|
|
@ -40,6 +41,7 @@ func (s streamProtocol) String() string {
@@ -40,6 +41,7 @@ func (s streamProtocol) String() string {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type program struct { |
|
|
|
|
protocols map[streamProtocol]struct{} |
|
|
|
|
rtspPort int |
|
|
|
|
rtpPort int |
|
|
|
|
rtcpPort int |
|
|
|
@ -52,7 +54,24 @@ type program struct {
@@ -52,7 +54,24 @@ type program struct {
|
|
|
|
|
publishers map[string]*client |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newProgram(rtspPort int, rtpPort int, rtcpPort int, publishKey string) (*program, error) { |
|
|
|
|
func newProgram(protocolsStr string, rtspPort int, rtpPort int, rtcpPort int, publishKey string) (*program, error) { |
|
|
|
|
protocols := make(map[streamProtocol]struct{}) |
|
|
|
|
for _, proto := range strings.Split(protocolsStr, ",") { |
|
|
|
|
switch proto { |
|
|
|
|
case "udp": |
|
|
|
|
protocols[_STREAM_PROTOCOL_UDP] = struct{}{} |
|
|
|
|
|
|
|
|
|
case "tcp": |
|
|
|
|
protocols[_STREAM_PROTOCOL_TCP] = struct{}{} |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
return nil, fmt.Errorf("unsupported protocol: %s", proto) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if len(protocols) == 0 { |
|
|
|
|
return nil, fmt.Errorf("no protocols supplied") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if publishKey != "" { |
|
|
|
|
if !regexp.MustCompile("^[a-zA-Z0-9]+$").MatchString(publishKey) { |
|
|
|
|
return nil, fmt.Errorf("publish key must be alphanumeric") |
|
|
|
@ -62,6 +81,7 @@ func newProgram(rtspPort int, rtpPort int, rtcpPort int, publishKey string) (*pr
@@ -62,6 +81,7 @@ func newProgram(rtspPort int, rtpPort int, rtcpPort int, publishKey string) (*pr
|
|
|
|
|
log.Printf("rtsp-simple-server %s", Version) |
|
|
|
|
|
|
|
|
|
p := &program{ |
|
|
|
|
protocols: protocols, |
|
|
|
|
rtspPort: rtspPort, |
|
|
|
|
rtpPort: rtpPort, |
|
|
|
|
rtcpPort: rtcpPort, |
|
|
|
@ -128,6 +148,7 @@ func main() {
@@ -128,6 +148,7 @@ func main() {
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
@ -140,7 +161,7 @@ func main() {
@@ -140,7 +161,7 @@ func main() {
|
|
|
|
|
os.Exit(0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
p, err := newProgram(*rtspPort, *rtpPort, *rtcpPort, *publishKey) |
|
|
|
|
p, err := newProgram(*protocols, *rtspPort, *rtpPort, *rtcpPort, *publishKey) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal("ERR: ", err) |
|
|
|
|
} |
|
|
|
|