11#pragma once
22
3- #include < mutex>
4- #include < chrono>
53#include < android/log.h>
4+ #include < chrono>
5+ #include < mutex>
66
7- class FecChangeController
8- {
7+ class FecChangeController {
98 static constexpr const char *TAG = " FecChangeController" ;
10- public:
9+
10+ public:
1111 // / \brief Query the current (possibly decayed) fec_change value.
1212 // / Call this as often as you like; the class handles its own timing.
13- int value ()
14- {
15- if (!mEnabled )
16- return 0 ;
13+ int value () {
14+ if (!mEnabled ) return 0 ;
1715
1816 std::lock_guard<std::mutex> lock (mx_);
1917 decayLocked_ ();
@@ -22,52 +20,47 @@ class FecChangeController
2220
2321 // / \brief Raise fec_change. If newValue <= current, the call is ignored.
2422 // / A successful bump resets the 5-second “hold” timer.
25- void bump (int newValue)
26- {
23+ void bump (int newValue) {
2724 std::lock_guard<std::mutex> lock (mx_);
2825 if (newValue > val_) {
2926 __android_log_print (ANDROID_LOG_ERROR, TAG, " bumping FEC: %d" , newValue);
3027
31- val_ = newValue;
28+ val_ = newValue;
3229 lastChange_ = Clock::now ();
3330 }
3431 }
3532
36- void setEnabled (bool use){
37- mEnabled = use;
38- }
33+ void setEnabled (bool use) { mEnabled = use; }
3934
40- private:
35+ private:
4136 using Clock = std::chrono::steady_clock;
42- static constexpr std::chrono::seconds kTick {1 }; // length of one hold/decay window
37+ static constexpr std::chrono::seconds kTick {1 }; // length of one hold/decay window
4338
44- void decayLocked_ ()
45- {
39+ void decayLocked_ () {
4640 if (val_ == 0 ) return ;
4741
48- auto now = Clock::now ();
42+ auto now = Clock::now ();
4943 auto elapsed = now - lastChange_;
5044
5145 // Still inside the mandatory 5-second hold? Do nothing.
5246 if (elapsed < kTick ) return ;
5347
5448 // How many *full* ticks have passed since lastChange_?
5549 auto ticks = std::chrono::duration_cast<std::chrono::seconds>(elapsed).count () / kTick .count ();
56- if (ticks == 0 ) return ; // safety net (shouldn’t hit)
50+ if (ticks == 0 ) return ; // safety net (shouldn’t hit)
5751
5852 int decayed = val_ - static_cast <int >(ticks);
5953 if (decayed < 0 ) decayed = 0 ;
6054
6155 // Commit the decay and anchor lastChange_ on the most recent tick boundary
6256 if (decayed != val_) {
63- val_ = decayed;
57+ val_ = decayed;
6458 lastChange_ += kTick * ticks;
6559 }
6660 }
6761
68- int val_ {0 };
69- Clock::time_point lastChange_ {Clock::now ()};
70- std::mutex mx_;
62+ int val_{0 };
63+ Clock::time_point lastChange_{Clock::now ()};
64+ std::mutex mx_;
7165 bool mEnabled = false ;
7266};
73-
0 commit comments