Add API support for unconstrained VBR
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Sun, 5 Dec 2010 22:22:06 +0000 (17:22 -0500)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Sun, 5 Dec 2010 22:22:06 +0000 (17:22 -0500)
celtenc now defaults to unconstrained VBR.

libcelt/celt.c
libcelt/celt.h
tools/celtenc.c

index c1ac116..3748721 100644 (file)
@@ -1313,6 +1313,12 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...)
          }   
       }
       break;
+      case CELT_SET_VBR_CONSTRAINT_REQUEST:
+      {
+         celt_int32 value = va_arg(ap, celt_int32);
+         st->constrained_vbr = value;
+      }
+      break;
       case CELT_SET_VBR_RATE_REQUEST:
       {
          celt_int32 value = va_arg(ap, celt_int32);
index 234f396..fddef5a 100644 (file)
@@ -95,6 +95,9 @@ extern "C" {
 #define CELT_RESET_STATE_REQUEST        8
 #define CELT_RESET_STATE       CELT_RESET_STATE_REQUEST
 
+#define CELT_SET_VBR_CONSTRAINT_REQUEST 10
+#define CELT_SET_VBR_CONSTRAINT(x)       CELT_SET_VBR_CONSTRAINT_REQUEST, _celt_check_int(x)
+
 #define CELT_SET_START_BAND_REQUEST    10000
 #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)
 
index 96f28a7..3cc0cc7 100644 (file)
@@ -255,6 +255,7 @@ int main(int argc, char **argv)
    void *st;
    unsigned char bits[MAX_FRAME_BYTES];
    int with_cbr = 0;
+   int with_cvbr = 0;
    int with_skeleton = 0;
    int total_bytes = 0;
    int peak_bytes = 0;
@@ -262,6 +263,7 @@ int main(int argc, char **argv)
    {
       {"bitrate", required_argument, NULL, 0},
       {"cbr",no_argument,NULL, 0},
+      {"cvbr",no_argument,NULL, 0},
       {"comp", required_argument, NULL, 0},
       {"noltp", no_argument, NULL, 0},
       {"independent", no_argument, NULL, 0},
@@ -328,6 +330,9 @@ int main(int argc, char **argv)
          } else if (strcmp(long_options[option_index].name,"cbr")==0)
          {
             with_cbr=1;
+         } else if (strcmp(long_options[option_index].name,"cvbr")==0)
+         {
+            with_cvbr=1;
          } else if (strcmp(long_options[option_index].name,"skeleton")==0)
          {
             with_skeleton=1;
@@ -529,7 +534,15 @@ int main(int argc, char **argv)
         fprintf (stderr, "VBR request failed\n");
         return 1;
      }
-   }     
+     if (!with_cvbr)
+     {
+        if (celt_encoder_ctl(st, CELT_SET_VBR_CONSTRAINT(0)) != CELT_OK)
+        {
+           fprintf (stderr, "VBR constraint failed\n");
+           return 1;
+        }
+     }
+   }
 
    if (celt_encoder_ctl(st, CELT_SET_PREDICTION(prediction)) != CELT_OK)
    {