-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAampLatencyMonitor.cpp
More file actions
671 lines (600 loc) · 20.2 KB
/
AampLatencyMonitor.cpp
File metadata and controls
671 lines (600 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2026 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file AampLatencyMonitor.cpp
* @brief Implementation of AampLatencyMonitor
*/
#include "AampLatencyMonitor.h"
#include "priv_aamp.h"
#include "AampStreamSinkManager.h"
#include "AampDefine.h"
#include "AampLogManager.h"
#include "AAMPAnomalyMessageType.h"
#include "AampProfiler.h"
#include <algorithm>
#include <cassert>
/**
* @brief AampLatencyMonitor constructor
* @param[in] aamp - Pointer to the AAMP instance.
*/
AampLatencyMonitor::AampLatencyMonitor(PrivateInstanceAAMP* aamp)
: mAamp{aamp}
, mConfig{}
, mThresholdMutex{}
, mMinLatencyMs{0.0}
, mTargetLatencyMs{0.0}
, mMaxLatencyMs{0.0}
, mLatencyIncrementAccumulatedMs{0.0}
, mRestorationWindowStartTime{}
, mStartStopMutex{}
, mState{State::kIdle}
, mCurrentRate{1.0}
, mCorrectionEnabled{true}
, mSleepMutex{}
, mSleepCv{}
, mWakeupSignalled{false}
, mThread{}
{
}
/**
* @brief AampLatencyMonitor destructor.
*/
AampLatencyMonitor::~AampLatencyMonitor()
{
Stop();
}
/**
* @brief Start the latency monitor worker thread.
* @param[in] config - LatencyConfig struct containing configuration parameters.
*/
void AampLatencyMonitor::Start(const LatencyConfig& config)
{
std::lock_guard<std::mutex> startStopLock(mStartStopMutex);
// Validate preconditions and guard against misuse.
if (mAamp == nullptr)
{
AAMPLOG_ERR("[LatencyMonitor] cannot start: null AAMP instance");
return;
}
// Guard against double-start. The mutex guarantees no concurrent
// Start()/Stop() can change mState between this check and the assignment
// below, so a plain load is sufficient here.
if (mState.load() != State::kIdle)
{
AAMPLOG_WARN("[LatencyMonitor] Start() called when already running (state=%d)",
static_cast<int>(mState.load()));
return;
}
mConfig = config;
// Initialise the dynamic thresholds from the supplied config.
{
std::lock_guard<std::mutex> lock(mThresholdMutex);
mMinLatencyMs = config.minLatencyMs;
mTargetLatencyMs = config.targetLatencyMs;
mMaxLatencyMs = config.maxLatencyMs;
mLatencyIncrementAccumulatedMs = 0.0;
mRestorationWindowStartTime = {};
mBelowDangerShifted.store(false, std::memory_order_relaxed);
}
// Initial correction rate matches the normal rate.
mCurrentRate.store(config.normalPlaybackRate);
mCorrectionEnabled.store(true);
{
std::lock_guard<std::mutex> lock(mSleepMutex);
mWakeupSignalled = false;
}
try
{
mState = State::kStarting;
mThread = std::thread(&AampLatencyMonitor::Run, this);
AAMPLOG_INFO("[LatencyMonitor] started [%zx]", GetPrintableThreadID(mThread));
}
catch (const std::exception& ex)
{
AAMPLOG_ERR("[LatencyMonitor] failed to start: %s", ex.what());
mState = State::kIdle;
}
}
/**
* @brief Stop the latency monitor worker thread.
*/
void AampLatencyMonitor::Stop()
{
std::lock_guard<std::mutex> startStopLock(mStartStopMutex);
if (mState.load() == State::kIdle)
{
return;
}
AAMPLOG_INFO("[LatencyMonitor] stopping");
mState.store(State::kStopping);
// Wake the sleeping worker so it exits promptly.
{
std::lock_guard<std::mutex> lock(mSleepMutex);
mWakeupSignalled = true;
mSleepCv.notify_all();
}
if (mThread.joinable())
{
try
{
mThread.join();
}
catch (const std::exception& ex)
{
AAMPLOG_ERR("[LatencyMonitor] join failed: %s", ex.what());
}
}
// The worker resets the rate to normal before exiting, but if it died
// before doing so, ensure a clean state here too.
mCurrentRate.store(mConfig.normalPlaybackRate);
// Reset dynamic thresholds back to config defaults so that if the monitor
// is reused the next Start() begins from a known baseline.
{
std::lock_guard<std::mutex> lock(mThresholdMutex);
ResetLatencyThresholdsLocked();
}
mState.store(State::kIdle);
AAMPLOG_INFO("[LatencyMonitor] stopped");
}
/**
* @brief Enable or disable rate correction at runtime.
* @param[in] enabled - true to allow corrections, false to suppress them.
*/
void AampLatencyMonitor::EnableRateCorrection(bool enabled)
{
AAMPLOG_INFO("[LatencyMonitor] state[%d] rate correction %s",
static_cast<int>(mState.load()), enabled ? "enabled" : "disabled");
// If the desired state matches the current state, no action is needed.
if (mCorrectionEnabled.load() == enabled)
{
return;
}
// Reset dynamic thresholds back to config defaults so that if the monitor
// resumes when seeked to live, the thresholds are used from a known baseline.
{
std::lock_guard<std::mutex> lock(mThresholdMutex);
ResetLatencyThresholdsLocked();
}
mCorrectionEnabled.store(enabled);
// Wake the worker so it can immediately reset the rate if needed.
{
std::lock_guard<std::mutex> lock(mSleepMutex);
mWakeupSignalled = true;
mSleepCv.notify_all();
}
}
/**
* @brief Get the current playback rate applied by the monitor.
* @return Current playback rate.
*/
double AampLatencyMonitor::GetCurrentRate() const
{
return mCurrentRate.load();
}
/**
* @brief Worker thread function that monitors latency and applies rate corrections.
*/
void AampLatencyMonitor::Run()
{
// Transition kStarting → kRunning. If Stop() was called between Start()
// spawning the thread and here, state is already kStopping — exit
// immediately so Stop()'s join() returns and it can finalize cleanup.
State expected = State::kStarting;
if (!mState.compare_exchange_strong(expected, State::kRunning))
{
AAMPLOG_WARN("[LatencyMonitor] worker aborted early (state=%d)",
static_cast<int>(expected));
return;
}
AAMPLOG_INFO("[LatencyMonitor] worker running — initial delay %d ms", mConfig.monitorDelayMs);
// Initial delay to avoid disturbing startup.
WaitMs(mConfig.monitorDelayMs);
const double normalRate = mConfig.normalPlaybackRate;
const double maxRate = mConfig.maxPlaybackRate;
const double minRate = mConfig.minPlaybackRate;
// Main loop: runs until Stop() sets state to kStopping.
while (mState.load() == State::kRunning)
{
WaitMs(mConfig.monitorIntervalMs);
// If Stop() was called while we were sleeping, exit now.
if (mState.load() != State::kRunning)
{
break;
}
// If rate correction is disabled, hold the rate at normal and skip monitoring.
if (!mCorrectionEnabled.load())
{
AAMPLOG_DEBUG("[LatencyMonitor] correction suppressed ");
ResetToNormalRate();
// Once rate correction is disabled, the monitor thread sleeps indefinitely until either
// correction is re-enabled or Stop() is called. This prevents any rate changes during
// track switches or ad insertions, which could cause playback issues.
WaitUntilSignalled();
continue;
}
// Skip monitoring if not currently playing, to avoid reacting to transient startup conditions
AAMPPlayerState playerState = mAamp->GetState();
if (playerState != eSTATE_PLAYING)
{
AAMPLOG_DEBUG("[LatencyMonitor] state=%d, skipping poll", playerState);
continue;
}
// Skip latency correction when CDAI ad is playing to avoid disrupting the ad experience.
// Latency monitor will be disabled for trickplay, so avoiding that check here.
if (mAamp->IsAdPlaying())
{
AAMPLOG_DEBUG("[LatencyMonitor] CDAI ad playing, skipping poll");
ResetToNormalRate();
continue;
}
// Collect measurements.
const long latencyMs = mAamp->GetCurrentLatencyMs();
const double bufferMs = mAamp->GetBufferedDurationSecs() * 1000.0;
// A negative bufferMs is the sentinel returned by GetBufferedDurationSecs()
// when mStreamLock could not be acquired (std::try_to_lock contention).
// Skip the entire poll so a transient read failure cannot masquerade as
// an empty buffer and trigger spurious threshold shifts or rate resets.
if (bufferMs < 0.0)
{
AAMPLOG_DEBUG("[LatencyMonitor] buffer reading unavailable (%.3fms), skipping poll",
bufferMs);
continue;
}
// Handle danger-buffer threshold tracking and threshold restoration.
//
// - Below danger: shift once per episode (episode guard prevents repeat).
// OnBufferLevelUpdate() wakes us early for the onset of each new episode
// so we respond immediately rather than waiting for the next poll.
// When downloads are failing (OnBufferLevelUpdate not called), the regular
// poll catches the low buffer here directly.
//
// - Above danger: clear the episode guard and run the restoration timer.
// (OnBufferLevelUpdate wakes us promptly on recovery so the restoration
// timer starts from the accurate moment the buffer became healthy,
// rather than waiting for the next scheduled poll.)
if (mConfig.dangerBufferMs > 0.0 && mConfig.rebufferingLatencyStepMs > 0.0)
{
UpdateDangerBufferState(bufferMs);
}
if (bufferMs < mConfig.correctionActivationThresholdMs)
{
AAMPLOG_DEBUG("[LatencyMonitor] Buffer level[%.3f] is too low for latency correction, skipping poll",
bufferMs);
ResetToNormalRate();
continue;
}
double minLatMs, targetLatMs, maxLatMs;
{
std::lock_guard<std::mutex> lock(mThresholdMutex);
minLatMs = mMinLatencyMs;
targetLatMs = mTargetLatencyMs;
maxLatMs = mMaxLatencyMs;
}
AAMPLOG_INFO("[LatencyMonitor] latency=%ldms buffer=%.3fms "
"rate=%.2f min=%.0fms target=%.0fms max=%.0fms ",
latencyMs, bufferMs, mCurrentRate.load(),
minLatMs, targetLatMs, maxLatMs);
// Determine the desired rate based on current latency and buffer state.
double desiredRate = mCurrentRate.load();
if (latencyMs > static_cast<long>(maxLatMs))
{
// Latency above band — speed up.
desiredRate = maxRate;
}
else if (latencyMs < static_cast<long>(minLatMs))
{
// Latency below band — slow down.
desiredRate = minRate;
}
else if ((latencyMs <= static_cast<long>(targetLatMs)) &&
(mCurrentRate.load() == maxRate))
{
// Latency caught up to target while running fast — return to normal.
desiredRate = normalRate;
}
else if ((latencyMs >= static_cast<long>(targetLatMs)) &&
(mCurrentRate.load() == minRate))
{
// Latency rose to target while running slow — return to normal.
desiredRate = normalRate;
}
// else: no change.
// Apply the new rate if it changed.
if (desiredRate != mCurrentRate.load())
{
ApplyRate(desiredRate);
}
}
// Worker is exiting — reset the sink rate to normal so the stream does
// not stay at a correction speed after the monitor terminates.
ResetToNormalRate();
// Do NOT write mState here. Stop() owns the kStopping → kIdle
// transition after join() returns, ensuring a clean hand-off.
AAMPLOG_INFO("[LatencyMonitor] worker exited");
}
/**
* @brief Sleep for the specified duration or until signalled to wake or stop.
* @param[in] ms - Duration to sleep in milliseconds.
*/
void AampLatencyMonitor::WaitMs(int ms)
{
std::unique_lock<std::mutex> lock(mSleepMutex);
mSleepCv.wait_for(lock,
std::chrono::milliseconds(ms),
[this]() {
return mWakeupSignalled || (mState.load() == State::kStopping);
});
mWakeupSignalled = false;
}
/**
* @brief Sleep indefinitely until signalled to wake or stop.
*/
void AampLatencyMonitor::WaitUntilSignalled()
{
std::unique_lock<std::mutex> lock(mSleepMutex);
mSleepCv.wait(lock,
[this]() {
return mWakeupSignalled || (mState.load() == State::kStopping);
});
mWakeupSignalled = false;
}
/**
* @brief Apply the specified playback rate to the stream sink.
* @param[in] newRate - The new playback rate to apply.
*/
void AampLatencyMonitor::ApplyRate(double newRate)
{
StreamSink* sink = AampStreamSinkManager::GetInstance().GetStreamSink(mAamp);
if (sink == nullptr)
{
AAMPLOG_WARN("[LatencyMonitor] no StreamSink — cannot apply rate %.2f",
newRate);
return;
}
if (!sink->SetPlayBackRate(newRate))
{
AAMPLOG_WARN("[LatencyMonitor] SetPlayBackRate(%.2f) failed", newRate);
return;
}
mCurrentRate.store(newRate);
// Telemetry on rate-correction events.
mAamp->UpdateVideoEndMetrics(newRate);
mAamp->SendAnomalyEvent(ANOMALY_WARNING, "[LatencyMonitor] rate changed to:%.2f", newRate);
mAamp->profiler.IncrementChangeCount(Count_RateCorrection);
AAMPLOG_WARN("[LatencyMonitor] rate -> %.2f", newRate);
}
/**
* @brief Reset the playback rate to the normal rate defined in the config.
*/
void AampLatencyMonitor::ResetToNormalRate()
{
const double normalRate = mConfig.normalPlaybackRate;
if (mCurrentRate.load() == normalRate)
{
return;
}
StreamSink* sink = AampStreamSinkManager::GetInstance().GetStreamSink(mAamp);
if (sink == nullptr)
{
return;
}
if (sink->SetPlayBackRate(normalRate))
{
mCurrentRate.store(normalRate);
AAMPLOG_INFO("[LatencyMonitor] rate reset to normal (%.2f)", normalRate);
}
else
{
AAMPLOG_WARN("[LatencyMonitor] failed to reset rate to normal");
}
}
/**
* @brief Apply one upward threshold shift (rebufferingLatencyStepMs).
* @pre mThresholdMutex must be held by the caller.
*/
void AampLatencyMonitor::IncreaseThresholdsLocked()
{
double newAccumulated = mLatencyIncrementAccumulatedMs
+ mConfig.rebufferingLatencyStepMs;
if (mConfig.rebufferingLatencyMaxIncrementMs > 0.0)
{
newAccumulated = std::min(newAccumulated,
mConfig.rebufferingLatencyMaxIncrementMs);
}
mLatencyIncrementAccumulatedMs = newAccumulated;
mMinLatencyMs = mConfig.minLatencyMs + mLatencyIncrementAccumulatedMs;
mTargetLatencyMs = mConfig.targetLatencyMs + mLatencyIncrementAccumulatedMs;
mMaxLatencyMs = mConfig.maxLatencyMs + mLatencyIncrementAccumulatedMs;
AAMPLOG_INFO("[LatencyMonitor] thresholds shifted +%.0fms "
"(accumulated=%.0fms) -> min=%.0fms target=%.0fms max=%.0fms",
mConfig.rebufferingLatencyStepMs, mLatencyIncrementAccumulatedMs,
mMinLatencyMs, mTargetLatencyMs, mMaxLatencyMs);
}
/**
* @brief Update danger-buffer state and the threshold restoration timer.
*
* Called from Run() on every poll where dangerBufferMs and
* rebufferingLatencyStepMs are both configured.
*
* - Below danger: shift thresholds up once per episode (episode guard
* mBelowDangerShifted prevents a repeat within the same dip).
* - Above danger: clear the episode guard and advance the restoration
* timer; when latencyStableSec of continuous healthy buffer has elapsed,
* call TryRestoreThresholdsLocked() to tighten by one step.
*
* @param[in] bufferMs - Current buffer level in milliseconds.
*/
void AampLatencyMonitor::UpdateDangerBufferState(double bufferMs)
{
std::lock_guard<std::mutex> lock(mThresholdMutex);
if (bufferMs < mConfig.dangerBufferMs)
{
if (!mBelowDangerShifted.load(std::memory_order_relaxed))
{
IncreaseThresholdsLocked();
mBelowDangerShifted.store(true, std::memory_order_relaxed);
}
mRestorationWindowStartTime = {};
}
else
{
// Buffer healthy — end the episode and run the restoration timer.
mBelowDangerShifted.store(false, std::memory_order_relaxed);
if (mConfig.latencyStableSec > 0.0)
{
if (mLatencyIncrementAccumulatedMs <= 0.0)
{
// Nothing accumulated — keep timer cleared.
mRestorationWindowStartTime = {};
}
else
{
const auto now = std::chrono::steady_clock::now();
if (mRestorationWindowStartTime == std::chrono::steady_clock::time_point{})
{
// Buffer just recovered — start the stability window.
mRestorationWindowStartTime = now;
}
else
{
const double stableTime =
std::chrono::duration<double>(now - mRestorationWindowStartTime).count();
if (stableTime >= mConfig.latencyStableSec)
{
TryRestoreThresholdsLocked();
// Reset; next window is measured independently.
mRestorationWindowStartTime = {};
}
}
}
}
}
}
/**
* @brief Notify the monitor of the current buffer level.
*
* This function follows the same notify-only pattern as the underflow monitor:
* it never shifts thresholds directly. Instead it acts as a wakeup trigger for
* the Run() worker, which is the sole owner of all threshold decisions.
*
* - Below danger: wakes Run() early (once per episode) so the shift happens
* immediately rather than waiting for the next scheduled poll interval.
* Subsequent low-buffer fragments in the same episode are no-ops (episode
* guard mBelowDangerShifted suppresses redundant wake-ups without a lock).
*
* - Above danger: clears the episode guard so the next distinct dip will
* trigger a fresh wakeup and shift. Run() handles the restoration timer
* on its next poll.
*/
void AampLatencyMonitor::OnBufferLevelUpdate(double bufferMs)
{
if (mConfig.dangerBufferMs <= 0.0 || mConfig.rebufferingLatencyStepMs <= 0.0)
{
return;
}
// Ignore the invalid sentinel (-1.0 * 1000 = -1000 ms) that
// GetBufferedDurationSecs() returns on lock-contention so a transient
// read failure cannot trigger a spurious wakeup and episode shift.
if (bufferMs < 0.0)
{
return;
}
// If correction is disabled (e.g. not at live point), the worker is
// sleeping indefinitely in WaitUntilSignalled(). Do not wake it on
// buffer events — it has nothing to act on and would immediately
// go back to sleep, burning a wakeup for no gain.
if (!mCorrectionEnabled.load(std::memory_order_relaxed))
{
return;
}
if (bufferMs < mConfig.dangerBufferMs)
{
// Only signal Run() for the onset of a new low-buffer episode.
// Once Run() has shifted and set mBelowDangerShifted, further low-buffer
// fragments during the same episode do not re-wake the thread.
if (!mBelowDangerShifted.load(std::memory_order_relaxed))
{
std::lock_guard<std::mutex> lock(mSleepMutex);
mWakeupSignalled = true;
mSleepCv.notify_one();
}
}
else
{
// Buffer has recovered from a danger episode — wake Run() once so it
// can clear the episode guard and start the restoration timer from the
// accurate moment of recovery. Run() owns all state transitions;
// we do not write mBelowDangerShifted here.
// The guard ensures only the first healthy fragment after a danger
// episode wakes the thread; subsequent healthy fragments are no-ops.
if (mBelowDangerShifted.load(std::memory_order_relaxed))
{
std::lock_guard<std::mutex> lock(mSleepMutex);
mWakeupSignalled = true;
mSleepCv.notify_one();
}
}
}
/**
* @brief Return the current effective latency thresholds.
*/
std::tuple<double, double, double> AampLatencyMonitor::GetCurrentThresholds() const
{
std::lock_guard<std::mutex> lock(mThresholdMutex);
return {mMinLatencyMs, mTargetLatencyMs, mMaxLatencyMs};
}
/**
* @brief Reset the three dynamic thresholds to config defaults.
* @pre mThresholdMutex must be held by the caller.
*/
void AampLatencyMonitor::ResetLatencyThresholdsLocked()
{
mMinLatencyMs = mConfig.minLatencyMs;
mTargetLatencyMs = mConfig.targetLatencyMs;
mMaxLatencyMs = mConfig.maxLatencyMs;
mLatencyIncrementAccumulatedMs = 0.0;
mRestorationWindowStartTime = {};
mBelowDangerShifted.store(false, std::memory_order_relaxed);
}
/**
* @brief Apply one restoration step toward the config-default thresholds.
*
* Decrements mLatencyIncrementAccumulatedMs by rebufferingLatencyStepMs, flooring
* at zero, then recomputes the three dynamic thresholds. No-op when the
* accumulated increment is already zero.
*
* @pre mThresholdMutex must be held by the caller.
*/
void AampLatencyMonitor::TryRestoreThresholdsLocked()
{
if (mLatencyIncrementAccumulatedMs <= 0.0)
{
return;
}
const double newAccumulated = std::max(0.0,
mLatencyIncrementAccumulatedMs - mConfig.rebufferingLatencyStepMs);
mLatencyIncrementAccumulatedMs = newAccumulated;
mMinLatencyMs = mConfig.minLatencyMs + mLatencyIncrementAccumulatedMs;
mTargetLatencyMs = mConfig.targetLatencyMs + mLatencyIncrementAccumulatedMs;
mMaxLatencyMs = mConfig.maxLatencyMs + mLatencyIncrementAccumulatedMs;
AAMPLOG_INFO("[LatencyMonitor] restoration: thresholds tightened -%.0fms "
"(accumulated=%.0fms) -> min=%.0fms target=%.0fms max=%.0fms",
mConfig.rebufferingLatencyStepMs, mLatencyIncrementAccumulatedMs,
mMinLatencyMs, mTargetLatencyMs, mMaxLatencyMs);
}