[FFmpeg-devel] [PATCH] Add the 'broadcast' option to udp protocol
Federico Fuga
fuga at studiofuga.com
Fri Aug 10 13:05:20 CEST 2012
This option specify that the provided address is a net broadcast address.
This is needed by some platform to transmit to and receive from network broadcast addresses.
Note that different, although Unix-based, Operating Systems behaves
differently with network broadcast addresses, certains allows transmissions,
other allows receiving only, other (like android) none of them. When in doubt,
specify this option when using broadcast addresses.
---
doc/protocols.texi | 8 ++++++++
libavformat/udp.c | 15 ++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/doc/protocols.texi b/doc/protocols.texi
index ae1c9b8..deb3d41 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -485,6 +485,14 @@ Choose the local IP address. This is useful e.g. if sending multicast
and the host has multiple interfaces, where the user can choose
which interface to send on by specifying the IP address of that interface.
+ at item broadcast=@var{1|0}
+The address is a net broadcast address. This is needed by some platform
+to transmit and receive from network broadcast addresses.
+Note that different, although Unix-based, Operating Systems behaves
+differently with network broadcast addresses, certains allows transmissions,
+other allows receiving only, other (like android) none of them. When in doubt,
+specify this option when using broadcast addresses.
+
@item pkt_size=@var{size}
set the size in bytes of UDP packets
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 51d7ed0..e1b5988 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -59,6 +59,7 @@ typedef struct {
int is_multicast;
int local_port;
int reuse_socket;
+ int is_broadcast;
int overrun_nonfatal;
struct sockaddr_storage dest_addr;
int dest_addr_len;
@@ -438,6 +439,13 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
av_strlcpy(localaddr, buf, sizeof(localaddr));
}
+ if (av_find_info_tag(buf, sizeof(buf), "broadcast", p)) {
+ char *endptr = NULL;
+ s->is_broadcast = strtol(buf, &endptr, 10);
+ /* assume if no digits were found it is a request to enable it */
+ if (buf == endptr)
+ s->is_broadcast = 1;
+ }
}
/* fill the dest addr */
@@ -467,7 +475,12 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
goto fail;
}
-
+
+ if (s->is_broadcast) {
+ if (setsockopt(udp_fd, SOL_SOCKET, SO_BROADCAST, &(s->is_broadcast), sizeof(s->is_broadcast)) != 0)
+ goto fail;
+ }
+
/* If multicast, try binding the multicast address first, to avoid
* receiving UDP packets from other sources aimed at the same UDP
* port. This fails on windows. This makes sending to the same address
--
1.7.9.5
More information about the ffmpeg-devel
mailing list