Skip to content

Commit

Permalink
Make sure ReplaceTrack resets all track encodings when called with nil
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben committed Nov 16, 2023
1 parent a183f6c commit 77972b5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions rtpsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,26 @@ func (r *RTPSender) ReplaceTrack(track TrackLocal) error {

var replacedTrack TrackLocal
var context *baseTrackLocalContext
if len(r.trackEncodings) != 0 {
replacedTrack = r.trackEncodings[0].track
context = r.trackEncodings[0].context
}
if r.hasSent() && replacedTrack != nil {
if err := replacedTrack.Unbind(context); err != nil {
return err
for _, e := range r.trackEncodings {
replacedTrack = e.track
context = e.context

if r.hasSent() && replacedTrack != nil {
if err := replacedTrack.Unbind(context); err != nil {
return err
}

Check warning on line 247 in rtpsender.go

View check run for this annotation

Codecov / codecov/patch

rtpsender.go#L246-L247

Added lines #L246 - L247 were not covered by tests
}

if !r.hasSent() || track == nil {
e.track = track
}
}

if !r.hasSent() || track == nil {
r.trackEncodings[0].track = track
return nil
}

// If we reach this point in the routine, there is only 1 track encoding
codec, err := track.Bind(&baseTrackLocalContext{
id: context.ID(),
params: r.api.mediaEngine.getRTPParametersByKind(track.Kind(), []RTPTransceiverDirection{RTPTransceiverDirectionSendonly}),
Expand All @@ -274,6 +279,7 @@ func (r *RTPSender) ReplaceTrack(track TrackLocal) error {
}

r.trackEncodings[0].track = track

return nil
}

Expand Down

0 comments on commit 77972b5

Please sign in to comment.