如何通过UDP发送实时数据?

发布于 2024-09-19 17:29:35 字数 1038 浏览 10 评论 0原文

我必须尽可能快、实时地通过 UDP 发送一系列视频帧,虽然我已经掌握了基础知识,但我遇到了各种各样的困难。我的一些目标:

  1. 数据通常通过拨号发送(因此使用 UDP 而不是 TCP),但也需要支持快速以太网。

  2. 偶尔丢帧是可以的(因此是 UDP 而不是 TCP)。

  3. 需要低延迟。远程接收的帧应该是最近发送的帧(缓冲区中等待的帧数不超过几帧)。

  4. 我需要能够检测有效带宽,以便我可以或多或少地压缩帧以保持帧速率。

我已经成功实现了大部分内容:

  1. 我将帧数据分解为一个或多个大约 500 字节的数据报,每个数据报都有一个序列号和其他信息。接收器重新组装整个帧并检测是否有任何数据报丢失。

  2. 如果接收方检测到超过一定比例的丢帧(例如,过去 10 帧中的丢帧率为 50%),我会向发送方发送一条 TCP 消息,以减慢 50% 的速度。发送方会缓慢地将每个后续帧的速度提高 5%。

  3. 使用System.Net.Sockets.UdpClient发送和接收数据。

  4. 我有一个单独的 TCP 通道,用于将控制消息返回给发送者。

我现在的主要困难是检测有效带宽并处理延迟,特别是通过拨号(最大约 4,000 字节/秒)。例如,如果我尝试使用 TcpClient.Send() 发送 100,000 字节/秒,它们似乎都已到达(没有丢失数据报),但在最后一个数据报到达时具有很大的延迟。我认为 TcpClient.Send() 函数会阻塞,直到缓冲区能够发送,这会扰乱我当前的算法。

任何人都可以向我指出任何有关如何执行以下操作的信息来源:

  1. 检测 UDP 上的实际带宽。

  2. 动态调整带宽以适应可用管道的更好算法。

  3. 以所需的带宽平滑地发送数据。

  4. 一种检测延迟并将其降至最低的方法。

上周我一直在旋转我的轮子,每次我解决一个问题时,似乎另一个问题就会出现。

I have to send a sequence of video frames over UDP as fast and real-time as possible and while I got the basics working, I am running into all sorts of difficulties. Some of my goals:

  1. Data will normally be sent over dial-up (hence UDP instead of TCP), but also needs to support fast Ethernet.

  2. It's OK to occasionally drop frames (hence UDP instead of TCP).

  3. Need low latency. The frame the remote receives should be one that was recently sent (no more than a few frames waiting in buffers).

  4. I need to be able to detect the effective bandwidth so that I can compress the frames more or less to keep frame rate up.

I have managed to implement most of the pieces:

  1. I break up frame data into one or more datagrams of about 500 bytes and each has a sequence number and other info. The receiver reassembles the entire frame and detects if any datagrams are missing.

  2. If the receiver detects more than a certain percentage of dropped frames (e.g. 50% over the last 10 frames), I send a TCP message to the sender to slow down by 50%. Sender than slowly increases speed by 5% each subsequent frame.

  3. Using System.Net.Sockets.UdpClient to send and receive the data.

  4. I have a separate TCP channel used for control messages back to sender.

My main difficulty right now is detecting the effective bandwidth and dealing with latency, especially over dial-up (max ~4,000 bytes/sec). For example, if I try to send 100,000 bytes/second using TcpClient.Send() they ALL seem to arrive (no dropped datagrams) but with large latency by the time last datagram arrives. I think the TcpClient.Send() function is blocking until the buffer is able to send which messes up my current algorithm.

Can anybody point me to any sources of information for how to:

  1. Detect actual bandwidth over UDP.

  2. A better algorithm for dynamically adjusting bandwidth to suit the available pipe.

  3. Send data smoothly at the desired bandwidth.

  4. A way to detect and keep latency down to a minimum.

I have been spinning my wheels over the last week and every time I solve one problem it seems another rears up is head.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恍梦境° 2024-09-26 17:29:35

您还可以为每个数据包添加时间戳。然后你可以检测延迟是否增加。在这种情况下,您发回一条消息以减少带宽。

创建连接时,您可以用很少的数据包检测到延迟。该值在运行时不应改变。

You can also to add a timestamp to every packet. Then you can detect if the delay increase. In this case you send back a message to reduce the bandwidth.

On creating the connection you detect the latency with very few packets. This value should not change at running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文