From 83a3086de7f4738d9d3dd2b0d86ba8796d101a50 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Sun, 12 Nov 2023 13:46:25 +0100 Subject: [PATCH] webrtc: prevent pion/webrtc from writing log lines (#2681) --- go.mod | 2 +- internal/core/webrtc_manager.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c0ef49e25b2..1ef6d3a1481 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/notedit/rtmp v0.0.2 github.com/pion/ice/v2 v2.3.11 github.com/pion/interceptor v0.1.25 + github.com/pion/logging v0.2.2 github.com/pion/rtcp v1.2.12 github.com/pion/rtp v1.8.3 github.com/pion/sdp/v3 v3.0.6 @@ -52,7 +53,6 @@ require ( github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pion/datachannel v1.5.5 // indirect github.com/pion/dtls/v2 v2.2.7 // indirect - github.com/pion/logging v0.2.2 // indirect github.com/pion/mdns v0.0.8 // indirect github.com/pion/randutil v0.1.0 // indirect github.com/pion/sctp v1.8.8 // indirect diff --git a/internal/core/webrtc_manager.go b/internal/core/webrtc_manager.go index a4faeb6e7b0..fdf2c8f7526 100644 --- a/internal/core/webrtc_manager.go +++ b/internal/core/webrtc_manager.go @@ -16,6 +16,7 @@ import ( "github.com/google/uuid" "github.com/pion/ice/v2" + "github.com/pion/logging" pwebrtc "github.com/pion/webrtc/v3" "github.com/bluenviron/mediamtx/internal/conf" @@ -32,6 +33,14 @@ const ( webrtcPayloadMaxSize = 1188 // 1200 - 12 (RTP header) ) +type nilWriter struct{} + +func (nilWriter) Write(p []byte) (int, error) { + return len(p), nil +} + +var webrtcNilLogger = logging.NewDefaultLeveledLoggerForScope("", 0, &nilWriter{}) + func randInt63() (int64, error) { var b [8]byte _, err := rand.Read(b[:]) @@ -257,7 +266,7 @@ func newWebRTCManager( ctxCancel() return nil, err } - iceUDPMux = pwebrtc.NewICEUDPMux(nil, m.udpMuxLn) + iceUDPMux = pwebrtc.NewICEUDPMux(webrtcNilLogger, m.udpMuxLn) } var iceTCPMux ice.TCPMux @@ -270,7 +279,7 @@ func newWebRTCManager( ctxCancel() return nil, err } - iceTCPMux = pwebrtc.NewICETCPMux(nil, m.tcpMuxLn, 8) + iceTCPMux = pwebrtc.NewICETCPMux(webrtcNilLogger, m.tcpMuxLn, 8) } m.api, err = webrtc.NewAPI(webrtc.APIConf{