Properly initialize the packetno field when returning header packets,
authorRalph Giles <giles@xiph.org>
Sun, 26 Jun 2005 18:36:49 +0000 (18:36 +0000)
committerRalph Giles <giles@xiph.org>
Sun, 26 Jun 2005 18:36:49 +0000 (18:36 +0000)
and start counting data packet sequence numbers with 3 instead of zero
so that all the ogg packets come out of the encoder with the same
packetno fields they would have in coming out of an Ogg file (as read by
libogg, anyway).

Previously data packets started counting from zero, and the packetno
field of the returned header packets was uninitialized.

We had two choices in resolving this. One was just to add 3 to the
vorbis_dsp_state and/or vorbis_block sequence field when writing it to
the ogg_packet packetno field. The other is to actually keep the
packetno in the internal sequence fields. I chose the later based on the
fact that this same field gets set directly from the ogg_packet packetno
on decode, so things are consistent.

svn path=/trunk/vorbis/; revision=9513

lib/block.c
lib/info.c

index c029877..d35188d 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.76 2003/12/30 11:02:22 xiphmont Exp $
+ last mod: $Id$
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -106,7 +106,7 @@ int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
       oggpack_writeinit(vbi->packetblob[i]);
     }    
   }
-  
+
   return(0);
 }
 
@@ -293,6 +293,10 @@ int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
 
   vorbis_bitrate_init(vi,&b->bms);
 
+  /* compressed audio packets start after the headers
+     with sequence number 3 */
+  v->sequence=3;
+
   return(0);
 }
 
index 007c5e1..69a5d18 100644 (file)
@@ -517,6 +517,7 @@ int vorbis_commentheader_out(vorbis_comment *vc,
   op->b_o_s=0;
   op->e_o_s=0;
   op->granulepos=0;
+  op->packetno=1;
 
   return 0;
 }
@@ -550,6 +551,7 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
   op->b_o_s=1;
   op->e_o_s=0;
   op->granulepos=0;
+  op->packetno=0;
 
   /* second header packet (comments) **********************************/
 
@@ -564,6 +566,7 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
   op_comm->b_o_s=0;
   op_comm->e_o_s=0;
   op_comm->granulepos=0;
+  op_comm->packetno=1;
 
   /* third header packet (modes/codebooks) ****************************/
 
@@ -578,6 +581,7 @@ int vorbis_analysis_headerout(vorbis_dsp_state *v,
   op_code->b_o_s=0;
   op_code->e_o_s=0;
   op_code->granulepos=0;
+  op_code->packetno=2;
 
   oggpack_writeclear(&opb);
   return(0);