Commit Graph

1414 Commits

Author SHA1 Message Date
Raja Subramanian
bd5382daaa Splitting transport close timeout logs. (#4108)
After adding more fields in
https://github.com/livekit/livekit/pull/4105/files, it was not even
logging. Access to one of the added fields must have ended up waiting on
a lock and blocked.

Unfotunately, the deadlock fix in https://github.com/pion/ice/pull/840
did not address the peer connection close hang.

Splitting the logs so that the base log still happens. Ordering after
looking at the code and guessing what could still log to see if we get
more of the logs and learn more about the state and which lock ends up
the first blocking one.
2025-11-27 10:02:01 +05:30
Raja Subramanian
a6418ae219 Log more peer conenction state on close timeout. (#4105) 2025-11-26 19:58:31 +05:30
Raja Subramanian
06d999748f Check for cancel on unsubscription/source track going away. (#4104) 2025-11-25 21:32:21 +05:30
Raja Subramanian
7f10e18bac Record join/publish/subscribe cancellations. (#4102)
To get better picture of success/failure rate.
2025-11-25 14:06:02 +05:30
Raja Subramanian
402936324c Clear stereo=1 if stereo is not enabled. (#4101) 2025-11-24 21:31:56 +05:30
Raja Subramanian
70f6def39d Add checks for participant and sub-components close. (#4100)
* Add checks for participant and sub-components close.

Looks like there might be some memory leak with participant sessions not
getting closed properly. Adding checks (to be cleaned up later) to see
if there is a consistent place where things might hang.

* init with right type

* Remove unnecessary goroutine, thank you @milos-lk

* clean up
2025-11-24 18:07:33 +05:30
aleb_the_flash
27d82a724e Fix "address" typo in transport logs (addddress → address) (#4097)
Correct triple-d spelling of "address" field in transport logs.

I’m not sure whether this was intentional, but I noticed it
while creating Grafana queries and filters. This matters because
anyone filtering logs using the correct spelling may
unintentionally miss relevant data, leading to incomplete or
misleading analysis.
2025-11-22 21:30:02 +05:30
cnderrauber
54cf7d46c8 Control latency of lossy data channel (#4088)
* Control latency of lossy data channel

* remove log

* test
2025-11-18 16:30:16 +08:00
cnderrauber
2d5054ad01 kind details for connector (#4072) 2025-11-11 21:50:48 +08:00
Raja Subramanian
a272e28ae0 Log raeson for subscriber not being to determine codec. (#4071) 2025-11-11 16:42:42 +05:30
Raja Subramanian
ca3c507b3f Prevent invalid track access while peer connection is shutting down. (#4054) 2025-11-05 17:48:27 +05:30
Trey Hakanson
1eefeb3089 Enable AbsCaptureTimeURI in RTC configuration (#4043)
Enable absolute capture time RTP extension. This logic was added a while back, but was disabled.
2025-10-31 09:42:36 +05:30
cnderrauber
075a7576ed Use simulcast codec as default policy for audio track (#4040) 2025-10-29 21:39:20 +08:00
Artur Melanchyk
c87eb8ed11 fix: add missing Unlock() in AddReceiver (#4036)
Signed-off-by: Artur Melanchyk <13834276+arturmelanchyk@users.noreply.github.com>
Co-authored-by: Artur Melanchyk <13834276+arturmelanchyk@users.noreply.github.com>
2025-10-27 18:45:44 +05:30
Raja Subramanian
15b19ccd26 Remove ~ from rid which indicates disabled layer to get the actual rid (#4032) 2025-10-26 15:44:32 +05:30
Raja Subramanian
a2ce73e0d0 Do not bind buffer if codec is invalid. (#4028)
Seeing cases of codec with zero clock rate. Do not bind to those.
2025-10-25 14:30:30 +05:30
Raja Subramanian
e63e8b6f2d Include mid -> trackID in both SDP offer and answer. (#4007)
This can be used by dual peer connection clients also.
2025-10-16 09:19:13 +05:30
Raja Subramanian
781dfede93 Do not call receiver methods under settings lock. (#4006)
* Do not call receiver methods under settings lock.

CI flagged a potential lock order reversal in https://github.com/livekit/livekit/actions/runs/18531658065/job/52815807499

* clean up
2025-10-15 21:06:28 +05:30
Raja Subramanian
69ff25a055 Use answer with mid -> trackID mapping when in single peer connection (#4005)
* Use answer with mid -> trackID mapping when in single peer connection
mode.

* mage generate

* staticcheck

* handle mapped answer in tests
2025-10-15 19:36:22 +05:30
Raja Subramanian
fe912acf37 Update pion/webrtc to prevent GetStats panic. (#4004)
Also, closing all data channels before closing peer connection.
2025-10-15 13:11:14 +05:30
Raja Subramanian
7930dcde25 Do not try to read stats from peer connection after close. (#4002)
Pion does not protect the stats getter and using it after close could
cause nil de-reference. Do a couple of things
1. Stop timer that access peer connection stats before closing peer
   connection.
2. Do not access stats if peer connection is already closed
2025-10-15 00:04:12 +05:30
Raja Subramanian
ca0d5ee972 Count request/response packets on both client and server side. (#4001)
Currently, the signal requests are counted on media side and signal
responses are counted on controller side. This does not provide the
granularity to check how many response messages each media node is
sending.

Seeing some cases where track subscriptions are slow under load. This
would be good to see if the media node is doing a lot of signal response
messages.
2025-10-14 16:58:36 +05:30
Raja Subramanian
dd62eb0072 Resort to full search for requested quality is not available. (#4000)
When doing code changes for dynamic rid, inadventently relied on
ordering of quality in track info layers to pick the highest layer if
the requested quality is higher than available qualities.
@cnderrauber addressed it in
https://github.com/livekit/livekit/pull/3998. Just adding some more
robustness behind that by doing a full search when requested quality is
not available.

Tested using JS SDK demo app and picking different qualities from
subscriber side with adaptive streaming turned off.
2025-10-14 10:05:33 +05:30
cnderrauber
0e2c59c8e4 Sort codec layers when adding track (#3998) 2025-10-14 10:34:52 +08:00
Raja Subramanian
a20bbe34fa Log RPC details. (#3991)
Seeing cases of `ConnectionTimeout` and `ResponseTimeout`.
So, logging destination identity in RPC request and also logging ACK and
response. Will pare back logs/log level of these messages after gettnig
some data.

Also a small change I noticed and had sitting in my local tree to set
the previous RTP marker on a padding packet.
2025-10-09 00:16:56 +05:30
Raja Subramanian
bf06596fcb Support Opus mixed with RED when encrypted. (#3986)
Even when encrypted, can set up opus as the second codec to support the
case of RED interspersed with Opus packets when the RED packet is too
big to fit in one packet.

The change here is to not go through all up stream codecs when trying to
find a match in DownTrack.Bind when source is encrypted. When encrypted,
the down track codec should match the primary upstream codec, i. e. the
codec at index 0.
2025-10-07 16:23:28 +05:30
lukasIO
ea208a1cf9 Add encryption datapacket type (#3869)
* Add encryption datapacket type

* update sum
2025-10-07 12:46:13 +02:00
Raja Subramanian
c7f625d626 Do not force codec regression between opus and red. (#3980)
The following scenario produced silence audio in egress
1. JS SDK publishing audio/red
2. Egress joins
3. Egress picks the RED primary receiver -> this converts RED to Opus in SFU
4. At the same time, codec regression is triggered back to the publisher. Publisher switches to publishing audio/opus and stops audio/red.
5. But, egress is still attached to audio/red and pulls down only silence.

Fix by checking if the negotiated codec needs publish before sending
subscribed codec udpate.
2025-10-04 00:17:17 +05:30
Raja Subramanian
3bd20ddb28 Revert unintentional change to not handle transport fallback on (#3970)
publisher peer connection.

While cleaning up during single peer connection changes, unintentionally
removed handler.

Also, another small change to log first packet time adjustment after
increment.
2025-09-30 10:24:26 +05:30
Paul Wells
3d73703152 add idempotent reference count to telemetry stats worker (#3964)
* add idempotent reference guard to telemetry stats worker

* tidy

* sync

* tidy
2025-09-29 02:35:16 -07:00
Raja Subramanian
00ff2ab941 Adjust for hold time when fowarding RTCP report. (#3956)
* Adjust for hold time when fowarding RTCP report.

When passing through RTCP sender report, holding it for some time before
sending means the remote receiver could see varying amount of
propagation delay if the remote uses something like local_clock -
ntp_sender_report_time and adapting to it.

Ideally, SFU should just forward RTCP Sender Report, but the current pull model to
group RTCP sender reports makes it a bigger change. So, adjust it by
hold time.

Also add a initial condition for one-way-delay estimator which can init
with a smaller value of latency if the first sample to measure
one-way-delay itself experienced higher delay than the prevailing
conditions.

* variable name

* log as duration
2025-09-26 18:57:21 +05:30
Paul Wells
e180be0622 short circuit participant broadcast filter in livestream mode (#3955) 2025-09-25 16:19:35 -07:00
Anunay Maheshwari
990c5fafbb feat: server rpc apis (#3904)
* feat: server rpc apis

* fix: cleanup

* fix: move rpc impl to participant

* cleanup

* cleanup, psrpc errors

* remove TODO comment

* update protocol, handle participant disconnect case

* add ephemeral participant identity to rpc data packet

* fix: panic

* chore(deps): bump proto
2025-09-24 13:16:27 +05:30
Raja Subramanian
d7f928783f Avoid matching on empty track id. (#3937)
Due to SDP ordering, Pion did not provide track ID on a receiver.

Pion needs a=msid line to be before a=ssrc line -> need to check if this
is a spec requirement

Because of the above, it had empty id for the receiver in onTrack.
That matched a published track because we do not duplicate SdpCid in
TrackInfo if the SDP cid matches the signal cid. But, the search checks
both and it matched on empty SDP cid.

Do not accept empty ids in searches to prevent this from happening.
2025-09-19 15:14:17 +05:30
Raja Subramanian
2c30a0640a Fix dynacast subscriber node clearing on move participant. (#3926) 2025-09-14 15:20:20 +05:30
Raja Subramanian
6489237e33 Simulcast audio fixes (#3925)
* Simulcast audio fixes

* clean up
2025-09-14 09:41:40 +05:30
Raja Subramanian
9f0ab8706f Wait for SetRemoteDescription before configuring senders. (#3924)
* Wait for `SetRemoteDescription` before configuring senders.

Details inline in code.

* comment
2025-09-12 23:24:56 +05:30
Raja Subramanian
df6c26dbf6 Subscrbed audio codecs - update from remote nodes. (#3921) 2025-09-12 13:01:00 +05:30
Raja Subramanian
798fa76110 Support simulcasting of audio (#3920)
* WIP

* WIP

* new files

* clean up

* test

* Deps

* clean up

* clean up

* goimports latest
2025-09-12 10:20:04 +05:30
Raja Subramanian
eee2001a31 Set publisher codec preferences after setting remote description (#3913)
* Set publisher codec preferences after setting remote description

Munging SDP prior to setting remote description was becoming problematic
in single peer connection mode. In that mode, it is possible that a
subscribe track m-section is added which sets the fmtp of H.265 to a
value that is different from when that client publishes. That gets
locked in as negotiated codecs when pion processes remote description.
Later when the client publishes H.265, the H.265 does only partial
match. So, if we munge offer and send it to SetRemoteDescription, the
H.265 does only a partial match due to different fmtp line and that gets
put at the end of the list. So, the answer does not enforce the
preferred codec. Changing pion to put partial match up front is more
risky given other projects. So, switch codec preferences to after remote
description is set and directly operate on transceiver which is a better
place to make these changes without munging SDP.

This fixes the case of
- firefox joins first
- Chrome preferring H.265 joining next. This causes a subscribe track
  m-section (for firefox's tracks) to be created first. So, the
  preferred codec munging was not working. Works after this change.

* clean up

* mage generate

* test

* clean up
2025-09-10 18:28:36 +05:30
Hamdan
fc995533e1 add incoming request id to request response message (#3912) 2025-09-10 08:58:12 +05:30
cnderrauber
76645fad5e Rpcs for ingress proxy WHIP (#3911)
See https://github.com/livekit/protocol/pull/1194
2025-09-09 22:49:42 +08:00
Raja Subramanian
991a4a4f53 Refactor subscribedTrack + mediaTrackSubscriptions. (#3908)
- Move downTrack instantiation to SubscribedTrack as it should own that
  DownTrack. Still more to do here as `DownTrack` is fetched from
  `SubscribedTrack` in a few places and used. Would like to avoid that,
  but doing this initially.
- Use an interface from sfu.Downtrack and replace a bunch of callbacks.
  SubscribedTrack is the implementation for DownTrackListener.
2025-09-08 18:20:19 +05:30
Raja Subramanian
07c40cf349 Use RequestResponse to report protocol handling errors (#3895)
* Send errors as necessary

* WIP

* WIP

* WIP

* WIP

* deps

* static check

* fix test

* test

* test

* logs
2025-09-04 11:27:07 +05:30
Raja Subramanian
f7291fdaa8 Do not send both asb-send-time and twcc. (#3890)
* Do not send both asb-send-time and twcc.

In single peer connection mode, both extensions are set on the media
engine and both would be negotiated. Unfortunately, pion/webrtc does
not yet support RTPSender.SetParameters() which would allow setting
specific header extensions for the sender. So, check for TWCC enabled
and use it. If not, do abs-send-time if that is enabled.

* check BWE type

* comment
2025-08-30 19:22:14 +05:30
Raja Subramanian
21b42fa6d9 Do not advertise NACK for RED. (#3889)
Set the transceiver codecs first in single peer connection mode and
then do audio specific config so that NACK is removed for RED.
2025-08-30 17:34:44 +05:30
Raja Subramanian
38f7906ecb Handle migration better in single peer connection case. (#3886)
* Handle migration better in single peer connection case.

Have to avoid creating a sender for publish tracks.
Otherwise, the sender messes up the answer SDP because
it forced to inactive and that gets used by type match when setting
remote description offer.

Create sender only for m-lines which was used to send.

* remove unnecessary RemoveTrack
2025-08-29 18:18:32 +05:30
Raja Subramanian
091e3c13a1 Revert to using answer for migration case. (#3884)
Was breaking migration in cases where there was inactive transceivers
because of direction check.

This change will break single peer connection case, but can look at that
one later.
2025-08-29 12:58:42 +05:30
Paul Wells
2aeadf14dc init ua parser once (#3883) 2025-08-28 05:20:25 -07:00
Raja Subramanian
890fd94249 Single peer connection mode (#3873)
* WIP

* check using protocol version

* revert

* clean up

* sdp cid argument

* WIP

* WIP

* test

* clean up

* clean up

* fixes

* clean up

* clean up

* clean up

* conditional checks

* tests for both dual and single peer connection

* test

* test

* test

* type check

* test

* todo

* munges

* combined config

* populate mid

* limit to receive only

* clean up

* clean up

* clean up

* older test

* clean up

* alternative audio codec

* dtx

* don't need to copy

* Anunay feedback

* use the available peer connection

* publisher check

* WIP

* WIP

* WIP

* no mid

* media sections requirement

* mage generate

* WIP

* WIP

* set data channel receive size for test

* handle early media better

* WIP

* do not do ICERestart if no subscriber

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* start up subscriber RTCP worker

* WIP

* WIP

* clean up

* clean up

* flag to indicate use of single peer connection

* remove unused interface method

* clean up

* clean up

* Jie feedback #1

* deps

* do not access subscriber in one shot mode

* more places for one shot mode

* more one shot fixes

* deps

* deps

* test
2025-08-28 12:16:18 +05:30