mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-04-24 00:47:23 +00:00
Fix Steam Link audio latency cap
This commit is contained in:
@@ -19,6 +19,10 @@ bool SLAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* o
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This number is pretty conservative (especially for surround), but
|
||||||
|
// it's hard to avoid since we get crushed by CPU limitations.
|
||||||
|
m_MaxQueuedAudioMs = 40 * opusConfig->channelCount / 2;
|
||||||
|
|
||||||
m_FrameDuration = opusConfig->samplesPerFrame / 48;
|
m_FrameDuration = opusConfig->samplesPerFrame / 48;
|
||||||
m_AudioBufferSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount;
|
m_AudioBufferSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount;
|
||||||
m_AudioStream = SLAudio_CreateStream(m_AudioContext,
|
m_AudioStream = SLAudio_CreateStream(m_AudioContext,
|
||||||
@@ -73,8 +77,7 @@ bool SLAudioRenderer::submitAudio(int bytesWritten)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only allow up to 40 ms of queued audio
|
if (LiGetPendingAudioFrames() * m_FrameDuration < m_MaxQueuedAudioMs) {
|
||||||
if (LiGetPendingAudioFrames() * m_FrameDuration < 40) {
|
|
||||||
SLAudio_SubmitFrame(m_AudioStream);
|
SLAudio_SubmitFrame(m_AudioStream);
|
||||||
m_AudioBuffer = nullptr;
|
m_AudioBuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ private:
|
|||||||
void* m_AudioBuffer;
|
void* m_AudioBuffer;
|
||||||
int m_AudioBufferSize;
|
int m_AudioBufferSize;
|
||||||
int m_FrameDuration;
|
int m_FrameDuration;
|
||||||
|
int m_MaxQueuedAudioMs;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,11 +49,13 @@ AUDIO_RENDERER_CALLBACKS Session::k_AudioCallbacks = {
|
|||||||
nullptr,
|
nullptr,
|
||||||
Session::arCleanup,
|
Session::arCleanup,
|
||||||
Session::arDecodeAndPlaySample,
|
Session::arDecodeAndPlaySample,
|
||||||
CAPABILITY_DIRECT_SUBMIT |
|
#ifndef STEAM_LINK
|
||||||
#ifdef STEAM_LINK
|
CAPABILITY_DIRECT_SUBMIT
|
||||||
CAPABILITY_SLOW_OPUS_DECODER
|
|
||||||
#else
|
#else
|
||||||
0
|
// We cannot use direct submit for Steam Link because the
|
||||||
|
// SLAudio renderer needs to look at the audio backlog to
|
||||||
|
// cap latency since playback is a blocking operation.
|
||||||
|
CAPABILITY_SLOW_OPUS_DECODER
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user