Terminate the connection if video isn't received for 10 seconds

This commit is contained in:
Cameron Gutman 2020-05-01 19:25:24 -07:00
parent 413ea9bc8e
commit b46e06fcf1
3 changed files with 24 additions and 1 deletions

View File

@ -564,7 +564,7 @@ static void controlReceiveThreadFunc(void* context) {
// SERVER_TERMINATED_INTENDED // SERVER_TERMINATED_INTENDED
if (terminationReason == 0x0100) { if (terminationReason == 0x0100) {
// Pass error code 0 to notify the client that this was not an error // Pass error code 0 to notify the client that this was not an error
terminationErrorCode = 0; terminationErrorCode = ML_ERROR_GRACEFUL_TERMINATION;
} }
else { else {
// Otherwise pass the reason unmodified // Otherwise pass the reason unmodified

View File

@ -352,6 +352,17 @@ typedef void(*ConnListenerConnectionStarted)(void);
// to LiStopConnection() or LiInterruptConnection(). // to LiStopConnection() or LiInterruptConnection().
typedef void(*ConnListenerConnectionTerminated)(int errorCode); typedef void(*ConnListenerConnectionTerminated)(int errorCode);
// This error code is passed to ConnListenerConnectionTerminated() when the stream
// is being gracefully terminated by the host. It usually means the app on the host
// PC has exited.
#define ML_ERROR_GRACEFUL_TERMINATION 0
// This error is passed to ConnListenerConnectionTerminated() if no video data
// was ever received for this connection after waiting several seconds. It likely
// indicates a problem with traffic on UDP 47998 due to missing or incorrect
// firewall or port forwarding rules.
#define ML_ERROR_NO_VIDEO_TRAFFIC -100
// This callback is invoked to log debug message // This callback is invoked to log debug message
typedef void(*ConnListenerLogMessage)(const char* format, ...); typedef void(*ConnListenerLogMessage)(const char* format, ...);

View File

@ -75,6 +75,7 @@ static void ReceiveThreadProc(void* context) {
char* buffer; char* buffer;
int queueStatus; int queueStatus;
int useSelect; int useSelect;
int waitingForVideoMs;
receiveSize = StreamConfig.packetSize + MAX_RTP_HEADER_SIZE; receiveSize = StreamConfig.packetSize + MAX_RTP_HEADER_SIZE;
bufferSize = receiveSize + sizeof(RTPFEC_QUEUE_ENTRY); bufferSize = receiveSize + sizeof(RTPFEC_QUEUE_ENTRY);
@ -89,6 +90,7 @@ static void ReceiveThreadProc(void* context) {
useSelect = 0; useSelect = 0;
} }
waitingForVideoMs = 0;
while (!PltIsThreadInterrupted(&receiveThread)) { while (!PltIsThreadInterrupted(&receiveThread)) {
PRTP_PACKET packet; PRTP_PACKET packet;
@ -108,6 +110,16 @@ static void ReceiveThreadProc(void* context) {
break; break;
} }
else if (err == 0) { else if (err == 0) {
if (!receivedDataFromPeer) {
// If we wait many seconds without ever receiving a video packet,
// assume something is broken and terminate the connection.
waitingForVideoMs += UDP_RECV_POLL_TIMEOUT_MS;
if (waitingForVideoMs >= FIRST_FRAME_TIMEOUT_SEC * 1000) {
ListenerCallbacks.connectionTerminated(ML_ERROR_NO_VIDEO_TRAFFIC);
break;
}
}
// Receive timed out; try again // Receive timed out; try again
continue; continue;
} }