X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/f0bae611d313b0833cf394d258e8aab100b23567..ca8d597cd34b87e21495bafc7d667b782e3192e0:/clients/playrtp.c diff --git a/clients/playrtp.c b/clients/playrtp.c index fb897ce..d5668b7 100644 --- a/clients/playrtp.c +++ b/clients/playrtp.c @@ -294,7 +294,7 @@ static const struct option options[] = { { 0, 0, 0, 0 } }; -/** @Brief Return a new packet */ +/** @brief Return a new packet */ static struct packet *new_packet(void) { struct packet *p; @@ -481,6 +481,8 @@ static inline int contains(const struct packet *p, uint32_t timestamp) { * Must be called with @ref lock held. */ static void fill_buffer(void) { + while(nsamples) + drop_first_packet(); info("Buffering..."); while(nsamples < readahead) pthread_cond_wait(&cond, &lock); @@ -755,7 +757,10 @@ static void play_rtp(void) { info("Playing..."); /* Keep playing until the buffer empties out, or ALSA tells us to get * lost */ - while(nsamples >= minbuffer && !escape) { + while((nsamples >= minbuffer + || (nsamples > 0 + && contains(pheap_first(&packets), next_timestamp))) + && !escape) { /* Wait for ALSA to ask us for more data */ pthread_mutex_unlock(&lock); wait_alsa(); @@ -826,7 +831,9 @@ static void play_rtp(void) { if(status) fatal(0, "AudioDeviceStart: %d", (int)status); /* Wait until the buffer empties out */ - while(nsamples >= minbuffer) + while(nsamples >= minbuffer + || (nsamples > 0 + && contains(pheap_first(&packets), next_timestamp))) pthread_cond_wait(&cond, &lock); /* Stop playing for a bit until the buffer re-fills */ status = AudioDeviceStop(adid, adioproc);