Commit Graph
515 Commits
Author SHA1 Message Date
David Chen d01ca0d966 Fix FEC write return after merging RTX feedback changes 2026-10-14 15:03:50 -07:00
David Chen 9a03bf5289 Merge updated fec_up into fec_up_2 2026-10-14 15:02:26 -07:00
David Chen 195cc74965 Merge latest master into dc/feature/fec_up 2026-10-14 15:02:12 -07:00
Raja SubramanianandClaude Opus 5.5 d0fd37eaa0 Send NACKs when processing RTX packets. (#5000)
* Send NACKs when processing RTX packets.

Applying the fix proposed in https://github.com/livekit/livekit/issues/4999

* Add test for NACKs sent while processing RTX packets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 11:07:35 +05:30
Raja SubramanianandClaude Opus 5.5 099e03fdf8 sfu: forward the dependency descriptor for VP8 simulcast (#4987)
* sfu: forward the dependency descriptor for VP8 simulcast

libwebrtc sends VP8 with a one byte payload descriptor when it sends the
dependency descriptor, so a VP8 subscriber gets neither picture IDs nor the
descriptor and finds frame references by sequence number alone. Under loss
with temporal filtering it stalls until a key frame.

DDForwarder rewrites the publisher's descriptor for each forwarded packet:
frame numbers continue across simulcast layer switches and stream restarts,
the structure goes out with the current layer's key frame, and the active
decode targets follow the forwarded temporal layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sfu: keep VP8 descriptor frame numbers from going back

Rebase frame numbers only when a new stream would go back past the last
number sent: on a layer switch, a stream restart (also when it starts with a
delta frame) and a new forwarder on the same downtrack, which now carries
over the last number sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sfu: set VP8 descriptor decode targets from the packet's layer

The active decode targets use the temporal layer the packet is forwarded at,
not the selector's next layer on the last packet before a down switch. They
also go out on key frames, combined with the publisher's own mask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sfu: carry the current active decode targets on every DD packet

The parser puts the stream's current mask on every packet, so a mask change
on a dropped packet still reaches the VP8 descriptor forwarder, which no
longer tracks the publisher's mask itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sfu: take the first DD active decode targets mask at any sequence number

A publisher whose first packet has RTP sequence number 0 never had its key
frame's mask applied, so every packet reported no active decode targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 12:08:49 +05:30
Raja SubramanianandClaude Opus 5.5 9ddcc50767 sfu: parse VP8 and VP9 payload descriptors without an allocation (#4981)
* sfu: parse VP8 and VP9 payload descriptors without an allocation

Replace ExtPacket.Payload with typed VP8 and VP9 pointer fields that point
at backing structs inside the ExtPacket, so parsing does not allocate and a
wrong codec type is a compile error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sfu: copy the VP8 descriptor in the test packet helper

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 20:43:17 +05:30
Raja SubramanianandClaude Fable 5.1 bc849eb47d sfu/buffer: parse the dependency descriptor without allocating (#4953)
* sfu/buffer: parse the dependency descriptor without allocating

Every VP9 and AV1 SVC packet allocated six objects in the dependency
descriptor parse: the descriptor, a clone of the frame template with
its three slices, a resolution copy, and a frame entity that took the
address of a parameter.

The pooled ExtDependencyDescriptor now owns the storage for the
descriptor, the template and the resolution, with fixed arrays for the
template's slices. The reader copies the matching template into that
storage.

Delta frame parse: 6 allocs, 176 B, 174 ns -> 0 allocs, 0 B, 122 ns.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* sfu/dd: never copy a parsed frame into a structure template

A caller can hand Unmarshal a descriptor whose FrameDependencies points
at one of the structure's templates. Copying the packet's custom fields
into it would change the template for every later packet, so the reader
allocates a fresh template in that case.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 19:46:20 +05:30
Raja SubramanianandClaude Fable 5.1 9b20c1da57 sfu/buffer: stop allocating per ingested packet (#4951)
* sfu/buffer: stop allocating per ingested packet

Buffer.Write allocated six objects for every RTP packet. They were
the parsed rtp.Packet, a copy of it in patchExtPacket, and the flow
state, whose address two rare log calls took. The rest were an
AbsCaptureTime, present on about one packet per second, and the
extension slice that pion grows with append.

Unmarshal into a pooled scratch packet. Give ExtPacket its own backing
rtp.Packet and an [8]rtp.Extension array, and copy the header into
them. Patch the payload in place. If the abs-capture-time extension is
present, parse it. Log a copy of the flow state.

Per packet, Write plus ReadExtended. Opus: 6 allocs, 448 B -> 0.
VP8: 6 allocs, 416 B -> 1 alloc, 32 B. Opus 240 -> 142 ns, VP8 269 -> 204 ns.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* sfu/buffer: point extension payloads at the bucket copy on read

Queued ExtPackets kept extension payload slices into the write input,
which the transport reuses for the next packet. ReadExtended now parses
the header again from the bucket copy, so extensions and CSRCs point
into RawPacket like the payload does.

The test writes every packet through one input buffer and checks the
audio level of each packet read back.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* sfu/buffer: test that a dropped padding packet keeps the shifted sequence number on read

The bucket stores the shifted number, so re-parsing the header on read
returns it. This test guards that.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:21:11 +05:30
RaphaelFakhri ad54223d1b sfu: fix data stats active window bitrate and duration units (#4922) 2026-09-29 23:18:25 +05:30
David Chen b08f67f61a do not NACK on fec recovered packet 2026-09-22 10:41:13 -07:00
cnderrauber 61ec725c52 Support VP9/AV1 simulcast (#4830)
Comes from #4718. Remove #2 of original PR as the simulcast SR
looks good to me.
2026-09-02 15:07:43 +08:00
David Chen 478f6937c3 Fix FlexFEC negotiation with libwebrtc publishers 2026-08-30 17:43:57 -07:00
David Chen 9a7cbee26f Test FlexFEC with E2EE media 2026-08-30 08:15:11 -07:00
David Chen a8b35cc818 Harden upstream FlexFEC handling 2026-08-29 22:02:23 -07:00
David Chen 390d40e70a Lower FlexFEC repair window to two seconds 2026-08-29 15:48:31 -07:00
David Chen 8e695e1b16 Limit pending FlexFEC repair packets 2026-08-29 12:36:05 -07:00
David Chen c844d357d5 Reuse RTP packet storage for FlexFEC recovery 2026-08-29 12:33:07 -07:00
David Chen f94500d624 Invoke FEC callbacks after unlocking 2026-08-28 20:45:16 -07:00
David Chen a0b56bcc5d Guard short TWCC extensions in FEC packets 2026-08-28 18:49:13 -07:00
David Chen 6a879f4f48 Add upstream FlexFEC recovery support 2026-08-28 17:46:41 -07:00
Raja SubramanianandClaude Opus 5 bbdfd50d62 Fix simulcast RTX pairing broken by pion/webrtc#3470 (#4800)
pion no longer starts the repair stream reader when a custom BufferFactory
is set, so the mid/rid/rsid extensions were never observed and simulcast RTX
streams were never paired with their primary streams.

Extract the extensions on the buffer write path instead. Migrated publishers
send no extensions at all, so pair those from SimTracks.

Adds an integration test covering both paths, and moves the vnet setup it
shares with the downtrack test into pkg/testutils/vnettest.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 13:01:22 +05:30
Raja SubramanianandClaude Opus 4.8 68ecd38c00 Flush sequencer on stream restart; bound frame-integrity loops (#4760)
Flush the downtrack sequencer on stream restart (Resync, ReceiverRestart,
codec change) so NACK retransmissions can't use metadata that no longer
matches the resynced bucket. Add a defensive bounds guard on the RTX and
forward payload slicing.

Cap the PacketHistory and FrameIntegrityChecker catch-up loops to the ring
size so a large sequence/frame-number jump can't drive a big per-packet
iteration count.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-14 17:00:29 +05:30
Raja Subramanian cc6551d617 Check slice length before access in a couple of more places (#4752)
* Check slice length before access in a couple of more places

* min 🤦

* lint
2026-08-13 18:20:37 +05:30
cnderrauber 7d556cfefe sample codec payload mismatch error log (#4751) 2026-08-13 19:32:21 +08:00
Raja Subramanian 7f1c175a38 Check layer value in dependency descriptor and keep it in bounds. (#4739) 2026-08-11 12:04:19 +05:30
Raja Subramanian 28468035d2 Check for pictureID existence in VP8 and VP9 (#4721)
* Check for pictureID existence in VP8 and VP9

* test
2026-08-03 15:22:59 +05:30
Raja Subramanian 1bbd4702b6 Spelling fixes (#4698) 2026-07-26 22:26:41 +05:30
Raja Subramanian c6303bb15a Fix skipped packets accounting. (#4604)
* Fix skipped packets accounting.

No need to copy unskipped packet RTP header to skipped packet.
That was causing padding bytes to be counted.

Also use Header.PaddingSize as base PaddingSize is deprecated.

* PaddingSize in header in utils
2026-06-18 11:58:39 +05:30
Raja Subramanian 062d12197f Use NACKQuueInterface type. (#4538)
And some extra logging for subscription permission when it fails.
2026-05-21 23:00:51 +05:30
Raja Subramanian 1ab2bf043b Clean up packet size logging (#4536)
Reverting
- https://github.com/livekit/livekit/pull/4521
- https://github.com/livekit/livekit/pull/4525

There are TWCC feedback packets that are larger than MTU. Seems to
happen under a couple of conditions
1. Bad client data, i. e. severely out-of-order packets, bad sequence
   numbers, etc.
2. On an ICE restart - this is rare, but it seemed to be flaky network
   with some packets arriving and some not and causing a lot of gaps.

Either case, not much to do. If fargmentation/re-assembly back to
publisher works, the feedback will make it through. If not, feedbacks
will be missed and clients have to work with some missing data which is
not unexpected and the protocol is designed to handle.

However, filed pion/interceptor issue just in case - https://github.com/pion/interceptor/issues/416
2026-05-20 23:58:05 +05:30
Raja Subramanian 4a7b1e8587 Create NACK tracker only once. (#4527)
Not a major issue, but just avoiding duplicate creation of NACK module.
RTCP feedback of `nack` and `nack pli` end up getting treated as `nack`
and was double creating.
2026-05-15 12:45:51 +05:30
Raja Subramanian ef2e5efe14 Log large packets receive/send. (#4521)
* Log large packets receive/send.

Seeing cases of servers reporting need for segmentation/re-assembly of
packets. So, logging packet receive/send for RTP/RTCP to check if
anything is seeing more than 1400 byte packets.

* log downtrack RTCP too
2026-05-13 16:04:53 +05:30
Raja Subramanian ccdf23c8a6 Use mediatransportutil/codec package, no functional change (#4497) 2026-05-01 20:06:29 +05:30
Raja Subramanian dc6b75058e reduce some heap use in packet path (#4478) 2026-04-25 14:24:23 +05:30
Raja Subramanian 701a37c2d1 Convert sort.Slice -> slices.SortFunc (#4472)
* Convert sort.Slice -> slices.SortFunc

* active speaker loudness in descending order
2026-04-23 15:12:24 +05:30
Raja Subramanian 27c2b149d7 Consolidate RTCP packets and do RTCP callback outside lock. (#4469)
Planning to do some find grained changes based on analysis by different
models. Will keep them as small as possible and focused.
2026-04-23 12:20:16 +05:30
David Zhao 4b3856125c chore: pin GH commits and switch to golangci-lint (#4444)
* chore: pin GH commits

* switch to golangci-lint-action

* fix lint issues
2026-04-11 13:04:22 -07:00
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 -
https://github.com/jech/galene/commit/c0b755f82fefeba776ac80ee1a2fe4883a83771d.

Addresses https://github.com/livekit/livekit/security/advisories/GHSA-qxj9-fmqx-r7j8
2026-03-29 09:53:15 +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 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 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 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 a9849340c3 Avoid logger data race. (#4284)
Also defer promise channel close.
2026-02-04 01:35:44 +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
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
Denys Smirnov 843d8c3ea1 Update Pion transport package. (#4237)
* Update Pion transport package.

* Update mediatransportutil package.
2026-01-13 19:56:41 +02:00