1190 Commits

Author SHA1 Message Date
Raja Subramanian
050909e627 Enable data tracks by default. (#4429) 2026-04-04 00:54:48 +05:30
Raja Subramanian
c6ddc879e7 isExpectedToResume is based on whether flushing or not. (#4425)
For a participant migrating out, the track could be resumed on a
different node, but ending on the migrating out node. So, `flush` should
be used to indicate if track is going to be resumed.
2026-04-03 00:49:12 +05:30
Raja Subramanian
9674ac48ab Cleaning up some logs and standardising log frequency. (#4420)
Removing some logs which have not been useful in terms of insights other
than saying that there are a bunch of packets missing. Going to start
looking at gaps in terms of time if the inter-packet gap is too high.

Also, using logging these events as first 20 and then every 200.
2026-04-01 21:17:43 +05:30
Raja Subramanian
7b92530461 Drop time inverted packets in RED -> Opus conversion. (#4418)
A bunch of edges to note here
RED packet does not have sequence number for redundant blocks. It only
has timestamp offset compared to the primary payload. The receivers are
supposed to use just timestamp to sequence the payload and decode.

But, when converting from RED -> Opus, the packets extracted from RED
packet should be assigned a sequence number before they can be
forwarded. The simple rule is, if packet N contains X redundant
payloads, they are assigned sequence number of N - X to N - 1.

However there are cases like the following sequence (with 1 packet
redundancy)
- Seq num 10, timestamp 2000, forwarded
- Seq num 11 is lost
- Seq num 12 has a redundant payload. Seq num 12 has timestamp of 4000.
  Ideally would expect the redundant payload to have a timestamp offset
  of 1000, so the redundant payload can be mapped to sequence number 11
  and timestamp 3000 (4000 - 1000). But, in the problematic case, it has
  an offset of 3000 resulting in sequence number 11 and timestamp of
  1000 causing an inversion with packet at sequence number 10.

Unclear if this a publisher issue, i. e. packing RED wrong or if this is
some expected behaviour with DTX. i. e. the DTX packets are not included
in redundant payload. For example, the sequence
- Seq num 10 -> DTX
- Seq num 11 -> DTX -> lost
- Seq num 12 -> Regular packet and include sequence num 9 as that is the
  last regular packet.

Anyhow, detect this condition and drop the time inverted packet.

Note however this handles only inversion against the highest sent packet
sequence number and timestamp. So, some old packet inverted with some
other old packet getting forwarded will get through. That has been the
case always though and detecting that would be expensive and
complicated.

At least for egress, will also look at adding a check for inversion so
that it can catch it before sending it down the gstreamer pipeline. As
the egress uses a jitter buffer with ordered sequence number emits, it
will be simpler to detect timestamp going back when sequence number is
moving forward (of course the mute/dtx challenege is there).
2026-04-01 11:40:01 +05:30
Raja Subramanian
4fe80877df Log time inversion between incoming packets (#4415)
* Log time inversion between incoming packets

Log of timestamp inversion within a red packet did not show anything.
Log across packets. Not dropping till there is more evidence of the
cause.

* save

* comment
2026-03-31 20:09:07 +05:30
Raja Subramanian
248d73948d Guard against timestamp inversion in RED -> Opus conversion. (#4414)
* Guard against timestamp inversion in RED -> Opus conversion.

Seeing timestamp inversion (sequence number is +1, but timestamp is
-960, i.e. 20ms) in the RED -> Opus conversion path. Not able to spot
any bugs in code. So, logging details upon detection and also dropping
the packet. If not dropped, downstream components like Egress treat it
as a big timestamp jump (because sequence number is moving forward) and
try to adjust pts which ends up causing drops.

* do not log time reversal at the start

* typo
2026-03-31 17:08:13 +05:30
Raja Subramanian
4bc5e6bbef Address malformed H264/H265 parsing issues. (#4407)
* Address malformed H264/H265 parsing issues.

Thank you for the report in
https://github.com/livekit/livekit/security/advisories/GHSA-qxj9-fmqx-r7j8#advisory-comment-179701
with examples. Addressing the parsing issues.

* early continue
2026-03-30 09:30:58 +05:30
Raja Subramanian
77a0a4fcc7 AV1 parser overflow fix. (#4405)
Upstream had patched this a while back -
c0b755f82f.

Addresses https://github.com/livekit/livekit/security/advisories/GHSA-qxj9-fmqx-r7j8
2026-03-29 09:53:15 +05:30
Raja Subramanian
34bd1e0851 do not log roll over for padding only packets (#4396)
* do not log roll over for padding only packets

* calculated expected earlier
2026-03-26 11:47:29 +05:30
David Chen
a5333a86bb add packet trailer stripping support (#4361)
* bump protocol version to 17 to enable packet trailer stripping functionality
* check subscriber protocol version for trailer stripping
2026-03-23 13:33:42 -07:00
Raja Subramanian
8f984c770a Fix repair stream ID reporting for RTX pairing. (#4369)
If RTX stream got a packet before primary stream, the pairing was not
getting set up properly.
2026-03-17 15:06:57 +05:30
Raja Subramanian
cdfaacfca3 Restart nacker on OOB sequence number restart. (#4368)
Clears NACKs based on old sequence number base and restarts it.
Also rename the function to be more reflective of what stats lite is
for.
2026-03-17 09:16:08 +05:30
Raja Subramanian
750d5904f0 Add API to restart lite stats. (#4366) 2026-03-16 15:20:13 +05:30
Raja Subramanian
77fc74a727 Do not block all ext ID determination on stream allocator listener (#4364)
availability.

Added checks for unexpected changes.
2026-03-15 14:30:47 +05:30
Raja Subramanian
7eaaaada5d Mark last run of grow bucket outside goroutine. (#4348)
* straem tracker debug logging

* tracker

* debug

* clean up
2026-03-06 19:36:13 +05:30
Raja Subramanian
52c28a938d Log a bit more details of out-of-order TWCC feedback report. (#4343)
* Log a bit more details of out-of-order TWCC feedback report.

* Revert to mono.Now()
2026-03-05 11:55:13 +05:30
Raja Subramanian
bab9186840 do not discount packets lost on duplicate packets (#4333) 2026-02-23 23:55:56 +05:30
Raja Subramanian
939794cf47 mark + restart (#4329) 2026-02-21 15:12:13 +05:30
Raja Subramanian
75f9c462be Add debug for receiver restart. (#4328)
* Add debug for receiver restart.

Have a suspicion that something is deadlocking between restart receiver
and buffer bind during replay. Adding debug to get a better picture of
state of receiver restart.

* consistent logging
2026-02-20 01:44:59 +05:30
Raja Subramanian
74891f30fe Protect against incorrect temporal layer. (#4327)
Seeing some tracks with temporal layer higher than array bounds.
Protect against it and log some info to understand better.
2026-02-19 23:57:58 +05:30
Raja Subramanian
35d7ef88c2 Avoid alloc in RTPStatsReceiver.Update (#4302)
Using a pointer to the logging context was doing allocations.
2026-02-09 11:53:17 +05:30
Raja Subramanian
bb744916fd More optimisation in RTPStats module. (#4298)
Was hoping for more hidden bits to optimise, but oh well.
2026-02-06 21:33:41 +05:30
Raja Subramanian
cefd5da940 Optimise some bits in rtpstats_receiver (#4297)
* Optimise some bits in rtpstats_receiver

RTPStatsReceiver.Update is one of the high CPU bits. Taking some
suggestions from Cursor. Makes the `Update` function verbose though :-(

* zap.Inline logging fields

* rename
2026-02-06 21:26:30 +05:30
Raja Subramanian
370e0a4d52 Set up audio config in audio level module when config is updated. (#4290)
* Set up audio config in audio level module when config is updated.

It is possible to get audio config after bind (bind is where the audio
level module is created) for remote tracks. So, split out setting audio
level config in audio level module and invoke it when config is updated.

* coderabbit review

* prevent divide-by-0

* not active before config
2026-02-05 09:35:26 +05:30
Raja Subramanian
f3e9b68854 Do not increase max expected layer on track info update. (#4285)
* Do not increase max expected layer on track info update.

When max expected layer increases, the corresponding trackers are reset
so that first packets from those layers can trigger a layer detected
change enabling quick detection of layer start.

A track info update changing max to what is in track info could set the
max expected to be higher without resetting the tracker. And that would
cause dynacast induced max layer change to miss tracker reset too.

Sequence
- dynacast sets max expected to 0
- track info update sets it to 2
- dynacast sets it to 1 --> this should have reset tracker on layer 1,
  but because it is less than current max (2), it is skipped.

* thank you CodeRabbit

* force update on start
2026-02-04 12:19:41 +05:30
Raja Subramanian
a9849340c3 Avoid logger data race. (#4284)
Also defer promise channel close.
2026-02-04 01:35:44 +05:30
Raja Subramanian
9701662757 Do not hold lock when creating buffer (#4283)
* create buffer outside lock

* more debug

* initialize on new buffer

* clean up

* address CodeRabbit catch
2026-02-04 00:55:49 +05:30
Raja Subramanian
6b68e3d536 Create buffer if needed when a PLI is requested. (#4282)
Useful across relay where a PLI may be requested before a buffer exists and
needs to be created.
2026-02-03 18:34:38 +05:30
Raja Subramanian
1e689e1a24 Reducing some info level logs. (#4274)
* Reducing some info level logs.

Also, relaxing the check for runaway RTCP receiver report to allow for
rollover to catch up if it is not too far away.

* set logger
2026-02-02 10:54:03 +05:30
cnderrauber
01bd966ff8 Add silent frame for pcmu/a (#4258)
* Add silent frame for pcmu/a

* use red

* solve comment
2026-01-21 16:11:08 +08:00
Anunay Maheshwari
0c33b8c671 chore: move codecs/mime stuff to protocol (#4255) 2026-01-20 20:54:32 +05:30
Raja Subramanian
aea044c5cb Defer setting clock rate in RTPStats module till codec is bound. (#4250)
With audio simulcast codecs, it is possible that the clock rate of the
primary codec is different from the secondary codec. If a subscriber
binds to the secondary codec, the clock rate should be set correctly. Do
it at bind time.
2026-01-15 22:08:50 +05:30
Raja Subramanian
d9f716c14a FIx receiver restart race (#4248) 2026-01-15 19:54:20 +05:30
Denys Smirnov
843d8c3ea1 Update Pion transport package. (#4237)
* Update Pion transport package.

* Update mediatransportutil package.
2026-01-13 19:56:41 +02:00
Raja Subramanian
7fae5ac9e6 Do not restart receiver on codec change mid-session. (#4225)
* Do not restart receiver on codec change mid-session.

This is not supported and was an erroneous change during the
receiver_base/buffer_base + RTP stream restart consolidation. Also make
the codec munger creation more resilient.

* fix test
2026-01-08 02:35:32 +05:30
Raja Subramanian
0a7dd40b35 Use only layer 0 for SVC codecs. (#4224)
GetOrCreateBuffer was using passed in layer when creating a new buffer.
But, it should always use layer 0 only for SVC.
2026-01-07 18:57:21 +05:30
Raja Subramanian
80ba93fa18 Do NACK updates as soon as flow state is processed. (#4221) 2026-01-06 11:59:21 +05:30
Raja Subramanian
4405afe24d Use atomic pointer and return interface from RED transformer constructors (#4220) 2026-01-06 06:45:52 +05:30
Raja Subramanian
b649c2fe95 Remove method not needed from REDTransformer. (#4219)
Also assert that the implementation aligns with the interface.
2026-01-05 11:53:24 +05:30
Raja Subramanian
f0080f35b2 Remove enable arrival time forwarding method. (#4217)
Will add it if necessary.
2026-01-03 23:25:44 +05:30
Raja Subramanian
46651c1978 Release v1.9.10 (#4214)
* Release v1.9.10

* move room exists service store op to Added section
2026-01-01 12:36:34 +05:30
Raja Subramanian
08ac4ecdc5 Support preserving external supplied time. (#4212)
In some paths, it is better to preserve pre-recorded time. So, make the
base implementations preserve the RTCP Sender Report receive time.

Also, add a method to enable forwarding packet arrival time. Could be
used across relay.
2025-12-31 14:41:59 +05:30
Raja Subramanian
1a4758ed9c Skip restart callback if external. (#4208)
* Skip restart callback if external.

Without out the external restart was bumping forwarder generation twice.

* fix sense
2025-12-30 22:14:06 +05:30
Raja Subramanian
dde4fb498e configurable dependency descriptor restart (#4207)
* configurable dependency descriptor restart

* KeyFrame -> IsKeyFrame

* use the params directly
2025-12-29 23:51:15 +05:30
Raja Subramanian
3606ce542f Do not warn about track not bound if participant is not ready. (#4205)
Analysed half a dozen cases and all of them were due to participant is
not active yet.

Also, some misc logging changes.
2025-12-29 18:16:11 +05:30
Raja Subramanian
b8ddd0f98c Taking interface{} -> any modernize bits (#4204) 2025-12-28 05:22:12 +05:30
Raja Subramanian
b91cd2e4ea Rework receiver restart. (#4202)
* Rework receiver restart.

- Protect against concurrent restarts
- Clean up and consolidate code around restarts
- Use `RestartStream` of buffer rather than creating new buffers.

* fix test
2025-12-27 17:17:16 +05:30
Raja Subramanian
bb00c86489 Restart API on receiver. (#4200)
Can be used when track moves forward/backward.
2025-12-27 03:42:23 +05:30
Raja Subramanian
25ece1e911 Minor refactor in buffer base and audio level (#4198)
* Minor refactor in buffer base and audio level

- Make a function for `restartStream`. Will be useful
  when external signal needs to restart a stream. Also restart all the
  bits (audio level, dd parser and frame rate calculator)
- make an audio level mode with RTP timestamp so that some state can be
  moved out of buffer base

* clean up

* log restart
2025-12-26 20:13:38 +05:30
Raja Subramanian
599002f890 ignore PLI requests for non-video (#4196)
* ignore PLI requests for non-video

* under lock
2025-12-26 12:26:22 +05:30