Better tuning hooks for mediaformatshaper
more appropriate "<Tuning .../>" in Codec XML to indicate parameters.
enhance per-mediatype default configurations.
Bug: 183211971
Test: logcat examination
Test: atest XMLParserTest
Change-Id: Ieb04ef7b0322fe8a9029b9023dabdd93959e17a2
diff --git a/media/libmediaformatshaper/CodecProperties.cpp b/media/libmediaformatshaper/CodecProperties.cpp
index d733c57..961f676 100644
--- a/media/libmediaformatshaper/CodecProperties.cpp
+++ b/media/libmediaformatshaper/CodecProperties.cpp
@@ -19,6 +19,7 @@
#include <utils/Log.h>
#include <string>
+#include <stdlib.h>
#include <media/formatshaper/CodecProperties.h>
@@ -63,17 +64,12 @@
ALOGD("setFeatureValue(%s,%d)", key.c_str(), value);
mFeatures.insert({key, value});
- if (!strcmp(key.c_str(), "vq-minimum-quality")) {
- setSupportedMinimumQuality(value);
- } else if (!strcmp(key.c_str(), "vq-supports-qp")) { // key from prototyping
+ if (!strcmp(key.c_str(), "qp-bounds")) { // official key
setSupportsQp(1);
- } else if (!strcmp(key.c_str(), "qp-bounds")) { // official key
+ } else if (!strcmp(key.c_str(), "vq-supports-qp")) { // key from prototyping
setSupportsQp(1);
- } else if (!strcmp(key.c_str(), "vq-target-qpmax")) {
- setTargetQpMax(value);
- } else if (!strcmp(key.c_str(), "vq-target-bppx100")) {
- double bpp = value / 100.0;
- setBpp(bpp);
+ } else if (!strcmp(key.c_str(), "vq-minimum-quality")) {
+ setSupportedMinimumQuality(1);
}
}
@@ -90,6 +86,63 @@
return false;
}
+// Tuning values (which differ from Features)
+// this is where we set up things like target bitrates and QP ranges
+// NB the tuning values arrive as a string, allowing us to convert it into an appropriate
+// format (int, float, ranges, other combinations)
+//
+void CodecProperties::setTuningValue(std::string key, std::string value) {
+ ALOGD("setTuningValue(%s,%s)", key.c_str(), value.c_str());
+ mTunings.insert({key, value});
+
+ bool legal = false;
+ // NB: old school strtol() because std::stoi() throws exceptions
+ if (!strcmp(key.c_str(), "vq-target-qpmax")) {
+ const char *p = value.c_str();
+ char *q;
+ int32_t iValue = strtol(p, &q, 0);
+ if (q != p) {
+ setTargetQpMax(iValue);
+ legal = true;
+ }
+ } else if (!strcmp(key.c_str(), "vq-target-bpp")) {
+ const char *p = value.c_str();
+ char *q;
+ double bpp = strtod(p, &q);
+ if (q != p) {
+ setBpp(bpp);
+ legal = true;
+ }
+ } else if (!strcmp(key.c_str(), "vq-target-bppx100")) {
+ const char *p = value.c_str();
+ char *q;
+ int32_t iValue = strtol(p, &q, 0);
+ if (q != p) {
+ double bpp = iValue / 100.0;
+ setBpp(bpp);
+ legal = true;
+ }
+ } else {
+ legal = true;
+ }
+
+ if (!legal) {
+ ALOGW("setTuningValue() unable to apply tuning '%s' with value '%s'",
+ key.c_str(), value.c_str());
+ }
+ return;
+}
+
+bool CodecProperties::getTuningValue(std::string key, std::string &value) {
+ ALOGV("getTuningValue(%s)", key.c_str());
+ auto mapped = mFeatures.find(key);
+ if (mapped != mFeatures.end()) {
+ value = mapped->second;
+ return true;
+ }
+ return false;
+}
+
std::string CodecProperties::getMapping(std::string key, std::string kind) {
ALOGV("getMapping(key %s, kind %s )", key.c_str(), kind.c_str());