[xiph-commits] r14508 - trunk/vorbis-tools/oggenc

conrad at svn.xiph.org conrad at svn.xiph.org
Thu Feb 14 03:25:23 PST 2008


Author: conrad
Date: 2008-02-14 03:25:23 -0800 (Thu, 14 Feb 2008)
New Revision: 14508

Modified:
   trunk/vorbis-tools/oggenc/skeleton.c
   trunk/vorbis-tools/oggenc/skeleton.h
Log:
skeleton.[ch]: fishead_from_ogg(), fisbone_from_ogg() now return an int
rather than a packet, so the magic check can return an error if it
doesn't match. Patch from ogg.k.ogg.k
+ Patch edited to fix memset error


Modified: trunk/vorbis-tools/oggenc/skeleton.c
===================================================================
--- trunk/vorbis-tools/oggenc/skeleton.c	2008-02-14 10:46:03 UTC (rev 14507)
+++ trunk/vorbis-tools/oggenc/skeleton.c	2008-02-14 11:25:23 UTC (rev 14508)
@@ -102,65 +102,74 @@
 }
 
 /* create a ogg_packet from a fishead_packet structure */
-ogg_packet ogg_from_fishead(fishead_packet *fp) {
+int ogg_from_fishead(fishead_packet *fp,ogg_packet *op) {
 
-    ogg_packet op;
+    if (!fp || !op) return -1;
 
-    memset(&op, 0, sizeof(op));
-    op.packet = _ogg_calloc(FISHEAD_SIZE, sizeof(unsigned char));
-    memset(op.packet, 0, FISHEAD_SIZE);
+    memset(op, 0, sizeof(*op));
+    op->packet = _ogg_calloc(FISHEAD_SIZE, sizeof(unsigned char));
+    if (!op->packet) return -1;
 
-    memcpy (op.packet, FISHEAD_IDENTIFIER, 8); /* identifier */
-    *((ogg_uint16_t*)(op.packet+8)) = _le_16 (SKELETON_VERSION_MAJOR); /* version major */
-    *((ogg_uint16_t*)(op.packet+10)) = _le_16 (SKELETON_VERSION_MINOR); /* version minor */
-    *((ogg_int64_t*)(op.packet+12)) = _le_64 (fp->ptime_n); /* presentationtime numerator */
-    *((ogg_int64_t*)(op.packet+20)) = _le_64 (fp->ptime_d); /* presentationtime denominator */
-    *((ogg_int64_t*)(op.packet+28)) = _le_64 (fp->btime_n); /* basetime numerator */
-    *((ogg_int64_t*)(op.packet+36)) = _le_64 (fp->btime_d); /* basetime denominator */
+    memset(op->packet, 0, FISHEAD_SIZE);
+
+    memcpy (op->packet, FISHEAD_IDENTIFIER, 8); /* identifier */
+    *((ogg_uint16_t*)(op->packet+8)) = _le_16 (SKELETON_VERSION_MAJOR); /* version major */
+    *((ogg_uint16_t*)(op->packet+10)) = _le_16 (SKELETON_VERSION_MINOR); /* version minor */
+    *((ogg_int64_t*)(op->packet+12)) = _le_64 (fp->ptime_n); /* presentationtime numerator */
+    *((ogg_int64_t*)(op->packet+20)) = _le_64 (fp->ptime_d); /* presentationtime denominator */
+    *((ogg_int64_t*)(op->packet+28)) = _le_64 (fp->btime_n); /* basetime numerator */
+    *((ogg_int64_t*)(op->packet+36)) = _le_64 (fp->btime_d); /* basetime denominator */
     /* TODO: UTC time, set to zero for now */
 
-    op.b_o_s = 1;   /* its the first packet of the stream */
-    op.e_o_s = 0;   /* its not the last packet of the stream */
-    op.bytes = FISHEAD_SIZE;  /* length of the packet in bytes */
+    op->b_o_s = 1;   /* its the first packet of the stream */
+    op->e_o_s = 0;   /* its not the last packet of the stream */
+    op->bytes = FISHEAD_SIZE;  /* length of the packet in bytes */
 
-    return op;
+    return 0;
 }
 
 /* create a ogg_packet from a fisbone_packet structure. 
  * call this method after the fisbone_packet is filled and all message header fields are added
  * by calling add_message_header_field method.
  */
-ogg_packet ogg_from_fisbone(fisbone_packet *fp) {
+int ogg_from_fisbone(fisbone_packet *fp,ogg_packet *op) {
 
-    ogg_packet op;
-    int packet_size = FISBONE_SIZE + fp->current_header_size;
+    int packet_size;
 
-    memset (&op, 0, sizeof (op));       
-    op.packet = _ogg_calloc (packet_size, sizeof(unsigned char));
-    memset (op.packet, 0, packet_size);
-    memcpy (op.packet, FISBONE_IDENTIFIER, 8); /* identifier */
-    *((ogg_uint32_t*)(op.packet+8)) = _le_32 (FISBONE_MESSAGE_HEADER_OFFSET); /* offset of the message header fields */
-    *((ogg_uint32_t*)(op.packet+12)) = _le_32 (fp->serial_no); /* serialno of the respective stream */
-    *((ogg_uint32_t*)(op.packet+16)) = _le_32 (fp->nr_header_packet); /* number of header packets */
-    *((ogg_int64_t*)(op.packet+20)) = _le_64 (fp->granule_rate_n); /* granulrate numerator */
-    *((ogg_int64_t*)(op.packet+28)) = _le_64 (fp->granule_rate_d); /* granulrate denominator */
-    *((ogg_int64_t*)(op.packet+36)) = _le_64 (fp->start_granule); /* start granule */
-    *((ogg_uint32_t*)(op.packet+44)) = _le_32 (fp->preroll); /* preroll, for theora its 0 */
-    *(op.packet+48) = fp->granule_shift; /* granule shift */
-    memcpy((op.packet+FISBONE_SIZE), fp->message_header_fields, fp->current_header_size);
+    if (!fp || !op) return -1;
 
-    op.b_o_s = 0;
-    op.e_o_s = 0;
-    op.bytes = packet_size; /* size of the packet in bytes */
+    packet_size = FISBONE_SIZE + fp->current_header_size;
 
-    return op;
+    memset (op, 0, sizeof (*op));       
+    op->packet = _ogg_calloc (packet_size, sizeof(unsigned char));
+    if (!op->packet) return -1;
+
+    memset (op->packet, 0, packet_size);
+    memcpy (op->packet, FISBONE_IDENTIFIER, 8); /* identifier */
+    *((ogg_uint32_t*)(op->packet+8)) = _le_32 (FISBONE_MESSAGE_HEADER_OFFSET); /* offset of the message header fields */
+    *((ogg_uint32_t*)(op->packet+12)) = _le_32 (fp->serial_no); /* serialno of the respective stream */
+    *((ogg_uint32_t*)(op->packet+16)) = _le_32 (fp->nr_header_packet); /* number of header packets */
+    *((ogg_int64_t*)(op->packet+20)) = _le_64 (fp->granule_rate_n); /* granulrate numerator */
+    *((ogg_int64_t*)(op->packet+28)) = _le_64 (fp->granule_rate_d); /* granulrate denominator */
+    *((ogg_int64_t*)(op->packet+36)) = _le_64 (fp->start_granule); /* start granule */
+    *((ogg_uint32_t*)(op->packet+44)) = _le_32 (fp->preroll); /* preroll, for theora its 0 */
+    *(op->packet+48) = fp->granule_shift; /* granule shift */
+    memcpy((op->packet+FISBONE_SIZE), fp->message_header_fields, fp->current_header_size);
+
+    op->b_o_s = 0;
+    op->e_o_s = 0;
+    op->bytes = packet_size; /* size of the packet in bytes */
+
+    return 0;
 }
 
 int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp) {
 
     ogg_packet op;
+    int ret;
 
-    op = ogg_from_fishead(fp);
+    ret = ogg_from_fishead(fp, &op);
+    if (ret<0) return ret;
     ogg_stream_packetin(os, &op);
     _ogg_free(op.packet);
 
@@ -170,8 +179,10 @@
 int add_fisbone_to_stream(ogg_stream_state *os, fisbone_packet *fp) {
 
     ogg_packet op;
+    int ret;
 
-    op = ogg_from_fisbone(fp);
+    ret = ogg_from_fisbone(fp, &op);
+    if (ret<0) return ret;
     ogg_stream_packetin(os, &op);
     _ogg_free(op.packet);
 

Modified: trunk/vorbis-tools/oggenc/skeleton.h
===================================================================
--- trunk/vorbis-tools/oggenc/skeleton.h	2008-02-14 10:46:03 UTC (rev 14507)
+++ trunk/vorbis-tools/oggenc/skeleton.h	2008-02-14 11:25:23 UTC (rev 14508)
@@ -49,8 +49,8 @@
 
 extern int add_message_header_field(fisbone_packet *fp, char *header_key, char *header_value);
 /* remember to deallocate the returned ogg_packet properly */
-extern ogg_packet ogg_from_fishead(fishead_packet *fp);
-extern ogg_packet ogg_from_fisbone(fisbone_packet *fp);
+extern int ogg_from_fishead(fishead_packet *fp,ogg_packet *op);
+extern int ogg_from_fisbone(fisbone_packet *fp,ogg_packet *op);
 extern int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp);
 extern int add_fisbone_to_stream(ogg_stream_state *os, fisbone_packet *fp);
 extern int add_eos_packet_to_stream(ogg_stream_state *os);



More information about the commits mailing list