[xiph-cvs] cvs commit: speex/libspeex speex_header.c speex_header.h

Jean-Marc Valin jm at xiph.org
Mon Jan 13 14:29:42 PST 2003



jm          03/01/13 17:29:42

  Modified:    src      speexdec.c
               libspeex speex_header.c speex_header.h
  Log:
  slightly changed the header format (still compatible)

Revision  Changes    Path
1.72      +16 -8     speex/src/speexdec.c

Index: speexdec.c
===================================================================
RCS file: /usr/local/cvsroot/speex/src/speexdec.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- speexdec.c	10 Jan 2003 07:27:54 -0000	1.71
+++ speexdec.c	13 Jan 2003 22:29:41 -0000	1.72
@@ -256,7 +256,7 @@
    printf ("Copyright (C) 2002 Jean-Marc Valin\n");
 }
 
-static void *process_header(ogg_packet *op, int enh_enabled, int *frame_size, int *rate, int *nframes, int forceMode, int *channels, SpeexStereoState *stereo)
+static void *process_header(ogg_packet *op, int enh_enabled, int *frame_size, int *rate, int *nframes, int forceMode, int *channels, SpeexStereoState *stereo, int *extra_headers)
 {
    void *st;
    SpeexMode *mode;
@@ -282,6 +282,12 @@
       modeID = forceMode;
    mode = speex_mode_list[modeID];
    
+   if (header->speex_version_id != 1)
+   {
+      fprintf (stderr, "This file was encoded with Speex bit-stream version %d, which I don't know how to decode\n", header->speex_version_id);
+      return NULL;
+   }
+
    if (mode->bitstream_version < header->mode_bitstream_version)
    {
       fprintf (stderr, "The file was encoded with a newer version of Speex. You need to upgrade in order to play it.\n");
@@ -342,6 +348,8 @@
    /*fprintf (stderr, "Decoding %d Hz audio at %d bps using %s mode\n", 
     *rate, mode->bitrate, mode->modeName);*/
 
+   *extra_headers = header->extra_headers;
+
    free(header);
    return st;
 }
@@ -392,6 +400,7 @@
    SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT;
    int channels=-1;
    int rate=0;
+   int extra_headers;
 
    enh_enabled = 1;
 
@@ -537,20 +546,19 @@
             /*If first packet, process as Speex header*/
             if (packet_count==0)
             {
-               st = process_header(&op, enh_enabled, &frame_size, &rate, &nframes, forceMode, &channels, &stereo);
+               st = process_header(&op, enh_enabled, &frame_size, &rate, &nframes, forceMode, &channels, &stereo, &extra_headers);
                if (!nframes)
                   nframes=1;
                if (!st)
                   exit(1);
                fout = out_file_open(outFile, rate, &channels);
 
-            } else if (packet_count==1){
+            } else if (packet_count==1)
+            {
                print_comments((char*)op.packet, op.bytes);
-               /*
-               fprintf (stderr, "File comments: ");
-               fwrite(op.packet, 1, op.bytes, stderr);
-               fprintf (stderr, "\n");
-               */
+            } else if (packet_count<=1+extra_headers)
+            {
+               /* Ignore extra headers */
             } else {
                
                int lost=0;

<p><p>1.12      +9 -7      speex/libspeex/speex_header.c

Index: speex_header.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_header.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- speex_header.c	11 Jan 2003 01:32:52 -0000	1.11
+++ speex_header.c	13 Jan 2003 22:29:41 -0000	1.12
@@ -46,7 +46,7 @@
 typedef struct SpeexHeader {
    char speex_string[8];
    char speex_version[SPEEX_HEADER_VERSION_LENGTH];
-   int speex_header_version;
+   int speex_version_id;
    int header_size;
    int rate;
    int mode;
@@ -56,9 +56,9 @@
    int frame_size;
    int vbr;
    int frames_per_packet;
+   int extra_headers;
    int reserved1;
    int reserved2;
-   int reserved3;
 } SpeexHeader;
 */
 
@@ -78,7 +78,7 @@
    for (;i<SPEEX_HEADER_VERSION_LENGTH;i++)
       header->speex_version[i]=0;
    
-   header->speex_header_version = SPEEX_HEADER_VERSION;
+   header->speex_version_id = 1;
    header->header_size = sizeof(SpeexHeader);
    
    header->rate = rate;
@@ -105,7 +105,7 @@
    speex_move(le_header, header, sizeof(SpeexHeader));
    
    /*Make sure everything is now little-endian*/
-   ENDIAN_SWITCH(le_header->speex_header_version);
+   ENDIAN_SWITCH(le_header->speex_version_id);
    ENDIAN_SWITCH(le_header->header_size);
    ENDIAN_SWITCH(le_header->rate);
    ENDIAN_SWITCH(le_header->mode);
@@ -115,6 +115,7 @@
    ENDIAN_SWITCH(le_header->frame_size);
    ENDIAN_SWITCH(le_header->vbr);
    ENDIAN_SWITCH(le_header->frames_per_packet);
+   ENDIAN_SWITCH(le_header->extra_headers);
 
    *size = sizeof(SpeexHeader);
    return (char *)le_header;
@@ -133,9 +134,9 @@
       }
    
    /*FIXME: Do we allow larger headers?*/
-   if (sizeof(SpeexHeader) != size)
+   if (size < sizeof(SpeexHeader))
    {
-      speex_warning("Speex header size mismarch");
+      speex_warning("Speex header too small");
       return NULL;
    }
    
@@ -144,7 +145,7 @@
    speex_move(le_header, packet, sizeof(SpeexHeader));
    
    /*Make sure everything is converted correctly from little-endian*/
-   ENDIAN_SWITCH(le_header->speex_header_version);
+   ENDIAN_SWITCH(le_header->speex_version_id);
    ENDIAN_SWITCH(le_header->header_size);
    ENDIAN_SWITCH(le_header->rate);
    ENDIAN_SWITCH(le_header->mode);
@@ -154,6 +155,7 @@
    ENDIAN_SWITCH(le_header->frame_size);
    ENDIAN_SWITCH(le_header->vbr);
    ENDIAN_SWITCH(le_header->frames_per_packet);
+   ENDIAN_SWITCH(le_header->extra_headers);
 
    return le_header;
 

<p><p>1.14      +1 -4      speex/libspeex/speex_header.h

Index: speex_header.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_header.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- speex_header.h	11 Jan 2003 01:24:46 -0000	1.13
+++ speex_header.h	13 Jan 2003 22:29:41 -0000	1.14
@@ -46,14 +46,11 @@
 /** Maximum number of characters for encoding the Speex version number in the header */
 #define SPEEX_HEADER_VERSION_LENGTH 20
 
-/** Current version of the Speex header */
-#define SPEEX_HEADER_VERSION 1
-
 /** Speex header info for file-based formats */
 typedef struct SpeexHeader {
    char speex_string[8];       /**< Identifies a Speex bit-stream, always set to "Speex   " */
    char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */
-   int speex_header_version;   /**< Version number for the header */
+   int speex_version_id;       /**< Version for Speex (for checking compatibility) */
    int header_size;            /**< Total size of the header ( sizeof(SpeexHeader) ) */
    int rate;                   /**< Sampling rate used */
    int mode;                   /**< Mode used (0 for narrowband, 1 for wideband) */

<p><p>--- >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