+static void SCR_CaptureVideo_Ogg_Interleave(void)
+{
+ LOAD_FORMATSPECIFIC_OGG();
+ ogg_page pg;
+
+ if(!cls.capturevideo.soundrate)
+ {
+ while(qogg_stream_pageout(&format->to, &pg) > 0)
+ {
+ FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
+ FS_Write(cls.capturevideo.videofile, pg.body, pg.body_len);
+ }
+ return;
+ }
+
+ for(;;)
+ {
+ // first: make sure we have a page of both types
+ if(!format->videopage.len)
+ if(qogg_stream_pageout(&format->to, &pg) > 0)
+ {
+ format->videopage.len = pg.header_len + pg.body_len;
+ format->videopage.time = qtheora_granule_time(&format->ts, qogg_page_granulepos(&pg));
+ if(format->videopage.len > sizeof(format->videopage.data))
+ Host_Error("video page too long");
+ memcpy(format->videopage.data, pg.header, pg.header_len);
+ memcpy(format->videopage.data + pg.header_len, pg.body, pg.body_len);
+ }
+ if(!format->audiopage.len)
+ if(qogg_stream_pageout(&format->vo, &pg) > 0)
+ {
+ format->audiopage.len = pg.header_len + pg.body_len;
+ format->audiopage.time = qvorbis_granule_time(&format->vd, qogg_page_granulepos(&pg));
+ if(format->audiopage.len > sizeof(format->audiopage.data))
+ Host_Error("audio page too long");
+ memcpy(format->audiopage.data, pg.header, pg.header_len);
+ memcpy(format->audiopage.data + pg.header_len, pg.body, pg.body_len);
+ }
+
+ if(format->videopage.len && format->audiopage.len)
+ {
+ // output the page that ends first
+ if(format->videopage.time < format->audiopage.time)
+ {
+ FS_Write(cls.capturevideo.videofile, format->videopage.data, format->videopage.len);
+ format->videopage.len = 0;
+ }
+ else
+ {
+ FS_Write(cls.capturevideo.videofile, format->audiopage.data, format->audiopage.len);
+ format->audiopage.len = 0;
+ }
+ }
+ else
+ break;
+ }
+}
+
+static void SCR_CaptureVideo_Ogg_FlushInterleaving(void)
+{
+ LOAD_FORMATSPECIFIC_OGG();
+
+ if(cls.capturevideo.soundrate)
+ if(format->audiopage.len)
+ {
+ FS_Write(cls.capturevideo.videofile, format->audiopage.data, format->audiopage.len);
+ format->audiopage.len = 0;
+ }
+
+ if(format->videopage.len)
+ {
+ FS_Write(cls.capturevideo.videofile, format->videopage.data, format->videopage.len);
+ format->videopage.len = 0;
+ }
+}
+
+static void SCR_CaptureVideo_Ogg_EndVideo(void)