From 6be352ec8631b7cd151bacf1800d270da6a8588e Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Thu, 15 Aug 2024 16:50:10 -0400 Subject: [PATCH] Only send PLIs for video tracks in examples --- examples/simulcast/main.go | 20 +++++++++++--------- examples/swap-tracks/main.go | 6 ++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/simulcast/main.go b/examples/simulcast/main.go index 96dac358f79..6e15708a717 100644 --- a/examples/simulcast/main.go +++ b/examples/simulcast/main.go @@ -111,16 +111,18 @@ func main() { // 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) - defer ticker.Stop() - for range ticker.C { - fmt.Printf("Sending pli for stream with rid: %q, ssrc: %d\n", track.RID(), track.SSRC()) - if writeErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); writeErr != nil { - fmt.Println(writeErr) + if track.Kind() == webrtc.RTPCodecTypeVideo { + go func() { + ticker := time.NewTicker(3 * time.Second) + defer ticker.Stop() + for range ticker.C { + fmt.Printf("Sending pli for stream with rid: %q, ssrc: %d\n", track.RID(), track.SSRC()) + if writeErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); writeErr != nil { + fmt.Println(writeErr) + } } - } - }() + }() + } 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 8b36b6120ce..a678dcdb12f 100644 --- a/examples/swap-tracks/main.go +++ b/examples/swap-tracks/main.go @@ -119,8 +119,10 @@ func main() { // nolint:gocognit // If just switched to this track, send PLI to get picture refresh if !isCurrTrack { isCurrTrack = true - if writeErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); writeErr != nil { - fmt.Println(writeErr) + if track.Kind() == webrtc.RTPCodecTypeVideo { + if writeErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); writeErr != nil { + fmt.Println(writeErr) + } } } packets <- rtp