diff --git a/peerconnection.go b/peerconnection.go index 9f2f8ad0112..da796d36f5b 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -1515,11 +1515,15 @@ func (pc *PeerConnection) undeclaredMediaProcessor() { return } - _, ssrc, err := srtcpSession.AcceptStream() + s, ssrc, err := srtcpSession.AcceptStream() if err != nil { pc.log.Warnf("Failed to accept RTCP %v", err) return } + time.AfterFunc(5*time.Minute, func() { + s.Close() + }) + pc.log.Warnf("Incoming unhandled RTCP ssrc(%d), OnTrack will not be fired", ssrc) } }() diff --git a/rtpreceiver.go b/rtpreceiver.go index 365b797ef94..ab3a43f9c06 100644 --- a/rtpreceiver.go +++ b/rtpreceiver.go @@ -335,9 +335,11 @@ func (r *RTPReceiver) Stop() error { } if fec := r.tracks[i].fecTrack; fec != nil { errs = append(errs, closefunc(fec)...) + r.api.interceptor.UnbindRemoteStream(&fec.streamInfo) } if rtx := r.tracks[i].rtxTrack; rtx != nil { errs = append(errs, closefunc(rtx)...) + r.api.interceptor.UnbindRemoteStream(&rtx.streamInfo) } err = util.FlattenErrs(errs) diff --git a/srtp_writer_future.go b/srtp_writer_future.go index 4d8bafe1bc8..b5437a6f31f 100644 --- a/srtp_writer_future.go +++ b/srtp_writer_future.go @@ -4,6 +4,7 @@ package webrtc import ( "io" + "sync" "sync/atomic" "time" @@ -17,6 +18,8 @@ type srtpWriterFuture struct { rtpSender *RTPSender rtcpReadStream atomic.Value // *srtp.ReadStreamSRTCP rtpWriteStream atomic.Value // *srtp.WriteStreamSRTP + mu sync.Mutex + closed bool } func (s *srtpWriterFuture) init(returnWhenNoSRTP bool) error { @@ -36,6 +39,12 @@ func (s *srtpWriterFuture) init(returnWhenNoSRTP bool) error { } } + s.mu.Lock() + defer s.mu.Unlock() + if s.closed { + return io.ErrClosedPipe + } + srtcpSession, err := s.rtpSender.transport.getSRTCPSession() if err != nil { return err @@ -62,6 +71,13 @@ func (s *srtpWriterFuture) init(returnWhenNoSRTP bool) error { } func (s *srtpWriterFuture) Close() error { + s.mu.Lock() + defer s.mu.Unlock() + if s.closed { + return nil + } + + s.closed = true if value := s.rtcpReadStream.Load(); value != nil { return value.(*srtp.ReadStreamSRTCP).Close() }