From 599cad7733718c75f405fd691a13dc2796045b2f Mon Sep 17 00:00:00 2001 From: Timothy B. Terriberry Date: Sun, 18 Sep 2011 12:38:06 -0700 Subject: [PATCH] Don't flush pages just because we have no packets. Previously, liboggz flushed the end of a page as soon as the packet queue ran dry. This worked fine when using the hungry callback, but when using a more traditional oggz_write_feed(...); while(oggz_write(...)>0); write loop, this would result in every packet on its own page. This patch stops doing this flushing, and now only flushes on EOF (which libogg should handle for us anyway). --- src/examples/write-feed.c | 2 +- src/liboggz/oggz_write.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/examples/write-feed.c b/src/examples/write-feed.c index 7898313..ade2bbd 100644 --- a/src/examples/write-feed.c +++ b/src/examples/write-feed.c @@ -81,7 +81,7 @@ main (int argc, char * argv[]) /* Feed it to the Oggz packet queue */ - oggz_write_feed (oggz, &op, serialno, OGGZ_FLUSH_AFTER, NULL); + oggz_write_feed (oggz, &op, serialno, 0, NULL); granulepos += 100; diff --git a/src/liboggz/oggz_write.c b/src/liboggz/oggz_write.c index ca6a1ec..8c60a16 100644 --- a/src/liboggz/oggz_write.c +++ b/src/liboggz/oggz_write.c @@ -645,8 +645,9 @@ oggz_writer_make_packet (OGGZ * oggz) #ifdef DEBUG printf ("oggz_writer_make_packet: packet queue empty\n"); #endif - /*writer->eos = 1;*/ } else { + /* We believe the eos value */ + writer->eos = next_zpacket->op.e_o_s; if ((writer->current_stream != NULL) && (next_zpacket->flush & OGGZ_FLUSH_BEFORE)) { writer->flushing = 1; @@ -718,7 +719,7 @@ oggz_write_output (OGGZ * oggz, unsigned char * buf, long n) printf ("oggz_write_output: no packets (cb_ret is %d)\n", cb_ret); #endif if (cb_ret == OGGZ_WRITE_EMPTY) { - writer->flushing = 1; + if (writer->eos) writer->flushing = 1; writer->no_more_packets = 1; } /* At this point, in contrast to oggz_write(), we break out of this @@ -836,10 +837,13 @@ oggz_write (OGGZ * oggz, long n) * the writing code below. */ if (cb_ret == OGGZ_WRITE_EMPTY) { + if (writer->eos) { #ifdef DEBUG - printf ("oggz_write: Inferred end of data, forcing a page flush.\n"); + printf ( + "oggz_write: Inferred end of data, forcing a page flush.\n"); #endif - writer->flushing = 1; + writer->flushing = 1; + } writer->no_more_packets = 1; cb_ret = OGGZ_CONTINUE; } else { -- 1.7.1