ngraziano / SharpRTSP

A RTSP handling library
Other
538 stars 180 forks source link

RtspClientExample/RTSPClient.cs UDP Socket Port Number Problem #62

Open poweryang1 opened 4 years ago

poweryang1 commented 4 years ago

if (rtp_transport == RTP_TRANSPORT.UDP) { video_udp_pair = new Rtsp.UDPSocket(40000, 41000); //video_udp_pair = new Rtsp.UDPSocket(50000, 51000);
video_udp_pair.DataReceived += Rtp_DataReceived; video_udp_pair.Start(); // start listening for data on the UDP ports

            audio_udp_pair = new Rtsp.UDPSocket(50000, 51000); 
            audio_udp_pair.DataReceived += Rtp_DataReceived;
            audio_udp_pair.Start(); // start listening for data on the UDP ports

}

I tested with VLC Stream Server. VLC Stream Server uses UDP Streaming, so I can find a bug in sample code.

The video_udp_pair Socket Port number is same as the audio_udp_pair Socket Port number. Can you fix it?

RogerHardiman commented 3 years ago

We need to look at the bug in a little more detail. The UDPSocket() function tries to open a UDP port and if it fails, it moves on to the next free port. So the code should open Port 50000 and 500001 for video.

Then when it comes to the audio it tries to open port 50000 and finds it is already in use, so it opens port 50002 (the next free one) for the audio.

That is what the software is supposed to do and why the port range (50000 to 510000) is the same for video and audio.

We need to work this way because other applications (or other instances of SharpRTSP) could be using UDP ports in this range so we have to search for free ports.

The workwound you have is good. It moves the video ports to a new range (40000 to 41000).

But I'd like to figure out why the existing code does not work for you.

Are you able to help with some extra tests?

Thanks Roger

ngraziano commented 1 week ago

Maybe related to #74