diff --git a/src/AudioStream.c b/src/AudioStream.c index 5a192cb..36d2397 100644 --- a/src/AudioStream.c +++ b/src/AudioStream.c @@ -319,11 +319,13 @@ int startAudioStream(void* audioContext, int arFlags) { int err; OPUS_MULTISTREAM_CONFIGURATION chosenConfig; + // TODO: Get these from RTSP ANNOUNCE surround-params if (StreamConfig.audioConfiguration == AUDIO_CONFIGURATION_STEREO) { chosenConfig = opusStereoConfig; } else if (StreamConfig.audioConfiguration == AUDIO_CONFIGURATION_51_SURROUND) { if (HighQualitySurroundEnabled) { + LC_ASSERT(HighQualitySurroundSupported); chosenConfig = opus51HighSurroundConfig; } else { diff --git a/src/Connection.c b/src/Connection.c index 5bf2991..77a101c 100644 --- a/src/Connection.c +++ b/src/Connection.c @@ -18,6 +18,7 @@ DECODER_RENDERER_CALLBACKS VideoCallbacks; AUDIO_RENDERER_CALLBACKS AudioCallbacks; int NegotiatedVideoFormat; volatile int ConnectionInterrupted; +int HighQualitySurroundSupported; int HighQualitySurroundEnabled; int OriginalVideoBitrate; int AudioPacketDuration; diff --git a/src/Limelight-internal.h b/src/Limelight-internal.h index f706684..7f92575 100644 --- a/src/Limelight-internal.h +++ b/src/Limelight-internal.h @@ -20,6 +20,7 @@ extern DECODER_RENDERER_CALLBACKS VideoCallbacks; extern AUDIO_RENDERER_CALLBACKS AudioCallbacks; extern int NegotiatedVideoFormat; extern volatile int ConnectionInterrupted; +extern int HighQualitySurroundSupported; extern int HighQualitySurroundEnabled; extern int OriginalVideoBitrate; extern int AudioPacketDuration; diff --git a/src/RtspConnection.c b/src/RtspConnection.c index 75d9139..fde6477 100644 --- a/src/RtspConnection.c +++ b/src/RtspConnection.c @@ -566,6 +566,15 @@ int performRtspHandshake(void) { NegotiatedVideoFormat = VIDEO_FORMAT_H264; } + // Check if high bitrate surround sound is available before attempting to request it. + // TODO: Parse these surround-params so we can get rid of our hardcoded Opus mappings + if (strstr(response.payload, "surround-params=660")) { + HighQualitySurroundSupported = 1; + } + else { + HighQualitySurroundSupported = 0; + } + freeMessage(&response); } diff --git a/src/SdpGenerator.c b/src/SdpGenerator.c index 5d8a0eb..f50b8e7 100644 --- a/src/SdpGenerator.c +++ b/src/SdpGenerator.c @@ -362,7 +362,7 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) { if (AppVersionQuad[0] >= 7) { // Decide to use HQ audio based on the original video bitrate, not the HEVC-adjusted value if (OriginalVideoBitrate >= HIGH_AUDIO_BITRATE_THRESHOLD && audioChannelCount > 2 && - (AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) == 0) { + HighQualitySurroundSupported && (AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) == 0) { // Enable high quality mode for surround sound err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "1");