From 011778fd4cb9606b68bfea1ed483d73c04fc6dcd Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Wed, 6 May 2015 11:52:00 -0700 Subject: stagefright: enable experiments Bug: 20894716 Change-Id: I8c05b99dca8b3099a3a1b2b465f0f58bef786572 --- media/libstagefright/foundation/ADebug.cpp | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'media/libstagefright/foundation') diff --git a/media/libstagefright/foundation/ADebug.cpp b/media/libstagefright/foundation/ADebug.cpp index ec4a960..0d1cea4 100644 --- a/media/libstagefright/foundation/ADebug.cpp +++ b/media/libstagefright/foundation/ADebug.cpp @@ -19,6 +19,7 @@ #include #define LOG_TAG "ADebug" +#include #include #include @@ -113,5 +114,43 @@ char *ADebug::GetDebugName(const char *name) { return debugName; } +//static +bool ADebug::getExperimentFlag( + bool allow, const char *name, uint64_t modulo, + uint64_t limit, uint64_t plus, uint64_t timeDivisor) { + static volatile int32_t haveSerial = 0; + static uint64_t serialNum; + if (!android_atomic_acquire_load(&haveSerial)) { + // calculate initial counter value based on serial number + static char serial[PROPERTY_VALUE_MAX]; + property_get("ro.serialno", serial, "0"); + uint64_t num = 0; // it is okay for this number to overflow + for (size_t i = 0; i < NELEM(serial) && serial[i] != '\0'; ++i) { + const char &c = serial[i]; + // try to use most letters of serialno + if (isdigit(c)) { + num = num * 10 + (c - '0'); + } else if (islower(c)) { + num = num * 26 + (c - 'a'); + } else if (isupper(c)) { + num = num * 26 + (c - 'A'); + } else { + num = num * 256 + c; + } + } + ALOGI("got serial"); + serialNum = num; + android_atomic_release_store(1, &haveSerial); + } + ALOGI("serial: %llu, time: %llu", (long long)serialNum, (long long)time(NULL)); + // MINOR: use modulo for counter and time, so that their sum does not + // roll over, and mess up the correlation between related experiments. + // e.g. keep (a mod 2N) = 0 impl (a mod N) = 0 + time_t counter = (time(NULL) / timeDivisor) % modulo + plus + serialNum % modulo; + bool enable = allow && (counter % modulo < limit); + ALOGI("experiment '%s': %s", name, enable ? "ENABLED" : "disabled"); + return enable; +} + } // namespace android -- cgit v1.1