Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
add unhandledrtcpreader handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cnderrauber committed Jul 23, 2021
1 parent 1c7f300 commit 336b358
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type PeerConnection struct {
onTrackHandler func(*TrackRemote, *RTPReceiver)
onDataChannelHandler func(*DataChannel)
onNegotiationNeededHandler atomic.Value // func()
onUnhandledRtcpHandler func(interceptor.RTCPReader)

iceGatherer *ICEGatherer
iceTransport *ICETransport
Expand Down Expand Up @@ -455,6 +456,29 @@ func (pc *PeerConnection) onTrack(t *TrackRemote, r *RTPReceiver) {
}
}

func (pc *PeerConnection) OnUnhandledRtcp(f func(interceptor.RTCPReader)) {
pc.mu.Lock()
defer pc.mu.Unlock()
pc.onUnhandledRtcpHandler = f
}

func (pc *PeerConnection) onUnhandledRtcp(r interceptor.RTCPReader, ssrc uint32) bool {
pc.mu.RLock()
h := pc.onUnhandledRtcpHandler
pc.mu.RUnlock()
pc.log.Debugf("got new unhandled rtcp: %+v", r)
if r != nil {
if h != nil {
go h(r)
return true
} else {
// pc.log.Warnf("OnTrack unset, unable to handle incoming media streams")
pc.log.Warnf("Incoming unhandled RTCP ssrc(%d), OnUnhandledRtcp is nil, will not be fired, ssrc: %d", ssrc)
}
}
return false
}

// OnICEConnectionStateChange sets an event handler which is called
// when an ICE connection state is changed.
func (pc *PeerConnection) OnICEConnectionStateChange(f func(ICEConnectionState)) {
Expand Down Expand Up @@ -1520,10 +1544,15 @@ func (pc *PeerConnection) undeclaredMediaProcessor() {
pc.log.Warnf("Failed to accept RTCP %v", err)
return
}
time.AfterFunc(5*time.Minute, func() {
s.Close()
})

r := pc.api.interceptor.BindRTCPReader(interceptor.RTCPReaderFunc(func(b []byte, a interceptor.Attributes) (int, interceptor.Attributes, error) {
n, err := s.Read(b)
return n, a, err
}))
if !pc.onUnhandledRtcp(r, ssrc) {
time.AfterFunc(5*time.Minute, func() {
s.Close()
})
}
pc.log.Warnf("Incoming unhandled RTCP ssrc(%d), OnTrack will not be fired", ssrc)
}
}()
Expand Down

0 comments on commit 336b358

Please sign in to comment.