hb_buffer_t * buf;
uint8_t * data;
- /* Feed libmpeg2 */
- if( buf_es->start > -1 )
+ if ( buf_es->size )
{
- mpeg2_tag_picture( m->libmpeg2, buf_es->start >> 32,
- buf_es->start & 0xFFFFFFFF );
+ /* Feed libmpeg2 */
+ if( buf_es->start > -1 )
+ {
+ mpeg2_tag_picture( m->libmpeg2, buf_es->start >> 32,
+ buf_es->start & 0xFFFFFFFF );
+ }
+ mpeg2_buffer( m->libmpeg2, buf_es->data,
+ buf_es->data + buf_es->size );
}
- mpeg2_buffer( m->libmpeg2, buf_es->data,
- buf_es->data + buf_es->size );
for( ;; )
{
hb_libmpeg2_decode( pv->libmpeg2, *buf_in, pv->list );
+ /* if we got an empty buffer signaling end-of-stream send it downstream */
+ if ( (*buf_in)->size == 0 )
+ {
+ hb_list_add( pv->list, *buf_in );
+ *buf_in = NULL;
+ }
+
*buf_out = NULL;
while( ( buf = hb_list_item( pv->list, 0 ) ) )
{
void decmpeg2Close( hb_work_object_t * w )
{
hb_work_private_t * pv = w->private_data;
+ hb_log( "mpeg2 done: %d frames", pv->libmpeg2->nframes );
hb_list_close( &pv->list );
hb_libmpeg2_close( &pv->libmpeg2 );
free( pv );
int64_t start_silence; /* if we're inserting silence, the time we started */
int64_t first_drop; /* PTS of first 'went backwards' frame dropped */
int drop_count; /* count of 'time went backwards' drops */
- int inserting_silence;
/* Raw */
SRC_STATE * state;
return HB_WORK_DONE;
}
- if( hb_thread_has_exited( job->reader ) &&
- !hb_fifo_size( job->fifo_mpeg2 ) &&
- !hb_fifo_size( job->fifo_raw ) )
- {
- pv->done = 1;
-
- hb_buffer_t * buf_tmp;
-
- // Drop an empty buffer into our output to ensure that things
- // get flushed all the way out.
- buf_tmp = hb_buffer_init(0); // Empty end buffer
- hb_fifo_push( job->fifo_sync, buf_tmp );
-
- return HB_WORK_DONE;
- }
-
if( !pv->cur && !( pv->cur = hb_fifo_get( job->fifo_raw ) ) )
{
/* We haven't even got a frame yet */
{
hb_buffer_t * buf_tmp;
+ if( next->size == 0 )
+ {
+ // we got the empty buffer that signals end-of-stream
+ // note that we're done but continue to the end of this
+ // loop so that the final frame gets processed.
+ pv->done = 1;
+ next->start = pv->next_pts + 90*30;
+ }
+
if( pv->pts_offset == INT64_MIN )
{
/* This is our first frame */
{
hb_log( "sync: got too many frames (%d), exiting early", pv->count_frames );
pv->done = 1;
+ }
- // Drop an empty buffer into our output to ensure that things
- // get flushed all the way out.
- buf_tmp = hb_buffer_init(0); // Empty end buffer
- hb_fifo_push( job->fifo_sync, buf_tmp );
+ if ( pv->done )
+ {
+ hb_buffer_close( &pv->cur );
- break;
+ // Drop an empty buffer into our output to ensure that things
+ // get flushed all the way out.
+ hb_fifo_push( job->fifo_sync, hb_buffer_init( 0 ) );
+ return HB_WORK_DONE;
}
}
-
return HB_WORK_OK;
}
buf->start = start;
buf->stop = start + duration;
sync->next_start = start + duration;
- while( hb_fifo_is_full( fifo ) )
- {
- hb_snooze( 50 );
- if ( job->done && hb_fifo_is_full( fifo ) )
- {
- /* don't block here if the job's finished */
- hb_buffer_close( &buf );
- return;
- }
- }
hb_fifo_push( fifo, buf );
}
sync->first_drop = 0;
sync->drop_count = 0;
}
-
- if ( sync->inserting_silence && (int64_t)(buf->start - sync->next_pts) > 0 )
- {
- /*
- * if we're within one frame time of the amount of silence
- * we need, insert just what we need otherwise insert a frame time.
- */
- int64_t framedur = buf->stop - buf->start;
- if ( buf->start - sync->next_pts <= framedur )
- {
- InsertSilence( w, i, buf->start - sync->next_pts );
- sync->inserting_silence = 0;
- }
- else
- {
- InsertSilence( w, i, framedur );
- }
- continue;
- }
if ( buf->start - sync->next_pts >= (90 * 70) )
{
/*
* there's a gap of at least 70ms between the last
* frame we processed & the next. Fill it with silence.
*/
- if ( ! sync->inserting_silence )
- {
- hb_log( "sync: adding %d ms of silence to audio %d"
- " start %lld, next %lld",
- (int)((buf->start - sync->next_pts) / 90),
- i, buf->start, sync->next_pts );
- sync->inserting_silence = 1;
- }
+ hb_log( "sync: adding %d ms of silence to audio %d"
+ " start %lld, next %lld",
+ (int)((buf->start - sync->next_pts) / 90),
+ i, buf->start, sync->next_pts );
InsertSilence( w, i, buf->start - sync->next_pts );
- continue;
+ return;
}
/*
/* FIXME: This feels really hackish, anything better? */
hb_work_object_t * audio_w = NULL;
hb_work_object_t * sub_w = NULL;
+ hb_work_object_t * encoder_w = NULL;
hb_audio_t * audio;
hb_subtitle_t * subtitle;
w->config = &job->config;
hb_list_add( job->list_work, w );
+ /* remember the encoder so we can wait for it to finish */
+ encoder_w = w;
if( job->select_subtitle && !job->indepth_scan )
{
audio->priv.config.vorbis.language = audio->config.lang.simple;
/* set up the audio work structures */
- audio->priv.fifo_in = hb_fifo_init( 2048 );
+ audio->priv.fifo_in = hb_fifo_init( 256 );
audio->priv.fifo_raw = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
- audio->priv.fifo_sync = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+ audio->priv.fifo_sync = hb_fifo_init( 256 );
audio->priv.fifo_out = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
done = 1;
}
if( done &&
- !hb_fifo_size( job->fifo_sync ) &&
- !hb_fifo_size( job->fifo_render ) &&
+ encoder_w->status == HB_WORK_DONE &&
!hb_fifo_size( job->fifo_mpeg4 ) )
{
break;
}
// w->thread_sleep_interval = MAX(1, (w->thread_sleep_interval - 1));
- w->work( w, &buf_in, &buf_out );
+ w->status = w->work( w, &buf_in, &buf_out );
// Propagate any chapter breaks for the worker if and only if the
// output frame has the same time stamp as the input frame (any