summaryrefslogtreecommitdiff
path: root/libavformat/udp.c
diff options
context:
space:
mode:
authorJindřich Makovička <makovick@gmail.com>2008-11-12 21:40:53 +0000
committerAndreas Öman <andreas@lonelycoder.com>2008-11-12 21:40:53 +0000
commit236bb1ab01319a08c50d93f12825acb55270d999 (patch)
tree22be8c20ca886a812db7094b7e85da5d9670c78d /libavformat/udp.c
parent2ae7e1243095ac8405f0cb5f78e7f179bb1493cb (diff)
Allow the UDP socket buffer size to be adjusted using a
'buffer_size' URL option. Patch by Jindrich Makovicka, makovick at gmail dot com Originally committed as revision 15807 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/udp.c')
-rw-r--r--libavformat/udp.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 6a2e642fe3..bdd66152fe 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -44,6 +44,7 @@
typedef struct {
int udp_fd;
int ttl;
+ int buffer_size;
int is_multicast;
int local_port;
int reuse_socket;
@@ -358,6 +359,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
h->priv_data = s;
s->ttl = 16;
+ s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
+
p = strchr(uri, '?');
if (p) {
s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
@@ -370,6 +373,9 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
h->max_packet_size = strtol(buf, NULL, 10);
}
+ if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
+ s->buffer_size = strtol(buf, NULL, 10);
+ }
}
/* fill the dest addr */
@@ -416,7 +422,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (is_output) {
/* limit the tx buf size to limit latency */
- tmp = UDP_TX_BUF_SIZE;
+ tmp = s->buffer_size;
if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
av_log(NULL, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno));
goto fail;
@@ -424,8 +430,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
} else {
/* set udp recv buffer size to the largest possible udp packet size to
* avoid losing data on OSes that set this too low by default. */
- tmp = UDP_MAX_PKT_SIZE;
- setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp));
+ tmp = s->buffer_size;
+ if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
+ av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno));
+ }
}
s->udp_fd = udp_fd;