Skip to content

Commit

Permalink
Enable Sender and Receiver Reports by default
Browse files Browse the repository at this point in the history
The play-from-disk examples sees the average bitrate using
Chromium 90.0.4412.3 when enabled on loopback for a 3 minute
session.

Before: 744.443
After: 3927.669

Introduced with pion/[email protected]
  • Loading branch information
Sean-Der committed Feb 24, 2021
1 parent ae0f74e commit 33d953e
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 24 deletions.
10 changes: 1 addition & 9 deletions examples/ice-tcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ func doSignaling(w http.ResponseWriter, r *http.Request) {
var err error

if peerConnection == nil {
m := webrtc.MediaEngine{}
if err = m.RegisterDefaultCodecs(); err != nil {
panic(err)
}

settingEngine := webrtc.SettingEngine{}

// Enable support only for TCP ICE candidates.
Expand All @@ -46,10 +41,7 @@ func doSignaling(w http.ResponseWriter, r *http.Request) {
tcpMux := webrtc.NewICETCPMux(nil, tcpListener, 8)
settingEngine.SetICETCPMux(tcpMux)

api := webrtc.NewAPI(
webrtc.WithMediaEngine(&m),
webrtc.WithSettingEngine(settingEngine),
)
api := webrtc.NewAPI(webrtc.WithSettingEngine(settingEngine))
if peerConnection, err = api.NewPeerConnection(webrtc.Configuration{}); err != nil {
panic(err)
}
Expand Down
16 changes: 14 additions & 2 deletions examples/reflect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

"github.com/pion/interceptor"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/examples/internal/signal"
Expand All @@ -15,7 +16,7 @@ func main() {
// Everything below is the Pion WebRTC API! Thanks for using it ❤️.

// Create a MediaEngine object to configure the supported codec
m := webrtc.MediaEngine{}
m := &webrtc.MediaEngine{}

// Setup the codecs you want to use.
// We'll use a VP8 and Opus but you can also define your own
Expand All @@ -26,8 +27,19 @@ func main() {
panic(err)
}

// Create a InterceptorRegistry. This is the user configurable RTP/RTCP Pipeline.
// This provides NACKs, RTCP Reports and other features. If you use `webrtc.NewPeerConnection`
// this is enabled by default. If you are manually managing You MUST create a InterceptorRegistry
// for each PeerConnection.
i := &interceptor.Registry{}

// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}

// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(&m))
api := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i))

// Prepare the configuration
config := webrtc.Configuration{
Expand Down
2 changes: 2 additions & 0 deletions examples/rtp-forwarder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ Run `ffprobe -i rtp-forwarder.sdp -protocol_whitelist file,udp,rtp` to get more

Run `ffplay -i rtp-forwarder.sdp -protocol_whitelist file,udp,rtp` to play your streams

You can add `-fflags nobuffer` to lower the latency. You will have worse playback in networks with jitter.

#### Twitch/RTMP
`ffmpeg -protocol_whitelist file,udp,rtp -i rtp-forwarder.sdp -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://live.twitch.tv/app/$STREAM_KEY` Make sure to replace `$STREAM_KEY` at the end of the URL first.
16 changes: 14 additions & 2 deletions examples/rtp-forwarder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"time"

"github.com/pion/interceptor"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
Expand All @@ -24,7 +25,7 @@ func main() {
// Everything below is the Pion WebRTC API! Thanks for using it ❤️.

// Create a MediaEngine object to configure the supported codec
m := webrtc.MediaEngine{}
m := &webrtc.MediaEngine{}

// Setup the codecs you want to use.
// We'll use a VP8 and Opus but you can also define your own
Expand All @@ -39,8 +40,19 @@ func main() {
panic(err)
}

// Create a InterceptorRegistry. This is the user configurable RTP/RTCP Pipeline.
// This provides NACKs, RTCP Reports and other features. If you use `webrtc.NewPeerConnection`
// this is enabled by default. If you are manually managing You MUST create a InterceptorRegistry
// for each PeerConnection.
i := &interceptor.Registry{}

// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}

// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(&m))
api := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i))

// Prepare the configuration
config := webrtc.Configuration{
Expand Down
16 changes: 14 additions & 2 deletions examples/save-to-disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/pion/interceptor"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/examples/internal/signal"
Expand Down Expand Up @@ -38,7 +39,7 @@ func main() {
// Everything below is the Pion WebRTC API! Thanks for using it ❤️.

// Create a MediaEngine object to configure the supported codec
m := webrtc.MediaEngine{}
m := &webrtc.MediaEngine{}

// Setup the codecs you want to use.
// We'll use a VP8 and Opus but you can also define your own
Expand All @@ -55,8 +56,19 @@ func main() {
panic(err)
}

// Create a InterceptorRegistry. This is the user configurable RTP/RTCP Pipeline.
// This provides NACKs, RTCP Reports and other features. If you use `webrtc.NewPeerConnection`
// this is enabled by default. If you are manually managing You MUST create a InterceptorRegistry
// for each PeerConnection.
i := &interceptor.Registry{}

// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}

// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(&m))
api := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i))

// Prepare the configuration
config := webrtc.Configuration{
Expand Down
5 changes: 5 additions & 0 deletions examples/simulcast/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# simulcast
demonstrates of how to handle incoming track with multiple simulcast rtp streams and show all them back.

The browser will not send higher quality streams unless it has the available bandwidth. You can look at
the bandwidth estimation in `chrome://webrtc-internals`. It is under `VideoBwe` when `Read Stats From: Legacy non-Standard`
is selected.

## Instructions
### Download simulcast
```
export GO111MODULE=on
go get github.com/pion/webrtc/v3/examples/simulcast
```

Expand Down
19 changes: 13 additions & 6 deletions examples/simulcast/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"time"

"github.com/pion/interceptor"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/examples/internal/signal"
Expand Down Expand Up @@ -40,8 +41,19 @@ func main() {
}
}

// Create a InterceptorRegistry. This is the user configurable RTP/RTCP Pipeline.
// This provides NACKs, RTCP Reports and other features. If you use `webrtc.NewPeerConnection`
// this is enabled by default. If you are manually managing You MUST create a InterceptorRegistry
// for each PeerConnection.
i := &interceptor.Registry{}

// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m)).NewPeerConnection(config)
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i)).NewPeerConnection(config)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -114,11 +126,6 @@ func main() {
if writeErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); writeErr != nil {
fmt.Println(writeErr)
}
// Send a remb message with a very high bandwidth to trigger chrome to send also the high bitrate stream
fmt.Printf("Sending remb for stream with rid: %q, ssrc: %d\n", track.RID(), track.SSRC())
if writeErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.ReceiverEstimatedMaximumBitrate{Bitrate: 10000000, SenderSSRC: uint32(track.SSRC())}}); writeErr != nil {
fmt.Println(writeErr)
}
}
}()
for {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/pion/datachannel v1.4.21
github.com/pion/dtls/v2 v2.0.7
github.com/pion/ice/v2 v2.0.15
github.com/pion/interceptor v0.0.9
github.com/pion/interceptor v0.0.10
github.com/pion/logging v0.2.2
github.com/pion/randutil v0.1.0
github.com/pion/rtcp v1.2.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/pion/dtls/v2 v2.0.7 h1:PNcUs/G1l9hb4jzMEorgFMxIBdp7fRN4LIApOTMtCYs=
github.com/pion/dtls/v2 v2.0.7/go.mod h1:QuDII+8FVvk9Dp5t5vYIMTo7hh7uBkra+8QIm7QGm10=
github.com/pion/ice/v2 v2.0.15 h1:KZrwa2ciL9od8+TUVJiYTNsCW9J5lktBjGwW1MacEnQ=
github.com/pion/ice/v2 v2.0.15/go.mod h1:ZIiVGevpgAxF/cXiIVmuIUtCb3Xs4gCzCbXB6+nFkSI=
github.com/pion/interceptor v0.0.9 h1:fk5hTdyLO3KURQsf/+RjMpEm4NE3yeTY9Kh97b5BvwA=
github.com/pion/interceptor v0.0.9/go.mod h1:dHgEP5dtxOTf21MObuBAjJeAayPxLUAZjerGH8Xr07c=
github.com/pion/interceptor v0.0.10 h1:dXFyFWRJFwmzQqyn0U8dUAbOJu+JJnMVAqxmvTu30B4=
github.com/pion/interceptor v0.0.10/go.mod h1:qzeuWuD/ZXvPqOnxNcnhWfkCZ2e1kwwslicyyPnhoK4=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/mdns v0.0.4 h1:O4vvVqr4DGX63vzmO6Fw9vpy3lfztVWHGCQfyw0ZLSY=
Expand Down
22 changes: 22 additions & 0 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/pion/interceptor"
"github.com/pion/interceptor/pkg/nack"
"github.com/pion/interceptor/pkg/report"
"github.com/pion/rtp"
)

Expand All @@ -18,6 +19,27 @@ func RegisterDefaultInterceptors(mediaEngine *MediaEngine, interceptorRegistry *
return err
}

if err := ConfigureRTCPReports(interceptorRegistry); err != nil {
return err
}

return nil
}

// ConfigureRTCPReports will setup everything necessary for generating Sender and Receiver Reports
func ConfigureRTCPReports(interceptorRegistry *interceptor.Registry) error {
reciver, err := report.NewReceiverInterceptor()
if err != nil {
return err
}

sender, err := report.NewSenderInterceptor()
if err != nil {
return err
}

interceptorRegistry.Add(reciver)
interceptorRegistry.Add(sender)
return nil
}

Expand Down

0 comments on commit 33d953e

Please sign in to comment.