ngraziano / SharpRTSP

A RTSP handling library
Other
557 stars 182 forks source link

RTSP Server Side implementation of RTSP over HTTP for RtspCameraExample #130

Open RogerHardiman opened 2 months ago

RogerHardiman commented 2 months ago

Hi I can see SharpRTSP has code to be a client of a RTSP over HTTP Server. I want to add support for RTSP over HTTP and RTSP over HTTPS to the RTSP Server code and test with RtspCameraExample

I wanted to check if anyone has tried this already or if there are any forks worth looking at.

I've already done the research and read the Apple mini spec.

I wanted to keep this on the same port as a RTSP connection so will handle RTSP and the HTTP connection on the same port (eg 8554) I'd like to keep the rest of the RTSP Server code reading from a Stream.

So I think I need to write some code that will sit between the TCP Server Connections and the Stream Read/Write functions which are written to Read and Write RTSP messages to a stream.

My new code would need to read data from the TCP Socket, and if it is a RTSP message, just pass data straight through. If the data read from the TCP socket is a HTTP Header, I need to respond and wait for the 2nd HTTP connection with the correct GUID and then pass data read from the HTTP connection to the stream the exisitng RTSP Sharp code uses and handle Stream Writes from the existing Sharp RTSP code.

So just wanted to check if anything has been tried already.

Thanks Roger

ngraziano commented 2 months ago

Hi,

I have think a little about adding RTSP over HTTP for the server side but I did not start to code. I think that using the same port for standard RTSP and RTSP over HTTP will make it a lot harder but it may be faisable, maybe you can try to make a dedicate RTSP over HTTP and add passthrough after for classic RTSP .

My thought was to make a new class (called something like RtspHttpListerner) to replace/wrap TcpListener and when it AcceptTcpClient, it check the different case

RtspHttpServerTransport will implement IRtspTransport, it return a special stream where all the magic happen (like RtspHttpTransport). This stream need to implement :

One subject I am not sure : can the client open new TCP connection to send a new POST for the same stream, using the same x-sessioncookie. If it is the case the RtspHttpListerner must maintain a dictionary of request channel and RtspHttpServerTransport must check this dictionary when the current channel is closed.

I think HTTPS can be added after if we have protected method to get the stream in the RtspHttpListerner, or we can ask user to use an external proxy.

Nicolas

RogerHardiman commented 2 months ago

Hi. Thanks for the suggestions. I agree it would be easier to have a different port and if I get stuck, I may try that first and make a little internal socket connection from the HTTP server to the RTSP Server port to forward the Stream once the tunnel is established.

But I've started with some additions to RtspTcpTransport and a custom Stream Class so I can implement a PeekLine() function but it will probably make the existing class too messy. It is a good idea to overload the TcpClient class with some extra Stream magic - including a StreamPeak.

I had avoiding doing the TcpClient because the TLS/SSL negotiation is done deeper into SharpRTSP in a GetStream() function so I'd need to do the TLS/SSL negotiation in the TcpClient so that I could add a PeakLine to see what the first bytes of the Socket contain (RTSP or HTTP)

If get stuck I'll do it on a different port and open an internal socket to the existing RTSP code.

When I have something working I'll push it to my fork and let you know.

Many thanks Roger