From 5700272dc47e95082d1f88604045508e6b05f008 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 30 Nov 2019 22:24:28 -0600 Subject: [PATCH] Improve low bandwidth audio performance for SDL and SLAudio and fix RTSP issues with broken PMTUD --- app/streaming/audio/renderers/sdl.h | 1 - app/streaming/audio/renderers/sdlaud.cpp | 7 +++---- app/streaming/audio/renderers/slaud.cpp | 9 ++++----- app/streaming/audio/renderers/slaud.h | 1 - moonlight-common-c/moonlight-common-c | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/streaming/audio/renderers/sdl.h b/app/streaming/audio/renderers/sdl.h index 63410a06..3e8234a1 100644 --- a/app/streaming/audio/renderers/sdl.h +++ b/app/streaming/audio/renderers/sdl.h @@ -21,6 +21,5 @@ public: private: SDL_AudioDeviceID m_AudioDevice; void* m_AudioBuffer; - int m_FrameDurationMs; int m_FrameSize; }; diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp index aa43dd2a..747decc3 100644 --- a/app/streaming/audio/renderers/sdlaud.cpp +++ b/app/streaming/audio/renderers/sdlaud.cpp @@ -34,7 +34,6 @@ bool SdlAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* want.samples = opusConfig->samplesPerFrame; m_FrameSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount; - m_FrameDurationMs = opusConfig->samplesPerFrame / 48; m_AudioDevice = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0); if (m_AudioDevice == 0) { @@ -97,7 +96,7 @@ bool SdlAudioRenderer::submitAudio(int bytesWritten) // Don't queue if there's already more than 30 ms of audio data waiting // in Moonlight's audio queue. - if (LiGetPendingAudioFrames() * m_FrameDurationMs > 30) { + if (LiGetPendingAudioDuration() > 30) { return true; } @@ -118,6 +117,6 @@ bool SdlAudioRenderer::submitAudio(int bytesWritten) int SdlAudioRenderer::getCapabilities() { - // Direct submit can't be used because we use LiGetPendingAudioFrames() - return 0; + // Direct submit can't be used because we use LiGetPendingAudioDuration() + return CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION; } diff --git a/app/streaming/audio/renderers/slaud.cpp b/app/streaming/audio/renderers/slaud.cpp index 32c995d6..425bf498 100644 --- a/app/streaming/audio/renderers/slaud.cpp +++ b/app/streaming/audio/renderers/slaud.cpp @@ -23,7 +23,6 @@ bool SLAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* o // it's hard to avoid since we get crushed by CPU limitations. m_MaxQueuedAudioMs = 40 * opusConfig->channelCount / 2; - m_FrameDuration = opusConfig->samplesPerFrame / 48; m_AudioBufferSize = opusConfig->samplesPerFrame * sizeof(short) * opusConfig->channelCount; m_AudioStream = SLAudio_CreateStream(m_AudioContext, opusConfig->sampleRate, @@ -37,8 +36,8 @@ bool SLAudioRenderer::prepareForPlayback(const OPUS_MULTISTREAM_CONFIGURATION* o } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, - "Using SLAudio renderer with %d ms frames", - m_FrameDuration); + "Using SLAudio renderer with %d samples per frame", + opusConfig->samplesPerFrame); return true; } @@ -100,7 +99,7 @@ bool SLAudioRenderer::submitAudio(int bytesWritten) return true; } - if (LiGetPendingAudioFrames() * m_FrameDuration < m_MaxQueuedAudioMs) { + if (LiGetPendingAudioDuration() < m_MaxQueuedAudioMs) { SLAudio_SubmitFrame(m_AudioStream); m_AudioBuffer = nullptr; } @@ -115,7 +114,7 @@ bool SLAudioRenderer::submitAudio(int bytesWritten) int SLAudioRenderer::getCapabilities() { - return CAPABILITY_SLOW_OPUS_DECODER; + return CAPABILITY_SLOW_OPUS_DECODER | CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION; } void SLAudioRenderer::slLogCallback(void*, ESLAudioLog logLevel, const char *message) diff --git a/app/streaming/audio/renderers/slaud.h b/app/streaming/audio/renderers/slaud.h index 54f7e7ae..eeb8cb2c 100644 --- a/app/streaming/audio/renderers/slaud.h +++ b/app/streaming/audio/renderers/slaud.h @@ -28,6 +28,5 @@ private: void* m_AudioBuffer; int m_AudioBufferSize; - int m_FrameDuration; int m_MaxQueuedAudioMs; }; diff --git a/moonlight-common-c/moonlight-common-c b/moonlight-common-c/moonlight-common-c index f4dad9ae..c1a26618 160000 --- a/moonlight-common-c/moonlight-common-c +++ b/moonlight-common-c/moonlight-common-c @@ -1 +1 @@ -Subproject commit f4dad9ae8bca90aada76c9bb858e4eea0fff5b76 +Subproject commit c1a26618d48d436657e47bcd38c2487d318c9fa0