mediasoup icon indicating copy to clipboard operation
mediasoup copied to clipboard

Evaluate `uv_udp_try_send2` available in libuv >= 1.50.0

Open ibc opened this issue 11 months ago • 7 comments

Details

  • libuv 1.50.0 comes with a new function uv_udp_try_send2.
  • https://github.com/libuv/libuv/releases/tag/v1.50.0
  • https://github.com/libuv/libuv/pull/4644

Add a version of uv_udp_try_send that can send multiple datagrams.

Uses sendmmsg on platforms that support it (Linux, FreeBSD, macOS), falls back to a regular sendmsgloop elsewhere.

ibc avatar Jan 16 '25 11:01 ibc

The only use case I find is when sending NACK-ed RTP packets. In that case we may want to send N packets at once to a single socket.

jmillan avatar Jan 16 '25 14:01 jmillan

Or when we send RTCP compound packets.

ibc avatar Jan 16 '25 14:01 ibc

how would compound RTCP which needs to be SRTP-encrypted in a single call work? NACK, FEC and maybe pacing... I hear @ggarber ponders re-pacing ;-)

fippo avatar Jan 28 '25 04:01 fippo

how would compound RTCP which needs to be SRTP-encrypted in a single call work?

I fail to understand the problem you mean. The RTCP compound packet is not split into N datagrams. It's not that way. When mediasoup needs to generate RTCP compound packets it calculates the total size it would need and instead generates N RTCP compound packets of size less than hardcoded MTU (13XX bytes AFAIR) and then it encrypts each compound packet independently before sending each one. Nothing changes here regarding that.

ibc avatar Jan 28 '25 05:01 ibc

yeah but how often does the get bigger than the MTU?

fippo avatar Jan 28 '25 06:01 fippo

yeah but how often does the get bigger than the MTU?

How is that related to using this new UDP api in libuv? Absolutely nothing changes here no matter the total size of data to place in RTCP Compound packets.

ibc avatar Jan 28 '25 11:01 ibc

PR updating libuv to 1.51.0 is here: https://github.com/versatica/mediasoup/pull/1543

ibc avatar Jun 13 '25 12:06 ibc

The only use case I find is when sending NACK-ed RTP packets. In that case we may want to send N packets at once to a single socket.

Can you explain that? I don't think that's the use case. AFAIU uv_udp_try_send2(uv_udp_t *handle, unsigned int count, uv_buf_t *bufs[/*count*/], unsigned int nbufs[/*count*/], struct sockaddr *addrs[/*count*/], unsigned int flags) is about being able to send data to different addresses in a single system call.

Anyway AFAIS this cannot help us much. There are little use cases in mediasoup in which we want to send the same UDP datagram to different endpoints from the same mediasoup UDP port:

  • In WebRTC we have to encode SRTP differently for each endpoint, so no use case here.
  • In plain transports we don't send the same packet to different endpoints from the same local port in mediasoup.
  • All ICE traffic is specific for each endpoint.
  • DTLS depends on each endpoint due to negotiated encryption, etc.

ibc avatar Jul 04 '25 10:07 ibc

I'm closing this ticket due to rationale in above comment.

ibc avatar Jul 04 '25 11:07 ibc