[FFmpeg-devel] [PATCH] Replace select with poll

Måns Rullgård mans
Fri Jan 28 02:26:51 CET 2011


Luca Barbato <lu_zero at gentoo.org> writes:

> Select has limitations on the fd values it could accept and silently
> breaks when it is reached.
> ---
>  libavformat/os_support.c |    3 --
>  libavformat/rtpproto.c   |   24 ++++++-------------
>  libavformat/rtsp.c       |   54 ++++++++++++++++++++++++---------------------
>  libavformat/rtsp.h       |    5 ++++
>  libavformat/rtspenc.c    |   19 +++++-----------
>  libavformat/sapdec.c     |   14 ++++-------
>  libavformat/tcp.c        |   48 ++++++++++++-----------------------------
>  libavformat/udp.c        |   15 ++++--------
>  8 files changed, 72 insertions(+), 110 deletions(-)
>
> diff --git a/libavformat/os_support.c b/libavformat/os_support.c
> index 83f0820..70cca92 100644
> --- a/libavformat/os_support.c
> +++ b/libavformat/os_support.c
> @@ -236,7 +236,6 @@ int ff_socket_nonblock(int socket, int enable)
>  }
>  #endif /* CONFIG_NETWORK */
>
> -#if CONFIG_FFSERVER
>  #if !HAVE_POLL_H
>  int poll(struct pollfd *fds, nfds_t numfds, int timeout)
>  {
> @@ -305,5 +304,3 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
>      return rc;
>  }
>  #endif /* HAVE_POLL_H */
> -#endif /* CONFIG_FFSERVER */
> -
> diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
> index 6ef6784..59519b9 100644
> --- a/libavformat/rtpproto.c
> +++ b/libavformat/rtpproto.c
> @@ -34,8 +34,8 @@
>  #include "network.h"
>  #include "os_support.h"
>  #include <fcntl.h>
> -#if HAVE_SYS_SELECT_H
> -#include <sys/select.h>

Does this patch remove all uses of select?  If so, we can drop the
check for sys/select.h too.

> +#if HAVE_POLL_H
> +#include <sys/poll.h>
>  #endif
>  #include <sys/time.h>
>
> @@ -221,9 +221,9 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
>      RTPContext *s = h->priv_data;
>      struct sockaddr_storage from;
>      socklen_t from_len;
> -    int len, fd_max, n;
> -    fd_set rfds;
> -    struct timeval tv;
> +    int len, n;
> +    struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0},
> +                          {s->rtcp_fd, POLLIN, 0} };

Odd formatting.


[...]

> +/**
> + * Parse the sdp description and allocate the rtp streams and the
> + * pollfd array used for udp ones.
> + */
> +
>  int ff_sdp_parse(AVFormatContext *s, const char *content)
>  {
> +    RTSPState *rt = s->priv_data;
>      const char *p;
>      int letter;
>      /* Some SDP lines, particularly for Realmedia or ASF RTSP streams,
> @@ -470,6 +476,7 @@ int ff_sdp_parse(AVFormatContext *s, const char *content)
>          if (*p == '\n')
>              p++;
>      }
> +    rt->p = av_malloc(sizeof(struct pollfd)*2*(rt->nb_rtsp_streams+1));

Unchecked malloc.

>      return 0;
>  }
>  #endif /* CONFIG_RTPDEC */
> @@ -531,6 +538,7 @@ void ff_rtsp_close_streams(AVFormatContext *s)
>          av_close_input_stream (rt->asf_ctx);
>          rt->asf_ctx = NULL;
>      }
> +    av_free(rt->p);
>      av_free(rt->recvbuf);
>  }

Rest looks good.

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



More information about the ffmpeg-devel mailing list