From 783af66324e2e72ded6d5059cb47dee5f0a3c994 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 27 May 2018 17:29:20 -0700 Subject: [PATCH] Reduce audio bitrate when streaming with a low video bitrate --- src/SdpGenerator.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/SdpGenerator.c b/src/SdpGenerator.c index 4653b45..c59df53 100644 --- a/src/SdpGenerator.c +++ b/src/SdpGenerator.c @@ -11,6 +11,8 @@ #define CHANNEL_MASK_STEREO 0x3 #define CHANNEL_MASK_51_SURROUND 0xFC +#define LOW_BITRATE_THRESHOLD 5000 + typedef struct _SDP_OPTION { char name[MAX_OPTION_NAME_LEN + 1]; void* payload; @@ -358,6 +360,25 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) { else { err |= addAttributeString(&optionHead, "x-nv-audio.surround.enable", "0"); } + + if (AppVersionQuad[0] >= 7) { + if (StreamConfig.bitrate < LOW_BITRATE_THRESHOLD && audioChannelCount == 2) { + // At low bitrates, cap the stereo audio bitrate to reduce data usage. For some reason, + // GFE seems to always enable high quality (512 Kbps) mode for stereo even though we + // don't specify that we want it via SDP. 5.1 audio properly remains at normal quality + // mode by default. To work around high quality mode, use adaptive bitrate with a + // min = max clamp (like we do for video). + err |= addAttributeString(&optionHead, "x-nv-audioBitrate.adaptiveBitrateEnable", "1"); + err |= addAttributeString(&optionHead, "x-nv-audioBitrate.local2chMin", "96"); + err |= addAttributeString(&optionHead, "x-nv-audioBitrate.local2chMax", "96"); + err |= addAttributeString(&optionHead, "x-nv-audioBitrate.remote2chMin", "96"); + err |= addAttributeString(&optionHead, "x-nv-audioBitrate.remote2chMax", "96"); + } + else { + // Disable audio bitrate cap + err |= addAttributeString(&optionHead, "x-nv-audioBitrate.adaptiveBitrateEnable", "0"); + } + } } if (err == 0) {