- uaudio_schedule_synchronize();
- header.timestamp = htonl((uint32_t)uaudio_schedule_timestamp);
- int written_bytes;
- do {
- written_bytes = writev(rtp_fd, vec, 2);
- } while(written_bytes < 0 && errno == EINTR);
- if(written_bytes < 0) {
- error(errno, "error transmitting audio data");
- ++rtp_errors;
- if(rtp_errors == 10)
- fatal(0, "too many audio tranmission errors");
- return 0;
- } else
- rtp_errors /= 2; /* gradual decay */
- written_bytes -= sizeof (struct rtp_header);
- const size_t written_samples = written_bytes / uaudio_sample_size;
- uaudio_schedule_update(written_samples);
- return written_samples;
+ 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_fd : 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;