Skip to content
Open
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
3 changes: 0 additions & 3 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1875,9 +1875,6 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream *srtp.ReadStreamSRTP, ssr
}

if rsid != "" {
receiver.mu.Lock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the atomic do you still need locking changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just moved the lock inside. Yeah, there are more internal state like tracks in RTPReceiver which needs locking. Not sure why the lock was not internal and called from peerconnection.go. Seemed like a good thing to move it inside.

defer receiver.mu.Unlock()

return receiver.receiveForRtx(SSRC(0), rsid, streamInfo, readStream, interceptor, rtcpReadStream, rtcpInterceptor)
}

Expand Down
36 changes: 33 additions & 3 deletions rtpreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (r *RTPReceiver) startReceive(parameters RTPReceiveParameters) error { //no
rtcpReadStream := result.rtcpReadStream
rtcpInterceptor := result.rtcpInterceptor

if err = r.receiveForRtx(
if err = r.receiveForRtxInternal(
rtxSsrc,
"",
streamInfo,
Expand Down Expand Up @@ -552,6 +552,10 @@ func (r *RTPReceiver) receiveForRid(
r.mu.Lock()
defer r.mu.Unlock()

if r.haveClosed() {
return nil, io.EOF
}

for i := range r.tracks {
if r.tracks[i].track.RID() == rid {
r.tracks[i].track.mu.Lock()
Expand All @@ -576,8 +580,6 @@ func (r *RTPReceiver) receiveForRid(
}

// receiveForRtx starts a routine that processes the repair stream.
//
//nolint:cyclop
func (r *RTPReceiver) receiveForRtx(
ssrc SSRC,
rsid string,
Expand All @@ -587,6 +589,34 @@ func (r *RTPReceiver) receiveForRtx(
rtcpReadStream *srtp.ReadStreamSRTCP,
rtcpInterceptor interceptor.RTCPReader,
) error {
r.mu.Lock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use haveClosed instead?

defer r.mu.Unlock()

return r.receiveForRtxInternal(
ssrc,
rsid,
streamInfo,
rtpReadStream,
rtpInterceptor,
rtcpReadStream,
rtcpInterceptor,
)
}

//nolint:gocognit,cyclop
func (r *RTPReceiver) receiveForRtxInternal(
ssrc SSRC,
rsid string,
streamInfo *interceptor.StreamInfo,
rtpReadStream *srtp.ReadStreamSRTP,
rtpInterceptor interceptor.RTPReader,
rtcpReadStream *srtp.ReadStreamSRTCP,
rtcpInterceptor interceptor.RTCPReader,
) error {
if r.haveClosed() {
return io.EOF
}

var track *trackStreams
if ssrc != 0 && len(r.tracks) == 1 {
track = &r.tracks[0]
Expand Down
Loading