Commit Graph

420 Commits

Author SHA1 Message Date
cnderrauber
b660c3b582 Extract video size from media stream (#3856)
* Extract video size from media stream

* fix test
2025-08-18 09:06:57 +08:00
Raja Subramanian
1b2289137d Support video layer mode from client and make most of the code mime aware (#3843) 2025-08-09 21:26:11 +05:30
Raja Subramanian
40028dc33c Normalize known rids. (#3779)
Normalize the rids in SDP to known patterns.
Currently,
- LK protocol uses q;h;f
- Sean's OBS WHIP uses 0;1;2

As the ordering in SDP could be different, normalize to known order.

For RIDs not in the known set, just use it as is.
2025-07-06 13:32:21 +05:30
Raja Subramanian
ddd923296b Return default layer for invalid rid + track info combination. (#3778) 2025-07-05 14:43:26 +05:30
Raja Subramanian
c69f1aae87 Revert "Temporary change: use pre-defined rids" (#3769)
* Revert "Temporary change: use pre-defined rids (#3767)"

This reverts commit d11da5f5fa.

* clean up

* add test and simplify

* clean up
2025-06-30 07:34:58 +05:30
Raja Subramanian
01bf96855d SVC with RID -> spatial layer mapping (#3754)
* SVC with RID -> spatial layer mapping

There are cases where an SVC track comes in with a RID.
As there is no RID announced in SDP, it maps to invalid layer.
Seems to happen with older browsers.

* test
2025-06-23 12:45:13 -07:00
cnderrauber
8c2fc0bcd9 Fix svc encoding for chrome mobile on iOS (#3751)
The browser could send rtp packets of svc encoding without
DD extension while the sdp negotiates it, sfu detects extension
in rtp packet for this case.
2025-06-23 22:39:12 +08:00
Raja Subramanian
0e03390744 Return highest available layer if requested quality is higher than (#3729)
highest available quality.
2025-06-13 08:44:45 -07:00
Raja Subramanian
670f927ff6 Set and use rid/spatial layer in TrackInfo. (#3724)
* Set and use rid/spatial layer in TrackInfo.

* test
2025-06-12 23:22:11 -07:00
Raja Subramanian
ce07740e11 Add simulcast support for WHIP. (#3719)
* Add simulcast support for WHIP.

- General change to have rids be anything.
- One issue is rid ordering not matching quality ordering, will need
  some dynamic layer quality determination for that.

* clean up

* deps

* test
2025-06-11 19:40:38 -07:00
Raja Subramanian
086704128c Limit buffer queue before Bind. (#3634)
* Limit buffer queue before Bind.

* more generic
2025-05-01 13:49:06 +05:30
Raja Subramanian
f24152b4c0 Call Broadcast in lock scope. (#3625)
* Call Broadcast in lock scope.

Seems like there is a possible window where things can hang forever
if a goroutine enters the Wait) after the lock is released but before
Broadcast gets called, it will never see that broadcast and will hang forever.

* RLock
2025-04-25 12:12:10 +05:30
Raja Subramanian
8eb81388e6 Use a generation to counter to stop key frame seeder on codec change (#3531) 2025-03-18 07:41:30 +05:30
Raja Subramanian
a6cb00b31e Reduce seeder duration to 30s and also do not force send PLI. (#3525)
Can use the normal PLI throttle cadence.
2025-03-13 10:41:42 +05:30
Raja Subramanian
c823320528 Add a key frame seeder in up track. (#3524) 2025-03-12 22:11:27 +05:30
cnderrauber
ff9115b228 Disable dd parser for vp8 if extension is not found (#3492)
Browser would not send dd extension for vp8 in some case even if
it is negotiated.
2025-03-06 17:20:00 +08:00
Raja Subramanian
7fef374b19 Split down stream snapshot into sender view and receiver view. (#3422)
Receiver view is used for connection quality.

Sender view is used for analytics. One thing that this introduces is
that sender view uses the packet loss information from receiver view as
true loss is available only in the RTCP Receiver Reports received from
the remote side. So, the time alignment is off, i. e. receiver report
happens periodically and it includes information till the time at which
it was sent from remote side, but sender could have sent more packets
after that time.

The split should ensure that analytics does not rely on remote side
sending proper receiver repoerts albeit at slight misalignment of loss
statistic for remotes that send RTCP RR (which should be majority of the
cases)
2025-02-11 16:05:00 +05:30
Raja Subramanian
9551c52c85 Try 2 to consolidate mime type (#3407)
* Normalize mime type and add utilities.

An attempt to normalize mime type and avoid string compares remembering
to do case insensitive search.

Not the best solution. Open to ideas. But, define our own mime types
(just in case Pion changes things and Pion also does not have red mime
type defined which should be easy to add though) and tried to use it everywhere.
But, as we get a bunch of callbacks and info from Pion, needed conversion in
more places than I anticipated. And also makes it necessary to carry
that cognitive load of what comes from Pion and needing to process it
properly.

* more locations

* test

* Paul feedback

* MimeType type

* more consolidation

* Remove unused

* test

* test

* mime type as int

* use string method

* Pass error details and timeouts. (#3402)

* go mod tidy (#3408)

* Rename CHANGELOG to CHANGELOG.md (#3391)

Enables markdown features in this otherwise already markdown'ish formatted document

* Update config.go to properly process bool env vars (#3382)

Fixes issue https://github.com/livekit/livekit/issues/3381

* fix(deps): update go deps (#3341)

Generated by renovateBot

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Use a Twirp server hook to send API call details to telemetry. (#3401)

* Use a Twirp server hook to send API call details to telemetry.

* mage generate and clean up

* Add project_id

* deps

* - Redact requests
- Do not store responses
- Extract top level fields room_name, room_id, participant_identity,
  participant_id, track_id as appropriate
- Store status as int

* deps

* Update pkg/sfu/mime/mimetype.go

* Fix prefer codec test

* handle down track mime changes

---------

Co-authored-by: Denys Smirnov <dennwc@pm.me>
Co-authored-by: Philzen <Philzen@users.noreply.github.com>
Co-authored-by: Pablo Fuente Pérez <pablofuenteperez@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Paul Wells <paulwe@gmail.com>
Co-authored-by: cnderrauber <zengjie9004@gmail.com>
2025-02-10 10:44:15 +05:30
cnderrauber
aeec75edeb H265 supoort and codec regression (#3358)
* H265 supoort and codec regression

Support H265 codec.
Add optional codec regression for subscribers don't
support advanced codecs like H265, AV1, VP9.

* restart forwarder on upstream codec change

* tests

* Reneogitate new codec if client doesn't support change

* Add option to disable codec regression

---------

Co-authored-by: boks1971 <raja.gobi@tutanota.com>
2025-02-06 11:56:49 +08:00
Raja Subramanian
7c58fdf329 move unrolled mime type check for broader use (#3326)
* move unrolled mime type check for broader use

* Use in IsSvcCodec and make MimeType exported

* test

* tidy branches

* tidy

---------

Co-authored-by: Paul Wells <paulwe@gmail.com>
2025-01-13 10:24:03 +05:30
Raja Subramanian
bfbc4fa81f Remove alloc in packet forwarding path. (#3305)
* Remove alloc in packet forwarding path.

Unlikely logger creation was doing allocs. Replace it with a function
like in rtpstats_receiver.go so that allocations do not happen
unnecessarily.

* variable rename

* one more place
2025-01-06 11:48:27 +05:30
cnderrauber
384e21abc0 vp8 temporal layer selection with dependency descriptor (#3302)
* vp8 with dd

* make temporal layer selection work with DD

* fix test

---------

Co-authored-by: boks1971 <raja.gobi@tutanota.com>
2025-01-03 21:26:03 +08:00
Raja Subramanian
c8b644934f Update deque and friends. (#3276) 2024-12-20 07:16:14 +05:30
Raja Subramanian
02117a4d46 Panic fixes (#3270)
Also, do negotiated down track extensions after bind.
2024-12-19 11:52:43 +05:30
cnderrauber
b684da380e log frame number jump on dd structure updating (#3261) 2024-12-17 17:31:05 +08:00
cnderrauber
54f9f7de51 upgrade to pion/webrtc v4 (#3213) 2024-11-28 16:05:38 +08:00
Raja Subramanian
ceb8a70696 Use same components when logger is updated (#3166)
Logger in buffer can get updated when the layer is known. Use the same
components used in destructor.
2024-11-11 11:38:48 +05:30
cnderrauber
ca77df8212 warn for multiple dd ext (#3135)
* warn for multiple dd ext

* unused
2024-10-24 16:59:24 +08:00
Raja Subramanian
40b10af960 Use monotonic time util. (#3112)
Thank you @paulwe for doing this. I was promising to do this for a
while, but just like other times, empty promises :-(
2024-10-17 10:49:24 +05:30
Raja Subramanian
2491ee7c7c Make lite version of RTPStatsReceiver called RTPStatsReceiverLite. (#3065)
* Make lite version of RTPStatsReceiver called RTPStatsReceiverLite.

Refactor around that.

Will probably make some more flavors to have lighter versions still.

* update deps

* use MarshalLogArray

* use util
2024-10-05 10:50:25 +05:30
Raja Subramanian
8ac33a868c Splitting out rtp stats stuff into its own package. (#3060)
* Splitting out rtp stats stuff into its own package.

Going to be making some lighter versions of these.
Will be cleaner to have all of these grouped together.
So, as a first step, just making a package for it.

* tests
2024-10-03 15:51:24 +05:30
Paul Wells
0b4fd32905 add unlikely logger (#3058) 2024-10-02 22:58:25 -07:00
Raja Subramanian
0656b623f7 use marshalled logger (#3057) 2024-10-03 10:27:47 +05:30
Raja Subramanian
4d7839bff3 Fix clock rate skew calculation. (#3055)
Cannot cast NTP timestamp diff to time.Duration.
That causes duration to appear more than it actually is.
Was causing a bunch of log spam.
2024-10-01 00:33:36 +05:30
Paul Wells
4deaac2f3f replace proto.Clone calls (#3024)
* replace proto.Clone calls

* deps

* tests
2024-09-18 22:47:33 -07:00
Raja Subramanian
914e5d6993 Set SenderReport to nil on seeding if empty. (#3008)
With protobuf marshalling/unmarshalling, the default struct was getting
used and nil checks for non existence were failing. That means the right
layers were not reported active on migration.

Also, restore the wrapped loggers as some fields needs some conversion
before logging.
2024-09-16 23:56:13 +05:30
Raja Subramanian
3c8a7d7828 Log down track state on seeding. (#3003)
Also, log when RTCP sender report for reference layer is received.

Cleaning up a bunch of wrapped logger calls as we already have
logger.Proto which I forgot about while doing those wrappers.
2024-09-14 23:07:54 +05:30
Raja Subramanian
b678ccdd66 Cache RTCP sender report in forwarder state. (#2994)
* Cache RTCP sender report in forwarder state.

To be used in migration.

TODO: need to check more places to operate pure in unix nano rather than
converting.

* match name
2024-09-10 20:50:50 +05:30
Raja Subramanian
6de871d4e8 Allow start streaming on an out-of-order packet. (#2971)
But, do not record first packet time on an out-of-order packet.
It so happens that packets get out-of-order a lot more across relay.
And it turns out with some H.264 stream, the first few packets of a key
frame are very small (may be SPS/PPS, haven't checked), they get
out-of-oder quite a lot, so much so a down track never starts even it
has 20 - 25 key frames have passed through.
2024-09-02 21:36:46 +05:30
Raja Subramanian
579f76cf7c Use 0 rollover when possible. (#2968) 2024-08-31 11:36:49 +05:30
Raja Subramanian
37c6f95fe4 Reduce threshold of out-of-order very old packet detection. (#2951)
There are cases where the very first packet on resume is an out-of-order
packet. In that case, the gap in both sequence number and time stamp is
a small(ish) negative number. With a high threshold to declare very old
packet, the condition does not trip and the packet gets through and
treated as a packet that has rolled over.

It should be fine to have smaller threshold (in fact, it is probably
okay to have something a little over 1.0 too) as the expected jump is
calculated based on elapsed time since last packet receive and new
packets should be coming in with a diff close to that. So, a factor of
just over 1.0 to prevent false triggers should be fine. Using 1.5 for
now.
2024-08-22 17:48:12 +05:30
Raja Subramanian
d78fdbf2a8 Handle another old packet condition. (#2947)
* Handle another old packet condition.

With this detection, the sequence number can be rolled over even when TS
rollover is not possible. For example, a track at 300 pps can rollver
the sequence number space in minutes compared to 13h+ for video time
stamp to roll over.

* fix typo
2024-08-21 13:32:20 +05:30
Raja Subramanian
1fb8964814 Refactor propagation delay estimator. (#2941)
* Refactor propagation delay estimator.

NOTE: It is not possible to calculate OWD (one-way-delay) in a passive
fashion. So, this should not be used for anything requiring high
precision.

But, mainly factoring it out as a separate object just in case it can be
re-used.

TODO:
- probably has some edge case that is not handled well
- maybe path change detection can be improved
- will write UT later. This is just purely splitting it out from what
  was embedded in RTPStatsReceiver.

* fix labels

* precision -> accuracy
2024-08-19 12:03:45 +05:30
Raja Subramanian
08b8ef56de Use monotonic clock in packet path. (#2940)
Set up a base time when starting a receiver and use that clock as base
for other packet times to ensure that clock is monotonic.
2024-08-17 23:19:27 +05:30
Raja Subramanian
1c265180f1 Fix ARM compile. (#2923)
(1 << 32) was outside range for 32-bit arch.
2024-08-11 11:14:40 +05:30
Raja Subramanian
7018e485f2 Do not start forwarding on an out-of-order packet. (#2917)
It is possible that old packets arrive on receiver. If subscriber starts
on that, the first packet time would be incorrect. Do not start
forwarding on out-of-order packets.
2024-08-08 23:15:04 +05:30
Raja Subramanian
01100650f6 Clean up packet checks. (#2910)
Still leaving the utility `ValidateRTPPacket` in helpers as it could be
useful.
2024-08-06 14:30:08 +05:30
Raja Subramanian
1993c87fd8 Do not force rollover if ts rollover is not active. (#2899)
There are cases of small negative sequence number jump and small
positive time stamp jump. Those should not force rollover. Maybe, they
should be dropped, but just logging for now till we learn more.
2024-08-01 22:08:53 +05:30
Raja Subramanian
18fd622802 Add API to get highest time stamp from RTPStatsReceiver. (#2898) 2024-08-01 13:26:25 +05:30
Raja Subramanian
c2c187202f Fix forced rollover of RTP time stamp. (#2896)
* Fix forced rollover of RTP time stamp.

Was erroneously forcing a rollover when the timestamp jump actually has
room to accommodate large jumps. For example, before pause ts = 10, then
eight hour pause, restart ts = 10  + (8 * 00 * 60 * 90000) = 2592000010
(at 90000 clock rate for video). In normal processing, it will look like
out-of-order as the difference 2592000000 is more than half the 32-bit
range. But, forcing a roll over is incorrect.

Fix by calculating excess over the full range and then account for wrap
around.

* log potential ts rollover

* clamp at min 0
2024-07-31 12:45:19 +05:30