X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/80fb0bd9ad2e970944fe1bd20922319592bfd994..dc24572f945d226d486c138ecf20102ceec4eb35:/lib/uaudio-rtp.c diff --git a/lib/uaudio-rtp.c b/lib/uaudio-rtp.c index d89f297..ff7e839 100644 --- a/lib/uaudio-rtp.c +++ b/lib/uaudio-rtp.c @@ -55,10 +55,12 @@ static int rtp_payload; /** @brief RTP output socket */ -static int rtp_fd; +static int rtp_fd = -1; /** @brief RTP output socket (IPv6) */ static int rtp_fd6; +/** @brief RTP unicast output socket (IPv6) */ +static int rtp_fd6 = -1; /** @brief RTP SSRC */ static uint32_t rtp_id; @@ -75,9 +77,6 @@ static uint16_t rtp_sequence; */ static int rtp_errors; -/** @brief Set while paused */ -static volatile int rtp_paused; - /** @brief RTP mode */ static int rtp_mode; @@ -245,11 +244,29 @@ static size_t rtp_play(void *buffer, size_t nsamples, unsigned flags) { return nsamples; } +static void hack_send_buffer_size(int fd, const char *what) { + int sndbuf, target_sndbuf = 131072; + socklen_t len = sizeof sndbuf; + + if(getsockopt(fd, SOL_SOCKET, SO_SNDBUF, + &sndbuf, &len) < 0) + disorder_fatal(errno, "error getting SO_SNDBUF on %s socket", what); + if(target_sndbuf > sndbuf) { + if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, + &target_sndbuf, sizeof target_sndbuf) < 0) + disorder_error(errno, "error setting SO_SNDBUF on %s socket to %d", + what, target_sndbuf); + else + disorder_info("changed socket send buffer size on %socket from %d to %d", + what, sndbuf, target_sndbuf); + } else + disorder_info("default socket send buffer on %s socket is %d", + what, sndbuf); +} + static void rtp_open(void) { struct addrinfo *dres, *sres; static const int one = 1; - int sndbuf, target_sndbuf = 131072; - socklen_t len; struct netaddress dst[1], src[1]; const char *mode; @@ -372,20 +389,9 @@ static void rtp_open(void) { break; } } - /* Enlarge the socket buffer */ - len = sizeof sndbuf; - if(getsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF, - &sndbuf, &len) < 0) - disorder_fatal(errno, "error getting SO_SNDBUF"); - if(target_sndbuf > sndbuf) { - if(setsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF, - &target_sndbuf, sizeof target_sndbuf) < 0) - disorder_error(errno, "error setting SO_SNDBUF to %d", target_sndbuf); - else - disorder_info("changed socket send buffer size from %d to %d", - sndbuf, target_sndbuf); - } else - disorder_info("default socket send buffer is %d", sndbuf); + /* Enlarge the socket buffers */ + hack_send_buffer_size(rtp_fd, "master socket"); + hack_send_buffer_size(rtp_fd6, "IPv6 on-demand socket"); /* We might well want to set additional broadcast- or multicast-related * options here */ if(rtp_mode != RTP_REQUEST) { @@ -443,17 +449,14 @@ static void rtp_start(uaudio_callback *callback, static void rtp_stop(void) { uaudio_thread_stop(); - close(rtp_fd); - rtp_fd = -1; - if(rtp_fd6 >= 0) { - close(rtp_fd6); - rtp_fd6 = -1; - } + close(rtp_fd); rtp_fd = -1; + if(rtp_fd6 >= 0) { close(rtp_fd6); rtp_fd6 = -1; } } static void rtp_configure(void) { char buffer[64]; + uaudio_set("rtp-mode", config->rtp_mode); rtp_set_netconfig("rtp-destination-af", "rtp-destination", "rtp-destination-port", &config->broadcast); @@ -484,7 +487,7 @@ int rtp_add_recipient(const struct sockaddr_storage *sa) { rc = -1; else { r = xmalloc(sizeof *r); - memcpy(&r->sa, sa, sizeof sa); + memcpy(&r->sa, sa, sizeof *sa); r->next = rtp_recipient_list; rtp_recipient_list = r; rc = 0;