diff --git a/rtpsender.go b/rtpsender.go index b50ad865c16..3a597619219 100644 --- a/rtpsender.go +++ b/rtpsender.go @@ -311,6 +311,12 @@ func (r *RTPSender) Send(parameters RTPSendParameters) error { trackEncoding.ssrc = parameters.Encodings[idx].SSRC trackEncoding.ssrcRTX = parameters.Encodings[idx].RTX.SSRC trackEncoding.ssrcFEC = parameters.Encodings[idx].FEC.SSRC + trackEncoding.rtcpInterceptor = r.api.interceptor.BindRTCPReader( + interceptor.RTCPReaderFunc(func(in []byte, a interceptor.Attributes) (n int, attributes interceptor.Attributes, err error) { + n, err = trackEncoding.srtpStream.Read(in) + return n, a, err + }), + ) trackEncoding.context = &baseTrackLocalContext{ id: r.id, params: rtpParameters, @@ -339,13 +345,6 @@ func (r *RTPSender) Send(parameters RTPSendParameters) error { parameters.HeaderExtensions, ) - trackEncoding.rtcpInterceptor = r.api.interceptor.BindRTCPReader( - interceptor.RTCPReaderFunc(func(in []byte, a interceptor.Attributes) (n int, attributes interceptor.Attributes, err error) { - n, err = trackEncoding.srtpStream.Read(in) - return n, a, err - }), - ) - rtpInterceptor := r.api.interceptor.BindLocalStream( &trackEncoding.streamInfo, interceptor.RTPWriterFunc(func(header *rtp.Header, payload []byte, _ interceptor.Attributes) (int, error) { diff --git a/rtpsender_test.go b/rtpsender_test.go index f0e85a82454..458e7e87ca8 100644 --- a/rtpsender_test.go +++ b/rtpsender_test.go @@ -484,3 +484,40 @@ func Test_RTPSender_RTX_Support(t *testing.T) { assert.NoError(t, peerConnection.Close()) }) } + +func Test_RTPSender_RTCPReader_Bind_Not_Nil(t *testing.T) { + track, err := NewTrackLocalStaticSample(RTPCodecCapability{MimeType: MimeTypeVP8}, "video", "pion") + assert.NoError(t, err) + + peerConnection, err := NewPeerConnection(Configuration{}) + assert.NoError(t, err) + + bindCalled := make(chan struct{}) + rtpSender, err := peerConnection.AddTrack(&TrackLocalCheckRTCPReaderOnBind{ + t: t, + TrackLocalStaticSample: track, + bindCalled: bindCalled, + }) + assert.NoError(t, err) + + parameter := rtpSender.GetParameters() + err = rtpSender.Send(parameter) + <-rtpSender.sendCalled + <-bindCalled + assert.NoError(t, err) + + assert.NoError(t, peerConnection.Close()) +} + +type TrackLocalCheckRTCPReaderOnBind struct { + *TrackLocalStaticSample + t *testing.T + bindCalled chan struct{} +} + +func (s *TrackLocalCheckRTCPReaderOnBind) Bind(ctx TrackLocalContext) (RTPCodecParameters, error) { + assert.NotNil(s.t, ctx.RTCPReader()) + p, err := s.TrackLocalStaticSample.Bind(ctx) + close(s.bindCalled) + return p, err +}