[xiph-commits] r9197 - trunk/theora/lib

tterribe at motherfish-iii.xiph.org tterribe at motherfish-iii.xiph.org
Sun May 1 11:53:44 PDT 2005


Author: tterribe
Date: 2005-05-01 11:53:43 -0700 (Sun, 01 May 2005)
New Revision: 9197

Modified:
   trunk/theora/lib/misc_common.c
Log:
Avoid division by zero in RegulateQ when there are no coded blocks.


Modified: trunk/theora/lib/misc_common.c
===================================================================
--- trunk/theora/lib/misc_common.c	2005-05-01 02:30:06 UTC (rev 9196)
+++ trunk/theora/lib/misc_common.c	2005-05-01 18:53:43 UTC (rev 9197)
@@ -230,25 +230,27 @@
 }
 
 void RegulateQ( CP_INSTANCE *cpi, ogg_int32_t UpdateScore ) {
-  double TargetUnitScoreBytes = (double)cpi->ThisFrameTargetBytes /
-    (double)UpdateScore;
   double PredUnitScoreBytes;
-  double LastBitError = 10000.0;       /* Silly high number */
   ogg_uint32_t QIndex = Q_TABLE_SIZE - 1;
   ogg_uint32_t i;
 
-  /* Search for the best Q for the target bitrate. */
-  for ( i = 0; i < Q_TABLE_SIZE; i++ ) {
-    PredUnitScoreBytes = GetEstimatedBpb( cpi, cpi->pb.QThreshTable[i] );
-    if ( PredUnitScoreBytes > TargetUnitScoreBytes ) {
-      if ( (PredUnitScoreBytes - TargetUnitScoreBytes) <= LastBitError ) {
-        QIndex = i;
+  if ( UpdateScore > 0 ) {
+    double TargetUnitScoreBytes = (double)cpi->ThisFrameTargetBytes /
+      (double)UpdateScore;
+    double LastBitError = 10000.0;       /* Silly high number */
+    /* Search for the best Q for the target bitrate. */
+    for ( i = 0; i < Q_TABLE_SIZE; i++ ) {
+      PredUnitScoreBytes = GetEstimatedBpb( cpi, cpi->pb.QThreshTable[i] );
+      if ( PredUnitScoreBytes > TargetUnitScoreBytes ) {
+        if ( (PredUnitScoreBytes - TargetUnitScoreBytes) <= LastBitError ) {
+          QIndex = i;
+        } else {
+          QIndex = i - 1;
+        }
+        break;
       } else {
-        QIndex = i - 1;
+        LastBitError = TargetUnitScoreBytes - PredUnitScoreBytes;
       }
-      break;
-    } else {
-      LastBitError = TargetUnitScoreBytes - PredUnitScoreBytes;
     }
   }
 



More information about the commits mailing list