- // 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;
- }
- }
-
- // we're all done muxing -- print final stats and cleanup.
-finished:
- if( job->pass == 0 || job->pass == 2 )
- {
- struct stat sb;
- uint64_t bytes_total, frames_total;
-
-#define p state.param.muxing
- /* Update the UI */
- hb_state_t state;
- state.state = HB_STATE_MUXING;
- p.progress = 0;
- hb_set_state( job->h, &state );
-#undef p
- if( m )
- {
- m->end( m );
- }
-
- if( !stat( job->file, &sb ) )
- {
- hb_deep_log( 2, "mux: file size, %lld bytes", (uint64_t) sb.st_size );
-
- bytes_total = 0;
- frames_total = 0;
- for( i = 0; i < mux->ntracks; ++i )
- {
- track = mux->track[i];
- hb_log( "mux: track %d, %lld frames, %lld bytes, %.2f kbps, fifo %d",
- i, track->frames, track->bytes,
- 90000.0 * track->bytes / mux->pts / 125,
- track->mf.flen );
- if( !i && ( job->vquality < 0.0 || job->vquality > 1.0 ) )
- {
- /* Video */
- hb_deep_log( 2, "mux: video bitrate error, %+lld bytes",
- track->bytes - mux->pts * job->vbitrate *
- 125 / 90000 );
- }
- bytes_total += track->bytes;
- frames_total += track->frames;
- }
-
- if( bytes_total && frames_total )
- {
- hb_deep_log( 2, "mux: overhead, %.2f bytes per frame",
- (float) ( sb.st_size - bytes_total ) /
- frames_total );
- }
- }
+ 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 = subtitle->fifo_out;
+ add_mux_track( mux, subtitle->mux_data, 0 );
+ w->done = &job->done;
+ hb_list_add( job->list_work, w );
+ w->thread = hb_thread_init( w->name, mux_loop, w, HB_NORMAL_PRIORITY );