static refbuf_t *get_buffer_finished (ogg_state_t *ogg_info, ogg_codec_t *codec) { vorbis_codec_t *source_vorbis = codec->specific; ogg_page page; refbuf_t *refbuf; if (ogg_stream_flush (&source_vorbis->new_os, &page) > 0) { source_vorbis->samples_in_page -= (ogg_page_granulepos (&page) - source_vorbis->prev_page_samples); source_vorbis->prev_page_samples = ogg_page_granulepos (&page); refbuf = make_refbuf_with_page (&page); DEBUG0 ("flushing page"); return refbuf; } ogg_stream_clear (&source_vorbis->new_os); ogg_stream_init (&source_vorbis->new_os, rand()); format_ogg_free_headers (ogg_info); source_vorbis->get_buffer_page = NULL; if (source_vorbis->prev_packet) source_vorbis->process_packet = process_vorbis_headers; else source_vorbis->process_packet = NULL; if (source_vorbis->initial_audio_packet == 0) source_vorbis->prev_window = 0; return NULL; }
/* routine for taking the provided page (should be a header page) and * placing it on the collection of header pages */ void format_ogg_attach_header (ogg_codec_t *codec, ogg_page *page) { ogg_state_t *ogg_info = codec->parent; refbuf_t *refbuf; if (codec->filtered) return; refbuf = make_refbuf_with_page (codec, page); if (ogg_page_bos (page)) { DEBUG0 ("attaching BOS page"); if (*ogg_info->bos_end == NULL) ogg_info->header_pages_tail = refbuf; refbuf->associated = *ogg_info->bos_end; *ogg_info->bos_end = refbuf; ogg_info->bos_end = &refbuf->associated; return; } DEBUG0 ("attaching header page"); if (ogg_info->header_pages_tail) ogg_info->header_pages_tail->associated = refbuf; ogg_info->header_pages_tail = refbuf; if (ogg_info->header_pages == NULL) ogg_info->header_pages = refbuf; }
/* Here, we just verify the page is ok and then add it to the queue */ static refbuf_t *process_midi_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page, format_plugin_t *plugin) { refbuf_t * refbuf; if (ogg_stream_pagein (&codec->os, page) < 0) { ogg_info->error = 1; return NULL; } refbuf = make_refbuf_with_page (page); return refbuf; }
static refbuf_t *get_buffer_audio (ogg_state_t *ogg_info, ogg_codec_t *codec) { refbuf_t *refbuf = NULL; ogg_page page; vorbis_codec_t *source_vorbis = codec->specific; int (*get_ogg_page)(ogg_stream_state*, ogg_page *) = ogg_stream_pageout; if (source_vorbis->samples_in_page > source_vorbis->page_samples_trigger) get_ogg_page = ogg_stream_flush; if (get_ogg_page (&source_vorbis->new_os, &page) > 0) { /* squeeze a page copy into a buffer */ source_vorbis->samples_in_page -= (ogg_page_granulepos (&page) - source_vorbis->prev_page_samples); source_vorbis->prev_page_samples = ogg_page_granulepos (&page); refbuf = make_refbuf_with_page (&page); } return refbuf; }
static refbuf_t *process_opus_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page) { refbuf_t *refbuf; if (codec->headers < 2) { ogg_packet packet; ogg_stream_pagein (&codec->os, page); while (ogg_stream_packetout (&codec->os, &packet) > 0) { /* first time around (normal case) yields comments */ codec->headers++; } /* add header page to associated list */ format_ogg_attach_header (codec, page); return NULL; } refbuf = make_refbuf_with_page (codec, page); return refbuf; }
/* routine for taking the provided page (should be a header page) and * placing it on the collection of header pages */ void format_ogg_attach_header (ogg_state_t *ogg_info, ogg_page *page) { refbuf_t *refbuf = make_refbuf_with_page (page); if (ogg_page_bos (page)) { DEBUG0 ("attaching BOS page"); if (*ogg_info->bos_end == NULL) ogg_info->header_pages_tail = refbuf; refbuf->next = *ogg_info->bos_end; *ogg_info->bos_end = refbuf; ogg_info->bos_end = &refbuf->next; return; } DEBUG0 ("attaching header page"); if (ogg_info->header_pages_tail) ogg_info->header_pages_tail->next = refbuf; ogg_info->header_pages_tail = refbuf; if (ogg_info->header_pages == NULL) ogg_info->header_pages = refbuf; }
/* Here, we just verify the page is ok and then add it to the queue */ static refbuf_t *process_flac_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page) { refbuf_t * refbuf; if (codec->headers) { ogg_packet packet; if (ogg_stream_pagein (&codec->os, page) < 0) { ogg_info->error = 1; return NULL; } while (ogg_stream_packetout (&codec->os, &packet)) { int type = packet.packet[0]; if (type == 0xFF) { codec->headers = 0; break; } if (type >= 1 && type <= 0x7E) continue; if (type >= 0x81 && type <= 0xFE) continue; ogg_info->error = 1; return NULL; } if (codec->headers) { format_ogg_attach_header (ogg_info, page); return NULL; } } refbuf = make_refbuf_with_page (page); return refbuf; }
/* no processing of pages, just wrap them up in a refbuf and pass * back for adding to the queue */ static refbuf_t *process_vorbis_passthru_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page) { return make_refbuf_with_page (page); }