shithub: libopusenc

Download patch

ref: bca77956e012e4df078c64a4b30512f3971392bc
parent: eeb1ee318000509938574869af185b61679053e9
author: Jean-Marc Valin <[email protected]>
date: Thu May 4 22:32:56 EDT 2017

refactor

--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -121,16 +121,6 @@
   if (err) return -1;
   length = page->header_len+page->body_len;
   if (enc->page_callback) enc->page_callback(user_data, length, 0);
-
-  {
-    unsigned char *page;
-    int len;
-    if (oggp_get_next_page(enc->oggp, &page, &len)) {
-      fwrite(page, 1, len, stdout);
-      fflush(stdout);
-    }
-  }
-
   return length;
 }
 
@@ -140,9 +130,18 @@
   int written = 0;
 
   oggp_flush_page(enc->oggp);
+  {
+    unsigned char *page;
+    int len;
+    while (oggp_get_next_page(enc->oggp, &page, &len)) {
+      fwrite(page, 1, len, stdout);
+      fflush(stdout);
+    }
+  }
 
-  while ( (ret = ogg_stream_flush(&enc->streams->os, &og)) ) {
+  while ( (ret = ogg_stream_flush_fill(&enc->streams->os, &og, 255*255))) {
     if (!ret) break;
+    if (ogg_page_packets(&og) != 0) enc->last_page_granule = ogg_page_granulepos(&og) + enc->streams->granule_offset;
     ret = oe_write_page(enc, &og, enc->streams->user_data);
     if (ret == -1) {
       return -1;
@@ -412,7 +411,18 @@
       /* FIXME: Also flush on too many segments. */
       flush_needed = op.e_o_s || enc->curr_granule - enc->last_page_granule > enc->max_ogg_delay;
       if (flush_needed) {
+#if 1
+        oe_flush_page(enc);
+#else
         oggp_flush_page(enc->oggp);
+        {
+          unsigned char *page;
+          int len;
+          while (oggp_get_next_page(enc->oggp, &page, &len)) {
+            fwrite(page, 1, len, stdout);
+            fflush(stdout);
+          }
+        }
         while (ogg_stream_flush_fill(&enc->streams->os, &og, 255*255)) {
           if (ogg_page_packets(&og) != 0) enc->last_page_granule = ogg_page_granulepos(&og) + enc->streams->granule_offset;
           int ret = oe_write_page(enc, &og, enc->streams->user_data);
@@ -419,6 +429,7 @@
           /* FIXME: what do we do if this fails? */
           assert(ret != -1);
         }
+#endif
       } else {
         while (ogg_stream_pageout_fill(&enc->streams->os, &og, 255*255)) {
           if (ogg_page_packets(&og) != 0) enc->last_page_granule = ogg_page_granulepos(&og) + enc->streams->granule_offset;