Port AudioCapabilities to native.
This is the first step of porting AudioCapabilities to native.
This commit only implement AudioCapabilities in native. JNI and Java layer are not changed. This implementation is not called by any Java API.
Test: atest AudioCapsAacTest AudioCapsRawTest
Bug: b/306023029
Change-Id: I27a464c2b084a92548d85ad7f4c422d7449c7b2c
diff --git a/media/libmedia/CodecCapabilitiesUtils.cpp b/media/libmedia/CodecCapabilitiesUtils.cpp
index 7f1463e..edfc9be 100644
--- a/media/libmedia/CodecCapabilitiesUtils.cpp
+++ b/media/libmedia/CodecCapabilitiesUtils.cpp
@@ -20,6 +20,7 @@
#include <algorithm>
#include <cmath>
+#include <regex>
#include <string>
#include <vector>
@@ -29,4 +30,24 @@
namespace android {
+std::optional<Range<int>> ParseIntRange(const std::string &str) {
+ if (str.empty()) {
+ ALOGW("could not parse empty integer range");
+ return std::nullopt;
+ }
+ int lower, upper;
+ std::regex regex("([0-9]+)-([0-9]+)");
+ std::smatch match;
+ if (std::regex_match(str, match, regex)) {
+ lower = std::atoi(match[1].str().c_str());
+ upper = std::atoi(match[2].str().c_str());
+ } else if (std::atoi(str.c_str()) != 0) {
+ lower = upper = std::atoi(str.c_str());
+ } else {
+ ALOGW("could not parse integer range: %s", str.c_str());
+ return std::nullopt;
+ }
+ return std::make_optional<Range<int>>(lower, upper);
+}
+
} // namespace android
\ No newline at end of file