Skip to content

feat: implement FEC reconstruction logic and support for packet filte… - #147

Open
mysamimi wants to merge 4 commits into
datarhei:mainfrom
mysamimi:feature/fec-packet-filter
Open

feat: implement FEC reconstruction logic and support for packet filte…#147
mysamimi wants to merge 4 commits into
datarhei:mainfrom
mysamimi:feature/fec-packet-filter

Conversation

@mysamimi

Copy link
Copy Markdown
Contributor

Overview

This Pull Request introduces Forward Error Correction (FEC) via the SRT Packet Filtering mechanism, based on the SMPTE 2022-1-2007 standard.

Currently, gosrt drops EXTTYPE_FILTER control packets and lacks FEC support. While the ARQ mechanism works great for most reliable networks, it struggles heavily in long-distance, high-latency, or lossy networks (e.g., satellite, microwave links, or unstable cellular networks). In such environments, ARQ retransmissions often arrive too late (exceeding the TSBPD threshold) and are ultimately dropped, causing stream corruption.

What this PR does

  1. Packet Filtering Negotiation: Adds support for parsing the PacketFilter configuration (e.g., fec,cols:10,rows:1,layout:even) and negotiating it during the CONCLUSION handshake.
  2. FEC Generator (Sender): Generates redundant control packets using XOR operations over blocks of data packets.
  3. FEC Reconstructor (Receiver): Intercepts FEC control packets (MessageNumber = 0) to rebuild lost data packets seamlessly, injecting them back into the processing pipeline long before ARQ would typically retransmit them.
  4. Documentation: Updated README.md with instructions and an example of how to enable FEC.

Why it is needed (The Benefit)

I have included a new simulation test (TestFEC_Benefit_WithFECReconstructsPackets) that mimics a lossy network with a 100ms delay (RTT=200ms) and 120ms Latency constraint.

  • Without FEC: ARQ retransmissions fail to meet the 120ms TSBPD deadline, resulting in massive packet drops (Too Late).
  • With FEC: The missing packets are proactively reconstructed on the fly by the receiver, resulting in 0 dropped application packets without needing to increase the overall latency.

This allows developers using gosrt to achieve lower latency while maintaining stream stability on unreliable links.

Testing

  • Added fec_test.go with a custom LossyProxy to rigorously test recovery behavior.
  • All existing protocol tests pass successfully.
  • Validated interoperability formatting for SMPTE 2022-1 control packets.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Comment thread fec/reconstructor.go Fixed
Comment thread fec/reconstructor.go Fixed
Comment thread fec/reconstructor.go Fixed
@codecov-commenter

codecov-commenter commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 9.96310% with 244 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.13%. Comparing base (cf68b37) to head (4a7c47c).

Files with missing lines Patch % Lines
fec/reconstructor.go 0.00% 78 Missing ⚠️
fec/generator.go 0.00% 39 Missing ⚠️
fec/fec.go 0.00% 37 Missing ⚠️
fec/packet.go 0.00% 35 Missing ⚠️
packet/packet.go 0.00% 29 Missing and 5 partials ⚠️
connection.go 50.00% 13 Missing and 6 partials ⚠️
config.go 0.00% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #147      +/-   ##
==========================================
- Coverage   56.77%   54.13%   -2.65%     
==========================================
  Files          24       28       +4     
  Lines        4264     4524     +260     
==========================================
+ Hits         2421     2449      +28     
- Misses       1517     1742     +225     
- Partials      326      333       +7     
Flag Coverage Δ
unit-linux 54.13% <9.96%> (-2.65%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants