[FFmpeg-devel] [PATCH] RTP local udp port issue fix (ticket 916)

Luca Abeni lucabe72 at email.it
Tue Jan 17 09:31:03 CET 2012


On 01/17/2012 09:02 AM, Dmitry Volyntsev wrote:
[...]
> 2012/1/17 Luca Abeni<lucabe72 at email.it>:
>> I have currently no time to look at all the details... But there is
>> something
>> wrong in what's happening: when the second ffmpeg instance tries to use port
>> 5000 for the RTP port, ffurl_open() should fail. And so port 5002 is tried
>> (thanks to the "while (j<= RTSP_RTP_PORT_MAX) {" loop) and so on...
>> Hence, there should be no collision.
>>
>> Maybe libavformat ends up using SO_REUSEADDR for some reason? I'd check
>> that...
>>
>> I think the proposed patch might be wrong, because it might end up in using
>> odd
>> numbers for the RTP port (I think RTP ports should be even numbers, and RTCP
>> ports should be odd).
>>
>>
>>                                 Luca
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
>> when the second ffmpeg instance tries to use port
>   5000 for the RTP port, ffurl_open() should fail. And so port 5002 is tried
> It is true, but only if the seconds instance starts while first
> instance still active. But the issue little-bit differs.
>
> If fact, the second instance starts when first instance already
> stopped (killed or something), so it closes opened udp ports. But (it
> is important for the issue), remote side still sends data to rtp/rtcp
> ports.

Ah, sorry... I missed this detail.


>> I think the proposed patch might be wrong, because it might end up in using
>> odd numbers for the RTP port (I think RTP ports should be even numbers, and RTCP
>> ports should be odd).
> Yes, you are right. I'm going consider this requirement in the next patch.

I suspect the simplest thing to do to avoid this issue is to add a random offset
to RTSP_RTP_PORT_MIN: instead of
	for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {
you can use
	offset = <random number>
	for (j = RTSP_RTP_PORT_MIN + offset, i = 0; i < rt->nb_rtsp_streams; ++i) {


BTW, unrelated to this issue, but... I think there is something quite wrong
in this code: things like
	if (RTSP_RTP_PORT_MIN != 0) {
look _very_ strange...
and there is an
	extern int rtsp_rtp_port_min;
in rtsp.h... But there is no "rtsp_rtp_port_min" variable anywhere.



			Luca


More information about the ffmpeg-devel mailing list