From 83f94f6f0c5c6f4b54c9cf660114f197a941e03c Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 24 Feb 2015 15:10:53 +0100 Subject: [PATCH] udp: add tx buffer size setup for udp_bind(_double) --- src/input/mpegts/iptv/iptv_udp.c | 2 +- src/input/mpegts/satip/satip_frontend.c | 2 +- src/udp.c | 22 +++++++++++++++------- src/udp.h | 5 +++-- src/upnp.c | 4 ++-- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/input/mpegts/iptv/iptv_udp.c b/src/input/mpegts/iptv/iptv_udp.c index feaa1e11..3989cc1d 100644 --- a/src/input/mpegts/iptv/iptv_udp.c +++ b/src/input/mpegts/iptv/iptv_udp.c @@ -41,7 +41,7 @@ iptv_udp_start ( iptv_mux_t *im, const char *raw, const url_t *url ) mpegts_mux_nice_name((mpegts_mux_t*)im, name, sizeof(name)); conn = udp_bind("iptv", name, url->host, url->port, - im->mm_iptv_interface, IPTV_BUF_SIZE); + im->mm_iptv_interface, IPTV_BUF_SIZE, 4*1024); if (conn == UDP_FATAL_ERROR) return SM_CODE_TUNING_FAILED; if (conn == NULL) diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index 64fd9f54..f36f0d42 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -1271,7 +1271,7 @@ new_tune: if (udp_bind_double(&rtp, &rtcp, "satip", "rtp", "rtpc", satip_frontend_bindaddr(lfe), lfe->sf_udp_rtp_port, - NULL, SATIP_BUF_SIZE, 16384) < 0) { + NULL, SATIP_BUF_SIZE, 16384, 4*1024, 4*1024) < 0) { satip_frontend_tuning_error(lfe, tr); goto done; } diff --git a/src/udp.c b/src/udp.c index 0732f7c1..58f41b54 100644 --- a/src/udp.c +++ b/src/udp.c @@ -151,7 +151,7 @@ udp_get_solip( void ) udp_connection_t * udp_bind ( const char *subsystem, const char *name, const char *bindaddr, int port, - const char *ifname, int rxsize ) + const char *ifname, int rxsize, int txsize ) { int fd, ifindex, reuse = 1; udp_connection_t *uc; @@ -271,9 +271,16 @@ udp_bind ( const char *subsystem, const char *name, goto error; } - /* Increase RX buffer size */ - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rxsize, sizeof(rxsize)) == -1) - tvhwarn(subsystem, "%s - cannot increase UDP rx buffer size [%s]", + /* Increase/Decrease RX buffer size */ + if (rxsize > 0 && + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rxsize, sizeof(rxsize)) == -1) + tvhwarn(subsystem, "%s - cannot change UDP rx buffer size [%s]", + name, strerror(errno)); + + /* Increase/Decrease TX buffer size */ + if (txsize > 0 && + setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &txsize, sizeof(txsize)) == -1) + tvhwarn(subsystem, "%s - cannot change UDP tx buffer size [%s]", name, strerror(errno)); uc->fd = fd; @@ -288,7 +295,8 @@ int udp_bind_double ( udp_connection_t **_u1, udp_connection_t **_u2, const char *subsystem, const char *name1, const char *name2, const char *host, int port, - const char *ifname, int rxsize1, int rxsize2 ) + const char *ifname, int rxsize1, int rxsize2, + int txsize1, int txsize2 ) { udp_connection_t *u1 = NULL, *u2 = NULL; udp_connection_t *ucs[10]; @@ -296,13 +304,13 @@ udp_bind_double ( udp_connection_t **_u1, udp_connection_t **_u2, memset(&ucs, 0, sizeof(ucs)); while (1) { - u1 = udp_bind(subsystem, name1, host, port, ifname, rxsize1); + u1 = udp_bind(subsystem, name1, host, port, ifname, rxsize1, txsize1); if (u1 == NULL || u1 == UDP_FATAL_ERROR) goto fail; port2 = ntohs(IP_PORT(u1->ip)); /* RTP port should be even, RTCP port should be odd */ if ((port2 % 2) == 0) { - u2 = udp_bind(subsystem, name2, host, port2 + 1, ifname, rxsize2); + u2 = udp_bind(subsystem, name2, host, port2 + 1, ifname, rxsize2, txsize2); if (u2 != NULL && u2 != UDP_FATAL_ERROR) break; } diff --git a/src/udp.h b/src/udp.h index 20a9d216..995bfa65 100644 --- a/src/udp.h +++ b/src/udp.h @@ -40,12 +40,13 @@ typedef struct udp_connection { udp_connection_t * udp_bind ( const char *subsystem, const char *name, const char *bindaddr, int port, - const char *ifname, int rxsize ); + const char *ifname, int rxsize, int txsize ); int udp_bind_double ( udp_connection_t **_u1, udp_connection_t **_u2, const char *subsystem, const char *name1, const char *name2, const char *host, int port, - const char *ifname, int rxsize1, int rxsize2 ); + const char *ifname, int rxsize1, int rxsize2, + int txsize1, int txsize2 ); udp_connection_t * udp_connect ( const char *subsystem, const char *name, const char *host, int port, diff --git a/src/upnp.c b/src/upnp.c index 23485e5a..6d832d3a 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -136,11 +136,11 @@ upnp_thread( void *aux ) multicast = udp_bind("upnp", "upnp_thread_multicast", "239.255.255.250", 1900, - NULL, 32*1024); + NULL, 32*1024, 32*1024); if (multicast == NULL || multicast == UDP_FATAL_ERROR) goto error; unicast = udp_bind("upnp", "upnp_thread_unicast", bindaddr, 0, - NULL, 32*1024); + NULL, 32*1024, 32*1024); if (unicast == NULL || unicast == UDP_FATAL_ERROR) goto error;