X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fmuxcommon.c;h=b6b5a2a579145bbd4cd525e12a34a32c46795b4c;hb=93b82f5fb7457e2e07dcf88e8d23e1739a9b0afe;hp=43b9710e9dbee2a74b10aff15006a50ce2b2f964;hpb=87387ff8aa2eb8b2daab625b9aec25d2b94c2b79;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/muxcommon.c b/libhb/muxcommon.c index 43b9710e..b6b5a2a5 100644 --- a/libhb/muxcommon.c +++ b/libhb/muxcommon.c @@ -103,10 +103,19 @@ static void add_mux_track( hb_mux_t *mux, hb_mux_data_t *mux_data, mux->allRdy |= is_continuous << t; } -static void mf_push( hb_track_t *track, hb_buffer_t *buf ) +static void mf_push( hb_mux_t * mux, int tk, hb_buffer_t *buf ) { + hb_track_t * track = mux->track[tk]; uint32_t mask = track->mf.flen - 1; uint32_t in = track->mf.in; + + if ( ( ( in + 2 ) & mask ) == ( track->mf.out & mask ) ) + { + if ( track->mf.flen >= 256 ) + { + mux->rdy = mux->allRdy; + } + } if ( ( ( in + 1 ) & mask ) == ( track->mf.out & mask ) ) { // fifo is full - expand it to double the current size. @@ -157,13 +166,11 @@ static hb_buffer_t *mf_peek( hb_track_t *track ) static void MoveToInternalFifos( int tk, hb_mux_t *mux, hb_buffer_t * buf ) { - hb_track_t *track = mux->track[tk]; - // move all the buffers on the track's fifo to our internal // fifo so that (a) we don't deadlock in the reader and // (b) we can control how data from multiple tracks is // interleaved in the output file. - mf_push( track, buf ); + mf_push( mux, tk, buf ); if ( buf->stop >= mux->pts ) { // buffer is past our next interleave point so @@ -178,9 +185,10 @@ static void OutputTrackChunk( hb_mux_t *mux, hb_track_t *track, hb_mux_object_t while ( ( buf = mf_peek( track ) ) != NULL && buf->start < mux->pts ) { - m->mux( m, track->mux_data, mf_pull( track ) ); + buf = mf_pull( track ); track->frames += 1; track->bytes += buf->size; + m->mux( m, track->mux_data, buf ); } } @@ -281,6 +289,19 @@ void muxClose( hb_work_object_t * w ) hb_lock( mux->mutex ); if ( --mux->ref == 0 ) { + // Update state before closing muxer. Closing the muxer + // may initiate optimization which can take a while and + // we want the muxing state to be visible while this is + // happening. + if( job->pass == 0 || job->pass == 2 ) + { + /* Update the UI */ + hb_state_t state; + state.state = HB_STATE_MUXING; + state.param.muxing.progress = 0; + hb_set_state( job->h, &state ); + } + if( mux->m ) { mux->m->end( mux->m ); @@ -293,12 +314,6 @@ void muxClose( hb_work_object_t * w ) struct stat sb; uint64_t bytes_total, frames_total; - /* Update the UI */ - hb_state_t state; - state.state = HB_STATE_MUXING; - state.param.muxing.progress = 0; - hb_set_state( job->h, &state ); - if( !stat( job->file, &sb ) ) { hb_deep_log( 2, "mux: file size, %"PRId64" bytes", (uint64_t) sb.st_size ); @@ -377,6 +392,10 @@ static void mux_loop( void * _w ) } w->status = w->work( w, &buf_in, NULL ); + if( buf_in ) + { + hb_buffer_close( &buf_in ); + } } } @@ -437,8 +456,7 @@ hb_work_object_t * hb_muxer_init( hb_job_t * job ) muxer->private_data->track = mux->ntracks; muxer->fifo_in = job->fifo_mpeg4; add_mux_track( mux, job->mux_data, 1 ); - muxer->done = &job->done; - muxer->thread = hb_thread_init( muxer->name, mux_loop, muxer, HB_NORMAL_PRIORITY ); + muxer->done = &muxer->private_data->mux->done; for( i = 0; i < hb_list_count( title->list_audio ); i++ ) {