mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-05-18 23:50:16 +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:
|
private:
|
||||||
SDL_AudioDeviceID m_AudioDevice;
|
SDL_AudioDeviceID m_AudioDevice;
|
||||||
void* m_AudioBuffer;
|
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.
|
// The buffering helps avoid audio underruns due to network jitter.
|
||||||
want.samples = SDL_max(480, opusConfig->samplesPerFrame * 3);
|
want.samples = SDL_max(480, opusConfig->samplesPerFrame * 3);
|
||||||
|
|
||||||
|
m_FrameDurationMs = opusConfig->samplesPerFrame / (opusConfig->sampleRate / 1000);
|
||||||
m_FrameSize = opusConfig->samplesPerFrame *
|
m_FrameSize = opusConfig->samplesPerFrame *
|
||||||
opusConfig->channelCount *
|
opusConfig->channelCount *
|
||||||
getAudioBufferSampleSize();
|
getAudioBufferSampleSize();
|
||||||
@@ -115,8 +116,8 @@ bool SdlAudioRenderer::submitAudio(int bytesWritten)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only queue more samples where there are 10 frames or less in SDL's queue
|
// Only queue more samples where there is 50 ms or less in SDL's queue
|
||||||
if (SDL_GetQueuedAudioSize(m_AudioDevice) / m_FrameSize <= 10) {
|
if (SDL_GetQueuedAudioSize(m_AudioDevice) / m_FrameSize * m_FrameDurationMs <= 50) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user