diff options
author | Harish Mahendrakar <hmahendrakar@google.com> | 2024-05-08 17:54:15 -0700 |
---|---|---|
committer | Harish Mahendrakar <hmahendrakar@google.com> | 2024-05-09 16:28:26 -0700 |
commit | 7b3f96f8214b5f19b6f2092fd6b7bf184026b283 (patch) | |
tree | 08ce334e6c255a8aab5087ca82661301bf023bde | |
parent | 591bc3abbf385a1094ae4e37c7f82e10c3e36227 (diff) | |
download | av-7b3f96f8214b5f19b6f2092fd6b7bf184026b283.tar.gz |
Codec2CommonUtils: Reduce android_get_device_api_level() calls
Instead of calling android_get_device_api_level() for every frame,
it is now called once and stored in a static variable.
Bug: 246792159
Test: Decode 10-bit clip and confirm android_get_device_api_level() is
called only once.
Change-Id: I10402a3f729910e87fc74d48e0afa0830c7873ba
-rw-r--r-- | media/codec2/sfplugin/utils/Codec2CommonUtils.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp b/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp index 77a76e8584..7a33af4096 100644 --- a/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp +++ b/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp @@ -32,10 +32,15 @@ namespace android { -static bool isAtLeast(int version, const char *codeName) { - char deviceCodeName[PROP_VALUE_MAX]; - __system_property_get("ro.build.version.codename", deviceCodeName); - return android_get_device_api_level() >= version || !strcmp(deviceCodeName, codeName); +static bool isAtLeast(int version, const std::string codeName) { + static std::once_flag sCheckOnce; + static std::string sDeviceCodeName; + static int sDeviceApiLevel; + std::call_once(sCheckOnce, [&](){ + sDeviceCodeName = base::GetProperty("ro.build.version.codename", ""); + sDeviceApiLevel = android_get_device_api_level(); + }); + return sDeviceApiLevel >= version || sDeviceCodeName == codeName; } bool isAtLeastT() { |