diff --git a/examples/broadcast/main.go b/examples/broadcast/main.go index 74fef697..d6663e3e 100644 --- a/examples/broadcast/main.go +++ b/examples/broadcast/main.go @@ -64,6 +64,18 @@ func main() { // nolint:gocognit } }() + // Read incoming RTCP packets + // Before these packets are returned they are processed by interceptors. For things + // like TWCC and RTCP Reports this needs to be called. + go func() { + rtcpBuf := make([]byte, 1500) + for { + if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil { + return + } + } + }() + // Create a local track, all our SFU clients will be fed via this track localTrack, newTrackErr := webrtc.NewTrackLocalStaticRTP(remoteTrack.Codec().RTPCodecCapability, "video", "pion") if newTrackErr != nil { diff --git a/examples/reflect/main.go b/examples/reflect/main.go index 0e667bab..668e2969 100644 --- a/examples/reflect/main.go +++ b/examples/reflect/main.go @@ -110,6 +110,18 @@ func main() { } }() + // Read incoming RTCP packets + // Before these packets are returned they are processed by interceptors. For things + // like TWCC and RTCP Reports this needs to be called. + go func() { + rtcpBuf := make([]byte, 1500) + for { + if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil { + return + } + } + }() + fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), track.Codec().MimeType) for { // Read RTP packets being sent to Pion diff --git a/examples/rtp-forwarder/main.go b/examples/rtp-forwarder/main.go index ebce7442..ffe61538 100644 --- a/examples/rtp-forwarder/main.go +++ b/examples/rtp-forwarder/main.go @@ -132,6 +132,18 @@ func main() { } }() + // Read incoming RTCP packets + // Before these packets are returned they are processed by interceptors. For things + // like TWCC and RTCP Reports this needs to be called. + go func() { + rtcpBuf := make([]byte, 1500) + for { + if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil { + return + } + } + }() + b := make([]byte, 1500) rtpPacket := &rtp.Packet{} for { diff --git a/examples/save-to-disk/main.go b/examples/save-to-disk/main.go index c657f218..59448beb 100644 --- a/examples/save-to-disk/main.go +++ b/examples/save-to-disk/main.go @@ -116,6 +116,18 @@ func main() { } }() + // Read incoming RTCP packets + // Before these packets are returned they are processed by interceptors. For things + // like TWCC and RTCP Reports this needs to be called. + go func() { + rtcpBuf := make([]byte, 1500) + for { + if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil { + return + } + } + }() + codec := track.Codec() if strings.EqualFold(codec.MimeType, webrtc.MimeTypeOpus) { fmt.Println("Got Opus track, saving to disk as output.opus (48 kHz, 2 channels)") diff --git a/examples/simulcast/main.go b/examples/simulcast/main.go index 2e41f683..ca1827da 100644 --- a/examples/simulcast/main.go +++ b/examples/simulcast/main.go @@ -123,8 +123,6 @@ func main() { peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) { fmt.Println("Track has started") - // Start reading from all the streams and sending them to the related output track - rid := track.RID() go func() { ticker := time.NewTicker(3 * time.Second) for range ticker.C { @@ -134,6 +132,21 @@ func main() { } } }() + + // Read incoming RTCP packets + // Before these packets are returned they are processed by interceptors. For things + // like TWCC and RTCP Reports this needs to be called. + go func() { + rtcpBuf := make([]byte, 1500) + for { + if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil { + return + } + } + }() + + // Start reading from all the streams and sending them to the related output track + rid := track.RID() for { // Read RTP packets being sent to Pion packet, _, readErr := track.ReadRTP() diff --git a/examples/swap-tracks/main.go b/examples/swap-tracks/main.go index 90ab309d..ddf12d4c 100644 --- a/examples/swap-tracks/main.go +++ b/examples/swap-tracks/main.go @@ -80,6 +80,18 @@ func main() { // nolint:gocognit // Set a handler for when a new remote track starts peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) { + // Read incoming RTCP packets + // Before these packets are returned they are processed by interceptors. For things + // like TWCC and RTCP Reports this needs to be called. + go func() { + rtcpBuf := make([]byte, 1500) + for { + if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil { + return + } + } + }() + fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), track.Codec().MimeType) trackNum := trackCount trackCount++