From 7a94394db0b429b0136265f4556512d5f4a05a0b Mon Sep 17 00:00:00 2001 From: arjunshajitech Date: Fri, 25 Jul 2025 10:35:26 +0530 Subject: [PATCH] Log error when Read is used with simulcast --- constants.go | 2 ++ rtpreceiver.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/constants.go b/constants.go index e1a74ef9..4415578d 100644 --- a/constants.go +++ b/constants.go @@ -44,6 +44,8 @@ const ( incomingUnhandledRTPSsrc = "Incoming unhandled RTP ssrc(%d), OnTrack will not be fired. %v" + useReadSimulcast = "Use ReadSimulcast(rid) instead of Read() when multiple tracks are present" + generatedCertificateOrigin = "WebRTC" // AttributeRtxPayloadType is the interceptor attribute added when Read() diff --git a/rtpreceiver.go b/rtpreceiver.go index 0e85b2d9..dacef04f 100644 --- a/rtpreceiver.go +++ b/rtpreceiver.go @@ -14,6 +14,7 @@ import ( "time" "github.com/pion/interceptor" + "github.com/pion/logging" "github.com/pion/rtcp" "github.com/pion/srtp/v3" "github.com/pion/webrtc/v4/internal/util" @@ -70,6 +71,8 @@ type RTPReceiver struct { api *API rtxPool sync.Pool + + log logging.LeveledLogger } // NewRTPReceiver constructs a new RTPReceiver. @@ -78,7 +81,7 @@ func (api *API) NewRTPReceiver(kind RTPCodecType, transport *DTLSTransport) (*RT return nil, errRTPReceiverDTLSTransportNil } - r := &RTPReceiver{ + rtpReceiver := &RTPReceiver{ kind: kind, transport: transport, api: api, @@ -88,9 +91,10 @@ func (api *API) NewRTPReceiver(kind RTPCodecType, transport *DTLSTransport) (*RT rtxPool: sync.Pool{New: func() any { return make([]byte, api.settingEngine.getReceiveMTU()) }}, + log: api.settingEngine.LoggerFactory.NewLogger("RTPReceiver"), } - return r, nil + return rtpReceiver, nil } func (r *RTPReceiver) setRTPTransceiver(tr *RTPTransceiver) { @@ -272,6 +276,10 @@ func (r *RTPReceiver) Receive(parameters RTPReceiveParameters) error { func (r *RTPReceiver) Read(b []byte) (n int, a interceptor.Attributes, err error) { select { case <-r.received: + if len(r.tracks) > 1 { + r.log.Errorf(useReadSimulcast) + } + return r.tracks[0].rtcpInterceptor.Read(b, a) case <-r.closed: return 0, nil, io.ErrClosedPipe