udp: Receive on the remote port number, if no local port is set

Message ID 1308293921-82396-1-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö June 17, 2011, 6:58 a.m.
From: Can Wu <wu.canus@gmail.com>

For a unicast udp stream to localhost:1234, currently
ffplay udp://:1234?localport=1234
works, but
ffplay udp://:1234
doesn't work.
---
 libavformat/udp.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

wucan June 17, 2011, 7:22 a.m. | #1
On 06/17/11 14:58, Martin Storsjö wrote:
OK, thanks.
> From: Can Wu<wu.canus@gmail.com>
>
> For a unicast udp stream to localhost:1234, currently
> ffplay udp://:1234?localport=1234
> works, but
> ffplay udp://:1234
> doesn't work.
> ---
>   libavformat/udp.c |    2 ++
>   1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index d6522bf..2c0275a 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -367,6 +367,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>
>       if (s->is_multicast&&  (h->flags&  AVIO_FLAG_READ))
>           s->local_port = port;
> +    if (!s->is_multicast&&  (h->flags&  AVIO_FLAG_READ)&&  !s->local_port)
> +        s->local_port = port;
>       udp_fd = udp_socket_create(s,&my_addr,&len);
>       if (udp_fd<  0)
>           goto fail;
Luca Barbato June 17, 2011, 7:41 a.m. | #2
On 6/17/11 1:58 AM, Martin Storsjö wrote:
>       if (s->is_multicast&&  (h->flags&  AVIO_FLAG_READ))
>           s->local_port = port;
> +    if (!s->is_multicast&&  (h->flags&  AVIO_FLAG_READ)&&  !s->local_port)

(h->flags&  AVIO_FLAG_READ) && (!s->local_port || s->is_multicast)

maybe?

lu

Patch

diff --git a/libavformat/udp.c b/libavformat/udp.c
index d6522bf..2c0275a 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -367,6 +367,8 @@  static int udp_open(URLContext *h, const char *uri, int flags)
 
     if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
         s->local_port = port;
+    if (!s->is_multicast && (h->flags & AVIO_FLAG_READ) && !s->local_port)
+        s->local_port = port;
     udp_fd = udp_socket_create(s, &my_addr, &len);
     if (udp_fd < 0)
         goto fail;