Commit Graph

2791 Commits

Author SHA1 Message Date
Raja Subramanian
2afbf0e8ca Some golang modernisation bits. (#4016)
Mainly doing this to check CI static check failures.
2025-10-21 12:53:18 +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
Raja Subramanian
f6ca82d177 Revert to using silence packets for audio dummy start. (#3999)
Effectively reverts https://github.com/livekit/livekit/pull/3984.
Using padding only packets for audio dummy start introduces dependencies
on other services and is not a necessary change. Would have been good to
use padding only for audio also from t=0. We can re-visit this for
better compatbility down the line.
2025-10-14 10:05:16 +05:30
cnderrauber
0e2c59c8e4 Sort codec layers when adding track (#3998) 2025-10-14 10:34:52 +08:00
Nishad
100bb46af3 Adding ProviderInfo to GetSIPTrunkAuthenticationResponse (#3993) 2025-10-12 15:40:32 +05:30
Alan Willard
a8d4df66f4 "Power of Two Random Choices" option for node selection (#3785)
* Added optional "Power of Two Random Choices" algorithm for the node selector sort_by feature. The current, default behavior of picking the lowest-valued node remains.
2025-10-08 15:31:01 -07: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
158496bca1 Increment RTP timestamp on padding when using dummy start. (#3989)
* Increment RTP timestamp on padding when using dummy start.

This allows things like egress to have proper sequence to start
the pipeline.

* test
2025-10-07 23:39:51 +05:30
Raja Subramanian
4f6ed65d61 Limit check to red + opus when looking for primary codec match. (#3988)
For codec regression, even if track is encrypted, should be able to fall
back to a backup codec and trigger a regression.
2025-10-07 23:28:26 +05:30
Denys Smirnov
a87f6c4bc8 Allow passing inline trunk for outbound calls. (#3987) 2025-10-07 17:30:14 +03:00
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
2a6adbe80e Use padding only packets for dummy start of audio. (#3984)
If egress does not need silence packets to start audio, this will
simplify dummy start by using the same mechanism for video and audio.
2025-10-07 10:11:15 +05:30
Benjamin Pracht
be018f97b6 Provide the InputVideo/AudioState to Ingress in WHIPRTCConnectionNotify (#3982) 2025-10-06 14:16:35 -07:00
Benjamin Pracht
146bd9699d Do not panic of redis is not configured (#3981) 2025-10-06 07:47:29 -07:00
Raja Subramanian
01337ba730 Do not start forawarding on out-of-order packet. (#3985)
It is posible that a subscriber joins when a publisher has reconnected
and has received a flood of retransmitted packets due to NACKing the
gap caused by the publisher reconnecting. Starting on that spurt means
the subscriber gets a burst of unpaced packets that could lead to issues
with calculating render time (especially obvious in cases like egress).
2025-10-06 13:16:48 +05:30
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
060719d17d add config for user data recording (#3966)
* add config for user data recording

* missing file

* wire

* deps
2025-09-29 14:01:39 -07:00
Paul Wells
b3ee219ccb fix stats worker closed condition (#3965)
* fix stats worker closed condition

* test

* tidy
2025-09-29 02:51:58 -07:00
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
735c663adc Update protocol for EventKey helper. (#3963) 2025-09-29 11:42:18 +05:30
Raja Subramanian
0bf7b178eb avoid logging on small values (#3958) 2025-09-28 10:46:41 +05:30
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
Raja Subramanian
bfba6feed4 Adjust stream allocator ping interval based on state. (#3951)
* Adjust stream allocator ping interval based on state.

In steady state, does a 15 second ping.
While deficient, to be able to react to probes faster, it pings at 100ms
interval.

* clean up

* log ops queue not able to wake up
2025-09-24 14:45:57 +05:30
Raja Subramanian
3837006b39 Revert "Switch ops queue a singly linked list. (#3949)" (#3950)
This reverts commit 80b1166292.
2025-09-24 14:10:01 +05:30
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
80b1166292 Switch ops queue a singly linked list. (#3949)
Seeing a good chunk of CPU in deque usage in some profiles.
2025-09-24 13:13:00 +05:30
Paul Wells
56ee23282f handle terminated job requests (#3948) 2025-09-23 23:54:01 -07:00
Raja Subramanian
49f9b9c8bd Flush stats when there are no packets. (#3947)
With no packets flowing through, the stat gets stuck.
Flush the pipe if there have been no packets in the report interval.
2025-09-23 16:57:41 +05:30
Raja Subramanian
e6a3df1edc ForwarStats.GetStats needs to be public (#3946)
* ForwarStats.GetStats needs to be public

* prevent deadlock
2025-09-23 15:46:12 +05:30
Raja Subramanian
824d116bfe Tweaks tresholds for logging high forwarding latency/jitter. (#3945)
* Tweaks tresholds for logging high forwarding latency/jitter.

Previous attempt showed skewed jitter (i. e. more than 10x latency),
But, no large latency.

So, reducing the latency treshold to declare high latency.
And also keeping track of lowest/highest per reporting window and
logging those along with short term and long term measurements.

NOTE: previously short term and long term were separate calls with locks
acquired. Now, it is all in one lock. So, it does increase the lock
duration a bit, but hopefully not by too much as the welford merge for
short term would go over 20 samples (at 50 ms sampling interval and 1 s
reporting window).

* revert skew factor
2025-09-23 14:46:43 +05:30
Raja Subramanian
408492e030 Log some information around high forwarding latency. (#3944)
* Log some information around high forwarding latency.

Latency is not 0 after switching to microseconds resolution.
But, still seeing high jitter. Logging a bit more to understand under
what conditions it happens.

More notes inline.

* compact
2025-09-23 12:37:09 +05:30
Raja Subramanian
6a41fae548 Use microseconds for forwarding stats. (#3943)
Latency is always 0, but jitter is high.
Not sure how that happens as latency is the welford mean and jitter is
welford standard deviation. Feels like some mis-labeling.

Anyhow, switching to microseconds units to get better resolution.
2025-09-23 02:28:19 +05:30
Raja Subramanian
b07e7a3828 Use difference in key frame counter to stop seeder. (#3936)
The key frame seeder could be started multiple times.
Use difference to detect stop condition.
2025-09-19 15:15:26 +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
56fb28858a Do DD restart only if DD structure is present. (#3935) 2025-09-19 02:39:08 +05:30
Raja Subramanian
86facce9f4 More debugging of DD jump (#3934) 2025-09-19 01:29:28 +05:30
Raja Subramanian
6058a3f622 Add debugging from DD frame number wrap around. (#3933)
* Add debugging from DD frame number wrap around.

On a DD parser restart, the extended highest sequence number oes not
seem to be updated. Adding some debug to understand it better.

* more logs

* log incoming sequence number and frame number
2025-09-19 00:17:45 +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