Remove RTX codec if no primary

While adding transceivers from SetRemoteDescription,
the filtered codecs could filter out the primart codec
and leave the RTX codec in. Generating an answer with
that fails `SetRemoteDescription` on remote peer due
to an unrecognisable codec. Fix it by filtering out
RTX is primary is not there.
This commit is contained in:
boks1971
2025-08-22 09:58:54 +05:30
committed by Raja Subramanian
parent 8efd17e592
commit c82d96cb75
3 changed files with 240 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ package webrtc
import (
"fmt"
"strings"
"sync"
"sync/atomic"
@@ -60,6 +61,19 @@ func (t *RTPTransceiver) SetCodecPreferences(codecs []RTPCodecParameters) error
}
}
// remove RTX codecs if there is no corresponding primary codec
for i := len(codecs) - 1; i >= 0; i-- {
c := codecs[i]
if !strings.EqualFold(c.MimeType, MimeTypeRTX) {
continue
}
if isRTX, primaryExists := primaryPayloadTypeForRTXExists(c, codecs); isRTX && !primaryExists {
// no primary for RTX, remove the RTX
codecs = append(codecs[:i], codecs[i+1:]...)
}
}
t.codecs = codecs
return nil