Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved loging in case of clamping visual position #12516

Merged
merged 4 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/waveform/visualplayposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,46 @@ double VisualPlayPosition::calcOffsetAtNextVSync(
const int refToVSync = pVSyncThread->fromTimerToNextSyncMicros(data.m_referenceTime);
const int syncIntervalTimeMicros = pVSyncThread->getSyncIntervalTimeMicros();
#endif
// The offset is limited to the audio buffer + 2 x waveform sync interval
// The positive offset is limited to the audio buffer + 2 x waveform sync interval
// This should be sufficient to compensate jitter, but does not continue
// in case of underflows.
const int maxOffset = static_cast<int>(
data.m_audioBufferMicroS + 2 * syncIntervalTimeMicros);

// The minimum offset is limited to -data.m_callbackEntrytoDac to avoid a more
// negative value indicating an outdated request that is no longer valid anyway.
// This is probably caused by a vsync problem.
const int minOffset = -data.m_callbackEntrytoDac;

// Calculate the offset in micros for the position of the sample that will be transferred
// to the DAC when the next display frame is displayed
int offset = refToVSync - data.m_callbackEntrytoDac;
if (offset < -maxOffset) {
offset = -maxOffset;
if (offset < minOffset) {
offset = minOffset;
if (!m_noTransport) {
qWarning() << "VisualPlayPosition::calcOffsetAtNextVSync"
<< m_key << "no transport (offset < -maxOffset)";
<< m_key << "outdated position request (offset < minOffset)";
qDebug() << m_key << "refToVSync:" << refToVSync
<< "data.m_callbackEntrytoDac:"
<< data.m_callbackEntrytoDac;
m_noTransport = true;
}
} else if (offset > maxOffset) {
offset = maxOffset;
if (!m_noTransport) {
qWarning() << "VisualPlayPosition::calcOffsetAtNextVSync"
<< m_key << "no transport (offset > maxOffset)";
qDebug() << m_key << "refToVSync:" << refToVSync
<< "data.m_callbackEntrytoDac:"
<< data.m_callbackEntrytoDac;
m_noTransport = true;
}
} else {
if (m_noTransport) {
qDebug() << m_key << "refToVSync:" << refToVSync
<< "data.m_callbackEntrytoDac:"
<< data.m_callbackEntrytoDac;
}
m_noTransport = false;
}
// Apply the offset proportional to m_positionStep
Expand Down
21 changes: 15 additions & 6 deletions src/waveform/vsyncthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void VSyncThread::run() {
//qDebug() << "VSyncThread::run()";
switch (m_vSyncMode) {
case ST_FREE:
m_syncIntervalTimeMicros = 1000;
m_waitToSwapMicros = m_syncIntervalTimeMicros;
runFree();
break;
case ST_PLL:
Expand Down Expand Up @@ -65,8 +67,7 @@ void VSyncThread::runFree() {
m_semaVsyncSlot.acquire();

m_sinceLastSwap = m_timer.restart();
m_waitToSwapMicros = 1000;
usleep(1000);
usleep(m_waitToSwapMicros);
}
}

Expand Down Expand Up @@ -168,9 +169,11 @@ int VSyncThread::elapsed() {
}

void VSyncThread::setSyncIntervalTimeMicros(int syncTime) {
m_syncIntervalTimeMicros = syncTime;
m_vSyncPerRendering = static_cast<int>(
round(m_displayFrameRate * m_syncIntervalTimeMicros / 1000));
if (m_vSyncMode != ST_FREE) {
m_syncIntervalTimeMicros = syncTime;
m_vSyncPerRendering = static_cast<int>(
round(m_displayFrameRate * m_syncIntervalTimeMicros / 1000));
}
}

void VSyncThread::setVSyncType(int type) {
Expand All @@ -187,7 +190,13 @@ void VSyncThread::setVSyncType(int type) {
int VSyncThread::fromTimerToNextSyncMicros(const PerformanceTimer& timer) {
int difference = static_cast<int>(m_timer.difference(timer).toIntegerMicros());
// int math is fine here, because we do not expect times > 4.2 s
return difference + m_waitToSwapMicros;
int toNextSync = difference + m_waitToSwapMicros;
while (toNextSync < 0) {
// this function is called during rendering. A negative value indicates
// an attempt to render an outdated frame. Render the next frame instead
toNextSync += m_syncIntervalTimeMicros;
}
return toNextSync;
}

int VSyncThread::droppedFrames() {
Expand Down
Loading