+ // EOF - mark this track as done
+ hb_buffer_close( &buf );
+ mux->eof |= ( 1 << pv->track );
+ mux->rdy |= ( 1 << pv->track );
+ }
+ else if ( ( job->pass != 0 && job->pass != 2 ) ||
+ ( mux->eof & (1 << pv->track) ) )
+ {
+ hb_buffer_close( &buf );
+ }
+ else
+ {
+ MoveToInternalFifos( pv->track, mux, buf );
+ }
+ *buf_in = NULL;
+
+ if ( ( mux->rdy & mux->allRdy ) != mux->allRdy )
+ {
+ hb_unlock( mux->mutex );
+ return HB_WORK_OK;
+ }
+
+ int more = mux->rdy;
+ // all tracks have at least 'interleave' ticks of data. Output
+ // all that we can in 'interleave' size chunks.
+ while ( ( mux->rdy & mux->allRdy ) == mux->allRdy && more )
+ {
+ more = 0;
+ for ( i = 0; i < mux->ntracks; ++i )
+ {
+ track = mux->track[i];
+ OutputTrackChunk( mux, track, mux->m );
+ if ( mf_full( track ) )
+ {
+ // If the track's fifo is still full, advance
+ // the currint interleave point and try again.
+ mux->rdy = mux->allRdy;
+ break;
+ }
+
+ // if the track is at eof or still has data that's past
+ // our next interleave point then leave it marked as rdy.
+ // Otherwise clear rdy.
+ if ( ( mux->eof & (1 << i) ) == 0 &&
+ ( track->mf.out == track->mf.in ||
+ track->mf.fifo[(track->mf.in-1) & (track->mf.flen-1)]->stop
+ < mux->pts + mux->interleave ) )
+ {
+ mux->rdy &=~ ( 1 << i );
+ }
+ if ( track->mf.out != track->mf.in )
+ {
+ more |= ( 1 << i );
+ }
+ }
+
+ // if all the tracks are at eof we're just purging their
+ // remaining data -- keep going until all internal fifos are empty.
+ if ( mux->eof == mux->allEof )