66 "net"
77 "os"
88 "regexp"
9+ "strings"
910 "sync"
1011
1112 "gopkg.in/alecthomas/kingpin.v2"
@@ -40,6 +41,7 @@ func (s streamProtocol) String() string {
4041}
4142
4243type program struct {
44+ protocols map [streamProtocol ]struct {}
4345 rtspPort int
4446 rtpPort int
4547 rtcpPort int
@@ -52,7 +54,24 @@ type program struct {
5254 publishers map [string ]* client
5355}
5456
55- func newProgram (rtspPort int , rtpPort int , rtcpPort int , publishKey string ) (* program , error ) {
57+ func newProgram (protocolsStr string , rtspPort int , rtpPort int , rtcpPort int , publishKey string ) (* program , error ) {
58+ protocols := make (map [streamProtocol ]struct {})
59+ for _ , proto := range strings .Split (protocolsStr , "," ) {
60+ switch proto {
61+ case "udp" :
62+ protocols [_STREAM_PROTOCOL_UDP ] = struct {}{}
63+
64+ case "tcp" :
65+ protocols [_STREAM_PROTOCOL_TCP ] = struct {}{}
66+
67+ default :
68+ return nil , fmt .Errorf ("unsupported protocol: %s" , proto )
69+ }
70+ }
71+ if len (protocols ) == 0 {
72+ return nil , fmt .Errorf ("no protocols supplied" )
73+ }
74+
5675 if publishKey != "" {
5776 if ! regexp .MustCompile ("^[a-zA-Z0-9]+$" ).MatchString (publishKey ) {
5877 return nil , fmt .Errorf ("publish key must be alphanumeric" )
@@ -62,6 +81,7 @@ func newProgram(rtspPort int, rtpPort int, rtcpPort int, publishKey string) (*pr
6281 log .Printf ("rtsp-simple-server %s" , Version )
6382
6483 p := & program {
84+ protocols : protocols ,
6585 rtspPort : rtspPort ,
6686 rtpPort : rtpPort ,
6787 rtcpPort : rtcpPort ,
@@ -128,6 +148,7 @@ func main() {
128148
129149 version := kingpin .Flag ("version" , "print rtsp-simple-server version" ).Bool ()
130150
151+ protocols := kingpin .Flag ("protocols" , "supported protocols" ).Default ("udp,tcp" ).String ()
131152 rtspPort := kingpin .Flag ("rtsp-port" , "port of the RTSP TCP listener" ).Default ("8554" ).Int ()
132153 rtpPort := kingpin .Flag ("rtp-port" , "port of the RTP UDP listener" ).Default ("8000" ).Int ()
133154 rtcpPort := kingpin .Flag ("rtcp-port" , "port of the RTCP UDP listener" ).Default ("8001" ).Int ()
@@ -140,7 +161,7 @@ func main() {
140161 os .Exit (0 )
141162 }
142163
143- p , err := newProgram (* rtspPort , * rtpPort , * rtcpPort , * publishKey )
164+ p , err := newProgram (* protocols , * rtspPort , * rtpPort , * rtcpPort , * publishKey )
144165 if err != nil {
145166 log .Fatal ("ERR: " , err )
146167 }
0 commit comments