uint8_t *buffer = av_malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE );
int out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
unsigned char *pbuffer;
- int pos = 0, pbuffer_size;
+ int pos, pbuffer_size;
- while ( pos < buf->size )
+ while ( buf && !ret )
{
- int len;
-
- if (parser != NULL )
- {
- len = av_parser_parse2( parser, context, &pbuffer, &pbuffer_size,
- buf->data + pos, buf->size - pos,
- buf->start, buf->start, AV_NOPTS_VALUE );
- }
- else
+ pos = 0;
+ while ( pos < buf->size )
{
- pbuffer = buf->data;
- len = pbuffer_size = buf->size;
- }
- pos += len;
- if ( pbuffer_size > 0 )
- {
- AVPacket avp;
- av_init_packet( &avp );
- avp.data = pbuffer;
- avp.size = pbuffer_size;
+ int len;
- len = avcodec_decode_audio3( context, (int16_t*)buffer, &out_size, &avp );
- if ( len > 0 && context->sample_rate > 0 )
+ if (parser != NULL )
{
- info->bitrate = context->bit_rate;
- info->rate = context->sample_rate;
- info->rate_base = 1;
- info->channel_layout =
- hb_ff_layout_xlat(context->channel_layout, context->channels);
- ret = 1;
- break;
+ len = av_parser_parse2( parser, context, &pbuffer,
+ &pbuffer_size, buf->data + pos,
+ buf->size - pos, buf->start,
+ buf->start, AV_NOPTS_VALUE );
+ }
+ else
+ {
+ pbuffer = buf->data;
+ len = pbuffer_size = buf->size;
+ }
+ pos += len;
+ if ( pbuffer_size > 0 )
+ {
+ AVPacket avp;
+ av_init_packet( &avp );
+ avp.data = pbuffer;
+ avp.size = pbuffer_size;
+
+ len = avcodec_decode_audio3( context, (int16_t*)buffer,
+ &out_size, &avp );
+ if ( len > 0 && context->sample_rate > 0 )
+ {
+ info->bitrate = context->bit_rate;
+ info->rate = context->sample_rate;
+ info->rate_base = 1;
+ info->channel_layout =
+ hb_ff_layout_xlat(context->channel_layout,
+ context->channels);
+ ret = 1;
+ break;
+ }
}
}
+ buf = buf->next;
}
+
av_free( buffer );
if ( parser != NULL )
av_parser_close( parser );
static void ScanFunc( void * );
static int DecodePreviews( hb_scan_t *, hb_title_t * title );
-static void LookForAudio( hb_title_t * title, hb_buffer_t * b );
+static int LookForAudio( hb_title_t * title, hb_buffer_t * b );
static int AllAudioOK( hb_title_t * title );
static const char *aspect_to_string( double aspect )
free( audio );
continue;
}
+ if ( audio->priv.scan_cache )
+ {
+ hb_fifo_flush( audio->priv.scan_cache );
+ hb_fifo_close( &audio->priv.scan_cache );
+ }
j++;
}
vid_buf = NULL;
}
}
- else if( ! AllAudioOK( title ) )
+ else
{
- LookForAudio( title, buf_es );
+ if( ! AllAudioOK( title ) )
+ if ( !LookForAudio( title, buf_es ) )
+ buf_es = NULL;
}
if ( buf_es )
hb_buffer_close( &buf_es );
++npreviews;
skip_preview:
+ /* Make sure we found audio rates and bitrates */
+ for( j = 0; j < hb_list_count( title->list_audio ); j++ )
+ {
+ hb_audio_t * audio = hb_list_item( title->list_audio, j );
+ if ( audio->priv.scan_cache )
+ {
+ hb_fifo_flush( audio->priv.scan_cache );
+ }
+ }
if ( vid_buf )
hb_buffer_close( &vid_buf );
}
* aren't (e.g., some European DVD Teletext streams use the same IDs as US ATSC
* AC-3 audio).
*/
-static void LookForAudio( hb_title_t * title, hb_buffer_t * b )
+static int LookForAudio( hb_title_t * title, hb_buffer_t * b )
{
int i;
if( !audio || audio->config.in.bitrate != 0 )
{
/* not found or already done */
- return;
+ return 1;
}
+ if ( audio->priv.scan_cache == NULL )
+ audio->priv.scan_cache = hb_fifo_init( 16, 16 );
+
+ if ( hb_fifo_size_bytes( audio->priv.scan_cache ) >= 4096 )
+ {
+ hb_buffer_t * tmp;
+ tmp = hb_fifo_get( audio->priv.scan_cache );
+ hb_buffer_close( &tmp );
+ }
+ hb_fifo_push( audio->priv.scan_cache, b );
+
hb_work_object_t *w = hb_codec_decoder( audio->config.in.codec );
if ( w == NULL || w->bsinfo == NULL )
hb_work_info_t info;
w->audio = audio;
w->codec_param = audio->config.in.codec_param;
+ b = hb_fifo_see( audio->priv.scan_cache );
int ret = w->bsinfo( w, b, &info );
if ( ret < 0 )
{
if ( !info.bitrate )
{
/* didn't find any info */
- return;
+ return 0;
}
+ hb_fifo_flush( audio->priv.scan_cache );
+ hb_fifo_close( &audio->priv.scan_cache );
+
audio->config.in.samplerate = info.rate;
audio->config.in.bitrate = info.bitrate;
audio->config.in.channel_layout = info.channel_layout;
audio->config.lang.description );
free( w );
- return;
+ return 1;
// We get here if there's no hope of finding info on an audio bitstream,
// either because we don't have a decoder (or a decoder with a bitstream
if ( w )
free( w );
+ hb_fifo_flush( audio->priv.scan_cache );
+ hb_fifo_close( &audio->priv.scan_cache );
hb_list_rem( title->list_audio, audio );
+ return -1;
}
/*