Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
udp: add tx buffer size setup for udp_bind(_double)
  • Loading branch information
perexg committed Mar 11, 2015
1 parent 56ac461 commit 83f94f6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/input/mpegts/iptv/iptv_udp.c
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/input/mpegts/satip/satip_frontend.c
Expand Up @@ -1271,7 +1271,7 @@ satip_frontend_input_thread ( void *aux )
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;
}
Expand Down
22 changes: 15 additions & 7 deletions src/udp.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -288,21 +295,22 @@ 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];
int tst = 40, pos = 0, i, port2;

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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/udp.h
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/upnp.c
Expand Up @@ -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;

Expand Down

0 comments on commit 83f94f6

Please sign in to comment.