Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rtcp interceptor nil panic #2930

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions peerconnection_renegotiation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,10 +1127,13 @@ func TestPeerConnection_Renegotiation_Simulcast(t *testing.T) {
defer trackMapLock.Unlock()

for _, track := range trackMap {
_, _, err := track.ReadRTP() // Ignore first Read, this is our peeked data
assert.Nil(t, err)
_, _, err := track.ReadRTP()

// Ignore first Read, this was our peeked data
if err == nil {
_, _, err = track.ReadRTP()
}

_, _, err = track.ReadRTP()
assert.Equal(t, err, io.EOF)
}
}
Expand Down
10 changes: 8 additions & 2 deletions rtpreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func (r *RTPReceiver) startReceive(parameters RTPReceiveParameters) error { //no
return errRTPReceiverReceiveAlreadyCalled
default:
}
defer close(r.received)

globalParams := r.getParameters()
codec := RTPCodecCapability{}
Expand Down Expand Up @@ -257,6 +256,8 @@ func (r *RTPReceiver) startReceive(parameters RTPReceiveParameters) error { //no
}
}

close(r.received)

return nil
}

Expand Down Expand Up @@ -404,7 +405,12 @@ func (r *RTPReceiver) streamsForTrack(t *TrackRemote) *trackStreams {

// readRTP should only be called by a track, this only exists so we can keep state in one place.
func (r *RTPReceiver) readRTP(b []byte, reader *TrackRemote) (n int, a interceptor.Attributes, err error) {
<-r.received
select {
case <-r.received:
case <-r.closed:
return 0, nil, io.EOF
}

if t := r.streamsForTrack(reader); t != nil {
return t.rtpInterceptor.Read(b, a)
}
Expand Down
36 changes: 36 additions & 0 deletions rtpreceiver_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package webrtc

import (
"context"
"io"
"testing"
"time"

Expand Down Expand Up @@ -74,3 +75,38 @@ func TestSetRTPParameters(t *testing.T) {
assert.NoError(t, wan.Stop())
closePairNow(t, sender, receiver)
}

func TestReceiveError(t *testing.T) {
api := NewAPI()

dtlsTransport, err := api.NewDTLSTransport(nil, nil)
assert.NoError(t, err)

rtpReceiver, err := api.NewRTPReceiver(RTPCodecTypeVideo, dtlsTransport)
assert.NoError(t, err)

rtpParameters := RTPReceiveParameters{
Encodings: []RTPDecodingParameters{
{
RTPCodingParameters: RTPCodingParameters{
SSRC: 1000,
},
},
},
}

assert.Error(t, rtpReceiver.Receive(rtpParameters))

chanErrs := make(chan error)
go func() {
_, _, chanErr := rtpReceiver.Read(nil)
chanErrs <- chanErr

_, _, chanErr = rtpReceiver.Track().ReadRTP()
chanErrs <- chanErr
}()

assert.NoError(t, rtpReceiver.Stop())
assert.Error(t, io.ErrClosedPipe, <-chanErrs)
assert.Error(t, io.ErrClosedPipe, <-chanErrs)
}
Loading