@@ -77,18 +77,18 @@ func sdpFilter(msgIn *sdp.Message, byteIn []byte) (*sdp.Message, []byte) {
7777 return msgOut , byteOut
7878}
7979
80- func interleavedChannelToTrack (channel int ) (int , trackFlow ) {
80+ func interleavedChannelToTrack (channel uint8 ) (int , trackFlow ) {
8181 if (channel % 2 ) == 0 {
82- return (channel / 2 ), _TRACK_FLOW_RTP
82+ return int (channel / 2 ), _TRACK_FLOW_RTP
8383 }
84- return ((channel - 1 ) / 2 ), _TRACK_FLOW_RTCP
84+ return int ((channel - 1 ) / 2 ), _TRACK_FLOW_RTCP
8585}
8686
87- func trackToInterleavedChannel (id int , flow trackFlow ) int {
87+ func trackToInterleavedChannel (id int , flow trackFlow ) uint8 {
8888 if flow == _TRACK_FLOW_RTP {
89- return id * 2
89+ return uint8 ( id * 2 )
9090 }
91- return ( id * 2 ) + 1
91+ return uint8 (( id * 2 ) + 1 )
9292}
9393
9494type clientState int
@@ -104,7 +104,7 @@ const (
104104
105105type client struct {
106106 p * program
107- conn * gortsplib.Conn
107+ conn * gortsplib.ConnServer
108108 state clientState
109109 ip net.IP
110110 path string
@@ -117,7 +117,7 @@ type client struct {
117117func newClient (p * program , nconn net.Conn ) * client {
118118 c := & client {
119119 p : p ,
120- conn : gortsplib .NewConn (nconn ),
120+ conn : gortsplib .NewConnServer (nconn ),
121121 state : _CLIENT_STATE_STARTING ,
122122 }
123123
@@ -195,12 +195,12 @@ func (c *client) writeResDeadline(res *gortsplib.Response) {
195195func (c * client ) writeResError (req * gortsplib.Request , err error ) {
196196 c .log ("ERR: %s" , err )
197197
198- if cseq , ok := req .Headers ["CSeq" ]; ok {
198+ if cseq , ok := req .Header ["CSeq" ]; ok && len ( cseq ) == 1 {
199199 c .writeResDeadline (& gortsplib.Response {
200200 StatusCode : 400 ,
201201 Status : "Bad Request" ,
202- Headers : map [ string ] string {
203- "CSeq" : cseq ,
202+ Header : gortsplib. Header {
203+ "CSeq" : [] string { cseq [ 0 ]} ,
204204 },
205205 })
206206 } else {
@@ -214,8 +214,8 @@ func (c *client) writeResError(req *gortsplib.Request, err error) {
214214func (c * client ) handleRequest (req * gortsplib.Request ) bool {
215215 c .log (req .Method )
216216
217- cseq , ok := req .Headers ["CSeq" ]
218- if ! ok {
217+ cseq , ok := req .Header ["CSeq" ]
218+ if ! ok || len ( cseq ) != 1 {
219219 c .writeResError (req , fmt .Errorf ("cseq missing" ))
220220 return false
221221 }
@@ -250,17 +250,17 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
250250 c .writeResDeadline (& gortsplib.Response {
251251 StatusCode : 200 ,
252252 Status : "OK" ,
253- Headers : map [ string ] string {
253+ Header : gortsplib. Header {
254254 "CSeq" : cseq ,
255- "Public" : strings .Join ([]string {
255+ "Public" : [] string { strings .Join ([]string {
256256 "DESCRIBE" ,
257257 "ANNOUNCE" ,
258258 "SETUP" ,
259259 "PLAY" ,
260260 "PAUSE" ,
261261 "RECORD" ,
262262 "TEARDOWN" ,
263- }, ", " ),
263+ }, ", " )} ,
264264 },
265265 })
266266 return true
@@ -290,10 +290,10 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
290290 c .writeResDeadline (& gortsplib.Response {
291291 StatusCode : 200 ,
292292 Status : "OK" ,
293- Headers : map [ string ] string {
294- "CSeq" : cseq ,
295- "Content-Base" : req .Url ,
296- "Content-Type" : "application/sdp" ,
293+ Header : gortsplib. Header {
294+ "CSeq" : [] string { cseq [ 0 ]} ,
295+ "Content-Base" : [] string { req .Url } ,
296+ "Content-Type" : [] string { "application/sdp" } ,
297297 },
298298 Content : sdp ,
299299 })
@@ -305,13 +305,13 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
305305 return false
306306 }
307307
308- ct , ok := req .Headers ["Content-Type" ]
309- if ! ok {
308+ ct , ok := req .Header ["Content-Type" ]
309+ if ! ok || len ( ct ) != 1 {
310310 c .writeResError (req , fmt .Errorf ("Content-Type header missing" ))
311311 return false
312312 }
313313
314- if ct != "application/sdp" {
314+ if ct [ 0 ] != "application/sdp" {
315315 c .writeResError (req , fmt .Errorf ("unsupported Content-Type '%s'" , ct ))
316316 return false
317317 }
@@ -338,8 +338,8 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
338338 c .writeResDeadline (& gortsplib.Response {
339339 StatusCode : 401 ,
340340 Status : "Unauthorized" ,
341- Headers : map [ string ] string {
342- "CSeq" : req . Headers [ "CSeq" ] ,
341+ Header : gortsplib. Header {
342+ "CSeq" : [] string { cseq [ 0 ]} ,
343343 },
344344 })
345345 return false
@@ -370,20 +370,20 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
370370 c .writeResDeadline (& gortsplib.Response {
371371 StatusCode : 200 ,
372372 Status : "OK" ,
373- Headers : map [ string ] string {
374- "CSeq" : cseq ,
373+ Header : gortsplib. Header {
374+ "CSeq" : [] string { cseq [ 0 ]} ,
375375 },
376376 })
377377 return true
378378
379379 case "SETUP" :
380- transportStr , ok := req .Headers ["Transport" ]
381- if ! ok {
380+ tsRaw , ok := req .Header ["Transport" ]
381+ if ! ok || len ( tsRaw ) != 1 {
382382 c .writeResError (req , fmt .Errorf ("transport header missing" ))
383383 return false
384384 }
385385
386- th := gortsplib .NewTransportHeader ( transportStr )
386+ th := gortsplib .ReadHeaderTransport ( tsRaw [ 0 ] )
387387
388388 if _ , ok := th ["unicast" ]; ! ok {
389389 c .writeResError (req , fmt .Errorf ("transport header does not contain unicast" ))
@@ -410,7 +410,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
410410 c .writeResDeadline (& gortsplib.Response {
411411 StatusCode : 461 ,
412412 Status : "Unsupported Transport" ,
413- Headers : map [ string ] string {
413+ Header : gortsplib. Header {
414414 "CSeq" : cseq ,
415415 },
416416 })
@@ -419,7 +419,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
419419
420420 rtpPort , rtcpPort := th .GetPorts ("client_port" )
421421 if rtpPort == 0 || rtcpPort == 0 {
422- c .writeResError (req , fmt .Errorf ("transport header does not have valid client ports (%s)" , transportStr ))
422+ c .writeResError (req , fmt .Errorf ("transport header does not have valid client ports (%s)" , tsRaw [ 0 ] ))
423423 return false
424424 }
425425
@@ -463,15 +463,15 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
463463 c .writeResDeadline (& gortsplib.Response {
464464 StatusCode : 200 ,
465465 Status : "OK" ,
466- Headers : map [ string ] string {
467- "CSeq" : cseq ,
468- "Transport" : strings .Join ([]string {
466+ Header : gortsplib. Header {
467+ "CSeq" : [] string { cseq [ 0 ]} ,
468+ "Transport" : [] string { strings .Join ([]string {
469469 "RTP/AVP/UDP" ,
470470 "unicast" ,
471471 fmt .Sprintf ("client_port=%d-%d" , rtpPort , rtcpPort ),
472472 fmt .Sprintf ("server_port=%d-%d" , c .p .rtpPort , c .p .rtcpPort ),
473- }, ";" ),
474- "Session" : "12345678" ,
473+ }, ";" )} ,
474+ "Session" : [] string { "12345678" } ,
475475 },
476476 })
477477 return true
@@ -483,7 +483,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
483483 c .writeResDeadline (& gortsplib.Response {
484484 StatusCode : 461 ,
485485 Status : "Unsupported Transport" ,
486- Headers : map [ string ] string {
486+ Header : gortsplib. Header {
487487 "CSeq" : cseq ,
488488 },
489489 })
@@ -532,20 +532,20 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
532532 c .writeResDeadline (& gortsplib.Response {
533533 StatusCode : 200 ,
534534 Status : "OK" ,
535- Headers : map [ string ] string {
536- "CSeq" : cseq ,
537- "Transport" : strings .Join ([]string {
535+ Header : gortsplib. Header {
536+ "CSeq" : [] string { cseq [ 0 ]} ,
537+ "Transport" : [] string { strings .Join ([]string {
538538 "RTP/AVP/TCP" ,
539539 "unicast" ,
540540 fmt .Sprintf ("interleaved=%s" , interleaved ),
541- }, ";" ),
542- "Session" : "12345678" ,
541+ }, ";" )} ,
542+ "Session" : [] string { "12345678" } ,
543543 },
544544 })
545545 return true
546546
547547 } else {
548- c .writeResError (req , fmt .Errorf ("transport header does not contain a valid protocol (RTP/AVP, RTP/AVP/UDP or RTP/AVP/TCP) (%s)" , transportStr ))
548+ c .writeResError (req , fmt .Errorf ("transport header does not contain a valid protocol (RTP/AVP, RTP/AVP/UDP or RTP/AVP/TCP) (%s)" , tsRaw [ 0 ] ))
549549 return false
550550 }
551551
@@ -578,7 +578,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
578578 c .writeResDeadline (& gortsplib.Response {
579579 StatusCode : 461 ,
580580 Status : "Unsupported Transport" ,
581- Headers : map [ string ] string {
581+ Header : gortsplib. Header {
582582 "CSeq" : cseq ,
583583 },
584584 })
@@ -587,7 +587,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
587587
588588 rtpPort , rtcpPort := th .GetPorts ("client_port" )
589589 if rtpPort == 0 || rtcpPort == 0 {
590- c .writeResError (req , fmt .Errorf ("transport header does not have valid client ports (%s)" , transportStr ))
590+ c .writeResError (req , fmt .Errorf ("transport header does not have valid client ports (%s)" , tsRaw [ 0 ] ))
591591 return false
592592 }
593593
@@ -620,15 +620,15 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
620620 c .writeResDeadline (& gortsplib.Response {
621621 StatusCode : 200 ,
622622 Status : "OK" ,
623- Headers : map [ string ] string {
624- "CSeq" : cseq ,
625- "Transport" : strings .Join ([]string {
623+ Header : gortsplib. Header {
624+ "CSeq" : [] string { cseq [ 0 ]} ,
625+ "Transport" : [] string { strings .Join ([]string {
626626 "RTP/AVP/UDP" ,
627627 "unicast" ,
628628 fmt .Sprintf ("client_port=%d-%d" , rtpPort , rtcpPort ),
629629 fmt .Sprintf ("server_port=%d-%d" , c .p .rtpPort , c .p .rtcpPort ),
630- }, ";" ),
631- "Session" : "12345678" ,
630+ }, ";" )} ,
631+ "Session" : [] string { "12345678" } ,
632632 },
633633 })
634634 return true
@@ -640,7 +640,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
640640 c .writeResDeadline (& gortsplib.Response {
641641 StatusCode : 461 ,
642642 Status : "Unsupported Transport" ,
643- Headers : map [ string ] string {
643+ Header : gortsplib. Header {
644644 "CSeq" : cseq ,
645645 },
646646 })
@@ -687,20 +687,20 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
687687 c .writeResDeadline (& gortsplib.Response {
688688 StatusCode : 200 ,
689689 Status : "OK" ,
690- Headers : map [ string ] string {
691- "CSeq" : cseq ,
692- "Transport" : strings .Join ([]string {
690+ Header : gortsplib. Header {
691+ "CSeq" : [] string { cseq [ 0 ]} ,
692+ "Transport" : [] string { strings .Join ([]string {
693693 "RTP/AVP/TCP" ,
694694 "unicast" ,
695695 fmt .Sprintf ("interleaved=%s" , interleaved ),
696- }, ";" ),
697- "Session" : "12345678" ,
696+ }, ";" )} ,
697+ "Session" : [] string { "12345678" } ,
698698 },
699699 })
700700 return true
701701
702702 } else {
703- c .writeResError (req , fmt .Errorf ("transport header does not contain a valid protocol (RTP/AVP, RTP/AVP/UDP or RTP/AVP/TCP) (%s)" , transportStr ))
703+ c .writeResError (req , fmt .Errorf ("transport header does not contain a valid protocol (RTP/AVP, RTP/AVP/UDP or RTP/AVP/TCP) (%s)" , tsRaw [ 0 ] ))
704704 return false
705705 }
706706
@@ -746,9 +746,9 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
746746 c .writeResDeadline (& gortsplib.Response {
747747 StatusCode : 200 ,
748748 Status : "OK" ,
749- Headers : map [ string ] string {
750- "CSeq" : cseq ,
751- "Session" : "12345678" ,
749+ Header : gortsplib. Header {
750+ "CSeq" : [] string { cseq [ 0 ]} ,
751+ "Session" : [] string { "12345678" } ,
752752 },
753753 })
754754
@@ -800,9 +800,9 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
800800 c .writeResDeadline (& gortsplib.Response {
801801 StatusCode : 200 ,
802802 Status : "OK" ,
803- Headers : map [ string ] string {
804- "CSeq" : cseq ,
805- "Session" : "12345678" ,
803+ Header : gortsplib. Header {
804+ "CSeq" : [] string { cseq [ 0 ]} ,
805+ "Session" : [] string { "12345678" } ,
806806 },
807807 })
808808 return true
@@ -836,9 +836,9 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
836836 c .writeResDeadline (& gortsplib.Response {
837837 StatusCode : 200 ,
838838 Status : "OK" ,
839- Headers : map [ string ] string {
840- "CSeq" : cseq ,
841- "Session" : "12345678" ,
839+ Header : gortsplib. Header {
840+ "CSeq" : [] string { cseq [ 0 ]} ,
841+ "Session" : [] string { "12345678" } ,
842842 },
843843 })
844844
@@ -856,24 +856,23 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
856856 // when protocol is TCP, the RTSP connection becomes a RTP connection
857857 // receive RTP data and parse it
858858 if c .streamProtocol == _STREAM_PROTOCOL_TCP {
859- buf := make ([]byte , 2048 )
860859 for {
861860 c .conn .NetConn ().SetReadDeadline (time .Now ().Add (_READ_TIMEOUT ))
862- channel , n , err := c .conn .ReadInterleavedFrame (buf )
861+ frame , err := c .conn .ReadInterleavedFrame ()
863862 if err != nil {
864863 c .log ("ERR: %s" , err )
865864 return false
866865 }
867866
868- trackId , trackFlow := interleavedChannelToTrack (channel )
867+ trackId , trackFlow := interleavedChannelToTrack (frame . Channel )
869868
870869 if trackId >= len (c .streamTracks ) {
871870 c .log ("ERR: invalid track id '%d'" , trackId )
872871 return false
873872 }
874873
875874 c .p .mutex .RLock ()
876- c .p .forwardTrack (c .path , trackId , trackFlow , buf [: n ] )
875+ c .p .forwardTrack (c .path , trackId , trackFlow , frame . Content )
877876 c .p .mutex .RUnlock ()
878877 }
879878 }
0 commit comments