WHIP: packet pacing fixup for WHIP/WHEP output

This commit is contained in:
Marco van Dijk 2023-11-28 15:32:20 +01:00 committed by Thulinma
parent cb2c63db61
commit d040421df9
2 changed files with 13 additions and 1 deletions

View file

@ -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){ void Socket::UDPConnection::sendPaced(const char *sdata, size_t len){
if (!paceQueue.size() && (!lastPace || Util::getMicros(lastPace) > 10000)){ if (!paceQueue.size() && (!lastPace || Util::getMicros(lastPace) > 10000)){
SendNow(sdata, len); 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 /// 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){ void Socket::UDPConnection::sendPaced(uint64_t uSendWindow){
uint64_t currPace = Util::getMicros(); uint64_t currPace = Util::getMicros();
do{ do{

View file

@ -8,6 +8,13 @@
#include <mist/triggers.h> #include <mist/triggers.h>
#include <netdb.h> // ifaddr, listing ip addresses. #include <netdb.h> // ifaddr, listing ip addresses.
#include <mist/stream.h> #include <mist/stream.h>
/*
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{ namespace Mist{
@ -318,7 +325,8 @@ namespace Mist{
void OutWebRTC::requestHandler(){ void OutWebRTC::requestHandler(){
if (noSignalling){ 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 //After 10s of no packets, abort
if (Util::bootMS() > lastRecv + 10000){ if (Util::bootMS() > lastRecv + 10000){
Util::logExitReason(ER_CLEAN_INACTIVE, "received no data for 10+ seconds"); Util::logExitReason(ER_CLEAN_INACTIVE, "received no data for 10+ seconds");