Allow encoder to pick optimal ref frame count if RFI is supported by the decoder

This commit is contained in:
Cameron Gutman 2023-04-29 13:11:38 -05:00
commit 169078d0a9
3 changed files with 12 additions and 7 deletions

View file

@ -76,6 +76,7 @@ extern SS_PING VideoPingPayload;
int serviceEnetHost(ENetHost* client, ENetEvent* event, enet_uint32 timeoutMs);
int gracefullyDisconnectEnetPeer(ENetHost* host, ENetPeer* peer, enet_uint32 lingerTimeoutMs);
int extractVersionQuadFromString(const char* string, int* quad);
bool isReferenceFrameInvalidationSupportedByDecoder(void);
bool isReferenceFrameInvalidationEnabled(void);
void* extendBuffer(void* ptr, size_t newSize);

View file

@ -119,18 +119,18 @@ void* extendBuffer(void* ptr, size_t newSize) {
return newBuf;
}
bool isReferenceFrameInvalidationEnabled(void) {
bool isReferenceFrameInvalidationSupportedByDecoder(void) {
LC_ASSERT(NegotiatedVideoFormat != 0);
// Even if the client wants it, we can't enable it without server support.
if (!ReferenceFrameInvalidationSupported) {
return false;
}
return ((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H264) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC)) ||
((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H265) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC));
}
bool isReferenceFrameInvalidationEnabled(void) {
// RFI must be supported by the server and the client decoder to be used
return ReferenceFrameInvalidationSupported && isReferenceFrameInvalidationSupportedByDecoder();
}
void LiInitializeStreamConfiguration(PSTREAM_CONFIGURATION streamConfig) {
memset(streamConfig, 0, sizeof(*streamConfig));
}

View file

@ -386,7 +386,11 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) {
}
if (AppVersionQuad[0] >= 7) {
if (isReferenceFrameInvalidationEnabled()) {
// If the decoder supports reference frame invalidation, that indicates it also supports
// the maximum number of reference frames allowed by the codec. Even if we can't use RFI
// due to lack of host support, we can still allow the host to pick a number of reference
// frames greater than 1 to improve encoding efficiency.
if (isReferenceFrameInvalidationSupportedByDecoder()) {
err |= addAttributeString(&optionHead, "x-nv-video[0].maxNumReferenceFrames", "0");
}
else {