ConnClient: send teardown only after playing

This commit is contained in:
aler9
2020-09-20 11:45:05 +02:00
parent 10469faa07
commit 04d55bc6c8

View File

@@ -65,6 +65,7 @@ type ConnClient struct {
udpLastFrameTimes map[int]*int64 udpLastFrameTimes map[int]*int64
udpRtpListeners map[int]*connClientUDPListener udpRtpListeners map[int]*connClientUDPListener
udpRtcpListeners map[int]*connClientUDPListener udpRtcpListeners map[int]*connClientUDPListener
playing bool
receiverReportTerminate chan struct{} receiverReportTerminate chan struct{}
receiverReportDone chan struct{} receiverReportDone chan struct{}
@@ -104,7 +105,7 @@ func NewConnClient(conf ConnClientConf) (*ConnClient, error) {
// Close closes all the ConnClient resources. // Close closes all the ConnClient resources.
func (c *ConnClient) Close() error { func (c *ConnClient) Close() error {
if c.streamUrl != nil { if c.playing {
c.Do(&Request{ c.Do(&Request{
Method: TEARDOWN, Method: TEARDOWN,
Url: c.streamUrl, Url: c.streamUrl,
@@ -601,6 +602,8 @@ func (c *ConnClient) Play(u *url.URL) (*Response, error) {
return nil, fmt.Errorf("bad status code: %d (%s)", res.StatusCode, res.StatusMessage) return nil, fmt.Errorf("bad status code: %d (%s)", res.StatusCode, res.StatusMessage)
} }
c.playing = true
// open the firewall by sending packets to every channel // open the firewall by sending packets to every channel
if *c.streamProtocol == StreamProtocolUDP { if *c.streamProtocol == StreamProtocolUDP {
for trackId := range c.udpRtpListeners { for trackId := range c.udpRtpListeners {