diff --git a/lib/socket.cpp b/lib/socket.cpp index 203a6b79..1b4eb4f3 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -1894,6 +1894,9 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len){ } } +/// Queues sdata, len for sending over this socket. +/// If there has been enough time since the last packet, sends immediately. +/// Warning: never call sendPaced for the same socket from a different thread! void Socket::UDPConnection::sendPaced(const char *sdata, size_t len){ if (!paceQueue.size() && (!lastPace || Util::getMicros(lastPace) > 10000)){ SendNow(sdata, len); @@ -1907,6 +1910,7 @@ void Socket::UDPConnection::sendPaced(const char *sdata, size_t len){ } /// Spends uSendWindow microseconds either sending paced packets or sleeping, whichever is more appropriate +/// Warning: never call sendPaced for the same socket from a different thread! void Socket::UDPConnection::sendPaced(uint64_t uSendWindow){ uint64_t currPace = Util::getMicros(); do{ diff --git a/src/output/output_webrtc.cpp b/src/output/output_webrtc.cpp index da49803c..62bb3896 100644 --- a/src/output/output_webrtc.cpp +++ b/src/output/output_webrtc.cpp @@ -8,6 +8,13 @@ #include #include // ifaddr, listing ip addresses. #include +/* +This file handles both input and output, and can operate in WHIP/WHEP as well as WebSocket signaling mode. +In case of WHIP/WHEP: the Socket is closed after signaling has happened and the keepGoing function + is overridden to handle this case +When handling WebRTC Input a second thread is started dedicated to UDP traffic. In this case + no UDP traffic may be handled on the main thread whatsoever +*/ namespace Mist{ @@ -318,7 +325,8 @@ namespace Mist{ void OutWebRTC::requestHandler(){ if (noSignalling){ - if (!parseData){udp.sendPaced(10000);} + // For WHEP, make sure we keep listening for packets while waiting for new data to come in for sending + if (parseData && !handleWebRTCInputOutput()){udp.sendPaced(10);} //After 10s of no packets, abort if (Util::bootMS() > lastRecv + 10000){ Util::logExitReason(ER_CLEAN_INACTIVE, "received no data for 10+ seconds");