mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Add support for requesting 20 ms audio frames for slow Opus decoders
This commit is contained in:
parent
1154cb1d3d
commit
59481c085a
@ -161,7 +161,7 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
PQUEUED_AUDIO_PACKET packet;
|
PQUEUED_AUDIO_PACKET packet;
|
||||||
int queueStatus;
|
int queueStatus;
|
||||||
int useSelect;
|
int useSelect;
|
||||||
int packetsToDrop = 100;
|
int packetsToDrop = 500 / AudioPacketDuration;
|
||||||
|
|
||||||
packet = NULL;
|
packet = NULL;
|
||||||
|
|
||||||
@ -321,17 +321,17 @@ void stopAudioStream(void) {
|
|||||||
|
|
||||||
int startAudioStream(void* audioContext, int arFlags) {
|
int startAudioStream(void* audioContext, int arFlags) {
|
||||||
int err;
|
int err;
|
||||||
POPUS_MULTISTREAM_CONFIGURATION chosenConfig;
|
OPUS_MULTISTREAM_CONFIGURATION chosenConfig;
|
||||||
|
|
||||||
if (StreamConfig.audioConfiguration == AUDIO_CONFIGURATION_STEREO) {
|
if (StreamConfig.audioConfiguration == AUDIO_CONFIGURATION_STEREO) {
|
||||||
chosenConfig = &opusStereoConfig;
|
chosenConfig = opusStereoConfig;
|
||||||
}
|
}
|
||||||
else if (StreamConfig.audioConfiguration == AUDIO_CONFIGURATION_51_SURROUND) {
|
else if (StreamConfig.audioConfiguration == AUDIO_CONFIGURATION_51_SURROUND) {
|
||||||
if (HighQualitySurroundEnabled) {
|
if (HighQualitySurroundEnabled) {
|
||||||
chosenConfig = &opus51HighSurroundConfig;
|
chosenConfig = opus51HighSurroundConfig;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chosenConfig = &opus51SurroundConfig;
|
chosenConfig = opus51SurroundConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -339,7 +339,9 @@ int startAudioStream(void* audioContext, int arFlags) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = AudioCallbacks.init(StreamConfig.audioConfiguration, chosenConfig, audioContext, arFlags);
|
chosenConfig.samplesPerFrame = 48 * AudioPacketDuration;
|
||||||
|
|
||||||
|
err = AudioCallbacks.init(StreamConfig.audioConfiguration, &chosenConfig, audioContext, arFlags);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ int NegotiatedVideoFormat;
|
|||||||
volatile int ConnectionInterrupted;
|
volatile int ConnectionInterrupted;
|
||||||
int HighQualitySurroundEnabled;
|
int HighQualitySurroundEnabled;
|
||||||
int OriginalVideoBitrate;
|
int OriginalVideoBitrate;
|
||||||
|
int AudioPacketDuration;
|
||||||
|
|
||||||
// Connection stages
|
// Connection stages
|
||||||
static const char* stageNames[STAGE_MAX] = {
|
static const char* stageNames[STAGE_MAX] = {
|
||||||
|
@ -22,6 +22,7 @@ extern int NegotiatedVideoFormat;
|
|||||||
extern volatile int ConnectionInterrupted;
|
extern volatile int ConnectionInterrupted;
|
||||||
extern int HighQualitySurroundEnabled;
|
extern int HighQualitySurroundEnabled;
|
||||||
extern int OriginalVideoBitrate;
|
extern int OriginalVideoBitrate;
|
||||||
|
extern int AudioPacketDuration;
|
||||||
|
|
||||||
#ifndef UINT24_MAX
|
#ifndef UINT24_MAX
|
||||||
#define UINT24_MAX 0xFFFFFF
|
#define UINT24_MAX 0xFFFFFF
|
||||||
|
@ -228,6 +228,7 @@ typedef struct _OPUS_MULTISTREAM_CONFIGURATION {
|
|||||||
int channelCount;
|
int channelCount;
|
||||||
int streams;
|
int streams;
|
||||||
int coupledStreams;
|
int coupledStreams;
|
||||||
|
int samplesPerFrame;
|
||||||
unsigned char mapping[6];
|
unsigned char mapping[6];
|
||||||
} OPUS_MULTISTREAM_CONFIGURATION, *POPUS_MULTISTREAM_CONFIGURATION;
|
} OPUS_MULTISTREAM_CONFIGURATION, *POPUS_MULTISTREAM_CONFIGURATION;
|
||||||
|
|
||||||
|
@ -368,11 +368,30 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) {
|
|||||||
// Let the audio stream code know that it needs to disable coupled streams when
|
// Let the audio stream code know that it needs to disable coupled streams when
|
||||||
// decoding this audio stream.
|
// decoding this audio stream.
|
||||||
HighQualitySurroundEnabled = 1;
|
HighQualitySurroundEnabled = 1;
|
||||||
|
|
||||||
|
// Use 5 ms frames since we don't have a slow decoder
|
||||||
|
AudioPacketDuration = 5;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "0");
|
err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "0");
|
||||||
HighQualitySurroundEnabled = 0;
|
HighQualitySurroundEnabled = 0;
|
||||||
|
|
||||||
|
if ((AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) == 0) {
|
||||||
|
// Use 5 ms packets by default for lowest latency
|
||||||
|
AudioPacketDuration = 5;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Use 20 ms packets for slow decoders to save CPU and bandwidth
|
||||||
|
AudioPacketDuration = 20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sprintf(payloadStr, "%d", AudioPacketDuration);
|
||||||
|
err |= addAttributeString(&optionHead, "x-nv-aqos.packetDuration", payloadStr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 5 ms duration for legacy servers
|
||||||
|
AudioPacketDuration = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user