Improve support for high-resolution stats

* This patch adds a new microsecond-resolution function call, LiGetMicroseconds(), to complement
the existing LiGetMillis(). Many variables used by stats have been updated to work at this
higher resolution and now provide better results when displaying e.g. sub-millisecond frametime stats.
To try and avoid confusion, variables that now contain microseconds have been renamed with a suffix
of 'Us', and those ending in 'Ms' contain milliseconds. I originally experimented with nanoseconds but it
felt like overkill for our needs.

Public API in Limelight.h:
uint64_t LiGetMicroseconds(void);
uint64_t LiGetMillis(void);
const RTP_AUDIO_STATS* LiGetRTPAudioStats(void);  // provides access to RTP data for the overlay stats
const RTP_VIDEO_STATS* LiGetRTPVideoStats(void);

Note: Users of this library may need to make changes. If using LiGetMillis() to track the duration of
something that is shown to the user, consider switching to LiGetMicroseconds(). Remember to divide by
1000 at time of display to show in milliseconds.
This commit is contained in:
Andy Grundman
2024-09-12 03:24:29 -04:00
committed by Cameron Gutman
parent 5f2280183c
commit 82ee2d6590
15 changed files with 354 additions and 108 deletions

View File

@@ -267,19 +267,19 @@ static bool transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE respons
payloadLength = request->payloadLength;
request->payload = NULL;
request->payloadLength = 0;
// Serialize the RTSP message into a message buffer
serializedMessage = serializeRtspMessage(request, &messageLen);
if (serializedMessage == NULL) {
goto Exit;
}
// Create the reliable packet that describes our outgoing message
packet = enet_packet_create(serializedMessage, messageLen, ENET_PACKET_FLAG_RELIABLE);
if (packet == NULL) {
goto Exit;
}
// Send the message
if (enet_peer_send(peer, 0, packet) < 0) {
enet_packet_destroy(packet);
@@ -299,10 +299,10 @@ static bool transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE respons
enet_packet_destroy(packet);
goto Exit;
}
enet_host_flush(client);
}
// Wait for a reply
if (serviceEnetHost(client, &event, RTSP_RECEIVE_TIMEOUT_SEC * 1000) <= 0 ||
event.type != ENET_EVENT_TYPE_RECEIVE) {
@@ -343,7 +343,7 @@ static bool transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE respons
offset += (int) event.packet->dataLength;
enet_packet_destroy(event.packet);
}
if (parseRtspMessage(response, responseBuffer, offset) == RTSP_ERROR_SUCCESS) {
// Successfully parsed response
ret = true;
@@ -583,7 +583,7 @@ static bool setupStream(PRTSP_MESSAGE response, char* target, int* error) {
else {
transportValue = " ";
}
if (addOption(&request, "Transport", transportValue) &&
addOption(&request, "If-Modified-Since",
"Thu, 01 Jan 1970 00:00:00 GMT")) {
@@ -992,21 +992,21 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
rtspClientVersion = 14;
break;
}
// Setup ENet if required by this GFE version
if (useEnet) {
ENetAddress address;
ENetEvent event;
enet_address_set_address(&address, (struct sockaddr *)&RemoteAddr, AddrLen);
enet_address_set_port(&address, RtspPortNumber);
// Create a client that can use 1 outgoing connection and 1 channel
client = enet_host_create(RemoteAddr.ss_family, NULL, 1, 1, 0, 0);
if (client == NULL) {
return -1;
}
// Connect to the host
peer = enet_host_connect(client, &address, 1, 0);
if (peer == NULL) {
@@ -1014,7 +1014,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
client = NULL;
return -1;
}
// Wait for the connect to complete
if (serviceEnetHost(client, &event, RTSP_CONNECT_TIMEOUT_SEC * 1000) <= 0 ||
event.type != ENET_EVENT_TYPE_CONNECT) {
@@ -1072,7 +1072,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
ret = -1;
goto Exit;
}
if ((StreamConfig.supportedVideoFormats & VIDEO_FORMAT_MASK_AV1) && strstr(response.payload, "AV1/90000")) {
if ((serverInfo->serverCodecModeSupport & SCM_AV1_HIGH10_444) && (StreamConfig.supportedVideoFormats & VIDEO_FORMAT_AV1_HIGH10_444)) {
NegotiatedVideoFormat = VIDEO_FORMAT_AV1_HIGH10_444;
@@ -1205,10 +1205,10 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
}
// Given there is a non-null session id, get the
// first token of the session until ";", which
// first token of the session until ";", which
// resolves any 454 session not found errors on
// standard RTSP server implementations.
// (i.e - sessionId = "DEADBEEFCAFE;timeout = 90")
// (i.e - sessionId = "DEADBEEFCAFE;timeout = 90")
sessionIdString = strdup(strtok_r(sessionId, ";", &strtokCtx));
if (sessionIdString == NULL) {
Limelog("Failed to duplicate session ID string\n");
@@ -1262,7 +1262,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
freeMessage(&response);
}
if (AppVersionQuad[0] >= 5) {
RTSP_MESSAGE response;
int error = -1;
@@ -1389,9 +1389,9 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
}
}
ret = 0;
Exit:
// Cleanup the ENet stuff
if (useEnet) {
@@ -1399,7 +1399,7 @@ Exit:
enet_peer_disconnect_now(peer, 0);
peer = NULL;
}
if (client != NULL) {
enet_host_destroy(client);
client = NULL;