mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-05-19 16:10:35 +00:00
Use queued audio duration instead of queued frame count to constrain latency
This avoids latency explosion when we negotiate 10 ms instead of 5 ms audio packets.
This commit is contained in:
@@ -21,5 +21,6 @@ public:
|
||||
private:
|
||||
SDL_AudioDeviceID m_AudioDevice;
|
||||
void* m_AudioBuffer;
|
||||
int m_FrameSize;
|
||||
Uint32 m_FrameSize;
|
||||
Uint32 m_FrameDurationMs;
|
||||
};
|
||||
|
||||
@@ -32,6 +32,7 @@ bool SdlAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION*
|
||||
// The buffering helps avoid audio underruns due to network jitter.
|
||||
want.samples = SDL_max(480, opusConfig->samplesPerFrame * 3);
|
||||
|
||||
m_FrameDurationMs = opusConfig->samplesPerFrame / (opusConfig->sampleRate / 1000);
|
||||
m_FrameSize = opusConfig->samplesPerFrame *
|
||||
opusConfig->channelCount *
|
||||
getAudioBufferSampleSize();
|
||||
@@ -115,8 +116,8 @@ bool SdlAudioRenderer::submitAudio(int bytesWritten)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only queue more samples where there are 10 frames or less in SDL's queue
|
||||
if (SDL_GetQueuedAudioSize(m_AudioDevice) / m_FrameSize <= 10) {
|
||||
// Only queue more samples where there is 50 ms or less in SDL's queue
|
||||
if (SDL_GetQueuedAudioSize(m_AudioDevice) / m_FrameSize * m_FrameDurationMs <= 50) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user