Implemented UDP socket packet send pacing, WebRTC now makes use of this new feature.

This commit is contained in:
Thulinma 2023-06-15 12:34:25 +02:00
parent a1232d56af
commit 2a8f2f75d3
8 changed files with 83 additions and 12 deletions

View file

@ -1607,7 +1607,7 @@ namespace Mist{
keepGoing()){
uint64_t amount = thisPacket.getTime() - (((Util::bootMS() - firstTime) * 1000) / realTime + maxSkipAhead);
if (amount > 1000){amount = 1000;}
Util::sleep(amount);
idleTime(amount);
//Make sure we stay responsive to requests and stats while waiting
if (wantRequest){
requestHandler();

View file

@ -127,6 +127,7 @@ namespace Mist{
std::set<size_t> getSupportedTracks(const std::string &type = "") const;
inline virtual bool keepGoing(){return config->is_active && myConn;}
virtual void idleTime(uint64_t ms){Util::sleep(ms);}
Comms::Connections statComm;
bool isBlocking; ///< If true, indicates that myConn is blocking.

View file

@ -306,7 +306,7 @@ namespace Mist{
void OutWebRTC::requestHandler(){
if (noSignalling){
if (!parseData){Util::sleep(500);}
if (!parseData){udp.sendPaced(10000);}
//After 10s of no packets, abort
if (Util::bootMS() > lastRecv + 10000){
Util::logExitReason("received no data for 10+ seconds");
@ -1155,7 +1155,7 @@ namespace Mist{
void OutWebRTC::handleWebRTCInputOutputFromThread(){
udp.allocateDestination();
while (keepGoing()){
if (!handleWebRTCInputOutput()){Util::sleep(20);}
if (!handleWebRTCInputOutput()){Util::sleep(10);}
}
}
@ -1291,7 +1291,7 @@ namespace Mist{
stun_writer.writeFingerprint();
stun_writer.end();
udp.SendNow((const char *)stun_writer.getBufferPtr(), stun_writer.getBufferSize());
udp.sendPaced((const char *)stun_writer.getBufferPtr(), stun_writer.getBufferSize());
myConn.addUp(stun_writer.getBufferSize());
}
@ -1336,7 +1336,7 @@ namespace Mist{
HIGH_MSG("Could not answer NACK for %" PRIu32 " #%" PRIu16 ": packet not buffered", pSSRC, seq);
return;
}
udp.SendNow(nb.getData(seq), nb.getSize(seq));
udp.sendPaced(nb.getData(seq), nb.getSize(seq));
myConn.addUp(nb.getSize(seq));
HIGH_MSG("Answered NACK for %" PRIu32 " #%" PRIu16, pSSRC, seq);
}
@ -1524,7 +1524,7 @@ namespace Mist{
/* ------------------------------------------------ */
int OutWebRTC::onDTLSHandshakeWantsToWrite(const uint8_t *data, int *nbytes){
udp.SendNow((const char *)data, (size_t)*nbytes);
udp.sendPaced((const char *)data, (size_t)*nbytes);
myConn.addUp(*nbytes);
return 0;
}
@ -1619,7 +1619,7 @@ namespace Mist{
return;
}
}
udp.SendNow(rtpOutBuffer, (size_t)protectedSize);
udp.sendPaced(rtpOutBuffer, (size_t)protectedSize);
RTP::Packet tmpPkt(rtpOutBuffer, protectedSize);
uint32_t pSSRC = tmpPkt.getSSRC();
@ -1658,7 +1658,7 @@ namespace Mist{
}
}
udp.SendNow(rtpOutBuffer, rtcpPacketSize);
udp.sendPaced(rtpOutBuffer, rtcpPacketSize);
myConn.addUp(rtcpPacketSize);
if (volkswagenMode){
@ -1681,7 +1681,7 @@ namespace Mist{
// first make sure that we complete the DTLS handshake.
if(doDTLS){
while (keepGoing() && !dtlsHandshake.hasKeyingMaterial()){
if (!handleWebRTCInputOutput()){Util::sleep(10);}
if (!handleWebRTCInputOutput()){udp.sendPaced(10000);}
if (lastRecv < Util::bootMS() - 10000){
WARN_MSG("Killing idle connection in handshake phase");
onFail("idle connection in handshake phase", false);
@ -1901,7 +1901,7 @@ namespace Mist{
}
}
udp.SendNow((const char *)&buffer[0], buffer_size_in_bytes);
udp.sendPaced((const char *)&buffer[0], buffer_size_in_bytes);
myConn.addUp(buffer_size_in_bytes);
if (volkswagenMode){
@ -1942,7 +1942,7 @@ namespace Mist{
}
}
udp.SendNow((const char *)&buffer[0], buffer_size_in_bytes);
udp.sendPaced((const char *)&buffer[0], buffer_size_in_bytes);
myConn.addUp(buffer_size_in_bytes);
if (volkswagenMode){
@ -1993,7 +1993,7 @@ namespace Mist{
}
}
udp.SendNow((const char *)&buffer[0], buffer_size_in_bytes);
udp.sendPaced((const char *)&buffer[0], buffer_size_in_bytes);
myConn.addUp(buffer_size_in_bytes);
if (volkswagenMode){

View file

@ -148,6 +148,8 @@ namespace Mist{
virtual void connStats(uint64_t now, Comms::Connections &statComm);
inline virtual bool keepGoing(){return config->is_active && (noSignalling || myConn);}
virtual void requestHandler();
protected:
virtual void idleTime(uint64_t ms){udp.sendPaced(ms*1000);}
private:
bool noSignalling;
uint64_t lastRecv;