Skip to content

Commit

Permalink
Enable Simulcast RTP Headers by default
Browse files Browse the repository at this point in the history
Relates to #2557
  • Loading branch information
Sean-Der committed Sep 12, 2023
1 parent 1345033 commit 8ec494f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
29 changes: 1 addition & 28 deletions examples/simulcast/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"os"
"time"

"github.com/pion/interceptor"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v4"
"github.com/pion/webrtc/v4/examples/internal/signal"
Expand All @@ -33,34 +32,8 @@ func main() {
},
}

// Enable Extension Headers needed for Simulcast
m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
panic(err)
}
for _, extension := range []string{
"urn:ietf:params:rtp-hdrext:sdes:mid",
"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",
} {
if err := m.RegisterHeaderExtension(webrtc.RTPHeaderExtensionCapability{URI: extension}, webrtc.RTPCodecTypeVideo); err != nil {
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 a new RTCPeerConnection
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i)).NewPeerConnection(config)
peerConnection, err := webrtc.NewPeerConnection(config)
if err != nil {
panic(err)
}
Expand Down
17 changes: 17 additions & 0 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func RegisterDefaultInterceptors(mediaEngine *MediaEngine, interceptorRegistry *
return err
}

if err := ConfigureSimulcastExtensionHeaders(mediaEngine); err != nil {
return err
}

return ConfigureTWCCSender(mediaEngine, interceptorRegistry)
}

Expand Down Expand Up @@ -123,6 +127,19 @@ func ConfigureCongestionControlFeedback(mediaEngine *MediaEngine, interceptorReg
return nil
}

// ConfigureSimulcastExtensionHeaders enables the RTP Extenison Headers needed for Simulcast
func ConfigureSimulcastExtensionHeaders(mediaEngine *MediaEngine) error {
if err := mediaEngine.RegisterHeaderExtension(RTPHeaderExtensionCapability{URI: sdp.SDESMidURI}, RTPCodecTypeVideo); err != nil {
return err
}

if err := mediaEngine.RegisterHeaderExtension(RTPHeaderExtensionCapability{URI: sdp.SDESRTPStreamIDURI}, RTPCodecTypeVideo); err != nil {
return err
}

return mediaEngine.RegisterHeaderExtension(RTPHeaderExtensionCapability{URI: sdesRepairRTPStreamIDURI}, RTPCodecTypeVideo)
}

type interceptorToTrackLocalWriter struct{ interceptor atomic.Value } // interceptor.RTPWriter }

func (i *interceptorToTrackLocalWriter) WriteRTP(header *rtp.Header, payload []byte) (int, error) {
Expand Down
7 changes: 4 additions & 3 deletions rtpreceiver_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"github.com/pion/sdp/v3"
"github.com/pion/webrtc/v4/pkg/media"
"github.com/stretchr/testify/assert"
)
Expand All @@ -34,9 +35,9 @@ func TestSetRTPParameters(t *testing.T) {
},
},
HeaderExtensions: []RTPHeaderExtensionParameter{
{URI: "urn:ietf:params:rtp-hdrext:sdes:mid"},
{URI: "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"},
{URI: "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"},
{URI: sdp.SDESMidURI},
{URI: sdp.SDESRTPStreamIDURI},
{URI: sdesRepairRTPStreamIDURI},
},
}

Expand Down

0 comments on commit 8ec494f

Please sign in to comment.