Commit Graph

382 Commits

Author SHA1 Message Date
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
Raja Subramanian
d68dd3033d Use extended sequence number in bucket (#2895) 2024-07-30 14:21:37 +05:30
Raja Subramanian
4e29e18129 Set gapSN when initing. (#2893) 2024-07-30 07:48:06 +05:30
Raja Subramanian
3e6e6e2732 Ignore really old packets. (#2891)
* Ignore really old packets.

There are cases where really old packets (time stamp is way back, but
sequence number looks like it is moving forward) which cause the
sequence number to update incorrectly. Drop those packets are they are
very old.

* test
2024-07-29 10:51:01 +05:30
Raja Subramanian
d27ecc0732 Switch order so that last calculated clock rate does not get (#2890)
divide-by-zero.
2024-07-26 10:50:51 +05:30
cnderrauber
f6f6cca133 don't push 0 ssrc probing packets to pending queue (#2888) 2024-07-23 17:58:04 +08:00
cnderrauber
0c5b5537b2 Don't create DDParser for non-svc codec (#2883) 2024-07-19 10:52:27 +08:00
Raja Subramanian
95f4b304ef Prevent data race. (#2881)
* Prevent data race.

CI is reporting some data race warnings. Prevent that.

* prevent recursive lock

* prevent more recursive locks

* more lock dance
2024-07-18 19:53:41 +05:30
Raja Subramanian
91782b68be Recalc gap of sequence number after forcing rollover. (#2880) 2024-07-18 18:58:10 +05:30
Raja Subramanian
4733e864bc Rollover sequence number when time stamp is moving forward. (#2876)
* Rollover sequence number when time stamp is moving forward.

Seeing large gaps in sequence number due to potential network issues.
In that gap, the sequence number could roll over.

Using packet time jumps to figure out if a roll over could have happened
and force roll over the sequence number to ensure that it does not flow
backwards.

* fix test
2024-07-18 11:02:52 +05:30
Raja Subramanian
f3d3ec1ce7 Record packet/octet count in sender report. (#2864)
Seeing cases of huge jumps in sender erport rtp time stamp
(of the order of minutes) a few hundred ms after start of track.
Only less than 20 packets have been published at that time as seen by
server. Adding these to sender report to check if client thinks it has
sent much more.
2024-07-16 07:59:27 +05:30
Raja Subramanian
faa66d1138 Make sender report pass through an option. (#2861)
Enabled by default.

Also, tweak the long term propagation delay a bit. The first propagation
delay itself was too high and the long term initialized with a high
value. Prevent that and also ensure large negtaives do not have an
effect by using a lower bound of 0. Lower bound of 0 is okay as the main
purpose is to track sustained high positive values.
2024-07-15 11:27:31 +05:30
Raja Subramanian
27f6794e77 Check sender report against media path. (#2843)
Seeing cases (mostly across relay) of large first packet time adjustment
getting ignored. From data, it looks like the first packet is extremely
delayed (some times of the order of minutes) which does not make sense.

Adding some checks against media path, i. e. compare RTP timestamp from
sender report against expected RTP timestamp based on media path
arrivals and log deviations more than 5 seconds.

Another puzzling case. Trying to understand more.

Also, refactoring SetRtcpSenderReportData() function as it was getting
unwieldy.
2024-07-09 09:20:27 +05:30
Raja Subramanian
acbd4ea104 Handle cases of long mute/rollover of time stamp. (#2842)
* Handle cases of long mute/rollover of time stamp.

There are cases where the track is muted for long enough for timestamp
roll over to happen. There are no packets in that window (typically
there should be black frames (for video) or silence (for audio)). But,
maybe the pause based implementation of mute is causing this.

Anyhow, use time since last packet to gauge how much roll over should
have happened and use that to update time stamp. There will be really
edge cases where this could also fail (for e. g. packet time is affected
by propagation delay, so it could theoretically happen that mute/unmute
+ packet reception could happen exactly around that rollover point and
  miscalculate, but should be rare).

As this happen per packet on receive side, changing time to `UnixNano()`
to make it more efficient to check this.

* spelling

* tests

* test util

* tests
2024-07-08 11:07:20 +05:30
Raja Subramanian
39c59d913d Do not warn on padding (#2839) 2024-07-07 12:30:54 +05:30
Raja Subramanian
bfb7db2d91 RTP packet validity check. (#2833)
Adding some checks before packet is forwarded to check for anomalies.
Will remove after a round of debug.
2024-07-04 12:42:25 +05:30
Raja Subramanian
b4134edf40 Log rtp stats state on large jumps. (#2829)
Forgot to include in receiver.
2024-07-01 11:51:05 +05:30
Raja Subramanian
57980fcc36 fix logging ignored key (#2826) 2024-06-28 10:34:41 +05:30
Raja Subramanian
fa490dd510 Log rtp stats more consistently. (#2816)
* Log rtp stats more consistently.

Thank you Paul for the logging tip.
Also update deps.

* remove duplicate logging field

* nil check
2024-06-25 14:55:42 +05:30
Raja Subramanian
6bb48dd6f1 Do not log duplicate on large negative on send side (#2815) 2024-06-24 12:51:35 +05:30
Raja Subramanian
cdb5f3ed68 Log more around unexpected cases (#2813)
- too many padding packets
- also fix cse of snapshot not getting any packets
2024-06-23 00:33:56 +05:30
Raja Subramanian
091eab556d Update mediatransportutil (#2812) 2024-06-22 11:32:28 +05:30
Raja Subramanian
d4e50b633f Do not log warns on duplicate. (#2807)
With RTX, some clients use very old packets for probing. Check for
duplicate before logging warning about old packet/negative sequence
number jump.

Also, double the history so that duplicate tracking is better. Adds
about 1/2 KB per RTP stream.
2024-06-20 10:52:12 +05:30
Raja Subramanian
5d969ba35b remove some debug (#2797) 2024-06-17 12:57:04 +05:30
Raja Subramanian
ea60368100 Do not error out on invalid packet. (#2789)
Remove the return when encountering invalid packet.
Also, log more sparesely.
Proper error returns from util so that we can selectively drop packets
based on error type, for example SSRC mismatches are okay type of thing.
2024-06-14 11:10:57 +05:30
Raja Subramanian
129ba62d61 Validate RTP packets. (#2778)
* Validate RTP packets.

Check version, payload type (if available) and SSRC (if available)
and drop bad packets. And let repair mechanisms take effect for those
packets.

* address data race reported by test

* fix an unlock and test packets
2024-06-10 15:43:59 +05:30
Raja Subramanian
a31f59b689 Log first time adjustment total. (#2776)
* Log first time adjustment total.

Seeing cases where the first time is 400ms+ before start time.
Possible it is getting that much adjustment, but would be good to see
how much total adjustment happens.

* log propagation delay
2024-06-09 23:07:01 +05:30
Raja Subramanian
38d213ed10 Do not compare payload type before bind (#2775) 2024-06-09 01:03:38 +05:30
Raja Subramanian
b58db82254 Log invalid RTP packet (#2774) 2024-06-08 10:36:05 +05:30
Raja Subramanian
73852d0a13 Reduce large sequence number jump threshold for logging. (#2770)
Seeing some unexplained large jumps on remotes across relay. Unclear if
there was a jump on origin side at some point. Reducing threshold for
large jump so that we can catch unexpected jumps more.
2024-06-07 12:36:02 +05:30
Raja Subramanian
7d035deef8 Clean up logging fields a bit (#2767) 2024-06-06 23:03:21 +05:30
cnderrauber
908baeb942 initialize bucket size by publish bitrates (#2763) 2024-06-06 14:31:20 +08:00
Raja Subramanian
03bb468472 Log range map for debugging. (#2754)
* Log range map for debugging.

* log details on errors

* log details
2024-06-04 08:00:26 +05:30
Raja Subramanian
447793d077 Move RTT errors to Debugw. (#2742)
With the move to forwarding NTP timestamp as is, we get a bunch more of
this error logged as the remote is basing it off of previous report and
local (i. e. server-side) bases it off of a more recent report.

Anyhow, this code has been around for a long time and there is nothing
new to learn from those errors. Just log it at Debugw in case we can
learn something from it for specific projects or environments where
Debugw is okay.
2024-05-29 11:26:30 +05:30
Raja Subramanian
9781d30611 Do not propagate RTCP if report is not processed. (#2739) 2024-05-28 19:29:54 +05:30
Raja Subramanian
8be2005e0f More detailed logging to understand old packets. (#2730) 2024-05-25 18:34:55 +05:30
Raja Subramanian
96cb829b84 Log more info when adjusting start timestamp. (#2722)
Seeing some large time stamp jump in relay down track once in a while.
Logging more details on time stamp switch to learn more.
2024-05-23 13:03:26 +05:30
Raja Subramanian
ef6f205fcc Pass through timestamp in abs capture time (#2715) 2024-05-15 11:41:37 +05:30
Raja Subramanian
91520a36e0 Add a flag to pass through timestamp. (#2714)
* Add a flag to psss through timestamp.

Can make it a config later if needed.

* log both adjusted and non-adjusted
2024-05-13 15:11:28 +05:30