@@ -5010,148 +5010,6 @@ static uint32_t vorbis_find_page(rvorbis *f, uint32_t *end, uint32_t *last)
50105010
50115011#define SAMPLE_unknown 0xffffffff
50125012
5013- /* ogg vorbis, in its insane infinite wisdom, only provides
5014- * information about the sample at the END of the page.
5015- * therefore we COULD have the data we need in the current
5016- * page, and not know it. we could just use the end location
5017- * as our only knowledge for bounds, seek back, and eventually
5018- * the binary search finds it. or we can try to be smart and
5019- * not waste time trying to locate more pages. we try to be
5020- * smart, since this data is already in memory anyway, so
5021- * doing needless I/O would be crazy!
5022- */
5023- static int vorbis_analyze_page (rvorbis * f , ProbedPage * z )
5024- {
5025- uint8_t lacing [255 ];
5026- uint8_t packet_type [255 ];
5027- int num_packet , packet_start ;
5028- int i ,len ;
5029- uint32_t samples ;
5030- uint8_t header [27 ] = {0 };
5031-
5032- /* record where the page starts */
5033- z -> page_start = (unsigned int )(f -> stream - f -> stream_start );
5034-
5035- /* parse the header */
5036- getn (f , header , 27 );
5037- assert (header [0 ] == 'O' && header [1 ] == 'g' && header [2 ] == 'g' && header [3 ] == 'S' );
5038- getn (f , lacing , header [26 ]);
5039-
5040- /* determine the length of the payload */
5041- len = 0 ;
5042- for (i = 0 ; i < header [26 ]; ++ i )
5043- len += lacing [i ];
5044-
5045- /* this implies where the page ends */
5046- z -> page_end = z -> page_start + 27 + header [26 ] + len ;
5047-
5048- /* read the last-decoded sample out of the data */
5049- z -> last_decoded_sample = header [6 ] + (header [7 ] << 8 ) + (header [8 ] << 16 ) + (header [9 ] << 24 );
5050-
5051- if (header [5 ] & 4 )
5052- {
5053- /* if this is the last page, it's not possible to work
5054- * backwards to figure out the first sample! whoops! fuck. */
5055- z -> first_decoded_sample = SAMPLE_unknown ;
5056- set_file_offset (f , z -> page_start );
5057- return 1 ;
5058- }
5059-
5060- /* scan through the frames to determine the sample-count of each one...
5061- * our goal is the sample # of the first fully-decoded sample on the
5062- * page, which is the first decoded sample of the 2nd packet */
5063-
5064- num_packet = 0 ;
5065-
5066- packet_start = ((header [5 ] & 1 ) == 0 );
5067-
5068- for (i = 0 ; i < header [26 ]; ++ i )
5069- {
5070- if (packet_start )
5071- {
5072- uint8_t n ,b ;
5073- if (lacing [i ] == 0 )
5074- goto bail ; /* trying to read from zero-length packet */
5075- n = get8 (f );
5076- /* if bottom bit is non-zero, we've got corruption */
5077- if (n & 1 )
5078- goto bail ;
5079- n >>= 1 ;
5080- b = ilog (f -> mode_count - 1 );
5081- n &= (1 << b )- 1 ;
5082- if (n >= f -> mode_count )
5083- goto bail ;
5084- packet_type [num_packet ++ ] = f -> mode_config [n ].blockflag ;
5085- skip (f , lacing [i ]- 1 );
5086- }
5087- else
5088- skip (f , lacing [i ]);
5089- packet_start = (lacing [i ] < 255 );
5090- }
5091-
5092- /* now that we know the sizes of all the pages, we can start determining
5093- * how much sample data there is. */
5094-
5095- samples = 0 ;
5096-
5097- /* for the last packet, we step by its whole length, because the definition
5098- * is that we encoded the end sample loc of the 'last packet completed',
5099- * where 'completed' refers to packets being split, and we are left to guess
5100- * what 'end sample loc' means. we assume it means ignoring the fact that
5101- * the last half of the data is useless without windowing against the next
5102- * packet... (so it's not REALLY complete in that sense)
5103- */
5104- if (num_packet > 1 )
5105- samples += f -> blocksize [packet_type [num_packet - 1 ]];
5106-
5107- for (i = num_packet - 2 ; i >= 1 ; -- i )
5108- {
5109- /* now, for this packet, how many samples do we have that
5110- * do not overlap the following packet? */
5111- if (packet_type [i ] == 1 )
5112- if (packet_type [i + 1 ] == 1 )
5113- samples += f -> blocksize_1 >> 1 ;
5114- else
5115- samples += ((f -> blocksize_1 - f -> blocksize_0 ) >> 2 ) + (f -> blocksize_0 >> 1 );
5116- else
5117- samples += f -> blocksize_0 >> 1 ;
5118- }
5119- /* now, at this point, we've rewound to the very beginning of the
5120- * _second_ packet. if we entirely discard the first packet after
5121- * a seek, this will be exactly the right sample number. HOWEVER!
5122- * we can't as easily compute this number for the LAST page. The
5123- * only way to get the sample offset of the LAST page is to use
5124- * the end loc from the previous page. But what that returns us
5125- * is _exactly_ the place where we get our first non-overlapped
5126- * sample. (I think. Stupid spec for being ambiguous.) So for
5127- * consistency it's better to do that here, too. However, that
5128- * will then require us to NOT discard all of the first frame we
5129- * decode, in some cases, which means an even weirder frame size
5130- * and extra code. what a fucking pain.
5131-
5132- * we're going to discard the first packet if we
5133- * start the seek here, so we don't care about it. (we could actually
5134- * do better; if the first packet is long, and the previous packet
5135- * is short, there's actually data in the first half of the first
5136- * packet that doesn't need discarding... but not worth paying the
5137- * effort of tracking that of that here and in the seeking logic)
5138- * except crap, if we infer it from the _previous_ packet's end
5139- * location, we DO need to use that definition... and we HAVE to
5140- * infer the start loc of the LAST packet from the previous packet's
5141- * end location. fuck you, ogg vorbis. */
5142-
5143- z -> first_decoded_sample = z -> last_decoded_sample - samples ;
5144-
5145- /* restore file state to where we were */
5146- set_file_offset (f , z -> page_start );
5147- return 1 ;
5148-
5149- /* restore file state to where we were */
5150- bail :
5151- set_file_offset (f , z -> page_start );
5152- return 0 ;
5153- }
5154-
51555013/* Latch the output pipeline (0 = float, 1 = fixed-point s16). In
51565014 * normal mixer use this runs once, on the first read; a mid-stream
51575015 * switch converts the persistent overlap state and any undelivered
0 commit comments