RTCP/RTP通信问题
不幸的是,我仍然坚持执行一些 RTP / RTCP 通信才能正确访问我的 IP 摄像机。
我想做什么
相机有一个我想读取的内部缓冲区。所以我通过 RTSP 与摄像头通信并告诉它传输数据。当摄像机遍历整个缓冲区时,流式传输将停止。
到目前为止我有什么
通过 RTSP 进行通信的 TCP 连接,用于
DESCRIBE
/SETUP
/PLAY
请求 ( RTSP ) 启动流。当相机传输数据时,此连接必须保持打开状态。我接收通过 RTP(基于 UDP)发送的数据的端口 - 处理这个与我无关,我什至完全无法访问它,我只是想为了完整性而提及它。< /p>
接收 RTCP
发送者报告
/源描述
的 UDP 套接字。这很重要,因为我不知道流何时停止(如第 2 点所述,我不能只查看流何时停止)。在这个套接字上,我一直读到 RTCPSender Report Goodbye
出现,这意味着流传输已经完成。然后我可以关闭 TCP 套接字(来自 RTSP 通信)。
出了什么问题
它适用于 2MB 或 4MB 等较小的缓冲区大小。我收到一些来源描述,然后是再见
。但在我的特定测试案例中,我想使用 16MB(这仍然不到相机容量的一半)。 我收到发件人报告,但在某个时刻(始终在 8MB +/-300KB 左右)相机停止发送。
值得注意的是,我可以通过 VLC 毫无问题地访问缓冲区。我什至查看了通信( RTSP 和 RTCP ),它几乎与我的应用程序中的完全相同......我将在下面提到缺少的一件事:
可能的原因
这是我需要您建议的部分。
可能性:缺少接收器报告
通过 VLC 进行流式传输时,我注意到有一些 RTCP 接收器报告
从 VLC 发送到摄像机(像发送器报告
一样循环)代码>)。那么相机是否期望在特定时间(或发送特定数量的字节后)至少收到一份接收器报告
? 目前我想不出任何其他原因。
解决方案?
如果我们假设摄像机因没有
接收器报告
而停止流式传输,我想知道是否有无需携带太多信息即可实现它们的方法。我已经阅读了一些 RFC 3550,我想这些报告消息背后仍然有一堆逻辑。现在我实际上不需要,所以我也不想在这里实现完整的 RTCP 协议。发送一些接收器报告
虚拟帧是否足以让相机继续流式传输?如果是这样,它们看起来怎么样?如果这与缺少
接收器报告
无关,而我只是不需要它们,那么摄像机停止流式传输的原因可能是什么?有什么建议吗?
编辑:
好吧,我刚刚设法创建了某种虚拟接收器报告
,它似乎有效(我只能收到 12MB,然后我得到了想要的再见)
我刚刚填写了28Byte 缓冲区,只是在标头字段中使用了一些值,这意味着:
buffer[0] = 0x80; // Version 2 , Padding = false, Reception Count = 0
buffer[1] = 0xC9; // Packet Type 201 Receiver Report
buffer[2] = 0x00; // Higher byte for total length
buffer[3] = 0x06; // Lower byte for total length ( in 32 Bit words -> 28 Byte )
缓冲区的其余部分我只是用零填充。是的,我知道这只是一个黑客行为,你不应该告诉你的孩子这样编程。
现在我的问题有点改变:这个黑客可以吗?它似乎有效,但我仍然有点担心我的相机会使用这些虚拟数据并更改配置,因为它会在其中插入一些奇怪的东西?
Unfortunately I'm still stuck with a little implementation of a RTP / RTCP communication to access my IP camera properly.
What do I want to do
The camera has an internal buffer which I want to read. So I communicate with the camera via RTSP and tell it to stream the data. When the camera went through the whole buffer, streaming will stop.
What do I have so far
A TCP connection which communicates via RTSP for the
DESCRIBE
/SETUP
/PLAY
Request ( RTSP ) to get the stream started. This connection must remain open while the Camera streams it's data.A Port on which I receive the data sent via RTP ( based on UDP ) - handling this is none of my concern, I even have absolutely no access to it, I just wanted to mention it for the sake of completeness.
A UDP Socket which receives the RTCP
Sender Reports
/Source Descriptions
. This is important since I don't know when the stream stops ( as mentioned in point 2, I can't just look when the streaming stopped ). On this Socket I read until the RTCPSender Report Goodbye
comes, which means streaming has finished. Then I can close the TCP Socket (from RTSP
communication).
What is going wrong
It is working for small buffer sizes like 2MB or 4MB. I receive some Source Descriptions and then a Goodbye
. But in my particular test case I wanted to use 16MB ( which is still less than half of what the camera is capable of ).
I receive the Sender Reports but at some point ( always at around 8MB +/-300KB ) the camera just stops sending.
Noteworthy is the fact that I can access the buffer via VLC without problems. I even looked at the communication ( RTSP and RTCP ) which is almost completely the same as in my application...the one thing missing I'm gonna mention below:
Possible Reasons
This is the part where I need your advise.
Possibility: Lack of Receiver Reports
When streaming via VLC I noticed that there were some RTCP Receiver Reports
sent from VLC to the camera ( cyclic like the Sender Reports
). So could it be that the camere expects at least one Receiver Report
in a specific time ( or after a particular amount of bytes sent ) ?
At the moment I can't think of any other reason.
Solution?
If we assume that the camera stops streaming because there are no
Receiver Reports
I'd like to know if there is a way to implement them without carrying to much information. I have already read some of the RFC 3550 and I guess there is still a bunch of logic behind those Report messages. Now I actually don't need and so I also don't want to implement a complete RTCP protocol here. Would it be enough to send someReceiver Report
Dummy frames so the camera just keeps on streaming? If so, how do they look?If it is not related to the lack of
Receiver Reports
and I just don't need them, what could be the reason then for the camera to stop streaming? Any suggestions?
Edit:
Okay I just managed to create some kind of Dummy Receiver Report
and it seems to work ( I just could receive 12MB then I got the desired Goodbye )
I just filled a 28Byte buffer and just used some values in the Header fields, meaning:
buffer[0] = 0x80; // Version 2 , Padding = false, Reception Count = 0
buffer[1] = 0xC9; // Packet Type 201 Receiver Report
buffer[2] = 0x00; // Higher byte for total length
buffer[3] = 0x06; // Lower byte for total length ( in 32 Bit words -> 28 Byte )
The rest of the buffer I just filled with zeros. Yeah I know it's just a hack and you should not tell your kids to program like this.
Now my question changes a bit: Is this okay with this hack? It seems to work, but I'm still a bit concerned that my camera will use those dummy data and change configuration cause it interpets some weird stuff in it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该自己从流中读取数据。这样您就可以提供真实的接收者报告,而不是虚拟的报告。
如果您需要将其转发到另一个应用程序或库的另一个端口,您只需这样做即可。
You should read the data from the stream yourself. That way you can give real receiver reports instead of dummy ones.
If you need to forward it to another port for another application or library, you can simply do that.
某些摄像机可以将接收器报告 (RR) 用作“保持活动”消息。如果相机接受 GET_PARAMETER,您可以尝试每分钟向相机发送 GET_PARAMETER 作为保持活动消息。查看它在响应 DESCRIBE 时告诉您的内容。
某些网络摄像机无法正确解析 RR。我实际上试图阻止我在客户端中使用的 live555 库发送 RR 消息,因为某些型号的三星相机断开连接(根据他们的技术支持)。
Receiver report (RR) can be used by some cameras as "keep alive" message. You can try instead to send to you camera GET_PARAMETER every minute as keep alive message, if GET_PARAMETER is accepted by the camera. See what it tells you in response to DESCRIBE.
Some IP cameras can't parse RR properly. I'm actually trying to prevent the live555 library that I use in my client from sending RR messages because some models of Samsung cameras drop connection (according to their tech support).