[xiph-cvs] cvs commit: vorbis-tools/vorbiscomment vcedit.c vcedit.h

Michael Smith msmith at xiph.org
Wed Nov 7 04:45:04 PST 2001



msmith      01/11/07 04:45:04

  Modified:    vorbiscomment vcedit.c vcedit.h
  Log:
  Patch (from Warren Spits) to make chained files work correctly again.

Revision  Changes    Path
1.15      +35 -13    vorbis-tools/vorbiscomment/vcedit.c

Index: vcedit.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcedit.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- vcedit.c	2001/10/18 10:28:17	1.14
+++ vcedit.c	2001/11/07 12:45:03	1.15
@@ -6,7 +6,7 @@
  *
  * Comment editing backend, suitable for use by nice frontend interfaces.
  *
- * last modified: $Id: vcedit.c,v 1.14 2001/10/18 10:28:17 msmith Exp $
+ * last modified: $Id: vcedit.c,v 1.15 2001/11/07 12:45:03 msmith Exp $
  */
 
 #include <stdio.h>
@@ -140,10 +140,9 @@
         return ret;
 }
 
-static int _fetch_next_packet(vcedit_state *s, ogg_packet *p)
+static int _fetch_next_packet(vcedit_state *s, ogg_packet *p, ogg_page *page)
 {
         int result;
-	ogg_page og;
         char *buffer;
         int bytes;
 
@@ -153,7 +152,9 @@
                 return 1;
         else
         {
-		while(ogg_sync_pageout(s->oy, &og) <= 0)
+		if(s->eosin)
+			return 0;
+		while(ogg_sync_pageout(s->oy, page) <= 0)
                 {
                         buffer = ogg_sync_buffer(s->oy, CHUNKSIZE);
                         bytes = s->read(buffer,1, CHUNKSIZE, s->in);
@@ -161,9 +162,17 @@
                         if(bytes == 0) 
                                 return 0;
                 }
+		if(ogg_page_eos(page))
+			s->eosin = 1;
+		else if(ogg_page_serialno(page) != s->serial)
+		{
+			s->eosin = 1;
+			s->extrapage = 1;
+			return 0;
+		}
 
-		ogg_stream_pagein(s->os, &og);
-		return _fetch_next_packet(s, p);
+		ogg_stream_pagein(s->os, page);
+		return _fetch_next_packet(s, p, page);
         }
 }
 
@@ -299,14 +308,17 @@
         ogg_packet header_comments;
         ogg_packet header_codebooks;
 
-	ogg_page ogout;
+	ogg_page ogout, ogin;
         ogg_packet op;
         ogg_int64_t granpos = 0;
         int result;
         char *buffer;
-	int bytes, eosin=0;
+	int bytes;
         int needflush=0, needout=0;
 
+	state->eosin = 0;
+	state->extrapage = 0;
+
         header_main.bytes = state->mainlen;
         header_main.packet = state->mainbuf;
         header_main.b_o_s = 1;
@@ -337,7 +349,7 @@
                         goto cleanup;
         }
 
-	while(_fetch_next_packet(state, &op))
+	while(_fetch_next_packet(state, &op, &ogin))
         {
                 int size;
                 size = _blocksize(state, &op);
@@ -406,9 +418,19 @@
         /* FIXME: freeing this here probably leaks memory */
         /* Done with this, now */
         vorbis_info_clear(&state->vi);
+
+	if (state->extrapage)
+	{
+		if(state->write(ogin.header,1,ogin.header_len,
+		                out) != (size_t) ogin.header_len)
+			goto cleanup;
+		if (state->write(ogin.body,1,ogin.body_len, out) !=
+				(size_t) ogin.body_len)
+			goto cleanup;
+	}
 
-	eosin=0; /* clear it, because not all paths to here do */
-	while(!eosin) /* We reached eos, not eof */
+	state->eosin=0; /* clear it, because not all paths to here do */
+	while(!state->eosin) /* We reached eos, not eof */
         {
                 /* We copy the rest of the stream (other logical streams)
                  * through, a page at a time. */
@@ -435,7 +457,7 @@
                 ogg_sync_wrote(state->oy, bytes);
                 if(bytes == 0) 
                 {
-			eosin = 1;
+			state->eosin = 1;
                         break;
                 }
         }
@@ -449,7 +471,7 @@
         free(state->bookbuf);
 
         vcedit_clear_internals(state);
-	if(!eosin)
+	if(!state->eosin)
         {
                 state->lasterror =  
                         "Error writing stream to output. "

1.9       +2 -0      vorbis-tools/vorbiscomment/vcedit.h

Index: vcedit.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcedit.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- vcedit.h	2001/08/15 08:33:26	1.8
+++ vcedit.h	2001/11/07 12:45:03	1.9
@@ -41,6 +41,8 @@
         char 	    *lasterror;
         char   *vendor;
         int prevW;
+	int extrapage;
+	int eosin;
 } vcedit_state;
 
 extern vcedit_state *	vcedit_new_state(void);

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list