Skip to content

Fix/821 mtu aware packet length#836

Closed
Ayoub-glitsh wants to merge 3 commits into
roc-streaming:masterfrom
Ayoub-glitsh:fix/821-mtu-aware-packet-length
Closed

Fix/821 mtu aware packet length#836
Ayoub-glitsh wants to merge 3 commits into
roc-streaming:masterfrom
Ayoub-glitsh:fix/821-mtu-aware-packet-length

Conversation

@Ayoub-glitsh
Copy link
Copy Markdown

Fixes #821

Implements the approach discussed with @baranovmv adds a packet_mtu parameter and auto-derives packet length from MTU when neither is set.

neither set → min(5ms, derived from 1200 bytes default MTU)
only packet_mtu set → derive length from it
only packet_length set → nothing changes
both set → warn and pick the smaller one
Existing stereo users are unaffected since 5ms fits fine within 1200 bytes.

The --rate flag only sets the input device sample rate, but the packet
encoding defaults to L16_Stereo at 44100 Hz. When input rate differs
from packet encoding rate, the sender creates a resampler even if the
user doesn't want one.

Add --packet-encoding option that lets users register a custom RTP
encoding and select it for outgoing packets. This allows sending at
48kHz (or any rate) without resampling:

  roc-send --rate=48000 --packet-encoding=96:s16/48000/stereo ...

The option accepts the format '<id>:<format>/<rate>/<channels>', e.g.:
  96:s16/48000/stereo
  97:s16/48000/mono

The encoding is registered in the context encoding map and the sender
is configured to use it as the packet encoding.
Tests cover:
- Initialization: valid/invalid configs, intact vs tuning profiles
- Bounds checking: latency at target, above max, below min, stalling
  suppression, no-metrics-yet behavior, intact profile ignores bounds
- Scaling: no scaling before first interval, near-1.0 at target,
  above-1.0 when latency high, below-1.0 when latency low, clamped
  to scaling_tolerance, intact profile never produces scaling
- E2E backend: no update without e2e metrics, terminates on out-of-bounds
When neither packet_length nor packet_mtu is configured, the sender now
derives packet_length from a default MTU of 1200 bytes (WebRTC default),
then uses min(5ms, mtu_derived_length). This fixes multitrack scenarios
where the default 5ms packet length exceeds the MTU for high channel counts.

Rules:
- neither set: use min(DefaultPacketLength, bytes_2_ns(DefaultMtu - RtpHeader))
- only packet_mtu set: derive packet_length from it
- only packet_length set: use it as-is (existing behavior)
- both set: log a warning and use whichever leads to smaller packet size

Changes:
- pipeline/config.h: add DefaultPacketMtu, RtpHeaderSize constants;
  add packet_mtu field to SenderSinkConfig; update deduce_defaults()
  signature to accept encoding SampleSpec
- pipeline/config.cpp: implement MTU resolution logic in deduce_defaults()
- pipeline/sender_sink.cpp: pass encoding spec to deduce_defaults()
- public_api/include/roc/config.h: add packet_mtu to roc_sender_config
- public_api/src/adapters.cpp: wire packet_mtu from public API
- tools/roc_send/cmdline.ggo: add --packet-mtu option
- tools/roc_send/main.cpp: parse and apply --packet-mtu
@rocstreaming-bot rocstreaming-bot added the contrib PR not by a maintainer label Apr 25, 2026
@rocstreaming-bot
Copy link
Copy Markdown

🤖 Pull request is not targeted to develop branch, which is usually wrong.
If this was not intentional, please rebase on fresh develop branch, force-push, and re-target pull request using github web interface. Remember to use rebase with force-push instead of regular merge.

@baranovmv
Copy link
Copy Markdown
Member

Hi @Ayoub-glitsh

Thanks for posting.

  1. target branch must be develop, not master
  2. make tests pass, before that better make a draft pr
  3. remove irrelevant changes

@Ayoub-glitsh Ayoub-glitsh closed this by deleting the head repository Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contrib PR not by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multitrack packets too big per default ("packetizer: can't prepare packet")

3 participants