[FFmpeg-devel] [PATCH] set udp receive buffer to max size

Måns Rullgård mans
Wed Aug 15 23:24:55 CEST 2007


Ramiro Polla <ramiro at lisha.ufsc.br> writes:

> Hello,
>
> Attached patch (based on patch by Michael Kohn) sets the recv udp
> buffer size to at least 64k, which is the largest any udp packet might
> be. It's needed for Windows [1], and maybe even other OSes.
> Some googling shows what other people have to say about this buffer
> size [2].
>
> Ramiro Polla
> [1] http://article.gmane.org/gmane.comp.video.ffmpeg.devel/43669
> [2] http://ussg.iu.edu/hypermail/linux/net/9702.1/0060.html
> Index: libavformat/udp.c
> ===================================================================
> --- libavformat/udp.c	(revision 10119)
> +++ libavformat/udp.c	(working copy)
> @@ -43,6 +43,7 @@
>  } UDPContext;
>
>  #define UDP_TX_BUF_SIZE 32768
> +#define UDP_MAX_PKT_SIZE 65536
>
>  #ifdef CONFIG_IPV6
>
> @@ -396,6 +397,16 @@
>              perror("setsockopt sndbuf");
>              goto fail;
>          }
> +    } else {
> +        /* set udp recv buffer size to at least the largest possible udp packet
> +         * size to avoid losing data on OSes that set this too low by default.
> +         */
> +        int optlen = sizeof(tmp);
> +        if (!getsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, &optlen) &&
> +            tmp < UDP_MAX_PKT_SIZE) {
> +            tmp = UDP_MAX_PKT_SIZE;
> +            setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp));
> +        }

Why complicate it like that?  Why not simply always set it to 64k?

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list