webrtc add interceptor.

This commit is contained in:
Miroslav Šedivý 2021-03-23 13:46:54 +01:00
parent 9fcc310685
commit 58854d38dd
3 changed files with 18 additions and 10 deletions

1
go.mod
View File

@ -11,6 +11,7 @@ require (
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pion/interceptor v0.0.10 // indirect
github.com/pion/logging v0.2.2
github.com/pion/transport v0.12.3 // indirect
github.com/pion/webrtc/v3 v3.0.15

View File

@ -27,7 +27,7 @@ func VP8() RTPCodec {
ClockRate: 90000,
Channels: 0,
SDPFmtpLine: "",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/vpx/vp8enc.html
// gstreamer1.0-plugins-good
@ -46,7 +46,7 @@ func VP9() RTPCodec {
ClockRate: 90000,
Channels: 0,
SDPFmtpLine: "profile-id=0",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/vpx/vp9enc.html
// gstreamer1.0-plugins-good
@ -65,7 +65,7 @@ func H264() RTPCodec {
ClockRate: 90000,
Channels: 0,
SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/x264/index.html
// gstreamer1.0-plugins-ugly
@ -86,7 +86,7 @@ func Opus() RTPCodec {
ClockRate: 48000,
Channels: 2,
SDPFmtpLine: "",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/opus/opusenc.html
// gstreamer1.0-plugins-base
@ -104,7 +104,7 @@ func G722() RTPCodec {
ClockRate: 8000,
Channels: 0,
SDPFmtpLine: "",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/libav/avenc_g722.html
// gstreamer1.0-libav
@ -122,7 +122,7 @@ func PCMU() RTPCodec {
ClockRate: 8000,
Channels: 0,
SDPFmtpLine: "",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/mulaw/mulawenc.html
// gstreamer1.0-plugins-good
@ -140,7 +140,7 @@ func PCMA() RTPCodec {
ClockRate: 8000,
Channels: 0,
SDPFmtpLine: "",
RTCPFeedback: nil,
RTCPFeedback: []webrtc.RTCPFeedback{},
},
// https://gstreamer.freedesktop.org/documentation/alaw/alawenc.html
// gstreamer1.0-plugins-good

View File

@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/pion/interceptor"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/pkg/media"
"github.com/rs/zerolog"
@ -120,8 +121,13 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
settings := manager.apiSettings(logger)
configuration := manager.apiConfiguration()
registry := &interceptor.Registry{}
if err := webrtc.RegisterDefaultInterceptors(engine, registry); err != nil {
return nil, err
}
// Create NewAPI with MediaEngine and SettingEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(engine), webrtc.WithSettingEngine(*settings))
api := webrtc.NewAPI(webrtc.WithMediaEngine(engine), webrtc.WithSettingEngine(settings), webrtc.WithInterceptorRegistry(registry))
connection, err := api.NewPeerConnection(*configuration)
if err != nil {
@ -401,8 +407,8 @@ func (manager *WebRTCManagerCtx) mediaEngine(videoID string) (*webrtc.MediaEngin
return engine, nil
}
func (manager *WebRTCManagerCtx) apiSettings(logger zerolog.Logger) *webrtc.SettingEngine {
settings := &webrtc.SettingEngine{
func (manager *WebRTCManagerCtx) apiSettings(logger zerolog.Logger) webrtc.SettingEngine {
settings := webrtc.SettingEngine{
LoggerFactory: loggerFactory{
logger: logger,
},
@ -412,6 +418,7 @@ func (manager *WebRTCManagerCtx) apiSettings(logger zerolog.Logger) *webrtc.Sett
settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
settings.SetICETimeouts(disconnectedTimeout, failedTimeout, keepAliveInterval)
settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
//settings.SetSRTPReplayProtectionWindow(512)
settings.SetLite(manager.config.ICELite)
return settings