1 #include "Limelight-internal.h"
2 
3 #define ENET_INTERNAL_TIMEOUT_MS 100
4 
5 // This function wraps enet_host_service() and hides the fact that it must be called
6 // multiple times for retransmissions to work correctly. It is meant to be a drop-in
7 // replacement for enet_host_service(). It also handles cancellation of the connection
8 // attempt during the wait.
serviceEnetHost(ENetHost * client,ENetEvent * event,enet_uint32 timeoutMs)9 int serviceEnetHost(ENetHost* client, ENetEvent* event, enet_uint32 timeoutMs) {
10     int ret;
11 
12     // We need to call enet_host_service() multiple times to make sure retransmissions happen
13     for (;;) {
14         int selectedTimeout = timeoutMs < ENET_INTERNAL_TIMEOUT_MS ? timeoutMs : ENET_INTERNAL_TIMEOUT_MS;
15 
16         // We want to report an interrupt event if we are able to read data
17         if (ConnectionInterrupted) {
18             Limelog("ENet wait interrupted\n");
19             ret = -1;
20             break;
21         }
22 
23         ret = enet_host_service(client, event, selectedTimeout);
24         if (ret != 0 || timeoutMs == 0) {
25             break;
26         }
27 
28         timeoutMs -= selectedTimeout;
29     }
30 
31     return ret;
32 }
33 
extractVersionQuadFromString(const char * string,int * quad)34 int extractVersionQuadFromString(const char* string, int* quad) {
35     char versionString[128];
36     char* nextDot;
37     char* nextNumber;
38     int i;
39 
40     strcpy(versionString, string);
41     nextNumber = versionString;
42 
43     for (i = 0; i < 4; i++) {
44         if (i == 3) {
45             nextDot = strchr(nextNumber, '\0');
46         }
47         else {
48             nextDot = strchr(nextNumber, '.');
49         }
50         if (nextDot == NULL) {
51             return -1;
52         }
53 
54         // Cut the string off at the next dot
55         *nextDot = '\0';
56 
57         quad[i] = atoi(nextNumber);
58 
59         // Move on to the next segment
60         nextNumber = nextDot + 1;
61     }
62 
63     return 0;
64 }
65 
isReferenceFrameInvalidationEnabled(void)66 int isReferenceFrameInvalidationEnabled(void) {
67     LC_ASSERT(NegotiatedVideoFormat != 0);
68     return ((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H264) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC)) ||
69            ((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H265) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC));
70 }
71 
LiInitializeStreamConfiguration(PSTREAM_CONFIGURATION streamConfig)72 void LiInitializeStreamConfiguration(PSTREAM_CONFIGURATION streamConfig) {
73     memset(streamConfig, 0, sizeof(*streamConfig));
74 }
75 
LiInitializeVideoCallbacks(PDECODER_RENDERER_CALLBACKS drCallbacks)76 void LiInitializeVideoCallbacks(PDECODER_RENDERER_CALLBACKS drCallbacks) {
77     memset(drCallbacks, 0, sizeof(*drCallbacks));
78 }
79 
LiInitializeAudioCallbacks(PAUDIO_RENDERER_CALLBACKS arCallbacks)80 void LiInitializeAudioCallbacks(PAUDIO_RENDERER_CALLBACKS arCallbacks) {
81     memset(arCallbacks, 0, sizeof(*arCallbacks));
82 }
83 
LiInitializeConnectionCallbacks(PCONNECTION_LISTENER_CALLBACKS clCallbacks)84 void LiInitializeConnectionCallbacks(PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
85     memset(clCallbacks, 0, sizeof(*clCallbacks));
86 }
87 
LiInitializeServerInformation(PSERVER_INFORMATION serverInfo)88 void LiInitializeServerInformation(PSERVER_INFORMATION serverInfo) {
89     memset(serverInfo, 0, sizeof(*serverInfo));
90 }
91 
LiGetMillis(void)92 uint64_t LiGetMillis(void) {
93     return PltGetMillis();
94 }
95