+ /* Check if frame buf is available */
+ if( p_waveheader[i].dwFlags & WHDR_DONE )
+ {
+ // next_date = mdate() + 1000000 * i_queued_frames /
+ // p_aout->output.output.i_rate * p_aout->output.i_nb_samples;
+
+ // the realtime has got our back-site:) to come in sync
+ if(next_date < mdate())
+ next_date = mdate();
+
+
+ /* Take into account the latency */
+ p_buffer = aout_OutputNextBuffer( p_aout,
+ next_date,
+ b_sleek );
+
+ if(!p_buffer)
+ {
+#if 0
+ msg_Dbg( p_aout, "aout_OutputNextBuffer no buffer "\
+ "got next_date=%d ms, "\
+ "%d frames to play, "\
+ "starving? %d",(int)(next_date/(mtime_t)1000),
+ i_queued_frames,
+ p_aout->output.b_starving);
+#endif
+ if(p_aout->output.b_starving)
+ {
+ // means we are too early to request a new buffer?
+ waveout_warn("waiting...")
+ next_date = aout_FifoFirstDate( p_aout, &p_aout->output.fifo );
+ mwait( next_date - AOUT_PTS_TOLERANCE/4 );
+ next_date = mdate();
+ p_buffer = aout_OutputNextBuffer( p_aout,
+ next_date,
+ b_sleek
+ );
+ }
+ }
+
+ if( !p_buffer && i_queued_frames )
+ {
+ /* We aren't late so no need to play a blank sample */
+ break;
+ }
+
+ if( p_buffer )
+ {
+ mtime_t buffer_length = p_buffer->i_length;
+ next_date = next_date + buffer_length;
+ i_buffer_length = buffer_length/1000;
+ }
+
+ /* Do the channel reordering */
+ if( p_buffer && p_sys->b_chan_reorder )
+ {
+ aout_ChannelReorder( p_buffer->p_buffer,
+ p_buffer->i_buffer,
+ p_sys->waveformat.Format.nChannels,
+ p_sys->pi_chan_table,
+ p_sys->waveformat.Format.wBitsPerSample );
+ }
+
+ PlayWaveOut( p_aout, p_sys->h_waveout,
+ &p_waveheader[i], p_buffer, b_sleek );
+
+ i_queued_frames++;
+ }