[FFmpeg-devel] [PATCH] udp: Enable address reuse by default for multicast

Brian Gitonga Marete bgmarete
Tue Feb 8 18:20:56 CET 2011


On Tue, Feb 8, 2011 at 12:14 AM, Martin Storsj? <martin at martin.st> wrote:
> From: David Fries <David at Fries.net>
>
> Keep the original corner case behaviour, where reuse is enabled
> for the case where no argument is given to the reuse url option.
> ---
> ?libavformat/udp.c | ? 17 +++++++++++++++--
> ?1 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index aa17c97..4c4db2a 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -313,6 +313,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> ? ? char buf[256];
> ? ? struct sockaddr_storage my_addr;
> ? ? int len;
> + ? ?int reuse_specified = 0;
>
> ? ? h->is_streamed = 1;
> ? ? h->max_packet_size = 1472;
> @@ -329,7 +330,14 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>
> ? ? p = strchr(uri, '?');
> ? ? if (p) {
> - ? ? ? ?s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
> + ? ? ? ?if (find_info_tag(buf, sizeof(buf), "reuse", p)) {
> + ? ? ? ? ? ?const char *endptr=NULL;
> + ? ? ? ? ? ?s->reuse_socket = strtol(buf, &endptr, 10);
> + ? ? ? ? ? ?/* assume if no digits were found it is a request to enable it */
> + ? ? ? ? ? ?if (buf == endptr)
> + ? ? ? ? ? ? ? ?s->reuse_socket = 1;
> + ? ? ? ? ? ?reuse_specified = 1;
> + ? ? ? ?}
> ? ? ? ? if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
> ? ? ? ? ? ? s->ttl = strtol(buf, NULL, 10);
> ? ? ? ? }
> @@ -366,9 +374,14 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> ? ? if (udp_fd < 0)
> ? ? ? ? goto fail;
>
> - ? ?if (s->reuse_socket)
> + ? ?/* Follow the requested reuse option, unless it's multicast in which
> + ? ? * case enable reuse unless explicitely disabled.
> + ? ? */
> + ? ?if (s->reuse_socket || (s->is_multicast && !reuse_specified)) {
> + ? ? ? ?s->reuse_socket = 1;
> ? ? ? ? if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
> ? ? ? ? ? ? goto fail;
> + ? ?}
>
> ? ? /* the bind is needed to give a port to the socket now */
> ? ? /* if multicast, try the multicast address bind first */
> --
> 1.7.3.1
>

This patch works for me. I can now open a multicast stream defined in
a *.sdp file even when another application is reading the same stream.

What is needed to get it in?

Thanks.


-- 
B. Gitonga Marete
Tel: +254-722-151-590



More information about the ffmpeg-devel mailing list