Stanley
Stanley

Reputation: 5491

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. It basically works as follows:

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. At the moment I am simply working on TCP which essentially handles the "handshaking" to start the video transfer. The actual video transfer over UDP will be my next step.

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:

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 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.

How can I modify the messages on the proxy so that references to the actual server (i.e. 127.0.0.1:8554) get replaced by references to the proxy (i.e. 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.

Upvotes: 2

Views: 1850

Answers (1)

Stanley
Stanley

Reputation: 5491

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). The big traffic will be handled through the UDP connections.

As such, it doesn't cause big performance issues if I unpack, manipulate, and repackage the messages that are being sent over TCP. So I just read the package, replace the necessary IP addresses as necessary and that's it. 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. Since the traffic over TCP is low, I'm able to do this.

Upvotes: 1

Related Questions