{ 0, 0, 0, 0 }
};
-/** @Brief Return a new packet */
+/** @brief Return a new packet */
static struct packet *new_packet(void) {
struct packet *p;
* 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);
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();
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);