GetLength optimization

This commit is contained in:
Glenn Maynard
2003-10-03 23:23:28 +00:00
parent 802d8c7aff
commit 9ade4fa722
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -348,13 +348,20 @@ void fill_frame_index_cache( madlib_t *mad )
} }
/* Handle first-stage decoding: extracting the MP3 frame data. */ /* Handle first-stage decoding: extracting the MP3 frame data. */
int RageSoundReader_MP3::do_mad_frame_decode() int RageSoundReader_MP3::do_mad_frame_decode( bool headers_only )
{ {
int bytes_read = 0; int bytes_read = 0;
while(1) while(1)
{ {
if( !mad_frame_decode(&mad->Frame,&mad->Stream) ) int ret;
/* Always actually decode the first packet, so we cleanly pass Xing tags. */
if( headers_only && !mad->first_frame )
ret=mad_header_decode( &mad->Frame.header,&mad->Stream );
else
ret=mad_frame_decode( &mad->Frame,&mad->Stream );
if( !ret )
{ {
/* OK. */ /* OK. */
if( mad->first_frame ) if( mad->first_frame )
@@ -1069,10 +1076,9 @@ int RageSoundReader_MP3::GetLengthInternal( bool fast )
} }
MADLIB_rewind(); MADLIB_rewind();
/* XXX use mad_header_decode (do_mad_frame_decode(true)?) */
while(1) while(1)
{ {
int ret = do_mad_frame_decode(); int ret = do_mad_frame_decode( true );
if( ret == -1 ) if( ret == -1 )
return -1; /* it set the error */ return -1; /* it set the error */
if( ret == 0 ) /* EOF */ if( ret == 0 ) /* EOF */
+1 -1
View File
@@ -25,7 +25,7 @@ public:
int FindOffsetFix(); int FindOffsetFix();
int fill_buffer(); int fill_buffer();
int do_mad_frame_decode(); int do_mad_frame_decode( bool headers_only=false );
int resync(); int resync();
void synth_output(); void synth_output();
int seek_stream_to_byte( int byte ); int seek_stream_to_byte( int byte );