// only increase headroom if doing so would have reduced the number of
// glitches that occured over the past second by 1% or more.
// prevent headroom from growing beyond rolling average of max.
- const int skipsAllowed =
- static_cast<int>(AutoHeadroomGlitchTolerance * mSampleRate / mPeerFPP);
+ int skipsAllowed;
+ if (mMsecTolerance >= (mPeerFPPdurMsec * 2)) {
+ // calculate skips allowed if tolerance if above or equal to duration of two
+ // packets
+ skipsAllowed =
+ static_cast<int>(AutoHeadroomGlitchTolerance * mSampleRate / mPeerFPP);
+ } else {
+ // zero skips allowed if tolerance is below duration of two packets
+ skipsAllowed = 0;
+ // also don't require two intervals in a row (override)
+ mSkipAutoHeadroom = false;
+ }
if (glitches > 0 && skipped > skipsAllowed
&& mCurrentHeadroom + 1 <= pushStat->longTermMax) {
if (mSkipAutoHeadroom) {
<< " (max=" << pushStat->longTermMax << ")" << endl;
}
} else {
- // require 2 seconds in a row if headroom >= two packet intervals
- mSkipAutoHeadroom = mMsecTolerance >= (mPeerFPPdurMsec * 2);
+ // thresholds not met: require 2 intervals in a row
+ mSkipAutoHeadroom = true;
}
} else {
// fixed headroom
mLastSkipped = totalSkipped;
if (mAuto && pushStat->lastTime > AutoInitDur) {
// after AutoInitDur: update auto tolerance once per second
- updateTolerance(newGlitches, newSkipped);
+ if (pushStat->lastTime <= (AutoInitDur + 3000)) {
+ // Ignore glitches and skips for the first 3 seconds after
+ // we have switched from using the startup tolerance to
+ // a calculated tolerance. Otherwise, the switch can
+ // sometimes cause it to bump headroom prematurely even
+ // though there are no real audio glitches.
+ updateTolerance(0, 0);
+ } else {
+ updateTolerance(newGlitches, newSkipped);
+ }
}
}
}
const int lastSeqNumIn = mLastSeqNumIn.load(std::memory_order_acquire);
int skipped = 0;
- if ((lastSeqNumIn == -1) || (!mInitialized)) {
+ if ((lastSeqNumIn == -1) || (!mInitialized) || (now < mMsecTolerance)) {
+ // return silence during startup:
+ // * no packets arrived yet
+ // * not initialized
+ // * hasn't run long enough to meet tolerance
goto ZERO_OUTPUT;
} else if (lastSeqNumIn == mLastSeqNumOut) {
goto UNDERRUN;
::setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));
#endif
- // set qos for windows after flow is established (requires peer address/port)
+ // set quality of service for the UDP socket
if (setSocketQos(sock_fd)) {
std::cout << "Set QoS for network socket" << std::endl;
} else {
// https://learn.microsoft.com/en-us/windows/win32/api/_qos/
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/qos/qwave-api-reference
+#if 0
+ // DISABLED SINCE THIS CAUSES GARBLED AUDIO FOR SOME PEOPLE
+
// Initialize the QoS version parameter.
QOS_VERSION Version;
Version.MajorVersion = 1;
std::cerr << WSAGetLastError() << std::endl;
return false;
}
+#endif
+
#elif defined(__APPLE__)
// set service type "Interactive Voice"
// TODO: this is supposed to be the right thing to do on OSX, but doesn't seem to do