static stream_processor * find_stream_processor (stream_set *set, ogg_page *page) { uint32_t serial = ogg_page_serialno (page) ; int i, invalid = 0 ; stream_processor *stream ; for (i = 0 ; i < set->used ; i++) { if (serial == set->streams [i].serial) { /* We have a match! */ stream = & (set->streams [i]) ; set->in_headers = 0 ; /* if we have detected EOS, then this can't occur here. */ if (stream->end) { stream->isillegal = 1 ; return stream ; } stream->isnew = 0 ; stream->end = ogg_page_eos (page) ; stream->serial = serial ; return stream ; } ; } ; /* If there are streams open, and we've reached the end of the ** headers, then we can't be starting a new stream. ** XXX: might this sometimes catch ok streams if EOS flag is missing, ** but the stream is otherwise ok? */ if (streams_open (set) && !set->in_headers) invalid = 1 ; set->in_headers = 1 ; if (set->allocated < set->used) stream = &set->streams [set->used] ; else { set->allocated += 5 ; set->streams = realloc (set->streams, sizeof (stream_processor) * set->allocated) ; stream = &set->streams [set->used] ; } ; set->used++ ; stream->isnew = 1 ; stream->isillegal = invalid ; { int res ; ogg_packet packet ; /* We end up processing the header page twice, but that's ok. */ ogg_stream_init (&stream->ostream, serial) ; ogg_stream_pagein (&stream->ostream, page) ; res = ogg_stream_packetout (&stream->ostream, &packet) ; if (res <= 0) return NULL ; else if (packet.bytes >= 7 && memcmp (packet.packet, "\x01vorbis", 7) == 0) { stream->lastgranulepos = 0 ; vorbis_comment_init (&stream->vcomment) ; vorbis_info_init (&stream->vinfo) ; } ; res = ogg_stream_packetout (&stream->ostream, &packet) ; /* re-init, ready for processing */ ogg_stream_clear (&stream->ostream) ; ogg_stream_init (&stream->ostream, serial) ; } stream->end = ogg_page_eos (page) ; stream->serial = serial ; return stream ; } /* find_stream_processor */
static stream_processor *find_stream_processor(stream_set *set, ogg_page *page) { ogg_uint32_t serial = ogg_page_serialno(page); int i, found = 0; int invalid = 0; int constraint = 0; stream_processor *stream; for(i=0; i < set->used; i++) { if(serial == set->streams[i].serial) { /* We have a match! */ found = 1; stream = &(set->streams[i]); set->in_headers = 0; /* if we have detected EOS, then this can't occur here. */ if(stream->end) { stream->isillegal = 1; stream->constraint_violated = CONSTRAINT_PAGE_AFTER_EOS; return stream; } stream->isnew = 0; stream->start = ogg_page_bos(page); stream->end = ogg_page_eos(page); stream->serial = serial; return stream; } } /* If there are streams open, and we've reached the end of the * headers, then we can't be starting a new stream. * XXX: might this sometimes catch ok streams if EOS flag is missing, * but the stream is otherwise ok? */ if(streams_open(set) && !set->in_headers) { constraint = CONSTRAINT_MUXING_VIOLATED; invalid = 1; } set->in_headers = 1; if(set->allocated < set->used) stream = &set->streams[set->used]; else { set->allocated += 5; set->streams = realloc(set->streams, sizeof(stream_processor)* set->allocated); stream = &set->streams[set->used]; } set->used++; stream->num = set->used; /* We count from 1 */ stream->isnew = 1; stream->isillegal = invalid; stream->constraint_violated = constraint; { int res; ogg_packet packet; /* We end up processing the header page twice, but that's ok. */ ogg_stream_init(&stream->os, serial); ogg_stream_pagein(&stream->os, page); res = ogg_stream_packetout(&stream->os, &packet); if(res <= 0) { DPRINTF(E_WARN, L_SCAN, "Invalid header page, no packet found\n"); null_start(stream); } else if(packet.bytes >= 7 && memcmp(packet.packet, "\001vorbis", 7)==0) vorbis_start(stream); else if(packet.bytes >= 8 && memcmp(packet.packet, "OggMIDI\0", 8)==0) other_start(stream, "MIDI"); else other_start(stream, NULL); res = ogg_stream_packetout(&stream->os, &packet); if(res > 0) { DPRINTF(E_WARN, L_SCAN, "Invalid header page in stream %d, " "contains multiple packets\n", stream->num); } /* re-init, ready for processing */ ogg_stream_clear(&stream->os); ogg_stream_init(&stream->os, serial); } stream->start = ogg_page_bos(page); stream->end = ogg_page_eos(page); stream->serial = serial; /* if(stream->serial == 0 || stream->serial == -1) { info(_("Note: Stream %d has serial number %d, which is legal but may " "cause problems with some tools."), stream->num, stream->serial); }*/ return stream; }