Skip to content

Commit

Permalink
Remove stopped member from RTPTransceiver
Browse files Browse the repository at this point in the history
It is unused. If needed in the future we can add it back
  • Loading branch information
boks1971 authored and Sean-Der committed Dec 15, 2024
1 parent 2585a2f commit 3e020d4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
89 changes: 44 additions & 45 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,56 +371,57 @@ func (pc *PeerConnection) checkNegotiationNeeded() bool { //nolint:gocognit
// return true
// }
m := getByMid(t.Mid(), localDesc)

// Step 5.2
if !t.stopped && m == nil {
if m == nil {
return true
}
if !t.stopped && m != nil {
// Step 5.3.1
if t.Direction() == RTPTransceiverDirectionSendrecv || t.Direction() == RTPTransceiverDirectionSendonly {
descMsid, okMsid := m.Attribute(sdp.AttrKeyMsid)
sender := t.Sender()
if sender == nil {
return true
}
track := sender.Track()
if track == nil {
// Situation when sender's track is nil could happen when
// a) replaceTrack(nil) is called
// b) removeTrack() is called, changing the transceiver's direction to inactive
// As t.Direction() in this branch is either sendrecv or sendonly, we believe (a) option is the case
// As calling replaceTrack does not require renegotiation, we skip check for this transceiver
continue
}
if !okMsid || descMsid != track.StreamID()+" "+track.ID() {
return true
}
}
switch localDesc.Type {
case SDPTypeOffer:
// Step 5.3.2
rm := getByMid(t.Mid(), remoteDesc)
if rm == nil {
return true
}

if getPeerDirection(m) != t.Direction() && getPeerDirection(rm) != t.Direction().Revers() {
return true
}
case SDPTypeAnswer:
// Step 5.3.3
if _, ok := m.Attribute(t.Direction().String()); !ok {
return true
}
default:
// Step 5.3.1
if t.Direction() == RTPTransceiverDirectionSendrecv || t.Direction() == RTPTransceiverDirectionSendonly {
descMsid, okMsid := m.Attribute(sdp.AttrKeyMsid)
sender := t.Sender()
if sender == nil {
return true
}
track := sender.Track()
if track == nil {
// Situation when sender's track is nil could happen when
// a) replaceTrack(nil) is called
// b) removeTrack() is called, changing the transceiver's direction to inactive
// As t.Direction() in this branch is either sendrecv or sendonly, we believe (a) option is the case
// As calling replaceTrack does not require renegotiation, we skip check for this transceiver
continue
}
if !okMsid || descMsid != track.StreamID()+" "+track.ID() {
return true
}
}
// Step 5.4
if t.stopped && t.Mid() != "" {
if getByMid(t.Mid(), localDesc) != nil || getByMid(t.Mid(), remoteDesc) != nil {
switch localDesc.Type {
case SDPTypeOffer:
// Step 5.3.2
rm := getByMid(t.Mid(), remoteDesc)
if rm == nil {
return true
}

if getPeerDirection(m) != t.Direction() && getPeerDirection(rm) != t.Direction().Revers() {
return true
}
case SDPTypeAnswer:
// Step 5.3.3
if _, ok := m.Attribute(t.Direction().String()); !ok {
return true
}
default:

Check warning on line 416 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L414-L416

Added lines #L414 - L416 were not covered by tests
}

// Step 5.4
// if t.stopped && t.Mid() != "" {
// if getByMid(t.Mid(), localDesc) != nil || getByMid(t.Mid(), remoteDesc) != nil {
// return true
// }
// }
}
// Step 6
return false
Expand Down Expand Up @@ -1872,7 +1873,7 @@ func (pc *PeerConnection) AddTrack(track TrackLocal) (*RTPSender, error) {
// transceiver can be reused only if it's currentDirection never be sendrecv or sendonly.
// But that will cause sdp inflate. So we only check currentDirection's current value,
// that's worked for all browsers.
if !t.stopped && t.kind == track.Kind() && t.Sender() == nil &&
if t.kind == track.Kind() && t.Sender() == nil &&
!(currentDirection == RTPTransceiverDirectionSendrecv || currentDirection == RTPTransceiverDirectionSendonly) {
sender, err := pc.api.NewRTPSender(track, pc.dtlsTransport)
if err == nil {
Expand Down Expand Up @@ -2213,9 +2214,7 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error {
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4)
pc.mu.Lock()
for _, t := range pc.rtpTransceivers {
if !t.stopped {
closeErrs = append(closeErrs, t.Stop())
}
closeErrs = append(closeErrs, t.Stop())
}
if nonMediaBandwidthProbe, ok := pc.nonMediaBandwidthProbe.Load().(*RTPReceiver); ok {
closeErrs = append(closeErrs, nonMediaBandwidthProbe.Stop())
Expand Down
3 changes: 1 addition & 2 deletions rtptransceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type RTPTransceiver struct {

codecs []RTPCodecParameters // User provided codecs via SetCodecPreferences

stopped bool
kind RTPCodecType
kind RTPCodecType

api *API
mu sync.RWMutex
Expand Down

0 comments on commit 3e020d4

Please sign in to comment.