pion / interceptor

Pluggable RTP/RTCP processors for building real time communication
https://pion.ly/
MIT License
109 stars 55 forks source link

Add an initial, very simple, jitter buffer #222

Closed thatsnotright closed 8 months ago

thatsnotright commented 8 months ago

Description

This PR adds a very simple jitter buffer for RTP packets. The goal of this is to slowly introduce jitter buffers in places which network jitter can critically impact stream performance without causing unnecessary delay. Right now the heuristic is set at a fixed packet count before moving to the playback state, but this algorithm will be adjusted (and additional dynamic algorithms introduced) in future work.

This jitter buffer relies on a priority queue based on the RTP packet's sequence number. It will insert new packets in priority of sequence number, tracks when its current simplistic total packet count is met to emit a playback event and allows Pop-ing packets off either from the play head (defined as the head position when the jitter buffer met its minimum length) or at a specific timestamp.

For elements which need to exhaust all packets at a specific timestamp, call PopAtTimestamp with the timestamp in a loop and wait for an error response.

More to come, statistics suggestions welcome, as well as any other feedback on approach or suggested algorithms.

codecov[bot] commented 8 months ago

Codecov Report

Attention: 40 lines in your changes are missing coverage. Please review.

Comparison is base (450ac84) 79.73% compared to head (00d52dd) 79.83%.

Files Patch % Lines
pkg/jitterbuffer/jitter_buffer.go 72.72% 19 Missing and 5 partials :warning:
pkg/jitterbuffer/priority_queue.go 85.96% 12 Missing and 4 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #222 +/- ## ========================================== + Coverage 79.73% 79.83% +0.10% ========================================== Files 68 70 +2 Lines 3587 3789 +202 ========================================== + Hits 2860 3025 +165 - Misses 602 631 +29 - Partials 125 133 +8 ``` | [Flag](https://app.codecov.io/gh/pion/interceptor/pull/222/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | | |---|---|---| | [go](https://app.codecov.io/gh/pion/interceptor/pull/222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | `79.83% <80.19%> (+0.18%)` | :arrow_up: | | [wasm](https://app.codecov.io/gh/pion/interceptor/pull/222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | `77.67% <80.19%> (+0.05%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

thatsnotright commented 8 months ago

I will work on code coverage, there are a few spots which should get tested that I missed.