diff --git a/examples/simulcast/main.go b/examples/simulcast/main.go index f2c90f55628..5ae22f1c36c 100644 --- a/examples/simulcast/main.go +++ b/examples/simulcast/main.go @@ -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" @@ -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) } diff --git a/interceptor.go b/interceptor.go index 2dfe5735bfe..fec45ab7e0f 100644 --- a/interceptor.go +++ b/interceptor.go @@ -30,6 +30,10 @@ func RegisterDefaultInterceptors(mediaEngine *MediaEngine, interceptorRegistry * return err } + if err := ConfigureSimulcastExtensionHeaders(mediaEngine); err != nil { + return err + } + return ConfigureTWCCSender(mediaEngine, interceptorRegistry) } @@ -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) { diff --git a/rtpreceiver_go_test.go b/rtpreceiver_go_test.go index 84f1d8fee28..7ea51cb767c 100644 --- a/rtpreceiver_go_test.go +++ b/rtpreceiver_go_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + "github.com/pion/sdp/v3" "github.com/pion/webrtc/v4/pkg/media" "github.com/stretchr/testify/assert" ) @@ -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}, }, }