chiark / gitweb /
arrange for a rounder number of samples per packet
[disorder] / server / speaker.c
index c5fc668db06008aff26bfd07aa4219178a602635..c167f7b80ea85a0718b74761e0463ecae1f88ce6 100644 (file)
  *
  * Don't make this too big or arithmetic will start to overflow.
  */
-#define NETWORK_BYTES 1024
+#define NETWORK_BYTES (1024+sizeof(struct rtp_header))
 
-/** @brief Maximum RTP playahead (seconds) */
-#define RTP_AHEAD 2
+/** @brief Maximum RTP playahead (ms) */
+#define RTP_AHEAD_MS 1000
 
 /** @brief Maximum number of FDs to poll for */
 #define NFDS 256
@@ -971,9 +971,10 @@ int main(int argc, char **argv) {
         struct timeval now;
         uint64_t target_us;
         uint64_t target_rtp_time;
-        const uint64_t ahead = RTP_AHEAD * config->sample_format.rate
-          * config->sample_format.channels;
-
+        const int64_t samples_ahead = ((uint64_t)RTP_AHEAD_MS
+                                           * config->sample_format.rate
+                                           * config->sample_format.channels
+                                           / 1000);
         static unsigned logit;
 
         /* If we're starting then initialize the base time */
@@ -988,14 +989,15 @@ int main(int argc, char **argv) {
                                      * config->sample_format.channels)
 
                           / 1000000;
+#if 1
         /* TODO remove logging guff */
         if(!(logit++ & 1023))
           info("rtp_time %llu target %llu difference %lld [%lld]", 
                rtp_time, target_rtp_time,
                rtp_time - target_rtp_time,
-               ahead);
-        if(rtp_time < target_rtp_time
-           || rtp_time - target_rtp_time < ahead)
+               samples_ahead);
+#endif
+        if((int64_t)(rtp_time - target_rtp_time) < samples_ahead)
           bfd_slot = addfd(bfd, POLLOUT);
         break;
       }