简体   繁体   English

如何修改通过C#代理传递的RTSP数据

[英]How to modify RTSP data as it is being passed through c# proxy

I am writing a proxy for an application that uses RTSP for streaming video content. 我正在为使用RTSP传输视频内容的应用程序编写代理。 It basically works as follows: 它的基本工作原理如下:

  • The application (server) makes an RTSP stream available on localhost port 8554. 应用程序(服务器)在本地主机端口8554上提供RTSP流。
  • A client wishing to connect to this stream connects to my proxy on localhost port 8553. 希望连接到此流的客户端在本地主机端口8553上连接到我的代理。
  • My proxy connects to the RTSP stream (server) on localhost port 8554 and passes the network traffic (bytes) along between client and server. 我的代理服务器连接到本地主机端口8554上的RTSP流(服务器),并在客户端和服务器之间传递网络流量(字节)。 (I don't inspect packets at all, I simply read the bytes on the one stream and pass those bytes along to the other stream.) (我根本不检查数据包,我只是读取一个流中的字节,然后将这些字节传递给另一流。)

Since RTSP uses both TCP and UDP communication, I will have to have listeners for both protocols on the proxy, however, I have not yet got to implementing the UDP part. 由于RTSP同时使用TCP和UDP通信,因此我必须在代理服务器上同时具有这两种协议的侦听器,但是,我还没有实现UDP部分。 At the moment I am simply working on TCP which essentially handles the "handshaking" to start the video transfer. 目前,我只是在研究TCP,该TCP本质上处理“握手”以开始视频传输。 The actual video transfer over UDP will be my next step. 通过UDP进行实际的视频传输将是我的下一步。

Now for my question: I am successfully passing messages ("OPTIONS", "DESCRIBE", "SETUP, etc.) along with the proxy. The problem is that the content of the messages itself contains some information about the streaming server. Specifically, when the server responds to the client's "DESCRIBE" request, it returns amongst others: 现在,我的问题是:我成功地将消息(“ OPTIONS”,“ DESCRIBE”,“ SETUP等”)与代理一起传递。问题是消息的内容本身包含有关流服务器的某些信息。当服务器响应客户端的“ DESCRIBE”请求时,它返回以下信息:

Content-Base: rtsp://127.0.0.1:8554/nurv/

Before passing it along to the client, I need to change this on the proxy to: 在将其传递给客户端之前,我需要将其在代理服务器上更改为:

Content-Base: rtsp://127.0.0.1:8553/nurv/

because at the moment, when the client issues the subsequent "SETUP" request, it requests: 因为目前,当客户端发出后续的“ SETUP”请求时,它会请求:

SETUP rtsp://127.0.0.1:8554/nurv/track1 RTSP/1.0

which means that for the actual streaming it bypasses my proxy on port 8553 and connects directly to the stream on 8554. 这意味着对于实际的流,它绕过了端口8553上的代理,并直接连接到8554上的流。

How can I modify the messages on the proxy so that references to the actual server (ie 127.0.0.1:8554) get replaced by references to the proxy (ie 127.0.0.1:8553)? 如何修改代理上的消息,以使对实际服务器的引用(即127.0.0.1:8554)被对代理的引用(即127.0.0.1:8553)代替? Obviously it isn't optimal to do a string search through each message being passed through the proxy since that would mean unpacking and inspecting each message before repacking and sending on. 显然,对通过代理传递的每条消息进行字符串搜索不是最佳选择,因为这将意味着在重新打包并继续发送之前先对每条消息进行拆包和检查。

I have solved this problem. 我已经解决了这个问题。 Since the TCP connection of the RTSP protocol typically only contains the control messages, the number of messages being passed through here aren't that many (5 or 6 from each side if it is a simple request to start playback and, in the end, to end it). 由于RTSP协议的TCP连接通常仅包含控制消息,因此此处传递的消息数量不是很多(如果是开始回放的简单请求,则从每一侧发送5或6条消息,最后,结束)。 The big traffic will be handled through the UDP connections. 大流量将通过UDP连接处理。

As such, it doesn't cause big performance issues if I unpack, manipulate, and repackage the messages that are being sent over TCP. 这样,如果我解压缩,处理和重新打包通过TCP发送的消息,就不会引起较大的性能问题。 So I just read the package, replace the necessary IP addresses as necessary and that's it. 因此,我只是阅读了该程序包,根据需要替换了必要的IP地址,仅此而已。 I also need to do this to read the UDP ports that the client and server negotiates so that my proxy can go in-between. 我还需要执行此操作以读取客户端和服务器协商的UDP端口,以便我的代理可以介于两者之间。 Since the traffic over TCP is low, I'm able to do this. 由于TCP上的流量很低,因此我能够做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM