-
- // The following 'while' is the main muxing loop.
-
- int thread_sleep_interval = 50;
- while( !*job->die )
- {
- MoveToInternalFifos( mux );
- if ( ( mux->rdy & mux->allRdy ) != mux->allRdy )
- {
- hb_snooze( thread_sleep_interval );
- continue;
- }
-
- // 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 )
- {
- for ( i = 0; i < mux->ntracks; ++i )
- {
- if ( mux->rdy & (1 << i) )
- {
- track = mux->track[i];
- OutputTrackChunk( mux, track, m );
-
- // 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 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 )
- {
- for ( i = 0; i < mux->ntracks; ++i )
- {
- if ( mux->track[i]->mf.out != mux->track[i]->mf.in )
- {
- break;
- }
- }
- if ( i >= mux->ntracks )
- {
- goto finished;
- }
- }
- mux->pts += mux->interleave;
- }
+ w = hb_get_work( WORK_MUX );
+ w->private_data = calloc( sizeof( hb_work_private_t ), 1 );
+ w->private_data->job = job;
+ w->private_data->mux = mux;
+ mux->ref++;
+ w->private_data->track = mux->ntracks;
+ w->fifo_in = audio->priv.fifo_out;
+ add_mux_track( mux, audio->priv.mux_data, 1 );
+ w->done = &job->done;
+ hb_list_add( job->list_work, w );
+ w->thread = hb_thread_init( w->name, mux_loop, w, HB_NORMAL_PRIORITY );