diff --git a/src/Limelight-internal.h b/src/Limelight-internal.h index 7f92575..90e6d71 100644 --- a/src/Limelight-internal.h +++ b/src/Limelight-internal.h @@ -39,10 +39,14 @@ extern int AudioPacketDuration; #define UDP_RECV_POLL_TIMEOUT_MS 100 -// At this value, we will request high quality audio unless CAPABILITY_SLOW_OPUS_DECODER +// At this value or above, we will request high quality audio unless CAPABILITY_SLOW_OPUS_DECODER // is set on the audio renderer. #define HIGH_AUDIO_BITRATE_THRESHOLD 15000 +// Below this value, we will request 20 ms audio frames to reduce bandwidth if the audio +// renderer sets CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION. +#define LOW_AUDIO_BITRATE_TRESHOLD 5000 + int serviceEnetHost(ENetHost* client, ENetEvent* event, enet_uint32 timeoutMs); int extractVersionQuadFromString(const char* string, int* quad); int isReferenceFrameInvalidationEnabled(void); diff --git a/src/Limelight.h b/src/Limelight.h index 4b9d811..0b92ea8 100644 --- a/src/Limelight.h +++ b/src/Limelight.h @@ -176,6 +176,12 @@ typedef struct _DECODE_UNIT { // used with video streams above 15 Mbps. #define CAPABILITY_SLOW_OPUS_DECODER 0x8 +// If set in the audio renderer capabilities field, this indicates that audio packets +// may contain more or less than 5 ms of audio. This requires that audio renderers read the +// samplesPerFrame field in OPUS_MULTISTREAM_CONFIGURATION to calculate the correct decoded +// buffer size rather than just assuming it will always be 240. +#define CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION 0x10 + // If set in the video renderer capabilities field, this macro specifies that the renderer // supports slicing to increase decoding performance. The parameter specifies the desired // number of slices per frame. This capability is only valid on video renderers. diff --git a/src/SdpGenerator.c b/src/SdpGenerator.c index f50b8e7..78eeb0a 100644 --- a/src/SdpGenerator.c +++ b/src/SdpGenerator.c @@ -377,7 +377,9 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) { err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "0"); HighQualitySurroundEnabled = 0; - if ((AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) == 0) { + if ((AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) != 0 || + ((AudioCallbacks.capabilities & CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION) != 0 && + OriginalVideoBitrate >= LOW_AUDIO_BITRATE_TRESHOLD)) { // Use 5 ms packets by default for lowest latency AudioPacketDuration = 5; }