Use new intervalpli interceptor in examples

Instead of manually spawning a goroutine this demonstrates how an
interceptor can be useful.

Co-authored-by: Antoine Baché <antoine@tenten.app>
This commit is contained in:
Sean DuBois
2023-04-25 22:10:07 -04:00
parent 98860dda8c
commit 03c83a178c
7 changed files with 79 additions and 76 deletions

View File

@@ -9,10 +9,9 @@ import (
"fmt"
"net"
"os"
"time"
"github.com/pion/interceptor"
"github.com/pion/rtcp"
"github.com/pion/interceptor/pkg/intervalpli"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/examples/internal/signal"
@@ -50,8 +49,18 @@ func main() {
// for each PeerConnection.
i := &interceptor.Registry{}
// Register a intervalpli factory
// This interceptor sends a PLI every 3 seconds. A PLI causes a video keyframe to be generated by the sender.
// This makes our video seekable and more error resilent, but at a cost of lower picture quality and higher bitrates
// A real world application should process incoming RTCP packets from viewers and forward them to senders
intervalPliFactory, err := intervalpli.NewReceiverInterceptor()
if err != nil {
panic(err)
}
i.Add(intervalPliFactory)
// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
if err = webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}
@@ -126,16 +135,6 @@ func main() {
return
}
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
go func() {
ticker := time.NewTicker(time.Second * 2)
for range ticker.C {
if rtcpErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); rtcpErr != nil {
fmt.Println(rtcpErr)
}
}
}()
b := make([]byte, 1500)
rtpPacket := &rtp.Packet{}
for {