+ /*
+ * Audio fifos must be initialized before sync
+ */
+ if( !job->indepth_scan )
+ {
+ // if we are doing passthru, and the input codec is not the same as the output
+ // codec, then remove this audio from the job. If we're not doing passthru and
+ // the input codec is the 'internal' ffmpeg codec, make sure that only one
+ // 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 );
+ if( ( ( audio->config.out.codec == HB_ACODEC_AC3_PASS ) && ( audio->config.in.codec != HB_ACODEC_AC3 ) ) ||
+ ( ( audio->config.out.codec == HB_ACODEC_DCA_PASS ) && ( audio->config.in.codec != HB_ACODEC_DCA ) ) )
+ {
+ hb_log( "Passthru requested and input codec is not the same as output codec for track %d",
+ audio->config.out.track );
+ hb_list_rem( title->list_audio, audio );
+ free( audio );
+ continue;
+ }
+ if( audio->config.out.codec != HB_ACODEC_AC3_PASS &&
+ audio->config.out.codec != HB_ACODEC_DCA_PASS &&
+ audio->config.out.samplerate > 48000 )
+ {
+ hb_log( "Sample rate %d not supported. Down-sampling to 48kHz.",
+ audio->config.out.samplerate );
+ audio->config.out.samplerate = 48000;
+ }
+ if( audio->config.out.codec == HB_ACODEC_AC3 &&
+ audio->config.out.bitrate > 640 )
+ {
+ hb_log( "Bitrate %d not supported. Reducing to 640Kbps.",
+ 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.
+ */
+ audio->config.out.track = i++;
+ }
+
+ int requested_mixdown = 0;
+ int best_mixdown = 0;
+ int requested_mixdown_index = 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 );
+
+ /* sense-check the current mixdown options */
+
+ /* 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 )
+ {
+ /*
+ * Mixdown wasn't specified and this is not pass-through,
+ * set a default mixdown
+ */
+ audio->config.out.mixdown = best_mixdown;
+ 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", i, 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 ( audio->config.out.mixdown > best_mixdown )
+ {
+ audio->config.out.mixdown = best_mixdown;
+ }
+ }
+
+ if ( audio->config.out.mixdown != requested_mixdown )
+ {
+ /* log the output mixdown */
+ for (j = 0; j < hb_audio_mixdowns_count; j++)
+ {
+ 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;
+ }
+ }
+ }
+
+ 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 );
+ }
+
+ }