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

ivo at svn.xiph.org ivo at svn.xiph.org
Fri Feb 1 11:02:07 PST 2008


Author: ivo
Date: 2008-02-01 11:02:05 -0800 (Fri, 01 Feb 2008)
New Revision: 14443

Modified:
   trunk/vorbis-tools/oggenc/skeleton.c
   trunk/vorbis-tools/oggenc/skeleton.h
Log:
Applied patch by Vincent Penquerc'h that fixes an off by one bug in the use of snprintf.  Cleaned up some useless whitespace as well.

Modified: trunk/vorbis-tools/oggenc/skeleton.c
===================================================================
--- trunk/vorbis-tools/oggenc/skeleton.c	2008-02-01 17:02:34 UTC (rev 14442)
+++ trunk/vorbis-tools/oggenc/skeleton.c	2008-02-01 19:02:05 UTC (rev 14443)
@@ -1,134 +1,133 @@
-/* 
- * skeleton.c 
- * author: Tahseen Mohammad 
- */ 
- 
-#include <stdlib.h> 
-#include <string.h> 
-#include <stdio.h> 
+/*
+ * skeleton.c
+ * author: Tahseen Mohammad
+ */
 
-#include <ogg/ogg.h> 
- 
-#include "skeleton.h" 
- 
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <ogg/ogg.h>
+
+#include "skeleton.h"
+
 int add_message_header_field(fisbone_packet *fp,
                                         char *header_key,
-                                        char *header_value) { 
- 
-    /* size of both key and value + ': ' + CRLF */ 
-    int this_message_size = strlen(header_key) + strlen(header_value) + 4; 
-    if (fp->message_header_fields == NULL) { 
-        fp->message_header_fields = _ogg_calloc(this_message_size, sizeof(char)); 
-    } else { 
-        int new_size = (fp->current_header_size + this_message_size) * sizeof(char); 
-        fp->message_header_fields = _ogg_realloc(fp->message_header_fields, new_size); 
-    } 
-    snprintf(fp->message_header_fields + fp->current_header_size,  
-                this_message_size+1,  
-                "%s: %s\r\n",  
-                header_key,  
-                header_value); 
-    fp->current_header_size += this_message_size; 
- 
-    return 0; 
-} 
- 
-/* create a ogg_packet from a fishead_packet structure */ 
-ogg_packet ogg_from_fishead(fishead_packet *fp) { 
- 
+                                        char *header_value) {
+
+    /* size of both key and value + ': ' + CRLF */
+    int this_message_size = strlen(header_key) + strlen(header_value) + 4;
+    if (fp->message_header_fields == NULL) {
+        fp->message_header_fields = _ogg_calloc(this_message_size+1, sizeof(char));
+    } else {
+        int new_size = (fp->current_header_size + this_message_size+1) * sizeof(char);
+        fp->message_header_fields = _ogg_realloc(fp->message_header_fields, new_size);
+    }
+    snprintf(fp->message_header_fields + fp->current_header_size,
+                this_message_size,
+                "%s: %s\r\n",
+                header_key,
+                header_value);
+    fp->current_header_size += this_message_size;
+
+    return 0;
+}
+
+/* create a ogg_packet from a fishead_packet structure */
+ogg_packet ogg_from_fishead(fishead_packet *fp) {
+
     ogg_packet op;
- 
+
     memset(&op, 0, sizeof(op));
-    op.packet = _ogg_calloc(FISHEAD_SIZE, sizeof(unsigned char)); 
-    memset(op.packet, 0, FISHEAD_SIZE); 
- 
-    memcpy (op.packet, FISHEAD_IDENTIFIER, 8); /* identifier */ 
-    *((ogg_uint16_t*)(op.packet+8)) = SKELETON_VERSION_MAJOR; /* version major */ 
-    *((ogg_uint16_t*)(op.packet+10)) = SKELETON_VERSION_MINOR; /* version minor */ 
-    *((ogg_int64_t*)(op.packet+12)) = (ogg_int64_t)fp->ptime_n; /* presentationtime numerator */ 
-    *((ogg_int64_t*)(op.packet+20)) = (ogg_int64_t)fp->ptime_d; /* presentationtime denominator */ 
-    *((ogg_int64_t*)(op.packet+28)) = (ogg_int64_t)fp->btime_n; /* basetime numerator */ 
-    *((ogg_int64_t*)(op.packet+36)) = (ogg_int64_t)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.packet = _ogg_calloc(FISHEAD_SIZE, sizeof(unsigned char));
+    memset(op.packet, 0, FISHEAD_SIZE);
+
+    memcpy (op.packet, FISHEAD_IDENTIFIER, 8); /* identifier */
+    *((ogg_uint16_t*)(op.packet+8)) = SKELETON_VERSION_MAJOR; /* version major */
+    *((ogg_uint16_t*)(op.packet+10)) = SKELETON_VERSION_MINOR; /* version minor */
+    *((ogg_int64_t*)(op.packet+12)) = (ogg_int64_t)fp->ptime_n; /* presentationtime numerator */
+    *((ogg_int64_t*)(op.packet+20)) = (ogg_int64_t)fp->ptime_d; /* presentationtime denominator */
+    *((ogg_int64_t*)(op.packet+28)) = (ogg_int64_t)fp->btime_n; /* basetime numerator */
+    *((ogg_int64_t*)(op.packet+36)) = (ogg_int64_t)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 */
+
     return op;
-} 
- 
-/* 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) { 
- 
-    ogg_packet op; 
-    int packet_size = FISBONE_SIZE + fp->current_header_size; 
- 
+}
+
+/* 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) {
+
+    ogg_packet op;
+    int packet_size = FISBONE_SIZE + fp->current_header_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 */ 
+    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)) = FISBONE_MESSAGE_HEADER_OFFSET; /* offset of the message header fields */
-    *((ogg_uint32_t*)(op.packet+12)) = fp->serial_no; /* serialno of the respective stream */ 
-    *((ogg_uint32_t*)(op.packet+16)) = fp->nr_header_packet; /* number of header packets */ 
-    *((ogg_int64_t*)(op.packet+20)) = fp->granule_rate_n; /* granulrate numerator */ 
-    *((ogg_int64_t*)(op.packet+28)) = fp->granule_rate_d; /* granulrate denominator */ 
-    *((ogg_int64_t*)(op.packet+36)) = fp->start_granule; /* start granule */ 
-    *((ogg_uint32_t*)(op.packet+44)) = 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 */ 
- 
+    *((ogg_uint32_t*)(op.packet+12)) = fp->serial_no; /* serialno of the respective stream */
+    *((ogg_uint32_t*)(op.packet+16)) = fp->nr_header_packet; /* number of header packets */
+    *((ogg_int64_t*)(op.packet+20)) = fp->granule_rate_n; /* granulrate numerator */
+    *((ogg_int64_t*)(op.packet+28)) = fp->granule_rate_d; /* granulrate denominator */
+    *((ogg_int64_t*)(op.packet+36)) = fp->start_granule; /* start granule */
+    *((ogg_uint32_t*)(op.packet+44)) = 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 op;
-} 
- 
-int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp) { 
- 
-    ogg_packet op; 
- 
-    op = ogg_from_fishead(fp); 
-    ogg_stream_packetin(os, &op); 
-    _ogg_free(op.packet); 
- 
-    return 0; 
-} 
- 
-int add_fisbone_to_stream(ogg_stream_state *os, fisbone_packet *fp) { 
- 
-    ogg_packet op; 
- 
-    op = ogg_from_fisbone(fp); 
-    ogg_stream_packetin(os, &op); 
+}
+
+int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp) {
+
+    ogg_packet op;
+
+    op = ogg_from_fishead(fp);
+    ogg_stream_packetin(os, &op);
     _ogg_free(op.packet);
- 
-    return 0; 
-} 
- 
-int add_eos_packet_to_stream(ogg_stream_state *os) { 
- 
-    ogg_packet op; 
- 
-    memset (&op, 0, sizeof(op)); 
-    op.e_o_s = 1; 
-    ogg_stream_packetin(os, &op); 
-} 
- 
-int flush_ogg_stream_to_file(ogg_stream_state *os, FILE *out) { 
- 
-    ogg_page og; 
-    int result, ret; 
- 
-    while((result = ogg_stream_flush(os, &og))) 
-    { 
-        if(!result) break; 
-        result = oe_write_page(&og, out); 
-        if(result != og.header_len + og.body_len) 
-            return 1; 
-    } 
+
+    return 0;
+}
+
+int add_fisbone_to_stream(ogg_stream_state *os, fisbone_packet *fp) {
+
+    ogg_packet op;
+
+    op = ogg_from_fisbone(fp);
+    ogg_stream_packetin(os, &op);
+    _ogg_free(op.packet);
+
+    return 0;
+}
+
+int add_eos_packet_to_stream(ogg_stream_state *os) {
+
+    ogg_packet op;
+
+    memset (&op, 0, sizeof(op));
+    op.e_o_s = 1;
+    ogg_stream_packetin(os, &op);
+}
+
+int flush_ogg_stream_to_file(ogg_stream_state *os, FILE *out) {
+
+    ogg_page og;
+    int result, ret;
+
+    while((result = ogg_stream_flush(os, &og))) {
+        if(!result) break;
+        result = oe_write_page(&og, out);
+        if(result != og.header_len + og.body_len)
+            return 1;
+    }
 }
\ No newline at end of file

Modified: trunk/vorbis-tools/oggenc/skeleton.h
===================================================================
--- trunk/vorbis-tools/oggenc/skeleton.h	2008-02-01 17:02:34 UTC (rev 14442)
+++ trunk/vorbis-tools/oggenc/skeleton.h	2008-02-01 19:02:05 UTC (rev 14443)
@@ -1,63 +1,63 @@
-/* 
- * skeleton.h 
- * author: Tahseen Mohammad 
- */ 
- 
-#ifndef _SKELETON_H 
-#define _SKELETON_H 
- 
-#ifdef __cplusplus 
-extern "C" { 
-#endif 
- 
-#include <ogg/ogg.h> 
- 
-#define SKELETON_VERSION_MAJOR 3 
-#define SKELETON_VERSION_MINOR 0 
-#define FISHEAD_IDENTIFIER "fishead\0" 
-#define FISBONE_IDENTIFIER "fisbone\0" 
-#define FISHEAD_SIZE 64 
-#define FISBONE_SIZE 52 
-#define FISBONE_MESSAGE_HEADER_OFFSET 44 
- 
-/* fishead_packet holds a fishead header packet. */ 
-typedef struct { 
-    /* Start time of the presentation. 
-     * For a new stream presentationtime & basetime is same. */ 
-    ogg_int64_t ptime_n;                                    /* presentation time numerator */ 
-    ogg_int64_t ptime_d;                                    /* presentation time denominator */ 
-    ogg_int64_t btime_n;                                    /* basetime numerator */ 
-    ogg_int64_t btime_d;                                    /* basetime denominator */ 
-    /* will holds the time of origin of the stream, a 20 bit field. */ 
-    unsigned char UTC[20]; 
-} fishead_packet; 
- 
-/* fisbone_packet holds a fisbone header packet. */ 
-typedef struct { 
-    ogg_uint32_t serial_no;                                 /* serial no of the corresponding stream */ 
-    ogg_uint32_t nr_header_packet;                      /* number of header packets */ 
-    /* granule rate is the temporal resolution of the logical bitstream */ 
-    ogg_int64_t granule_rate_n;                            /* granule rate numerator */ 
-    ogg_int64_t granule_rate_d;                            /* granule rate denominator */ 
-    ogg_int64_t start_granule;                             /* start granule value */ 
-    ogg_uint32_t preroll;                                   /* preroll */ 
-    unsigned char granule_shift; // a 8-bit field           /* 1 byte value holding the granule shift */ 
-    char *message_header_fields;                            /* holds all the message header fields */ 
-    /* current total size of the message header fields, for realloc purpose, initially zero */ 
-    ogg_uint32_t current_header_size; 
-} fisbone_packet; 
- 
-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 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); 
-extern int flush_ogg_stream_to_file(ogg_stream_state *os, FILE *out); 
- 
-#ifdef __cplusplus 
-} 
-#endif 
- 
-#endif  /* _SKELETON_H */
\ No newline at end of file
+/*
+ * skeleton.h
+ * author: Tahseen Mohammad
+ */
+
+#ifndef _SKELETON_H
+#define _SKELETON_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ogg/ogg.h>
+
+#define SKELETON_VERSION_MAJOR 3
+#define SKELETON_VERSION_MINOR 0
+#define FISHEAD_IDENTIFIER "fishead\0"
+#define FISBONE_IDENTIFIER "fisbone\0"
+#define FISHEAD_SIZE 64
+#define FISBONE_SIZE 52
+#define FISBONE_MESSAGE_HEADER_OFFSET 44
+
+/* fishead_packet holds a fishead header packet. */
+typedef struct {
+    /* Start time of the presentation.
+     * For a new stream presentationtime & basetime is same. */
+    ogg_int64_t ptime_n;                                    /* presentation time numerator */
+    ogg_int64_t ptime_d;                                    /* presentation time denominator */
+    ogg_int64_t btime_n;                                    /* basetime numerator */
+    ogg_int64_t btime_d;                                    /* basetime denominator */
+    /* will holds the time of origin of the stream, a 20 bit field. */
+    unsigned char UTC[20];
+} fishead_packet;
+
+/* fisbone_packet holds a fisbone header packet. */
+typedef struct {
+    ogg_uint32_t serial_no;                                 /* serial no of the corresponding stream */
+    ogg_uint32_t nr_header_packet;                      /* number of header packets */
+    /* granule rate is the temporal resolution of the logical bitstream */
+    ogg_int64_t granule_rate_n;                            /* granule rate numerator */
+    ogg_int64_t granule_rate_d;                            /* granule rate denominator */
+    ogg_int64_t start_granule;                             /* start granule value */
+    ogg_uint32_t preroll;                                   /* preroll */
+    unsigned char granule_shift; // a 8-bit field           /* 1 byte value holding the granule shift */
+    char *message_header_fields;                            /* holds all the message header fields */
+    /* current total size of the message header fields, for realloc purpose, initially zero */
+    ogg_uint32_t current_header_size;
+} fisbone_packet;
+
+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 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);
+extern int flush_ogg_stream_to_file(ogg_stream_state *os, FILE *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* _SKELETON_H */



More information about the commits mailing list