[cvs-annodex] commit (/annodex): liboggz/trunk/src/liboggz/oggz.c liboggz/trunk/src/liboggz/oggz_private.h liboggz/trunk/src/liboggz/oggz_write.c

conrad nobody at lists.annodex.net
Tue Sep 7 10:45:26 EST 2004


Update of /annodex (new revision 540)

Modified files:
   liboggz/trunk/src/liboggz/oggz.c
   liboggz/trunk/src/liboggz/oggz_private.h
   liboggz/trunk/src/liboggz/oggz_write.c

Log Message:
ensure ogg_stream flushing during oggz_flush() and oggz_close() when writing


Modified: liboggz/trunk/src/liboggz/oggz.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz.c	2004-09-07 00:43:56 UTC (rev 539)
+++ liboggz/trunk/src/liboggz/oggz.c	2004-09-07 00:45:26 UTC (rev 540)
@@ -148,6 +148,10 @@
 {
   if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
 
+  if (OGGZ_CONFIG_WRITE && (oggz->flags & OGGZ_WRITE)) {
+    oggz_write_flush (oggz);
+  }
+
   return oggz_io_flush (oggz);
 }
 
@@ -172,15 +176,15 @@
 {
   if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
 
-  oggz_vector_foreach (oggz->streams, oggz_stream_clear);
-  oggz_vector_delete (oggz->streams);
-
   if (OGGZ_CONFIG_WRITE && (oggz->flags & OGGZ_WRITE)) {
     oggz_write_close (oggz);
   } else if (OGGZ_CONFIG_READ) {
     oggz_read_close (oggz);
   }
 
+  oggz_vector_foreach (oggz->streams, oggz_stream_clear);
+  oggz_vector_delete (oggz->streams);
+
   if (oggz->file != NULL) {
     if (fclose (oggz->file) == EOF) {
       return OGGZ_ERR_SYSTEM;
@@ -188,6 +192,7 @@
   }
 
   if (oggz->io != NULL) {
+    oggz_io_flush (oggz);
     oggz_free (oggz->io);
   }
 

Modified: liboggz/trunk/src/liboggz/oggz_private.h
===================================================================
--- liboggz/trunk/src/liboggz/oggz_private.h	2004-09-07 00:43:56 UTC (rev 539)
+++ liboggz/trunk/src/liboggz/oggz_private.h	2004-09-07 00:45:26 UTC (rev 540)
@@ -196,6 +196,7 @@
 OGGZ * oggz_read_close (OGGZ * oggz);
 
 OGGZ * oggz_write_init (OGGZ * oggz);
+int oggz_write_flush (OGGZ * oggz);
 OGGZ * oggz_write_close (OGGZ * oggz);
 
 oggz_stream_t * oggz_get_stream (OGGZ * oggz, long serialno);

Modified: liboggz/trunk/src/liboggz/oggz_write.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_write.c	2004-09-07 00:43:56 UTC (rev 539)
+++ liboggz/trunk/src/liboggz/oggz_write.c	2004-09-07 00:45:26 UTC (rev 540)
@@ -56,7 +56,8 @@
 
 /* #define DEBUG */
 
-/* #define ALWAYS_FLUSH */
+/* Define to 0 or 1 */
+#define ALWAYS_FLUSH 0
 
 /* #define ZPACKET_CMP */
 
@@ -136,11 +137,30 @@
   return 0;
 }
 
+int
+oggz_write_flush (OGGZ * oggz)
+{
+  OggzWriter * writer = &oggz->x.writer;
+  ogg_stream_state * os;
+  ogg_page * og;
+  int ret = 0;
+
+  os = writer->current_stream;
+  og = &oggz->current_page;
+
+  if (os != NULL)
+    ret = ogg_stream_flush (os, og);
+
+  return ret;
+}
+
 OGGZ *
 oggz_write_close (OGGZ * oggz)
 {
   OggzWriter * writer = &oggz->x.writer;
 
+  oggz_write_flush (oggz);
+
   oggz_vector_foreach (writer->packet_queue,
 		       (OggzFunc)oggz_writer_packet_free);
   oggz_vector_delete (writer->packet_queue);
@@ -183,6 +203,10 @@
   int b_o_s, e_o_s, bos_auto;
   int strict;
 
+#ifdef DEBUG
+  printf ("oggz_write_feed: IN\n");
+#endif
+
   if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
 
   if (!(oggz->flags & OGGZ_WRITE)) {
@@ -288,6 +312,11 @@
     return -1;
   }
 
+#ifdef DEBUG
+  printf ("oggz_write_feed: enqueued packet, queue size %d\n",
+	  oggz_vector_size (writer->packet_queue));
+#endif
+
   return 0;
 }
 
@@ -328,21 +357,17 @@
   os = writer->current_stream;
   og = &oggz->current_page;
 
-#ifdef ALWAYS_FLUSH
-  ret = ogg_stream_flush (os, og);
-#else
-  if (writer->flushing) {
+  if (ALWAYS_FLUSH || writer->flushing) {
 #ifdef DEBUG
-    printf ("*** ATTEMPT FLUSH: ");
+    printf ("oggz_page_init: ATTEMPT FLUSH: ");
 #endif
-    ret = ogg_stream_flush (os, og);
+    ret = oggz_write_flush (oggz);
   } else {
 #ifdef DEBUG
-    printf ("*** ATTEMPT pageout: ");
+    printf ("oggz_page_init: ATTEMPT pageout: ");
 #endif
     ret = ogg_stream_pageout (os, og);
   }
-#endif
 
   if (ret) {
     writer->page_offset = 0;
@@ -528,7 +553,7 @@
   int cb_ret = 0, ret = 0;
 
 #ifdef DEBUG
-  printf ("make packet ...\n");
+  printf ("oggz_writer_make_packet: IN\n");
 #endif
 
   /* finished with current packet; unguard */
@@ -547,6 +572,9 @@
   if (cb_ret == 0) {
     /* dequeue and init the next packet */
     if ((next_zpacket = oggz_dequeue_packet (oggz)) == NULL) {
+#ifdef DEBUG
+      printf ("oggz_writer_make_packet: packet queue empty\n");
+#endif
       /*writer->eos = 1;*/
       ret = 0;
     } else {
@@ -722,6 +750,12 @@
   return NULL;
 }
 
+int
+oggz_write_flush (OGGZ * oggz)
+{
+  return OGGZ_ERR_DISABLED;
+}
+
 OGGZ *
 oggz_write_close (OGGZ * oggz)
 {


-- 
conrad



More information about the cvs-annodex mailing list