OSDN Git Service

LinGui: make Help->Guide work on windows/mingw
[handbrake-jp/handbrake-jp-git.git] / libhb / muxcommon.c
index a5ee9b0..b6b5a2a 100644 (file)
@@ -185,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 );
     }
 }
 
@@ -288,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 );
@@ -300,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 );
@@ -384,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 );
+        }
     }
 }
 
@@ -444,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++ )
     {