Keep adaptive requests above baseline and test backend fault events
This commit is contained in:
1 parent
e37b3be7da
commit
b463fc3309
3 files changed
+24
-3
No files matched your search
@@ -9,7 +9,7 @@
|
||||
* Состояние живёт до смены устройства/сессии; begin() сохраняет подобранный размер при reopen. */
|
||||
struct AudioBufferTuning {
|
||||
enum Result { Unchanged, Increase, Limit };
|
||||
unsigned requestedMs = 0, actualMs = 0, periods = 1;
|
||||
unsigned requestedMs = 0, baseMs = 0, actualMs = 0, periods = 1;
|
||||
int64_t settleUntil = 0, changeAfter = 0, firstFaultAt = -1;
|
||||
unsigned faultPolls = 0;
|
||||
|
||||
@@ -24,7 +24,7 @@ struct AudioBufferTuning {
|
||||
faultPolls = std::min(faultPolls + 1, 2u);
|
||||
if (faultPolls < 2 || now < changeAfter) return Unchanged;
|
||||
firstFaultAt = -1; faultPolls = 0; changeAfter = now + 5000;
|
||||
unsigned current = std::max(actualMs, requestedMs), maximum = 100 / periods;
|
||||
unsigned current = std::max({actualMs, requestedMs, baseMs}), maximum = 100 / periods;
|
||||
if (!current || current >= maximum) return Limit;
|
||||
requestedMs = std::min(current + 5, maximum);
|
||||
return Increase;
|
||||
|
||||
@@ -48,6 +48,8 @@ bool AudioDevice::init(ma_context* context, ma_device_config config, const char*
|
||||
m_bufferKeyValid = true; m_bufferBackend = context->backend; m_bufferType = config.deviceType;
|
||||
m_bufferSession = session; m_bufferSelected = selected != nullptr;
|
||||
if (selected) m_bufferDeviceId = *selected;
|
||||
m_bufferTuning.baseMs = config.periodSizeInFrames && config.sampleRate
|
||||
? unsigned((uint64_t(config.periodSizeInFrames) * 1000 + config.sampleRate - 1) / config.sampleRate) : config.periodSizeInMilliseconds;
|
||||
if (m_bufferTuning.requestedMs) {
|
||||
config.periodSizeInFrames = 0; config.periodSizeInMilliseconds = m_bufferTuning.requestedMs;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user