diff --git a/apps/srt-live-transmit.cpp b/apps/srt-live-transmit.cpp index 572faae87..29d099664 100644 --- a/apps/srt-live-transmit.cpp +++ b/apps/srt-live-transmit.cpp @@ -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; @@ -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) diff --git a/common/transmitbase.hpp b/common/transmitbase.hpp index bc9776ffe..03c957c78 100644 --- a/common/transmitbase.hpp +++ b/common/transmitbase.hpp @@ -10,10 +10,10 @@ typedef std::vector 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; diff --git a/common/transmitmedia.cpp b/common/transmitmedia.cpp index d5f65d742..6691f97bb 100644 --- a/common/transmitmedia.cpp +++ b/common/transmitmedia.cpp @@ -2,6 +2,7 @@ // Just for formality. This file should be used #include +#include #include #include #include @@ -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 { @@ -86,15 +87,15 @@ template 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; } @@ -667,7 +668,7 @@ SrtSource::SrtSource(string host, int port, const map& par) bytevector SrtSource::Read(size_t chunk) { - static size_t counter = 1; + static unsigned long counter = 1; bytevector data(chunk); bool ready = true; @@ -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); } @@ -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. @@ -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; }