FastLED 3.9.15
Loading...
Searching...
No Matches

◆ is_whole_packet_present()

static int32_t fl::third_party::vorbis::is_whole_packet_present ( stb_vorbis * f)
static

Definition at line 3249 of file stb_vorbis.cpp.hpp.

3250{
3251 // make sure that we have the packet available before continuing...
3252 // this requires a full ogg parse, but we know we can fetch from f->stream
3253
3254 // instead of coding this out explicitly, we could save the current read state,
3255 // read the next packet with get8() until end-of-packet, check f->eof, then
3256 // reset the state? but that would be slower, esp. since we'd have over 256 bytes
3257 // of state to restore (primarily the page segment table)
3258
3259 int32_t s = f->next_seg, first = true;
3260 uint8 *p = f->stream;
3261
3262 if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag
3263 for (; s < f->segment_count; ++s) {
3264 p += f->segments[s];
3265 if (f->segments[s] < 255) // stop at first short segment
3266 break;
3267 }
3268 // either this continues, or it ends it...
3269 if (s == f->segment_count)
3270 s = -1; // set 'crosses page' flag
3271 if (p > f->stream_end) return error(f, VORBIS_need_more_data);
3272 first = false;
3273 }
3274 for (; s == -1;) {
3275 uint8 *q;
3276 int32_t n;
3277
3278 // check that we have the page header ready
3279 if (p + 26 >= f->stream_end) return error(f, VORBIS_need_more_data);
3280 // validate the page
3281 if (memcmp(p, ogg_page_header, 4)) return error(f, VORBIS_invalid_stream);
3282 if (p[4] != 0) return error(f, VORBIS_invalid_stream);
3283 if (first) { // the first segment must NOT have 'continued_packet', later ones MUST
3284 if (f->previous_length)
3285 if ((p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream);
3286 // if no previous length, we're resynching, so we can come in on a continued-packet,
3287 // which we'll just drop
3288 } else {
3289 if (!(p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream);
3290 }
3291 n = p[26]; // segment counts
3292 q = p+27; // q points to segment table
3293 p = q + n; // advance past header
3294 // make sure we've read the segment table
3295 if (p > f->stream_end) return error(f, VORBIS_need_more_data);
3296 for (s=0; s < n; ++s) {
3297 p += q[s];
3298 if (q[s] < 255)
3299 break;
3300 }
3301 if (s == n)
3302 s = -1; // set 'crosses page' flag
3303 if (p > f->stream_end) return error(f, VORBIS_need_more_data);
3304 first = false;
3305 }
3306 return true;
3307}
static int32_t error(vorb *f, enum STBVorbisError e) FL_NOEXCEPT
static uint8 ogg_page_header[4]
int memcmp(const void *s1, const void *s2, size_t n) FL_NOEXCEPT
static constexpr uint8_t PAGEFLAG_continued_packet
fl::i32 int32_t
Definition coder.h:220
fl::i32 int32_t
Definition s16x16x4.h:220

References error(), FL_NOEXCEPT, memcmp(), ogg_page_header, PAGEFLAG_continued_packet, VORBIS_invalid_stream, and VORBIS_need_more_data.

Referenced by start_decoder(), and stb_vorbis_decode_frame_pushdata().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: