-static void update_audio_description( const char *codec, hb_audio_t *audio,
- int is_dolby )
-{
- hb_log( "scan: %s, rate=%dHz, bitrate=%d", codec, audio->config.in.samplerate,
- audio->config.in.bitrate );
-
- /* XXX */
- if ( is_dolby )
- {
- strcat( audio->config.lang.description, " (Dolby Surround)" );
- return;
- }
-
- char *desc = audio->config.lang.description +
- strlen( audio->config.lang.description );
- sprintf( desc, " (%d.%d ch)",
- HB_INPUT_CH_LAYOUT_GET_DISCRETE_FRONT_COUNT(audio->config.in.channel_layout) +
- HB_INPUT_CH_LAYOUT_GET_DISCRETE_REAR_COUNT(audio->config.in.channel_layout),
- HB_INPUT_CH_LAYOUT_GET_DISCRETE_LFE_COUNT(audio->config.in.channel_layout));
-}
-
-static int hb_setup_a52_audio( hb_audio_t *audio, hb_buffer_t *b )
-{
- int i, rate, bitrate, flags;
-
- /* since AC3 frames don't line up with MPEG ES frames scan the
- * entire frame for an AC3 sync pattern. */
- for ( i = 0; i < b->size - 7; ++i )
- {
- if( a52_syncinfo( &b->data[i], &flags, &rate, &bitrate ) != 0 )
- {
- break;
- }
- }
- if ( i >= b->size - 7 )
- {
- /* didn't find AC3 sync */
- return 0;
- }
-
- audio->config.in.samplerate = rate;
- audio->config.in.bitrate = bitrate;
-
- switch( flags & A52_CHANNEL_MASK )
- {
- /* mono sources */
- case A52_MONO:
- case A52_CHANNEL1:
- case A52_CHANNEL2:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_MONO;
- break;
- /* stereo input */
- case A52_CHANNEL:
- case A52_STEREO:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
- break;
- /* dolby (DPL1 aka Dolby Surround = 4.0 matrix-encoded) input */
- case A52_DOLBY:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_DOLBY;
- break;
- /* 3F/2R input */
- case A52_3F2R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_3F2R;
- break;
- /* 3F/1R input */
- case A52_3F1R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_3F1R;
- break;
- /* other inputs */
- case A52_3F:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_3F;
- break;
- case A52_2F1R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_2F1R;
- break;
- case A52_2F2R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_2F2R;
- break;
- /* unknown */
- default:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
- }
-
- if (flags & A52_LFE)
- {
- audio->config.in.channel_layout |= HB_INPUT_CH_LAYOUT_HAS_LFE;
- }
-
- /* store the AC3 flags for future reference
- * This enables us to find out if we had a stereo or Dolby source later on
- * Store the ac3 flags in the public ac3flags property too, so we can access
- * it from the GUI
- */
- audio->config.flags.ac3 = audio->priv.config.a52.ac3flags = flags;
- update_audio_description( "AC3", audio, (flags & A52_CHANNEL_MASK) == A52_DOLBY );
- return 1;
-}
-
-static int hb_setup_dca_audio( hb_audio_t *audio, hb_buffer_t *b )
-{
- int i, flags, rate, bitrate, frame_length;
- dca_state_t * state = dca_init( 0 );
-
- /* since DCA frames don't line up with MPEG ES frames scan the
- * entire frame for an DCA sync pattern. */
- for ( i = 0; i < b->size - 7; ++i )
- {
- if( dca_syncinfo( state, &b->data[i], &flags, &rate, &bitrate,
- &frame_length ) )
- {
- break;
- }
- }
- if ( i >= b->size - 7 )
- {
- /* didn't find DCA sync */
- return 0;
- }
-
- audio->config.in.samplerate = rate;
- audio->config.in.bitrate = bitrate;
- switch( flags & DCA_CHANNEL_MASK )
- {
- /* mono sources */
- case DCA_MONO:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_MONO;
- break;
- /* stereo input */
- case DCA_CHANNEL:
- case DCA_STEREO:
- case DCA_STEREO_SUMDIFF:
- case DCA_STEREO_TOTAL:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
- break;
- /* 3F/2R input */
- case DCA_3F2R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_3F2R;
- break;
- /* 3F/1R input */
- case DCA_3F1R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_3F1R;
- break;
- /* other inputs */
- case DCA_3F:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_3F;
- break;
- case DCA_2F1R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_2F1R;
- break;
- case DCA_2F2R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_2F2R;
- break;
- case DCA_4F2R:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_4F2R;
- break;
- /* unknown */
- default:
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
- }
-
- if (flags & DCA_LFE)
- {
- audio->config.in.channel_layout |= HB_INPUT_CH_LAYOUT_HAS_LFE;
- }
-
- /* store the DCA flags for future reference
- * This enables us to find out if we had a stereo or Dolby source later on
- * store the dca flags in the public dcaflags property too, so we can access
- * it from the GUI
- */
- audio->config.flags.dca = audio->priv.config.dca.dcaflags = flags;
- update_audio_description( "DCA", audio, (flags & DCA_CHANNEL_MASK) == DCA_DOLBY );
- return 1;
-}
-
-static int hb_setup_pcm_audio( hb_audio_t *audio, hb_buffer_t *b )
-{
- // LPCM doesn't have a sync pattern like AC3 or DCA but every
- // LPCM elementary stream packet starts with a 7 byte header
- // giving the characteristics of the stream.
- // See libhb/declpcm.c for a description of the LPCM header.
-
- static const int hdr2samplerate[] = { 48000, 96000, 44100, 32000 };
- static const int hdr2samplesize[] = { 16, 20, 24, 16 };
- static const int hdr2layout[] = {
- HB_INPUT_CH_LAYOUT_MONO, HB_INPUT_CH_LAYOUT_STEREO,
- HB_INPUT_CH_LAYOUT_2F1R, HB_INPUT_CH_LAYOUT_2F2R,
- HB_INPUT_CH_LAYOUT_3F2R, HB_INPUT_CH_LAYOUT_4F2R,
- HB_INPUT_CH_LAYOUT_STEREO, HB_INPUT_CH_LAYOUT_STEREO,
- };
-
- int nchannels = ( b->data[4] & 7 ) + 1;
- int sample_size = hdr2samplesize[b->data[4] >> 6];
-
- int rate = hdr2samplerate[ ( b->data[4] >> 4 ) & 0x3 ];
- int bitrate = rate * sample_size * nchannels;
-
- audio->config.in.samplerate = rate;
- audio->config.in.bitrate = bitrate;
- audio->config.in.channel_layout = hdr2layout[nchannels - 1];
- update_audio_description( "LPCM", audio, 0 );
- return 1;
-}
-
-static int hb_setup_mpg_audio( hb_audio_t *audio, hb_buffer_t *b )
-{
- /* XXX
- * This is a placeholder to get the audio sample rate set.
- * It should be replaced by something that extracts the correct info from
- * the mpeg audio bitstream.
- */
- audio->config.in.samplerate = 48000;
- audio->config.in.bitrate = 384000;
- audio->config.in.channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
- update_audio_description( "MPGA", audio, 0 );
- return 1;
-}
-