@@ -15,6 +15,9 @@ import (
1515
1616 "github.com/pion/interceptor"
1717 "github.com/pion/interceptor/pkg/intervalpli"
18+ "github.com/pion/interceptor/pkg/packetdump"
19+ "github.com/pion/interceptor/pkg/report"
20+ "github.com/pion/rtp"
1821 "github.com/pion/webrtc/v4"
1922)
2023
@@ -49,7 +52,7 @@ func main() {
4952 panic (http .ListenAndServe (":8080" , nil )) // nolint: gosec
5053}
5154
52- func whipHandler (res http.ResponseWriter , req * http.Request ) {
55+ func whipHandler (res http.ResponseWriter , req * http.Request ) { // nolint: cyclop
5356 // Read the offer from HTTP Request
5457 offer , err := io .ReadAll (req .Body )
5558 if err != nil {
@@ -94,8 +97,6 @@ func whipHandler(res http.ResponseWriter, req *http.Request) {
9497 // Create the API object with the MediaEngine
9598 api := webrtc .NewAPI (webrtc .WithMediaEngine (mediaEngine ), webrtc .WithInterceptorRegistry (interceptorRegistry ))
9699
97- // Prepare the configuration
98-
99100 // Create a new RTCPeerConnection
100101 peerConnection , err := api .NewPeerConnection (peerConnectionConfiguration )
101102 if err != nil {
@@ -110,19 +111,25 @@ func whipHandler(res http.ResponseWriter, req *http.Request) {
110111 // Set a handler for when a new remote track starts, this handler saves buffers to disk as
111112 // an ivf file, since we could have multiple video tracks we provide a counter.
112113 // In your application this is where you would handle/process video
113- peerConnection .OnTrack (func (track * webrtc.TrackRemote , receiver * webrtc.RTPReceiver ) { //nolint: revive
114+ peerConnection .OnTrack (func (track * webrtc.TrackRemote , receiver * webrtc.RTPReceiver ) {
115+ go func () {
116+ for {
117+ _ , _ , rtcpErr := receiver .ReadRTCP ()
118+ if rtcpErr != nil {
119+ panic (rtcpErr )
120+ }
121+ }
122+ }()
114123 for {
115124 pkt , _ , err := track .ReadRTP ()
116125 if err != nil {
117126 panic (err )
118127 }
119-
120128 if err = videoTrack .WriteRTP (pkt ); err != nil {
121129 panic (err )
122130 }
123131 }
124132 })
125-
126133 // Send answer via HTTP Response
127134 writeAnswer (res , peerConnection , offer , "/whip" )
128135}
@@ -134,8 +141,27 @@ func whepHandler(res http.ResponseWriter, req *http.Request) {
134141 panic (err )
135142 }
136143
144+ interceptorRegistry := & interceptor.Registry {}
145+ packetDump , err := packetdump .NewSenderInterceptor (
146+ // filter out all RTP packets, only RTCP packets will be logged
147+ packetdump .RTPFilter (func (_ * rtp.Packet ) bool {
148+ return false
149+ }),
150+ )
151+ if err != nil {
152+ panic (err )
153+ }
154+ interceptorRegistry .Add (packetDump )
155+ senderInterceptor , err := report .NewSenderInterceptor ()
156+ if err != nil {
157+ panic (err )
158+ }
159+ interceptorRegistry .Add (senderInterceptor )
160+
161+ api := webrtc .NewAPI (webrtc .WithInterceptorRegistry (interceptorRegistry ))
162+
137163 // Create a new RTCPeerConnection
138- peerConnection , err := webrtc .NewPeerConnection (peerConnectionConfiguration )
164+ peerConnection , err := api .NewPeerConnection (peerConnectionConfiguration )
139165 if err != nil {
140166 panic (err )
141167 }
0 commit comments