Skip to content

Conversation

@cptpcrd
Copy link
Contributor

@cptpcrd cptpcrd commented May 29, 2024

Description

Currently, when Pion is receiving simulcast, PeerConnection.handleIncomingSSRC reads (at least) 2 packets: one packet is used to determine the payload type, and one (or more) packets are used to determine the MID, RID, and repair stream ID. This means that the first video frame is always partially lost, which is undesirable.

To fix this:

  1. Get the initial payload type from the SRTP read stream to avoid having to consume the first packet.
  2. Peek (instead of reading) from the SRTP read stream to avoid having to consume the second packet (assuming that the MID/RID/repair stream ID come in right away).

(This patch relies on corresponding changes to pion/srtp which I will PR shortly and link back here.)

Reference issue

N/A

@codecov
Copy link

codecov bot commented May 29, 2024

Codecov Report

❌ Patch coverage is 90.69767% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.05%. Comparing base (c457479) to head (f71415b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
rtpreceiver.go 81.25% 3 Missing ⚠️
stats_go.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2777      +/-   ##
==========================================
+ Coverage   83.99%   84.05%   +0.06%     
==========================================
  Files          80       80              
  Lines        9070     9076       +6     
==========================================
+ Hits         7618     7629      +11     
+ Misses       1027     1024       -3     
+ Partials      425      423       -2     
Flag Coverage Δ
go 84.05% <90.69%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adriancable
Copy link
Contributor

@cptpcrd - does your issue #1 (consuming the first packet) also impact non-simulcast?

@cptpcrd
Copy link
Contributor Author

cptpcrd commented Jun 6, 2024

@cptpcrd - does your issue #1 (consuming the first packet) also impact non-simulcast?

As far as I'm aware, no.

@jech
Copy link
Member

jech commented Jan 2, 2025

Is this still relevant? It looks like a thing that's worth fixing.

Sean-Der added a commit to cptpcrd/srtp that referenced this pull request Nov 28, 2025
This will be used while probing for PayloadType and Simulcast.

Relates to pion/webrtc#2777

Co-authored-by: cptpcrd <[email protected]>
Sean-Der added a commit to cptpcrd/srtp that referenced this pull request Nov 28, 2025
This will be used while probing for PayloadType and Simulcast.

Relates to pion/webrtc#2777

Co-authored-by: cptpcrd <[email protected]>
Sean-Der added a commit to pion/srtp that referenced this pull request Nov 28, 2025
This will be used while probing for PayloadType and Simulcast.

Relates to pion/webrtc#2777

Co-authored-by: cptpcrd <[email protected]>
@Sean-Der Sean-Der force-pushed the fix-simulcast-probing branch 2 times, most recently from 68d8623 to beba940 Compare November 28, 2025 17:59
@Sean-Der Sean-Der changed the base branch from v3 to master November 28, 2025 18:00
@Sean-Der Sean-Der force-pushed the fix-simulcast-probing branch 2 times, most recently from e4e02a9 to 96a2e1a Compare November 28, 2025 21:29
@Sean-Der
Copy link
Member

Sorry this took so long to get merged. With the holidays I hope to have more time to get through backlog.

Super impressed that you diagnosed and fixed this!

@Sean-Der Sean-Der force-pushed the fix-simulcast-probing branch 2 times, most recently from bfd17cb to 1f7fa14 Compare November 29, 2025 00:03

return n, attributes, err
}
if receiver.haveClosed() {
Copy link
Member

Choose a reason for hiding this comment

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

Before calling Read would return peaked packets (even though the Transceiver) was closed.

@Sean-Der
Copy link
Member

Good from me!

@JoeTurki @boks197 @jech 1 just as a 'heads up' I am changing a core code path, want to make sure I am not messing anything up. If you don't mind looking it over

Copy link
Contributor

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

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

lgtm!

}

// Simulcast probe would lose packets. This test asserts that we don't drop
// any packets during the probe.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe remove comment which says Simulcast probe would lose packets. This PR fixes it. So, would be good to just say that this test ensures no drops during probe.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed!

Before any packets that we read during the probe would get lost

Co-authored-by: cptpcrd <[email protected]>
@Sean-Der Sean-Der force-pushed the fix-simulcast-probing branch from 1f7fa14 to f71415b Compare November 29, 2025 11:59
Copy link
Member

@JoeTurki JoeTurki left a comment

Choose a reason for hiding this comment

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

tested it :)

@Sean-Der Sean-Der merged commit 71b8a13 into pion:master Nov 29, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants