mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 21:40:20 +00:00
GUI: recv_loss: Factor report collection into own class
This commit is contained in:
52
gui/QT/util/ssrc_container.hpp
Normal file
52
gui/QT/util/ssrc_container.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef SSRC_CONTAINER_HPP_1b2b8951b25f
|
||||
#define SSRC_CONTAINER_HPP_1b2b8951b25f
|
||||
|
||||
#include <vector>
|
||||
|
||||
template<typename T, typename Ts_type>
|
||||
class SSRC_container{
|
||||
public:
|
||||
struct Holder{
|
||||
T item;
|
||||
uint32_t ssrc;
|
||||
Ts_type timestamp;
|
||||
};
|
||||
|
||||
void insert(uint32_t ssrc, const T& item, Ts_type timestamp);
|
||||
const std::vector<Holder>& get() const { return items; }
|
||||
void remove_timed_out(Ts_type timeout, Ts_type now);
|
||||
void clear() { items.clear(); }
|
||||
|
||||
private:
|
||||
std::vector<Holder> items;
|
||||
};
|
||||
|
||||
template<typename T, typename Ts_type>
|
||||
inline void SSRC_container<T, Ts_type>::insert(uint32_t ssrc, const T& item, Ts_type timestamp){
|
||||
Holder *h = nullptr;
|
||||
for(auto& i : items){
|
||||
if(i.ssrc == ssrc){
|
||||
h = &i;
|
||||
}
|
||||
}
|
||||
|
||||
if(!h){
|
||||
Holder newItem;
|
||||
newItem.ssrc = ssrc;
|
||||
items.push_back(newItem);
|
||||
h = &items.back();
|
||||
}
|
||||
|
||||
h->item = item;
|
||||
h->timestamp = timestamp;
|
||||
}
|
||||
|
||||
template<typename T, typename Ts_type>
|
||||
inline void SSRC_container<T, Ts_type>::remove_timed_out(Ts_type timeout, Ts_type now){
|
||||
auto endIt = std::remove_if(items.begin(), items.end(),
|
||||
[now, timeout](const Holder& h){ return now - h.timestamp > timeout; });
|
||||
|
||||
items.erase(endIt, items.end());
|
||||
}
|
||||
|
||||
#endif //SSRC_CONTAINER_HPP_1b2b8951b25f
|
||||
@@ -75,6 +75,7 @@ HEADERS += window/ultragrid_window.hpp \
|
||||
util/debug.hpp \
|
||||
util/line_buffer.hpp \
|
||||
util/control_port.hpp \
|
||||
util/ssrc_container.hpp \
|
||||
|
||||
FORMS += ui/ultragrid_window.ui \
|
||||
ui/log_window.ui \
|
||||
|
||||
@@ -47,41 +47,24 @@ void RecvLossWidget::parseLine(std::string_view line){
|
||||
}
|
||||
|
||||
void RecvLossWidget::addReport(int ssrc, int received, int total){
|
||||
SSRC_report *rep = nullptr;
|
||||
for(auto& r : reports){
|
||||
if(r.ssrc == ssrc){
|
||||
rep = &r;
|
||||
}
|
||||
}
|
||||
|
||||
if(!rep){
|
||||
SSRC_report newRep;
|
||||
newRep.ssrc = ssrc;
|
||||
reports.push_back(newRep);
|
||||
rep = &reports.back();
|
||||
}
|
||||
|
||||
rep->received = received;
|
||||
rep->total = total;
|
||||
rep->lastReportMs = elapsedTimer.elapsed();
|
||||
SSRC_report rep;
|
||||
rep.received = received;
|
||||
rep.total = total;
|
||||
reports.insert(ssrc, rep, elapsedTimer.elapsed());
|
||||
}
|
||||
|
||||
void RecvLossWidget::updateVal(){
|
||||
int received = 0;
|
||||
int total = 0;
|
||||
|
||||
auto now = elapsedTimer.elapsed();
|
||||
auto endIt = std::remove_if(reports.begin(), reports.end(),
|
||||
[now](const SSRC_report& r){ return now - r.lastReportMs > timeout_msec; });
|
||||
|
||||
reports.erase(endIt, reports.end());
|
||||
reports.remove_timed_out(timeout_msec, elapsedTimer.elapsed());
|
||||
|
||||
QString tooltip;
|
||||
for(auto& r : reports){
|
||||
received += r.received;
|
||||
total += r.total;
|
||||
for(auto& r : reports.get()){
|
||||
received += r.item.received;
|
||||
total += r.item.total;
|
||||
tooltip += QString::number(r.ssrc, 16) + ": "
|
||||
+ QString::number(r.received) + '/' + QString::number(r.total) + '\n';
|
||||
+ QString::number(r.item.received) + '/' + QString::number(r.item.total) + '\n';
|
||||
}
|
||||
|
||||
if(tooltip.endsWith('\n'))
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
#include <QProgressBar>
|
||||
#include <QTimer>
|
||||
|
||||
#include <vector>
|
||||
#include <QElapsedTimer>
|
||||
#include <string_view>
|
||||
|
||||
#include "ssrc_container.hpp"
|
||||
|
||||
class RecvLossWidget : public QProgressBar{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -27,13 +28,10 @@ private:
|
||||
QElapsedTimer elapsedTimer;
|
||||
|
||||
struct SSRC_report{
|
||||
int ssrc = 0;
|
||||
int received = 0;
|
||||
int total = 0;
|
||||
|
||||
qint64 lastReportMs = 0;
|
||||
};
|
||||
std::vector<SSRC_report> reports;
|
||||
SSRC_container<SSRC_report, decltype(elapsedTimer.elapsed())> reports;
|
||||
|
||||
void addReport(int ssrc, int received, int total);
|
||||
void updateVal();
|
||||
|
||||
Reference in New Issue
Block a user