Skip to content

Commit

Permalink
stransmit cleanup stats and print sender
Browse files Browse the repository at this point in the history
  • Loading branch information
lars18th committed Jan 29, 2018
1 parent dc2a555 commit 5b648ab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
8 changes: 4 additions & 4 deletions apps/srt-live-transmit.cpp
Expand Up @@ -257,7 +257,7 @@ int main( int argc, char** argv )
}

int timeout = stoi(Option("30", "t", "to", "timeout"), 0, 0);
size_t chunk = stoul(Option("0", "c", "chunk"), 0, 0);
unsigned long chunk = stoul(Option("0", "c", "chunk"), 0, 0);
if ( chunk == 0 )
{
chunk = SRT_LIVE_DEF_PLSIZE;
Expand All @@ -276,14 +276,14 @@ int main( int argc, char** argv )
bool skip_flushing = Option("no", "S", "skipflush") != "no";

// Options that require integer conversion
size_t bandwidth;
size_t stoptime;
unsigned long bandwidth;
unsigned long stoptime;

try
{
bandwidth = stoul(Option("0", "b", "bandwidth", "bitrate"));
transmit_bw_report = stoul(Option("0", "r", "report", "bandwidth-report", "bitrate-report"));
transmit_stats_report = stoi(Option("0", "s", "stats", "stats-report-frequency"));
transmit_stats_report = stoul(Option("0", "s", "stats", "stats-report-frequency"));
stoptime = stoul(Option("0", "d", "stoptime"));
}
catch (std::invalid_argument)
Expand Down
6 changes: 3 additions & 3 deletions common/transmitbase.hpp
Expand Up @@ -10,10 +10,10 @@
typedef std::vector<char> bytevector;
extern bool transmit_verbose;
extern volatile bool transmit_throw_on_interrupt;
extern int transmit_bw_report;
extern unsigned transmit_stats_report;
extern unsigned long transmit_bw_report;
extern unsigned long transmit_stats_report;
extern std::ostream* transmit_cverb;
extern size_t transmit_chunk_size;
extern unsigned long transmit_chunk_size;

static const struct VerboseLogNoEol { VerboseLogNoEol() {} } VerbNoEOL;

Expand Down
48 changes: 33 additions & 15 deletions common/transmitmedia.cpp
Expand Up @@ -2,6 +2,7 @@

// Just for formality. This file should be used
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
Expand All @@ -22,9 +23,9 @@ using namespace std;
bool transmit_verbose = false;
std::ostream* transmit_cverb = nullptr;
volatile bool transmit_throw_on_interrupt = false;
int transmit_bw_report = 0;
unsigned transmit_stats_report = 0;
size_t transmit_chunk_size = SRT_LIVE_DEF_PLSIZE;
unsigned long transmit_bw_report = 0;
unsigned long transmit_stats_report = 0;
unsigned long transmit_chunk_size = SRT_LIVE_DEF_PLSIZE;

class FileSource: public Source
{
Expand Down Expand Up @@ -86,15 +87,15 @@ template <class PerfMonType>
void PrintSrtStats(int sid, const PerfMonType& mon)
{
cout << "======= SRT STATS: sid=" << sid << endl;
cout << "PACKETS SENT: " << mon.pktSent << " RECEIVED: " << mon.pktRecv << endl;
cout << "LOST PKT SENT: " << mon.pktSndLoss << " RECEIVED: " << mon.pktRcvLoss << endl;
cout << "REXMIT SENT: " << mon.pktRetrans << " RECEIVED: " << mon.pktRcvRetrans << endl;
cout << "RATE SENDING: " << mon.mbpsSendRate << " RECEIVING: " << mon.mbpsRecvRate << endl;
cout << "BELATED RECEIVED: " << mon.pktRcvBelated << " AVG TIME: " << mon.pktRcvAvgBelatedTime << endl;
cout << "REORDER DISTANCE: " << mon.pktReorderDistance << endl;
cout << "WINDOW: FLOW: " << mon.pktFlowWindow << " CONGESTION: " << mon.pktCongestionWindow << " FLIGHT: " << mon.pktFlightSize << endl;
cout << "RTT: " << mon.msRTT << "ms BANDWIDTH: " << mon.mbpsBandwidth << "Mb/s\n";
cout << "BUFFERLEFT: SND: " << mon.byteAvailSndBuf << " RCV: " << mon.byteAvailRcvBuf << endl;
cout << "PACKETS SENT: " << setw(11) << mon.pktSent << " RECEIVED: " << setw(11) << mon.pktRecv << endl;
cout << "LOST PKT SENT: " << setw(11) << mon.pktSndLoss << " RECEIVED: " << setw(11) << mon.pktRcvLoss << endl;
cout << "REXMIT SENT: " << setw(11) << mon.pktRetrans << " RECEIVED: " << setw(11) << mon.pktRcvRetrans << endl;
cout << "RATE SENDING: " << setw(11) << mon.mbpsSendRate << " RECEIVING: " << setw(11) << mon.mbpsRecvRate << endl;
cout << "BELATED RECEIVED: " << setw(11) << mon.pktRcvBelated << " AVG TIME: " << setw(11) << mon.pktRcvAvgBelatedTime << endl;
cout << "REORDER DISTANCE: " << setw(11) << mon.pktReorderDistance << endl;
cout << "WINDOW: FLOW: " << setw(11) << mon.pktFlowWindow << " CONGESTION: " << setw(11) << mon.pktCongestionWindow << " FLIGHT: " << setw(11) << mon.pktFlightSize << endl;
cout << "RTT: " << setw(9) << mon.msRTT << "ms BANDWIDTH: " << setw(7) << mon.mbpsBandwidth << "Mb/s " << endl;
cout << "BUFFERLEFT: SND: " << setw(11) << mon.byteAvailSndBuf << " RCV: " << setw(11) << mon.byteAvailRcvBuf << endl;
}


Expand Down Expand Up @@ -667,7 +668,7 @@ SrtSource::SrtSource(string host, int port, const map<string,string>& par)

bytevector SrtSource::Read(size_t chunk)
{
static size_t counter = 1;
static unsigned long counter = 1;

bytevector data(chunk);
bool ready = true;
Expand Down Expand Up @@ -715,12 +716,12 @@ bytevector SrtSource::Read(size_t chunk)

CBytePerfMon perf;
srt_bstats(m_sock, &perf, true);
if ( transmit_bw_report && int(counter % transmit_bw_report) == transmit_bw_report - 1 )
if ( transmit_bw_report && (counter % transmit_bw_report) == transmit_bw_report - 1 )
{
cout << "+++/+++SRT BANDWIDTH: " << perf.mbpsBandwidth << endl;
}

if ( transmit_stats_report && counter % transmit_stats_report == transmit_stats_report - 1)
if ( transmit_stats_report && (counter % transmit_stats_report) == transmit_stats_report - 1)
{
PrintSrtStats(m_sock, perf);
}
Expand Down Expand Up @@ -750,6 +751,8 @@ int SrtTarget::ConfigurePre(SRTSOCKET sock)

void SrtTarget::Write(const bytevector& data)
{
static unsigned long counter = 1;

::transmit_throw_on_interrupt = true;

// Check first if it's ready to write.
Expand All @@ -765,6 +768,21 @@ void SrtTarget::Write(const bytevector& data)
int stat = srt_sendmsg2(m_sock, data.data(), data.size(), nullptr);
if ( stat == SRT_ERROR )
Error(UDT::getlasterror(), "srt_sendmsg");

CBytePerfMon perf;
srt_bstats(m_sock, &perf, true);
if ( transmit_bw_report && (counter % transmit_bw_report) == transmit_bw_report - 1 )
{
cout << "+++/+++SRT BANDWIDTH: " << perf.mbpsBandwidth << endl;
}

if ( transmit_stats_report && (counter % transmit_stats_report) == transmit_stats_report - 1)
{
PrintSrtStats(m_sock, perf);
}

++counter;

::transmit_throw_on_interrupt = false;
}

Expand Down

0 comments on commit 5b648ab

Please sign in to comment.