Skip to content

Commit

Permalink
Only send PLIs for video tracks in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tmatth authored and Sean-Der committed Aug 15, 2024
1 parent ddb9219 commit d54f787
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 11 additions & 9 deletions examples/simulcast/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions examples/swap-tracks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d54f787

Please sign in to comment.