Increase audio packet duration for low bandwidth connections

This commit is contained in:
Cameron Gutman 2019-11-30 21:59:34 -06:00
parent 6b42954b47
commit c1a26618d4
3 changed files with 14 additions and 2 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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;
}