Tweaks to mediaformatshaper

-- parameterize the % boost if QP is desired but not present
-- parameterize the upper bounds for where shaping is phased out
-- tuning default bits-per-pixel for AVC

Bug: 183211971
Test: video quality test scripts
Change-Id: I2e83c574e766606c50d7ed5dc26c49ba92ecb2a4
diff --git a/media/libmediaformatshaper/CodecProperties.cpp b/media/libmediaformatshaper/CodecProperties.cpp
index 315b3ec..b118af6 100644
--- a/media/libmediaformatshaper/CodecProperties.cpp
+++ b/media/libmediaformatshaper/CodecProperties.cpp
@@ -60,6 +60,13 @@
     mTargetQpMax = qpMax;
 }
 
+void CodecProperties::setMissingQpBoost(double boost) {
+    mMissingQpBoost = boost;
+}
+void CodecProperties::setPhaseOut(double phaseout) {
+    mPhaseOut = phaseout;
+}
+
 // what API is this codec set up for (e.g. API of the associated partition)
 // vendor-side (OEM) codecs may be older, due to 'vendor freeze' and treble
 int CodecProperties::supportedApi() {
@@ -134,6 +141,22 @@
             setBpp(bpp);
             legal = true;
         }
+    } else if (!strcmp(key.c_str(), "vq-bitrate-phaseout")) {
+        const char *p = value.c_str();
+        char *q;
+        double phaseout = strtod(p, &q);
+        if (q != p) {
+            setPhaseOut(phaseout);
+            legal = true;
+        }
+    } else if (!strcmp(key.c_str(), "vq-boost-missing-qp")) {
+        const char *p = value.c_str();
+        char *q;
+        double boost = strtod(p, &q);
+        if (q != p) {
+            setMissingQpBoost(boost);
+            legal = true;
+        }
     } else {
         legal = true;
     }
diff --git a/media/libmediaformatshaper/CodecProperties.h b/media/libmediaformatshaper/CodecProperties.h
index ff7051f..98ab99e 100644
--- a/media/libmediaformatshaper/CodecProperties.h
+++ b/media/libmediaformatshaper/CodecProperties.h
@@ -82,6 +82,14 @@
     void setSupportsQp(bool supported) { mSupportsQp = supported;}
     bool supportsQp() { return mSupportsQp;}
 
+    // defines our range of operation -- multiplier on the floor bitrate
+    double getPhaseOut() { return mPhaseOut; }
+    void setPhaseOut(double overageMultiplier);
+
+    // how much (0.20 = +20%) do we add if Qp is requested but unsupported
+    double getMissingQpBoost() {return mMissingQpBoost; }
+    void setMissingQpBoost(double boost);
+
     int  supportedApi();
 
     // a codec is not usable until it has been registered with its
@@ -98,6 +106,11 @@
     bool mSupportsQp = false;
     double mBpp = 0.0;
 
+    // target bitrates above floor * mPhaseOut are left untouched
+    double mPhaseOut = 1.75;
+    // 20% bump if QP is configured but it is unavailable
+    double mMissingQpBoost = 0.20;
+
     // allow different target bits-per-pixel based on resolution
     // similar to codec 'performance points'
     // uses 'next largest' (by pixel count) point as minimum bpp
diff --git a/media/libmediaformatshaper/CodecSeeding.cpp b/media/libmediaformatshaper/CodecSeeding.cpp
index 7fe1075..292b6df 100644
--- a/media/libmediaformatshaper/CodecSeeding.cpp
+++ b/media/libmediaformatshaper/CodecSeeding.cpp
@@ -49,25 +49,28 @@
  */
 
 static preloadTuning_t featuresAvc[] = {
-      // {true, "vq-target-bpp", "2.45"},
-      {true, "vq-target-bpp-1080p", "2.40"},
-      {true, "vq-target-bpp-540p", "2.60"},
+      {true, "vq-target-bpp-1080p", "1.90"},
+      {true, "vq-target-bpp-720p", "2.25"},
+      {true, "vq-target-bpp-540p", "2.65"},
       {true, "vq-target-bpp-480p", "3.00"},
       {true, "vq-target-qpmax", "40"},
+      {true, "vq-bitrate-phaseout", "1.75"},
+      {true, "vq-boost-missing-qp", "0.20"},
       {true, nullptr, 0}
 };
 
 static preloadTuning_t featuresHevc[] = {
-      // {true, "vq-target-bpp", "1.80"},
       {true, "vq-target-bpp-1080p", "1.50"},
       {true, "vq-target-bpp-720p", "1.80"},
       {true, "vq-target-bpp-540p", "2.10"},
-      // no qp for hevc, at least for now
+      {true, "vq-target-qpmax", "40"},
+      {true, "vq-bitrate-phaseout", "1.75"},
+      {true, "vq-boost-missing-qp", "0.20"},
       {true, nullptr, 0}
 };
 
 static preloadTuning_t featuresGenericVideo[] = {
-      {true, "vq-target-bpp", "2.40"},
+      {true, "vq-target-bpp", "2.00"},
       {true, nullptr, 0}
 };
 
diff --git a/media/libmediaformatshaper/VQApply.cpp b/media/libmediaformatshaper/VQApply.cpp
index 4f6a6c3..28ce43f 100644
--- a/media/libmediaformatshaper/VQApply.cpp
+++ b/media/libmediaformatshaper/VQApply.cpp
@@ -49,14 +49,6 @@
 static const int BITRATE_MODE_VBR = 1;
 
 
-// constants we use within the calculations
-//
-constexpr double BITRATE_LEAVE_UNTOUCHED = 1.75;
-
-// 20% bump if QP is configured but it is unavailable
-constexpr double BITRATE_QP_UNAVAILABLE_BOOST = 0.20;
-
-
 //
 // Caller retains ownership of and responsibility for inFormat
 //
@@ -100,7 +92,7 @@
     double minimumBpp = codec->getBpp(width, height);
 
     int64_t bitrateFloor = pixels * minimumBpp;
-    int64_t bitrateCeiling = bitrateFloor * BITRATE_LEAVE_UNTOUCHED;
+    int64_t bitrateCeiling = bitrateFloor * codec->getPhaseOut();
     if (bitrateFloor > INT32_MAX) bitrateFloor = INT32_MAX;
     if (bitrateCeiling > INT32_MAX) bitrateCeiling = INT32_MAX;
 
@@ -144,8 +136,7 @@
     // if QP is desired but not supported, compensate with additional bits
     if (!codec->supportsQp()) {
         if (qpChosen != INT32_MAX) {
-            int64_t boost = 0;
-            boost = bitrateChosen * BITRATE_QP_UNAVAILABLE_BOOST;
+            int64_t boost = bitrateChosen * codec->getMissingQpBoost();
             ALOGD("minquality: requested QP unsupported, boost bitrate %" PRId64 " by %" PRId64,
                 bitrateChosen, boost);
             bitrateChosen =  bitrateChosen + boost;
@@ -165,7 +156,7 @@
 
     if (bitrateChosen != bitrateConfigured) {
         if (bitrateChosen > bitrateCeiling) {
-            ALOGD("minquality: bitrate clamped at ceiling %" PRId64,  bitrateCeiling);
+            ALOGD("minquality: bitrate increase clamped at ceiling %" PRId64,  bitrateCeiling);
             bitrateChosen = bitrateCeiling;
         }
         ALOGD("minquality/target bitrate raised from %" PRId64 " to %" PRId64 " bps",