-retry:
- xgettimeofday(&now, NULL);
- if(rtp_reactivated) {
- /* We've been deactivated for some unknown interval. We need to advance
- * rtp_timestamp to account for the dead air. */
- /* On the first run through we'll set the start time. */
- if(!rtp_timeval.tv_sec)
- rtp_timeval = now;
- /* See how much time we missed.
- *
- * This will be 0 on the first run through, in which case we'll not modify
- * anything.
- *
- * It'll be negative in the (rare) situation where the deactivation
- * interval is shorter than the last packet we sent. In this case we wait
- * for that much time and then return having sent no samples, which will
- * cause uaudio_play_thread_fn() to retry.
- *
- * In the normal case it will be positive.
- */
- const int64_t delay = tvsub_us(now, rtp_timeval); /* microseconds */
- if(delay < 0) {
- usleep(-delay);
- goto retry;
+ 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?