Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed RTCP packet lost calculation #3653

Merged
merged 6 commits into from
Aug 31, 2023
Merged

Fixed RTCP packet lost calculation #3653

merged 6 commits into from
Aug 31, 2023

Conversation

sauwming
Copy link
Member

@sauwming sauwming commented Aug 9, 2023

Suppose RTP packets arrive in the following order: seq 5, 10, 6, 7, 8, 9

Currently, upon receiving seq 10, we will calculate it as 4 lost packets (6 until 9) in pjmedia_rtcp_rx_rtp2(): sess->stat.rx.loss += (seq_st.diff - 1).

According to the RFC https://datatracker.ietf.org/doc/html/rfc3550#appendix-A.3, we should calculate it as lost = expected - s->received instead. But we commented this code in 84f4589 because we have done the calculation earlier in pjmedia_rtcp_rx_rtp2(). So we probably should use the later calculation instead.

@sauwming
Copy link
Member Author

sauwming commented Aug 9, 2023

The first commits introduce a behavioural change, i.e. in that the packet lost will be calculated even if the probation is not over. For example, RTP packets received in order: seq 1, 12, 13, 14, ... will previously be considered 0 loss, but now will be 10 losses (2 until 11).
This is because previously pjmedia_rtp_seq_update() will not consider the seq diff when we're still in probation.

According to the RFC https://datatracker.ietf.org/doc/html/rfc3550#appendix-A.1:

               if (s->probation == 0) {
                   init_seq(s, seq);
                   s->received++;
...

we only init the sequence and start counting the packets received once the probation has ended, and the seq is inited to the last seq received during probation, not the first seq.

@sauwming
Copy link
Member Author

The third commit is to fix #3655, to handle seq rollover during probation.

@sauwming sauwming linked an issue Aug 11, 2023 that may be closed by this pull request
sess->stat.rx.loss = 0;
*/
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this calculation is done on each incoming RTP instead of in building RTCP for faster stats update (by moving this block there perhaps), because the RTCP interval is configurable so it can be long, default is not that long though, 5 seconds.

Also, perhaps only update/calculate it when out-of-order flag is not set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done in the latest commit.

There are a couple of drawbacks though:

  • Calculating only when not out of order means that the packet loss stat may not always be accurate.
  • There is also complication with updating the loss period. The stats such as avg, max, std, etc will be inaccurate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: first drawback should be acceptable, as I think most RTP packets are ordered (e.g: every second there should be at least two properly ordered packets).

Re: second drawback. Currently the count is the total loss count since the beginning of the session? If it is, the period should not be counted using count. IMO the loss period represents the consecutive loss packets (in time unit) of every packet loss occurance. So the calculation is perhaps: when total loss count is increased, compare the current loss count vs previous loss count, the difference should be the period?

Comment on lines 391 to 392
period = count * sess->dec_pkt_size * 1000 / sess->clock_rate;
period *= 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: move this period calculation to inside the loss_period update block below?

@sauwming sauwming merged commit ee5879b into master Aug 31, 2023
34 checks passed
@sauwming sauwming deleted the rtcp-lost branch August 31, 2023 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fixed RTP packet lost when seq == 0
2 participants