@@ -10,7 +10,6 @@ import (
1010 "net/url"
1111 "strconv"
1212 "strings"
13- "sync"
1413
1514 "rtsp-server/rtsp"
1615)
@@ -40,29 +39,34 @@ func newRtspClient(p *program, nconn net.Conn) *rtspClient {
4039}
4140
4241func (c * rtspClient ) close () error {
42+ // already deleted
43+ if _ , ok := c .p .clients [c ]; ! ok {
44+ return nil
45+ }
46+
4347 delete (c .p .clients , c )
48+ c .nconn .Close ()
4449
4550 if c .p .streamAuthor == c {
4651 c .p .streamAuthor = nil
4752 c .p .streamSdp = nil
4853
49- // if the streamer has disconnected
54+ // if the publisher has disconnected
5055 // close all other connections
5156 for oc := range c .p .clients {
5257 oc .close ()
5358 }
5459 }
5560
56- return c . nconn . Close ()
61+ return nil
5762}
5863
5964func (c * rtspClient ) log (format string , args ... interface {}) {
6065 format = "[RTSP client " + c .nconn .RemoteAddr ().String () + "] " + format
6166 log .Printf (format , args ... )
6267}
6368
64- func (c * rtspClient ) run (wg sync.WaitGroup ) {
65- defer wg .Done ()
69+ func (c * rtspClient ) run () {
6670 defer c .log ("disconnected" )
6771 defer func () {
6872 c .p .mutex .Lock ()
@@ -278,7 +282,7 @@ func (c *rtspClient) run(wg sync.WaitGroup) {
278282 fmt .Sprintf ("client_port=%d-%d" , clientPort1 , clientPort2 ),
279283 // use two fake server ports, since we do not want to receive feedback
280284 // from the client
281- fmt .Sprintf ("server_port=%d-%d" , c .p .rtpPort + 2 , c .p .rtcpPort + 2 ),
285+ fmt .Sprintf ("server_port=%d-%d" , c .p .rtpPort + 2 , c .p .rtcpPort + 2 ),
282286 "ssrc=1234ABCD" ,
283287 }, ";" ),
284288 "Session" : "12345678" ,
0 commit comments