Skip to content

Single peer connection mode - #3873

Merged
boks1971 merged 78 commits into
masterfrom
raja_ppc
Aug 28, 2025
Merged

boks1971 merged 78 commits into
masterfrom
raja_ppc

Conversation

@boks1971

Copy link
Copy Markdown
Contributor

Use publisher peer connection only for both upstream and down stream tracks.

The flow is

Made all integration tests to run with dual peer connection protocol and single peer connection protocol.

Will leave more notes inline.

Comment thread pkg/routing/interfaces.go
AddTrackRequests []*livekit.AddTrackRequest
PublisherOffer *livekit.SessionDescription
SyncState *livekit.SyncState
UseSinglePeerConnection bool

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is set automatically on ParticipantInit based on how the initial request is received. If client uses the WrappedJoinRequest, this is automatically enabled.

Comment thread pkg/rtc/config.go
}

func getPublisherConfig(consolidated bool) DirectionConfig {
if consolidated {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

using the union of subscriber and publisher when in single peer connection mode so that the media engine has all the options.

Separately, RTCP config is set on subscribed track media sections using SetCodecPreferences when a subscribed track is assigned to a transceiver. Will make a note of where that happens in the relevant file below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is an option to use sendside or recvside bandwidth estimation for subscriber before, is it still possible to use recvside bandwidth estimation for subscribed track in signle peer connection mode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch Jie. Actually, I only have receive side (meaning REMB) available here as it is the default. send side (TWCC) is config based now. And I think I have it now such that it can be enabled only for subscriber peer connection. I had a mental note to address it, but forgot. I will check what is a good way to do that and will also check that it works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

by doing consolidated config both extensions are available in SDP. Actually, just checked and the code to enable send side (TWCC) in downstream via config should work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cnderrauber Just wanted to make sure that you were able to see the above replies. I frequently forget to hit submit. Looks like I did it this time. Did you not get a notification?

Comment thread pkg/rtc/mediaengine.go
return mime.MimeTypeOpus.String()
}

func filterCodecs(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is used by subscribed track side to filter out non-subscribe enabled codecs.

In a single peer connection mode, the media engine is configured with all codecs. The filtering happens when subscribed track is added to the peer connection on the corresponding transceiver.

info := t.params.MediaTrack.ToProto()
addTrackParams := types.AddTrackParams{
Stereo: info.Stereo,
Stereo: slices.Contains(info.AudioFeatures, livekit.AudioTrackFeature_TF_STEREO),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just clean up to not rely on deprecated/legacy fields.

Comment thread pkg/rtc/participant.go
return p.TransportManager.AddTrackLocal(
trackLocal,
params,
p.enabledSubscribeCodecs,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made a note above about subscribed tracks filtering only subscribe enabled codecs. This is the place where the subscribed enabled codecs are given to AddTrack when using single peer connection mode. It is given nil when in dual peer connection mode.

return err
}

func (p *ParticipantImpl) sendMediaSectionsRequirement(numAudios uint32, numVideos uint32) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the new signal response message to require clients to send another offer maybe with more media sections added.

Comment thread pkg/rtc/transport.go Outdated
// As Firefox does not support migration, ICE Lite can be disabled.
se.SetLite(false)
}
se.SetDisableTransceiverReuseInRecvonly(params.DisableRecvonlyTransceiverReuse)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the new flag to disable transceiver re-use when in recvonly. Details in pion PR - pion/webrtc#3200. Will look at maintaining state in transceiver like Nils suggested later. In that case, this flag may not be required.

Comment thread pkg/rtc/transport.go
if trackLocal.Kind() == webrtc.RTPCodecTypeAudio {
configureAudioTransceiver(transceiver, params.Stereo, !params.Red || !t.params.ClientInfo.SupportsAudioRED())
}
configureTransceiverCodecs(transceiver, enabledCodecs, rtcpFeedbackConfig, !t.params.IsOfferer)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made a note in couple of places about subscribed track filtering enabled codecs and setting codec preferences. This is where it happens when a track is added to the peer connection. The preferences are set on the corresponding transceiver.

Comment thread test/agent_test.go

return ""
}, AssignJobTimeout)
for _, useSinglePeerConnection := range []bool{false, true} {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using this for all tests to test both dual peer connection and single peer connection modes. Using a separate argument to createRTCClient helper to indicate use of single peer connection. But, it is possible to roll it into testclient.Options. But, wanted to use an extra argument to ensure I have covered all the places which uses this helper to test both modes. Once it is working, will probably change it to use an option.

@boks1971
boks1971 requested a review from a team August 24, 2025 19:52

@cnderrauber cnderrauber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work!! This will improve connectivity for edge case!

Comment thread pkg/rtc/config.go
}

func getPublisherConfig(consolidated bool) DirectionConfig {
if consolidated {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is an option to use sendside or recvside bandwidth estimation for subscriber before, is it still possible to use recvside bandwidth estimation for subscribed track in signle peer connection mode?

Comment thread pkg/rtc/participant_sdp.go Outdated

if info == nil {
p.pendingTracksLock.RUnlock()
if ti != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

put this block below the ti == nil check?

Comment thread pkg/rtc/participant_sdp.go Outdated
// configure publisher answer for audio track's dtx and stereo settings
func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescription) webrtc.SessionDescription {
offer := p.TransportManager.LastPublisherOffer()
if offer == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it possible a nil offer when setting answer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it should not be. Left over from when I was trying to do the subscriber peer connection as single peer connection I think. Will remove.

@boks1971
boks1971 merged commit 890fd94 into master Aug 28, 2025
@boks1971
boks1971 deleted the raja_ppc branch August 28, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants