[xiph-commits] r7185 - trunk/vorbis/lib

xiphmont at dactyl.lonelymoon.com xiphmont
Mon Jul 19 23:27:10 PDT 2004


Author: xiphmont
Date: Mon Jul 19 23:27:10 2004
New Revision: 7185

Modified:
trunk/vorbis/lib/bitrate.c
Log:
Fix one comment (bitrate.c no longer uses a circular packet queue)

Correct a bug-that-isn't-a-bug; the bitrate manager's setpoint gravity
code relied on subtlety that just took me a while to figure out even
though I wrote it.  Given that, I could see it causing trouble in the
future if other changes broke the subtlety, so I increased the
heavy-handed logic explicitness to bulletproof the gravity code in the
cases where there's a minimum but not a maximum and vice versa.

The only change that makes a difference: the bit reservoir is set to
the bias setpoint in initialization as opposed to always starting with
a full reservoir.  This is unrelated to above, but seemed like a good
idea.



Modified: trunk/vorbis/lib/bitrate.c
===================================================================
--- trunk/vorbis/lib/bitrate.c	2004-07-20 05:36:50 UTC (rev 7184)
+++ trunk/vorbis/lib/bitrate.c	2004-07-20 06:27:09 UTC (rev 7185)
@@ -25,7 +25,7 @@
#include "misc.h"
#include "bitrate.h"

-/* compute bitrate tracking setup, allocate circular packet size queue */
+/* compute bitrate tracking setup  */
void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
codec_setup_info *ci=vi->codec_setup;
bitrate_manager_info *bi=&ci->bi;
@@ -45,6 +45,14 @@

bm->avgfloat=PACKETBLOBS/2;

+    /* not a necessary fix, but one that leads to a more balanced
+       typical initialization */
+    {
+      long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
+      bm->minmax_reservoir=desired_fill;
+      bm->avg_reservoir=desired_fill;
+    }
+
}
}

@@ -80,7 +88,7 @@
long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
if(!bm->managed){
/* not a bitrate managed stream, but for API simplicity, we'll
-       buffer one packet to keep the code path clean */
+       buffer the packet to keep the code path clean */

if(bm->vb)return(-1); /* one has been submitted without
being claimed */
@@ -193,11 +201,19 @@
}else{
/* inbetween; we want to take reservoir toward but not past desired_fill */
if(bm->minmax_reservoir>desired_fill){
-	bm->minmax_reservoir+=(this_bits-max_target_bits);
-	if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
+	if(max_target_bits>0){ /* logical bulletproofing against initialization state */
+	  bm->minmax_reservoir+=(this_bits-max_target_bits);
+	  if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
+	}else{
+	  bm->minmax_reservoir=desired_fill;
+	}
}else{
-	bm->minmax_reservoir+=(this_bits-min_target_bits);
-	if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
+	if(min_target_bits>0){ /* logical bulletproofing against initialization state */
+	  bm->minmax_reservoir+=(this_bits-min_target_bits);
+	  if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
+	}else{
+	  bm->minmax_reservoir=desired_fill;
+	}
}
}
}
@@ -211,6 +227,7 @@
return(0);
}

+#include <stdio.h>
int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
private_state         *b=vd->backend_state;
bitrate_manager_state *bm=&b->bms;
@@ -224,6 +241,8 @@
if(vorbis_bitrate_managed(vb))
choice=bm->choice;

+    fprintf(stderr,"%d ",choice);
+
op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
op->bytes=oggpack_bytes(vbi->packetblob[choice]);
op->b_o_s=0;



More information about the commits mailing list