[FFmpeg-cvslog] r26245 - in trunk: doc/protocols.texi libavformat/udp.c

mstorsjo subversion
Thu Jan 6 16:16:50 CET 2011


Author: mstorsjo
Date: Thu Jan  6 16:16:50 2011
New Revision: 26245

Log:
udp: Allow specifying the connect option in udp_set_remote_url, too

If the remote address is updated later with this function, the caller
shouldn't set the connect option until in this call.

Modified:
   trunk/doc/protocols.texi
   trunk/libavformat/udp.c

Modified: trunk/doc/protocols.texi
==============================================================================
--- trunk/doc/protocols.texi	Thu Jan  6 16:16:09 2011	(r26244)
+++ trunk/doc/protocols.texi	Thu Jan  6 16:16:50 2011	(r26245)
@@ -415,9 +415,13 @@ set the time to live value (for multicas
 @item connect=@var{1|0}
 Initialize the UDP socket with @code{connect()}. In this case, the
 destination address can't be changed with udp_set_remote_url later.
+If the destination address isn't known at the start, this option can
+be specified in udp_set_remote_url, too.
 This allows finding out the source address for the packets with getsockname,
 and makes writes return with AVERROR(ECONNREFUSED) if "destination
 unreachable" is received.
+For receiving, this gives the benefit of only receiving packets from
+the specified peer address/port.
 @end table
 
 Some usage examples of the udp protocol with @file{ffmpeg} follow.

Modified: trunk/libavformat/udp.c
==============================================================================
--- trunk/libavformat/udp.c	Thu Jan  6 16:16:09 2011	(r26244)
+++ trunk/libavformat/udp.c	Thu Jan  6 16:16:50 2011	(r26245)
@@ -245,8 +245,9 @@ static int udp_port(struct sockaddr_stor
 int udp_set_remote_url(URLContext *h, const char *uri)
 {
     UDPContext *s = h->priv_data;
-    char hostname[256];
+    char hostname[256], buf[10];
     int port;
+    const char *p;
 
     av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
 
@@ -256,6 +257,21 @@ int udp_set_remote_url(URLContext *h, co
         return AVERROR(EIO);
     }
     s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr);
+    p = strchr(uri, '?');
+    if (p) {
+        if (find_info_tag(buf, sizeof(buf), "connect", p)) {
+            int was_connected = s->is_connected;
+            s->is_connected = strtol(buf, NULL, 10);
+            if (s->is_connected && !was_connected) {
+                if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr,
+                            s->dest_addr_len)) {
+                    s->is_connected = 0;
+                    av_log(NULL, AV_LOG_ERROR, "connect: %s\n", strerror(errno));
+                    return AVERROR(EIO);
+                }
+            }
+        }
+    }
 
     return 0;
 }



More information about the ffmpeg-cvslog mailing list