{
hb_list_t * jobs;
hb_job_t ** current_job;
- int cpu_count;
int * error;
volatile int * die;
} hb_work_t;
static void work_func();
-static void do_job( hb_job_t *, int cpu_count );
+static void do_job( hb_job_t *);
static void work_loop( void * );
+#define FIFO_UNBOUNDED 65536
+#define FIFO_UNBOUNDED_WAKE 65535
#define FIFO_LARGE 32
#define FIFO_LARGE_WAKE 16
#define FIFO_SMALL 16
/**
* Allocates work object and launches work thread with work_func.
* @param jobs Handle to hb_list_t.
- * @param cpu_count Humber of CPUs found in system.
* @param die Handle to user inititated exit indicator.
* @param error Handle to error indicator.
*/
-hb_thread_t * hb_work_init( hb_list_t * jobs, int cpu_count,
- volatile int * die, int * error, hb_job_t ** job )
+hb_thread_t * hb_work_init( hb_list_t * jobs, volatile int * die, int * error, hb_job_t ** job )
{
hb_work_t * work = calloc( sizeof( hb_work_t ), 1 );
work->jobs = jobs;
work->current_job = job;
- work->cpu_count = cpu_count;
work->die = die;
work->error = error;
job->die = work->die;
*(work->current_job) = job;
InitWorkState( job->h );
- do_job( job, work->cpu_count );
+ do_job( job );
*(work->current_job) = NULL;
}
hb_log( " + custom color matrix: %s", job->color_matrix == 1 ? "ITU Bt.601 (SD)" : "ITU Bt.709 (HD)");
break;
- case HB_MUX_AVI:
- hb_log(" + container: AVI");
- break;
-
case HB_MUX_MKV:
hb_log(" + container: Matroska (.mkv)");
break;
-
- case HB_MUX_OGM:
- hb_log(" + conttainer: Ogg Media (.ogm)");
- break;
}
if( job->chapter_markers )
}
else
{
- hb_log( " + dimensions: %d * %d -> %d * %d, crop %d/%d/%d/%d",
+ hb_log( " + dimensions: %d * %d -> %d * %d, crop %d/%d/%d/%d, mod %i",
title->width, title->height, job->width, job->height,
- job->crop[0], job->crop[1], job->crop[2], job->crop[3] );
+ job->crop[0], job->crop[1], job->crop[2], job->crop[3], job->modulus );
}
if ( job->grayscale )
job->vrate = job->vrate_base * ( (double)real_frames * 90000 / interjob->total_time );
}
+static int check_ff_audio( hb_list_t *list_audio, hb_audio_t *ff_audio )
+{
+ int i;
+
+ for( i = 0; i < hb_list_count( list_audio ); i++ )
+ {
+ hb_audio_t * audio = hb_list_item( list_audio, i );
+
+ if ( audio == ff_audio )
+ break;
+
+ if ( audio->config.in.codec == HB_ACODEC_FFMPEG &&
+ audio->id == ff_audio->id )
+ {
+ hb_list_add( audio->priv.ff_audio_list, ff_audio );
+ return 1;
+ }
+ }
+ return 0;
+}
+
/**
* Job initialization rountine.
* Initializes fifos.
* Exits loop when conversion is done and fifos are empty.
* Closes threads and frees fifos.
* @param job Handle work hb_job_t.
- * @param cpu_count number of CPUs found in system.
*/
-static void do_job( hb_job_t * job, int cpu_count )
+static void do_job( hb_job_t * job )
{
hb_title_t * title;
int i, j;
job->anamorphic.par_width >>= 1;
job->anamorphic.par_height >>= 1;
}
+ hb_reduce( &job->anamorphic.par_width, &job->anamorphic.par_height, job->anamorphic.par_width, job->anamorphic.par_height );
}
}
hb_log( "New dimensions %i * %i", job->width, job->height );
}
- if( job->mux & HB_MUX_AVI )
- {
- // The concept of variable frame rate video was a bit too advanced
- // for Microsoft so AVI doesn't support it. Since almost all dvd
- // video is VFR we have to convert it to constant frame rate to
- // put it in an AVI container. So duplicate, drop and
- // otherwise trash video frames to appease the gods of Redmond.
- job->cfr = 1;
- }
-
if ( job->cfr == 0 )
{
/* Ensure we're using "Same as source" FPS */
// audio references that audio stream since the codec context is specific to
// the audio id & multiple copies of the same stream will garble the audio
// or cause aborts.
- uint8_t aud_id_uses[MAX_STREAMS];
- memset( aud_id_uses, 0, sizeof(aud_id_uses) );
for( i = 0; i < hb_list_count( title->list_audio ); )
{
audio = hb_list_item( title->list_audio, i );
audio->config.out.bitrate );
audio->config.out.bitrate = 640;
}
- if ( audio->config.in.codec == HB_ACODEC_FFMPEG )
- {
- if ( aud_id_uses[audio->id] )
- {
- hb_log( "Multiple decodes of audio id %d, removing track %d",
- audio->id, audio->config.out.track );
- hb_list_rem( title->list_audio, audio );
- free( audio );
- continue;
- }
- ++aud_id_uses[audio->id];
- }
/* Adjust output track number, in case we removed one.
* Output tracks sadly still need to be in sequential order.
*/
}
int requested_mixdown = 0;
- int best_mixdown = 0;
int requested_mixdown_index = 0;
+ int best_mixdown = 0;
+ int requested_bitrate = 0;
+ int best_bitrate = 0;
for( i = 0; i < hb_list_count( title->list_audio ); i++ )
{
audio = hb_list_item( title->list_audio, i );
best_mixdown = hb_get_best_mixdown( audio->config.out.codec,
- audio->config.in.channel_layout );
+ audio->config.in.channel_layout, 0 );
/* sense-check the current mixdown options */
- /* log the requested mixdown */
- for (j = 0; j < hb_audio_mixdowns_count; j++) {
- if (hb_audio_mixdowns[j].amixdown == audio->config.out.mixdown) {
- requested_mixdown = audio->config.out.mixdown;
- requested_mixdown_index = j;
- }
- }
-
/* sense-check the requested mixdown */
if( audio->config.out.mixdown == 0 &&
- audio->config.out.codec != HB_ACODEC_AC3_PASS &&
- audio->config.out.codec != HB_ACODEC_DCA_PASS )
+ !( audio->config.out.codec & HB_ACODEC_PASS_FLAG ) )
{
/*
* Mixdown wasn't specified and this is not pass-through,
* set a default mixdown
*/
- audio->config.out.mixdown = best_mixdown;
+ audio->config.out.mixdown = hb_get_default_mixdown( audio->config.out.codec,
+ audio->config.in.channel_layout );
+ for (j = 0; j < hb_audio_mixdowns_count; j++)
+ {
+ if (hb_audio_mixdowns[j].amixdown == audio->config.out.mixdown)
+ {
+ hb_log("work: mixdown not specified, track %i setting mixdown %s", audio->config.out.track, hb_audio_mixdowns[j].human_readable_name);
+ break;
+ }
+ }
+ }
+
+ /* log the requested mixdown */
+ for (j = 0; j < hb_audio_mixdowns_count; j++) {
+ if (hb_audio_mixdowns[j].amixdown == audio->config.out.mixdown) {
+ requested_mixdown = audio->config.out.mixdown;
+ requested_mixdown_index = j;
+ break;
+ }
}
if ( !( audio->config.out.codec & HB_ACODEC_PASS_FLAG ) )
{
if (hb_audio_mixdowns[j].amixdown == audio->config.out.mixdown)
{
- hb_log("work: sanitizing track %i mixdown %s to %s", i, hb_audio_mixdowns[requested_mixdown_index].human_readable_name, hb_audio_mixdowns[j].human_readable_name);
- break;
+ hb_log("work: sanitizing track %i mixdown %s to %s",
+ audio->config.out.track,
+ hb_audio_mixdowns[requested_mixdown_index].human_readable_name,
+ hb_audio_mixdowns[j].human_readable_name);
+ break;
}
}
}
+
+ /* sense-check the current bitrates */
+
+ /* sense-check the requested bitrate */
+ if( audio->config.out.bitrate == 0 &&
+ !( audio->config.out.codec & HB_ACODEC_PASS_FLAG ) )
+ {
+ /*
+ * Bitrate wasn't specified and this is not pass-through,
+ * set a default bitrate
+ */
+ audio->config.out.bitrate = hb_get_default_audio_bitrate( audio->config.out.codec,
+ audio->config.out.samplerate,
+ audio->config.out.mixdown );
+
+ hb_log( "work: bitrate not specified, track %d setting bitrate %d",
+ audio->config.out.track, audio->config.out.bitrate );
+ }
+
+ /* log the requested bitrate */
+ requested_bitrate = audio->config.out.bitrate;
+ best_bitrate = hb_get_best_audio_bitrate( audio->config.out.codec,
+ audio->config.out.bitrate,
+ audio->config.out.samplerate,
+ audio->config.out.mixdown );
+
+ if ( !( audio->config.out.codec & HB_ACODEC_PASS_FLAG ) )
+ {
+ if ( audio->config.out.bitrate != best_bitrate )
+ {
+ audio->config.out.bitrate = best_bitrate;
+ }
+ }
+
+ if ( audio->config.out.bitrate != requested_bitrate )
+ {
+ /* log the output bitrate */
+ hb_log( "work: sanitizing track %d audio bitrate %d to %d",
+ audio->config.out.track, requested_bitrate,
+ audio->config.out.bitrate);
+ }
if (audio->config.out.codec == HB_ACODEC_VORBIS)
audio->priv.config.vorbis.language = audio->config.lang.simple;
/* set up the audio work structures */
- audio->priv.fifo_in = hb_fifo_init( FIFO_LARGE, FIFO_LARGE_WAKE );
audio->priv.fifo_raw = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
audio->priv.fifo_sync = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
audio->priv.fifo_out = hb_fifo_init( FIFO_LARGE, FIFO_LARGE_WAKE );
+
+ audio->priv.ff_audio_list = hb_list_init();
+ if ( audio->config.in.codec == HB_ACODEC_FFMPEG )
+ {
+ if ( !check_ff_audio( title->list_audio, audio ) )
+ {
+ audio->priv.fifo_in = hb_fifo_init( FIFO_LARGE, FIFO_LARGE_WAKE );
+ }
+ }
+ else
+ {
+ audio->priv.fifo_in = hb_fifo_init( FIFO_LARGE, FIFO_LARGE_WAKE );
+ }
}
}
/* Video decoder */
int vcodec = title->video_codec? title->video_codec : WORK_DECMPEG2;
+#if defined(USE_FF_MPEG2)
+ if (vcodec == WORK_DECMPEG2)
+ {
+ vcodec = WORK_DECAVCODECV;
+ title->video_codec_param = CODEC_ID_MPEG2VIDEO;
+ }
+#endif
hb_list_add( job->list_work, ( w = hb_get_work( vcodec ) ) );
w->codec_param = title->video_codec_param;
w->fifo_in = job->fifo_mpeg2;
if( subtitle )
{
subtitle->fifo_in = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
- subtitle->fifo_raw = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
+ // Must set capacity of the raw-FIFO to be set >= the maximum number of subtitle
+ // lines that could be decoded prior to a video frame in order to prevent the following
+ // deadlock condition:
+ // 1. Subtitle decoder blocks trying to generate more subtitle lines than will fit in the FIFO.
+ // 2. Blocks the processing of further subtitle packets read from the input stream.
+ // 3. And that blocks the processing of any further video packets read from the input stream.
+ // 4. And that blocks the sync work-object from running, which is needed to consume the subtitle lines in the raw-FIFO.
+ // Since that number is unbounded, the FIFO must be made (effectively) unbounded in capacity.
+ subtitle->fifo_raw = hb_fifo_init( FIFO_UNBOUNDED, FIFO_UNBOUNDED_WAKE );
subtitle->fifo_sync = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
subtitle->fifo_out = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
/*
* Audio Decoder Thread
*/
- if ( ( w = hb_codec_decoder( audio->config.in.codec ) ) == NULL )
+ if ( audio->priv.fifo_in )
{
- hb_error("Invalid input codec: %d", audio->config.in.codec);
- *job->die = 1;
- goto cleanup;
- }
- w->fifo_in = audio->priv.fifo_in;
- w->fifo_out = audio->priv.fifo_raw;
- w->config = &audio->priv.config;
- w->audio = audio;
- w->codec_param = audio->config.in.codec_param;
+ if ( ( w = hb_codec_decoder( audio->config.in.codec ) ) == NULL )
+ {
+ hb_error("Invalid input codec: %d", audio->config.in.codec);
+ *job->die = 1;
+ goto cleanup;
+ }
+ w->fifo_in = audio->priv.fifo_in;
+ w->fifo_out = audio->priv.fifo_raw;
+ w->config = &audio->priv.config;
+ w->audio = audio;
+ w->codec_param = audio->config.in.codec_param;
- hb_list_add( job->list_work, w );
+ hb_list_add( job->list_work, w );
+ }
/*
* Audio Encoder Thread
w = muxer;
}
+ hb_buffer_t * buf_in, * buf_out;
+
while ( !*job->die && !*w->done && w->status != HB_WORK_DONE )
{
- hb_buffer_t * buf_in, * buf_out;
-
buf_in = hb_fifo_get_wait( w->fifo_in );
if ( buf_in == NULL )
continue;
if ( hb_fifo_full_wait( w->fifo_out ) )
{
hb_fifo_push( w->fifo_out, buf_out );
+ buf_out = NULL;
break;
}
}
}
}
+ if ( buf_out )
+ {
+ hb_buffer_close( &buf_out );
+ }
+
hb_handle_t * h = job->h;
hb_state_t state;
hb_get_state( h, &state );
if ( hb_fifo_full_wait( w->fifo_out ) )
{
hb_fifo_push( w->fifo_out, buf_out );
+ buf_out = NULL;
break;
}
}
}
}
+ if ( buf_out )
+ {
+ hb_buffer_close( &buf_out );
+ }
+
// Consume data in incoming fifo till job complete so that
// residual data does not stall the pipeline
while( !*w->done )