如何通过UDP发送实时数据?
我必须尽可能快、实时地通过 UDP 发送一系列视频帧,虽然我已经掌握了基础知识,但我遇到了各种各样的困难。我的一些目标:
数据通常通过拨号发送(因此使用 UDP 而不是 TCP),但也需要支持快速以太网。
偶尔丢帧是可以的(因此是 UDP 而不是 TCP)。
需要低延迟。远程接收的帧应该是最近发送的帧(缓冲区中等待的帧数不超过几帧)。
我需要能够检测有效带宽,以便我可以或多或少地压缩帧以保持帧速率。
我已经成功实现了大部分内容:
我将帧数据分解为一个或多个大约 500 字节的数据报,每个数据报都有一个序列号和其他信息。接收器重新组装整个帧并检测是否有任何数据报丢失。
如果接收方检测到超过一定比例的丢帧(例如,过去 10 帧中的丢帧率为 50%),我会向发送方发送一条 TCP 消息,以减慢 50% 的速度。发送方会缓慢地将每个后续帧的速度提高 5%。
使用System.Net.Sockets.UdpClient发送和接收数据。
我有一个单独的 TCP 通道,用于将控制消息返回给发送者。
我现在的主要困难是检测有效带宽并处理延迟,特别是通过拨号(最大约 4,000 字节/秒)。例如,如果我尝试使用 TcpClient.Send() 发送 100,000 字节/秒,它们似乎都已到达(没有丢失数据报),但在最后一个数据报到达时具有很大的延迟。我认为 TcpClient.Send() 函数会阻塞,直到缓冲区能够发送,这会扰乱我当前的算法。
任何人都可以向我指出任何有关如何执行以下操作的信息来源:
检测 UDP 上的实际带宽。
动态调整带宽以适应可用管道的更好算法。
以所需的带宽平滑地发送数据。
一种检测延迟并将其降至最低的方法。
上周我一直在旋转我的轮子,每次我解决一个问题时,似乎另一个问题就会出现。
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:
Data will normally be sent over dial-up (hence UDP instead of TCP), but also needs to support fast Ethernet.
It's OK to occasionally drop frames (hence UDP instead of TCP).
Need low latency. The frame the remote receives should be one that was recently sent (no more than a few frames waiting in buffers).
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:
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.
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.
Using System.Net.Sockets.UdpClient to send and receive the data.
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:
Detect actual bandwidth over UDP.
A better algorithm for dynamically adjusting bandwidth to suit the available pipe.
Send data smoothly at the desired bandwidth.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以为每个数据包添加时间戳。然后你可以检测延迟是否增加。在这种情况下,您发回一条消息以减少带宽。
创建连接时,您可以用很少的数据包检测到延迟。该值在运行时不应改变。
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.