UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
BandwidthWidget Class Reference

#include <bandwidth_widget.hpp>

Inheritance diagram for BandwidthWidget:
Inheritance graph
Collaboration diagram for BandwidthWidget:
Collaboration graph

Classes

struct  BandwidthReport
 

Public Member Functions

 BandwidthWidget (QWidget *parent=nullptr)
 
 ~BandwidthWidget ()=default
 
void parseLine (std::string_view line)
 
void reset ()
 
void updateVal ()
 

Private Slots

void timeout ()
 

Private Attributes

QElapsedTimer elapsedTimer
 
SSRC_container< BandwidthReport, decltype(elapsedTimer.elapsed())> reports
 
const int timeout_msec = 2500
 
QTimer timer
 

Detailed Description

Definition at line 13 of file bandwidth_widget.hpp.

Constructor & Destructor Documentation

◆ BandwidthWidget()

BandwidthWidget::BandwidthWidget ( QWidget * parent = nullptr)

Definition at line 21 of file bandwidth_widget.cpp.

21 : QLabel(parent){
22 elapsedTimer.start();
23 reset();
24 QObject::connect(&timer, &QTimer::timeout, this, &BandwidthWidget::timeout);
25 timer.setInterval(timeout_msec);
26}
QElapsedTimer elapsedTimer
const char * parent
Definition settings.cpp:198

References elapsedTimer, reset(), timeout(), timeout_msec, and timer.

Here is the call graph for this function:

◆ ~BandwidthWidget()

BandwidthWidget::~BandwidthWidget ( )
default

Member Function Documentation

◆ parseLine()

void BandwidthWidget::parseLine ( std::string_view line)

Definition at line 56 of file bandwidth_widget.cpp.

56 {
57 static constexpr std::string_view prefix = "stats tx_send";
58 if(!sv_is_prefix(line, prefix))
59 return;
60
61 line.remove_prefix(prefix.size());
62
63 auto ssrc_sv = tokenize(line, ' ');
64 if(ssrc_sv.substr(0, 2) == "0x")
65 ssrc_sv.remove_prefix(2);
66 auto type = tokenize(line, ' ');
67 auto bytes_sv = tokenize(line, ' ');
68
69 long long bytes = 0;
70 uint32_t ssrc = 0;
71 if(!parse_num(bytes_sv, bytes)
72 || !parse_num(ssrc_sv, ssrc, 16))
73 {
74 return;
75 }
76
77 BandwidthReport report = {};
78 report.bitsPerSecond = 0;
79 report.type = type;
80
81 for(const auto& r : reports.get()){
82 if(r.ssrc != ssrc)
83 continue;
84
85 auto duration = std::max<qint64>(elapsedTimer.elapsed() - r.timestamp, 1);
86 report.bitsPerSecond = bytes * 8 * 1000 / duration;
87 }
88
89 reports.insert(ssrc, report, elapsedTimer.elapsed());
90 updateVal();
91}
SSRC_container< BandwidthReport, decltype(elapsedTimer.elapsed())> reports
steady_clock::duration duration
Definition echo.cpp:67
Option::OptType type
Definition settings.cpp:194
std::string_view tokenize(std::string_view &str, char delim, char quot)
Tokenizer for string_view.
bool parse_num(std::string_view sv, T &res, int base=10)
bool sv_is_prefix(std::string_view haystack, std::string_view needle)

References BandwidthWidget::BandwidthReport::bitsPerSecond, elapsedTimer, parse_num(), reports, sv_is_prefix(), tokenize(), BandwidthWidget::BandwidthReport::type, type, and updateVal().

Referenced by UltragridWindow::UltragridWindow().

Here is the call graph for this function:

◆ reset()

void BandwidthWidget::reset ( )

Definition at line 93 of file bandwidth_widget.cpp.

93 {
94 reports.clear();
95 updateVal();
96 timer.stop();
97}

References reports, timer, and updateVal().

Referenced by BandwidthWidget(), and timeout().

Here is the call graph for this function:

◆ timeout

void BandwidthWidget::timeout ( )
privateslot

Definition at line 99 of file bandwidth_widget.cpp.

99 {
100 reset();
101}

References reset().

Referenced by BandwidthWidget().

Here is the call graph for this function:

◆ updateVal()

void BandwidthWidget::updateVal ( )

Definition at line 28 of file bandwidth_widget.cpp.

28 {
29 reports.remove_timed_out(timeout_msec, elapsedTimer.elapsed());
30
31 if(!isEnabled()){
32 setText("-- bps");
33 setToolTip("");
34 return;
35 }
36
37 long long total = 0;
38 QString tooltip;
39 for(const auto& i : reports.get()){
40 total += i.item.bitsPerSecond;
41 tooltip += QString::number(i.ssrc, 16)
42 + " (" + QString::fromStdString(i.item.type) + "): "
43 + getBitrateStr(i.item.bitsPerSecond) + "\n";
44 }
45
46 if(tooltip.endsWith('\n'))
47 tooltip.chop(1);
48
49 setToolTip(tooltip);
50
51 setText(getBitrateStr(total));
52
53 timer.start();
54}

References elapsedTimer, reports, timeout_msec, and timer.

Referenced by parseLine(), and reset().

Member Data Documentation

◆ elapsedTimer

QElapsedTimer BandwidthWidget::elapsedTimer
private

Definition at line 28 of file bandwidth_widget.hpp.

Referenced by BandwidthWidget(), parseLine(), and updateVal().

◆ reports

SSRC_container<BandwidthReport, decltype(elapsedTimer.elapsed())> BandwidthWidget::reports
private

Definition at line 35 of file bandwidth_widget.hpp.

Referenced by parseLine(), reset(), and updateVal().

◆ timeout_msec

const int BandwidthWidget::timeout_msec = 2500
private

Definition at line 37 of file bandwidth_widget.hpp.

Referenced by BandwidthWidget(), and updateVal().

◆ timer

QTimer BandwidthWidget::timer
private

Definition at line 27 of file bandwidth_widget.hpp.

Referenced by BandwidthWidget(), reset(), and updateVal().


The documentation for this class was generated from the following files: