+ const uint32_t timestamp = uaudio_schedule_sync();
+ header.timestamp = htonl(rtp_base + (uint32_t)timestamp);
+
+ /* We send ~120 packets a second with current arrangements. So if we log
+ * once every 8192 packets we log about once a minute. */
+
+ if(!(ntohs(header.seq) & 8191)
+ && config->rtp_verbose)
+ disorder_info("RTP: seq %04"PRIx16" %08"PRIx32"+%08"PRIx32"=%08"PRIx32" ns %zu%s",
+ ntohs(header.seq),
+ rtp_base,
+ timestamp,
+ header.timestamp,
+ nsamples,
+ flags & UAUDIO_PAUSED ? " [paused]" : "");
+
+ /* If we're paused don't actually end a packet, we just pretend */
+ if(flags & UAUDIO_PAUSED) {
+ uaudio_schedule_sent(nsamples);
+ return nsamples;
+ }
+ if(rtp_mode == RTP_REQUEST) {
+ struct rtp_recipient *r;
+ struct msghdr m;
+ memset(&m, 0, sizeof m);
+ m.msg_iov = vec;
+ m.msg_iovlen = 2;
+ pthread_mutex_lock(&rtp_lock);
+ for(r = rtp_recipient_list; r; r = r->next) {
+ m.msg_name = &r->sa;
+ m.msg_namelen = r->sa.ss_family == AF_INET ?
+ sizeof(struct sockaddr_in) : sizeof (struct sockaddr_in6);
+ sendmsg(r->sa.ss_family == AF_INET ? rtp_fd4 : rtp_fd6,
+ &m, MSG_DONTWAIT|MSG_NOSIGNAL);
+ // TODO similar error handling to other case?
+ }
+ pthread_mutex_unlock(&rtp_lock);
+ } else {
+ int written_bytes;
+ do {
+ written_bytes = writev(rtp_fd, vec, 2);
+ } while(written_bytes < 0 && errno == EINTR);
+ if(written_bytes < 0) {
+ disorder_error(errno, "error transmitting audio data");
+ ++rtp_errors;
+ if(rtp_errors == 10)
+ disorder_fatal(0, "too many audio transmission errors");
+ return 0;
+ } else
+ rtp_errors /= 2; /* gradual decay */
+ }
+ /* TODO what can we sensibly do about short writes here? Really that's just
+ * an error and we ought to be using smaller packets. */
+ uaudio_schedule_sent(nsamples);
+ 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);