ngraziano / SharpRTSP

A RTSP handling library
Other
538 stars 180 forks source link

Multiplexer, how it actually works? #72

Open kamilk91 opened 2 years ago

kamilk91 commented 2 years ago

Hello, i have implemented your code but i have some troubles:

So i created server with .Net 6:

public RtcpServerService(ILogger<RtcpServerService> logger)
        {
            this._logger = logger;
            Contract.EndContractBlock();

            RtspUtils.RegisterUri();
            _RTSPServerListener = new TcpListener(IPAddress.Any, ConfigInstance.config.RTSPPort); //port is 2525
        }

And i wanted to connect to port 2525 with OBS Studio.

image

i realized that there is wrong way, because i have received bla bla bla Invalid header, so my idea was it is port to connect with Client and it was good move. I connected with VLC, received message, logged it and stayed connected.

Then i tried to transmit video from mp4 to vlc, and your also to your Client sample.

private void AcceptConnection()
        {
            try
            {
                while (!_Stopping.WaitOne(0))
                {
                    TcpClient oneClient = _RTSPServerListener.AcceptTcpClient();
                    RtspListener newListener = new RtspListener(
                        new RtspTcpTransport(oneClient));
                    RTSPDispatcher.Instance.AddListener(newListener);

                    newListener.Start();

                    try
                    {

                        string path = "./wwwroot/victor.mp4";

                        var msg = new Rtsp.Messages.RtspMessage
                        {

                            Data = System.IO.File.ReadAllBytes(path),

                        };
                        msg.AddHeader("Transport: RTP/AVP/TCP;interleaved=0");
                        newListener.SendMessage(msg);
                    }
                    catch (Exception) { }
                }
            }
            catch (SocketException error)
            {
                _logger.LogWarning("Got an error listening, I have to handle the stopping which also throw an error", error);
            }
            catch (Exception error)
            {
                _logger.LogError("Got an error listening...", error);
                throw;
            }

        }

So, your client printed some string representation of unreadable bytes, and then vlc just crashed (propably didn't know what to do with this data).

I still have no idea how to make connection like:

Me with camera/desktop sharing from OBS => RtspServer with your library => receiver in web client. I see that your library is opening some connections and ports like

Connection Open 127.0.0.1:6431
Receive from 127.0.0.1:6431

Can you give me some tips how to achieve that? I will be greatful!