[xiph-commits] r14012 - trunk/theora/examples

giles at svn.xiph.org giles at svn.xiph.org
Thu Oct 18 09:59:02 PDT 2007


Author: giles
Date: 2007-10-18 09:59:02 -0700 (Thu, 18 Oct 2007)
New Revision: 14012

Modified:
   trunk/theora/examples/png2theora.c
Log:
Properly drain the page queue after encoding a frame and properly flush 
the queue at the end of the file. Thanks to Jim Mayer for pointing out
the cause of this bug.


Modified: trunk/theora/examples/png2theora.c
===================================================================
--- trunk/theora/examples/png2theora.c	2007-10-18 14:32:30 UTC (rev 14011)
+++ trunk/theora/examples/png2theora.c	2007-10-18 16:59:02 UTC (rev 14012)
@@ -132,22 +132,24 @@
     fwrite(og.header, og.header_len, 1, ogg_fp);
     fwrite(og.body, og.body_len, 1, ogg_fp);
   }
+  /* libogg flushes automatically after the first header */
 
   theora_comment_init(&tc);
   theora_encode_comment(&tc, &op);
   ogg_stream_packetin(&ogg_os, &op);
-  if(ogg_stream_pageout(&ogg_os, &og)) {
+  while(ogg_stream_pageout(&ogg_os, &og)) {
     fwrite(og.header, og.header_len, 1, ogg_fp);
     fwrite(og.body, og.body_len, 1, ogg_fp);
   }
 
   theora_encode_tables(&theora_td, &op);
   ogg_stream_packetin(&ogg_os, &op);
-  if(ogg_stream_pageout(&ogg_os, &og)) {
+  while(ogg_stream_pageout(&ogg_os, &og)) {
     fwrite(og.header, og.header_len, 1, ogg_fp);
     fwrite(og.body, og.body_len, 1, ogg_fp);
   }
 
+  /* flush at the end of the headers */
   if(ogg_stream_flush(&ogg_os, &og)) {
     fwrite(og.header, og.header_len, 1, ogg_fp);
     fwrite(og.body, og.body_len, 1, ogg_fp);
@@ -234,7 +236,7 @@
   }
 
   ogg_stream_packetin(&ogg_os, &op);
-  if(ogg_stream_pageout(&ogg_os, &og)) {
+  while(ogg_stream_pageout(&ogg_os, &og)) {
     fwrite(og.header, og.header_len, 1, ogg_fp);
     fwrite(og.body, og.body_len, 1, ogg_fp);
   }
@@ -254,10 +256,14 @@
 
   if (theora_initialized) {
     theora_encode_packetout(&theora_td, 1, &op);
-    if(ogg_stream_pageout(&ogg_os, &og)) {
+    while(ogg_stream_pageout(&ogg_os, &og)) {
       fwrite(og.header, og.header_len, 1, ogg_fp);
       fwrite(og.body, og.body_len, 1, ogg_fp);
     }
+    if(ogg_stream_flush(&ogg_os, &og)) {
+      fwrite(og.header, og.header_len, 1, ogg_fp);
+      fwrite(og.body, og.body_len, 1, ogg_fp);
+    }
   
     theora_info_clear(&theora_ti);
     theora_clear(&theora_td);



More information about the commits mailing list