Enable high quality surround sound when the video bitrate is over 15 Mbps

This commit is contained in:
Cameron Gutman 2018-05-27 18:45:09 -07:00
parent 783af66324
commit a8b01d6c29
4 changed files with 26 additions and 3 deletions

View File

@ -17,7 +17,7 @@ static unsigned short lastSeq;
#define RTP_PORT 48000 #define RTP_PORT 48000
#define MAX_PACKET_SIZE 400 #define MAX_PACKET_SIZE 1400
// This is much larger than we should typically have buffered, but // This is much larger than we should typically have buffered, but
// it needs to be. We need a cushion in case our thread gets blocked // it needs to be. We need a cushion in case our thread gets blocked
@ -282,9 +282,16 @@ void stopAudioStream(void) {
int startAudioStream(void* audioContext, int arFlags) { int startAudioStream(void* audioContext, int arFlags) {
int err; int err;
OPUS_MULTISTREAM_CONFIGURATION chosenConfig;
err = AudioCallbacks.init(StreamConfig.audioConfiguration, memcpy(&chosenConfig, opusConfigArray[StreamConfig.audioConfiguration], sizeof(chosenConfig));
opusConfigArray[StreamConfig.audioConfiguration], audioContext, arFlags); if (HighQualitySurroundEnabled) {
// With high quality mode enabled, the encoder stops using coupled streams
chosenConfig.coupledStreams = 0;
chosenConfig.streams = chosenConfig.channelCount;
}
err = AudioCallbacks.init(StreamConfig.audioConfiguration, &chosenConfig, audioContext, arFlags);
if (err != 0) { if (err != 0) {
return err; return err;
} }

View File

@ -18,6 +18,7 @@ DECODER_RENDERER_CALLBACKS VideoCallbacks;
AUDIO_RENDERER_CALLBACKS AudioCallbacks; AUDIO_RENDERER_CALLBACKS AudioCallbacks;
int NegotiatedVideoFormat; int NegotiatedVideoFormat;
volatile int ConnectionInterrupted; volatile int ConnectionInterrupted;
int HighQualitySurroundEnabled;
// Connection stages // Connection stages
static const char* stageNames[STAGE_MAX] = { static const char* stageNames[STAGE_MAX] = {

View File

@ -20,6 +20,7 @@ extern DECODER_RENDERER_CALLBACKS VideoCallbacks;
extern AUDIO_RENDERER_CALLBACKS AudioCallbacks; extern AUDIO_RENDERER_CALLBACKS AudioCallbacks;
extern int NegotiatedVideoFormat; extern int NegotiatedVideoFormat;
extern volatile int ConnectionInterrupted; extern volatile int ConnectionInterrupted;
extern int HighQualitySurroundEnabled;
#ifndef UINT24_MAX #ifndef UINT24_MAX
#define UINT24_MAX 0xFFFFFF #define UINT24_MAX 0xFFFFFF

View File

@ -12,6 +12,7 @@
#define CHANNEL_MASK_51_SURROUND 0xFC #define CHANNEL_MASK_51_SURROUND 0xFC
#define LOW_BITRATE_THRESHOLD 5000 #define LOW_BITRATE_THRESHOLD 5000
#define HIGH_BITRATE_THRESHOLD 15000
typedef struct _SDP_OPTION { typedef struct _SDP_OPTION {
char name[MAX_OPTION_NAME_LEN + 1]; char name[MAX_OPTION_NAME_LEN + 1];
@ -362,6 +363,19 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) {
} }
if (AppVersionQuad[0] >= 7) { if (AppVersionQuad[0] >= 7) {
if (StreamConfig.bitrate > HIGH_BITRATE_THRESHOLD && audioChannelCount > 2) {
// Enable high quality mode for surround sound
err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "1");
// Let the audio stream code know that it needs to disable coupled streams when
// decoding this audio stream.
HighQualitySurroundEnabled = 1;
}
else {
err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "0");
HighQualitySurroundEnabled = 0;
}
if (StreamConfig.bitrate < LOW_BITRATE_THRESHOLD && audioChannelCount == 2) { if (StreamConfig.bitrate < LOW_BITRATE_THRESHOLD && audioChannelCount == 2) {
// At low bitrates, cap the stereo audio bitrate to reduce data usage. For some reason, // 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 // GFE seems to always enable high quality (512 Kbps) mode for stereo even though we