Fix publish-only limitations being incorrectly applied to receivers (#4495)

* Fix publish-only limitations being incorrectly applied receive-side in a single PC

* `StaticConfigurations` disabled some codecs for publish only, which worked in dual PC
* In single PC, the server incorrectly disabled these codecs in both directions
* Dual PC mode is unchanged; single PC handles per-direction filtering correctly

* Filter recv-side codecs to publish list in single-PC SDP answer

* Confirm H264 is present in offer in test
This commit is contained in:
olafal0
2026-04-30 18:49:34 +05:30
committed by GitHub
parent a002337db1
commit f51798bcf6
5 changed files with 213 additions and 7 deletions
+37 -2
View File
@@ -307,7 +307,8 @@ type TransportParams struct {
Twcc *lktwcc.Responder
DirectionConfig DirectionConfig
CongestionControlConfig config.CongestionControlConfig
EnabledCodecs []*livekit.Codec
EnabledPublishCodecs []*livekit.Codec
EnabledSubscribeCodecs []*livekit.Codec
Logger logger.Logger
Transport livekit.SignalTarget
SimTracks map[uint32]sfuinterceptor.SimulcastTrackInfo
@@ -339,7 +340,11 @@ func newPeerConnection(
// Some of the browser clients do not handle H.264 High Profile in signalling properly.
// They still decode if the actual stream is H.264 High Profile, but do not handle it well in signalling.
// So, disable H.264 High Profile for SUBSCRIBER peer connection to ensure it is not offered.
me, err := createMediaEngine(params.EnabledCodecs, directionConfig, params.IsOfferer)
//
// Single-PC mode registers the union of publish and subscribe codecs so subscriptions
// can negotiate subscribe-only codecs; per-direction filtering happens at the transceiver
// level (configureSenderCodecs, restrictReceiverCodecsToPublishList).
me, err := createMediaEngine(mergeCodecsByMime(params.EnabledPublishCodecs, params.EnabledSubscribeCodecs), directionConfig, params.IsOfferer)
if err != nil {
return nil, nil, nil, err
}
@@ -2736,6 +2741,8 @@ func (t *PCTransport) createAndSendAnswer() error {
t.numRequestSentAudios, t.numRequestSentVideos = 0, 0
t.lock.Unlock()
t.restrictReceiverCodecsToPublishList()
answer, err := t.pc.CreateAnswer(nil)
if err != nil {
if errors.Is(err, webrtc.ErrConnectionClosed) {
@@ -3122,6 +3129,34 @@ func configureSenderCodecs(
tr.SetCodecPreferences(filteredCodecs)
}
// restrictReceiverCodecsToPublishList narrows recv-side transceiver codec
// preferences to the publish list, so the answer doesn't advertise
// subscribe-only codecs as receivable. No-op in dual-PC mode.
func (t *PCTransport) restrictReceiverCodecsToPublishList() {
for _, tr := range t.pc.GetTransceivers() {
if tr.Direction() != webrtc.RTPTransceiverDirectionRecvonly &&
tr.Direction() != webrtc.RTPTransceiverDirectionSendrecv {
continue
}
receiver := tr.Receiver()
if receiver == nil {
continue
}
filtered := filterCodecs(
receiver.GetParameters().Codecs,
t.params.EnabledPublishCodecs,
t.params.DirectionConfig.RTCPFeedback,
false,
)
if len(filtered) == 0 {
continue
}
if err := tr.SetCodecPreferences(filtered); err != nil {
t.params.Logger.Warnw("failed to set recv codec preferences", err, "mid", tr.Mid())
}
}
}
func configureReceiverCodecs(
tr *webrtc.RTPTransceiver,
preferredMimeType string,