[xiph-cvs] cvs commit: vorbis-tools/vorbiscomment vcedit.c vcedit.h
Michael Smith
msmith at xiph.org
Wed Aug 15 01:33:27 PDT 2001
msmith 01/08/15 01:33:27
Modified: vorbiscomment vcedit.c vcedit.h
Log:
Write the comment header packet ourselves, not using libvorbis - we don't
want the vendor tag from the current libvorbis, we want the one present
in the original file. So this is basically a copy of a couple of functions
in info.c, so we can do this.
Patch from Warren Spits.
Revision Changes Path
1.13 +62 -2 vorbis-tools/vorbiscomment/vcedit.c
Index: vcedit.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcedit.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- vcedit.c 2001/08/12 05:02:27 1.12
+++ vcedit.c 2001/08/15 08:33:26 1.13
@@ -6,7 +6,7 @@
*
* Comment editing backend, suitable for use by nice frontend interfaces.
*
- * last modified: $Id: vcedit.c,v 1.12 2001/08/12 05:02:27 msmith Exp $
+ * last modified: $Id: vcedit.c,v 1.13 2001/08/15 08:33:26 msmith Exp $
*/
#include <stdio.h>
@@ -57,6 +57,11 @@
free(state->oy);
state->oy=NULL;
}
+ if(state->vendor)
+ {
+ free(state->vendor);
+ state->vendor=NULL;
+ }
}
void vcedit_clear(vcedit_state *state)
@@ -68,6 +73,57 @@
}
}
+/* Next two functions pulled straight from libvorbis, apart from one change
+ * - we don't want to overwrite the vendor string.
+ */
+static void _v_writestring(oggpack_buffer *o,char *s)
+{
+ while(*s)
+ {
+ oggpack_write(o,*s++,8);
+ }
+}
+
+static int _commentheader_out(vorbis_comment *vc, char *vendor, ogg_packet *op)
+{
+ oggpack_buffer opb;
+
+ oggpack_writeinit(&opb);
+
+ /* preamble */
+ oggpack_write(&opb,0x03,8);
+ _v_writestring(&opb,"vorbis");
+
+ /* vendor */
+ oggpack_write(&opb,strlen(vendor),32);
+ _v_writestring(&opb,vendor);
+
+ /* comments */
+ oggpack_write(&opb,vc->comments,32);
+ if(vc->comments){
+ int i;
+ for(i=0;i<vc->comments;i++){
+ if(vc->user_comments[i]){
+ oggpack_write(&opb,vc->comment_lengths[i],32);
+ _v_writestring(&opb,vc->user_comments[i]);
+ }else{
+ oggpack_write(&opb,0,32);
+ }
+ }
+ }
+ oggpack_write(&opb,1,1);
+
+ op->packet = _ogg_malloc(oggpack_bytes(&opb));
+ memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
+
+ op->bytes=oggpack_bytes(&opb);
+ op->b_o_s=0;
+ op->e_o_s=0;
+ op->granulepos=0;
+
+ return 0;
+}
+
static int _blocksize(vcedit_state *s, ogg_packet *p)
{
int this = vorbis_packet_blocksize(&s->vi, p);
@@ -223,6 +279,10 @@
ogg_sync_wrote(state->oy, bytes);
}
+ /* Copy the vendor tag */
+ state->vendor = malloc(strlen(state->vc->vendor) +1);
+ strcpy(state->vendor, state->vc->vendor);
+
/* Headers are done! */
return 0;
@@ -260,7 +320,7 @@
ogg_stream_init(&streamout, state->serial);
- vorbis_commentheader_out(state->vc, &header_comments);
+ _commentheader_out(state->vc, state->vendor, &header_comments);
ogg_stream_packetin(&streamout, &header_main);
ogg_stream_packetin(&streamout, &header_comments);
1.8 +1 -0 vorbis-tools/vorbiscomment/vcedit.h
Index: vcedit.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcedit.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- vcedit.h 2001/08/12 05:02:27 1.7
+++ vcedit.h 2001/08/15 08:33:26 1.8
@@ -39,6 +39,7 @@
int mainlen;
int booklen;
char *lasterror;
+ char *vendor;
int prevW;
} vcedit_state;
--- >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