From 5b1521c5c8e48ca094c1a5d1b242fe2f42a4f07e Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 5 Nov 2021 14:24:42 +0100 Subject: [PATCH] Tweaks to Sender Report timings, fixed lost packet counter in WebRTC output, WebRTC lost packets are now counted per SSRC instead of globally --- src/output/output_webrtc.cpp | 30 +++++++++++++++++++++++++----- src/output/output_webrtc.h | 5 ++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/output/output_webrtc.cpp b/src/output/output_webrtc.cpp index 94fd1fdd..2bd33f44 100644 --- a/src/output/output_webrtc.cpp +++ b/src/output/output_webrtc.cpp @@ -1355,9 +1355,21 @@ namespace Mist{ } } }else if (pt == 73){ - //73 = receiver report - uint32_t packets = Bit::btoh24(udp.data + 13); - totalLoss = packets; + //73 = receiver report: https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.2 + //Packet may contain more than one report + char * ptr = udp.data + 8; + while (ptr + 24 <= udp.data + udp.data.size()){ + //Update the counter for this ssrc + uint32_t ssrc = Bit::btoh24(ptr); + lostPackets[ssrc] = Bit::btoh24(ptr + 5); + //Update pointer to next report + ptr += 24; + } + //Count total lost packets + totalLoss = 0; + for (std::map::iterator it = lostPackets.begin(); it != lostPackets.end(); ++it){ + totalLoss += it->second; + } }else{ if (packetLog.is_open()){packetLog << "[" << Util::bootMS() << "]" << "Unknown payload type: " << pt << std::endl;} WARN_MSG("Unknown RTP feedback payload type: %u", pt); @@ -1632,8 +1644,16 @@ namespace Mist{ rtcTrack.rtpPacketizer.sendData(&udp, onRTPPacketizerHasDataCallback, dataPointer, dataLen, rtcTrack.payloadType, M.getCodec(thisIdx)); - if (!lastSR.count(thisIdx) || lastSR[thisIdx]+500 < Util::bootMS()){ - lastSR[thisIdx] = Util::bootMS(); + //Trigger a re-send of the Sender Report for every track every ~250ms + if (lastSR+250 < Util::bootMS()){ + for (std::map::iterator it = userSelect.begin(); it != userSelect.end(); it++){ + mustSendSR.insert(it->first); + } + lastSR = Util::bootMS(); + } + //If this track hasn't sent yet, actually sent + if (mustSendSR.count(thisIdx)){ + mustSendSR.erase(thisIdx); rtcTrack.rtpPacketizer.sendRTCP_SR((void *)&udp, onRTPPacketizerHasRTCPDataCallback); } } diff --git a/src/output/output_webrtc.h b/src/output/output_webrtc.h index b2b528c5..f98f47be 100644 --- a/src/output/output_webrtc.h +++ b/src/output/output_webrtc.h @@ -228,6 +228,7 @@ namespace Mist{ uint64_t stats_lossnum; double stats_lossperc; std::deque stats_loss_avg; + std::map lostPackets; #if defined(WEBRTC_PCAP) PCAPWriter pcapOut; ///< Used during development to write unprotected packets that can be @@ -240,7 +241,9 @@ namespace Mist{ ///< supports RED/ULPFEC; can also be used to map RTX in the ///< future. std::map outBuffers; - std::map lastSR; + + uint64_t lastSR; + std::set mustSendSR; int64_t ntpClockDifference; bool syncedNTPClock;