Skip to content

Commit

Permalink
Post-merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Jan 17, 2024
1 parent 9ba8c1e commit 1a06628
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 65 deletions.
1 change: 1 addition & 0 deletions apps/socketoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ const SocketOption srt_options [] {
{ "mininputbw", 0, SRTO_MININPUTBW, SocketOption::POST, SocketOption::INT64, nullptr},
{ "oheadbw", 0, SRTO_OHEADBW, SocketOption::POST, SocketOption::INT, nullptr},
{ "latency", 0, SRTO_LATENCY, SocketOption::PRE, SocketOption::INT, nullptr},
{ "tsbpdmode", 0, SRTO_TSBPDMODE, SocketOption::PRE, SocketOption::BOOL, nullptr},
{ "tlpktdrop", 0, SRTO_TLPKTDROP, SocketOption::PRE, SocketOption::BOOL, nullptr},
{ "snddropdelay", 0, SRTO_SNDDROPDELAY, SocketOption::POST, SocketOption::INT, nullptr},
{ "nakreport", 0, SRTO_NAKREPORT, SocketOption::PRE, SocketOption::BOOL, nullptr},
Expand Down
1 change: 0 additions & 1 deletion srtcore/congctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class LiveCC: public SrtCongestionControlBase

/// @brief On RTO event update an inter-packet send interval.
/// @param arg EventVariant::STAGE to distinguish between INIT and actual RTO.

void onRTO(ETransmissionEvent , ECheckTimerStage stage)
{
if (stage != TEV_CHT_INIT)
Expand Down
13 changes: 8 additions & 5 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,9 @@ class CUDT
bool updateCC(typename EventMapping<Ev>::type arg);

public:
// Parts. Made public due to being called from external structs.
// Parts. Made public due to being called from external structs
// that are necessary to forward to a real caller or empty caller
// depending on whether allowed for particular event type.
bool updateCC_Checks();
void updateCC_INIT(EInitEvent istage);
void updateCC_GETRATE();
Expand Down Expand Up @@ -1291,6 +1293,7 @@ template<> struct updateCC_CallIf_GETRATE<event> \
ALLOW_GETRATE(TEV_ACK);
ALLOW_GETRATE(TEV_LOSSREPORT);
ALLOW_GETRATE(TEV_CHECKTIMER);
ALLOW_GETRATE(TEV_SYNC);
#undef ALLOW_GETRATE

// UPDATE part - allow for others, except given
Expand Down Expand Up @@ -1320,20 +1323,20 @@ bool CUDT::updateCC(typename EventMapping<Ev>::type arg)

typedef typename EventMapping<Ev>::type arg_t;

HLOGC(rslog.Debug, log << "updateCC: EVENT:" << TransmissionEventStr(Ev));

if (!updateCC_Checks())
{
HLOGC(rslog.Error, log << "updateCC: EVENT FAILED:" << TransmissionEventStr(Ev));
return false;
}

HLOGC(rslog.Debug, log << "updateCC: EVENT:" << TransmissionEventStr(Ev));

// --> Follow: updateCC_INIT(), only if Ev == TEV_INIT
updateCC_CallIf_INIT<Ev, arg_t>::call(this, arg);

// --> Follow: updateCC_GETRATE(), only if Ev is ACK, LOSSREPORT, CHECKTIMER
// --> Follow: updateCC_GETRATE(), only if Ev is ACK, LOSSREPORT, CHECKTIMER, SYNC
updateCC_CallIf_GETRATE<Ev>::call(this);
// This part is also required only by LiveSmoother, however not
// This part is also required only by LiveCC, however not
// moved there due to that it needs access to CSndBuffer.

EmitSignal<Ev>(arg);
Expand Down
2 changes: 1 addition & 1 deletion srtcore/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,5 @@ inline void LogDispatcher::PrintLogLine(const char* file SRT_ATR_UNUSED, int lin

}

#endif // INC__SRT_LOGGING_H
#endif // INC_SRT_LOGGING_H

14 changes: 14 additions & 0 deletions srtcore/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,10 @@ struct PassFilter
T lower, median, upper;
};

// This utility is used in window.cpp where it is required to calculate
// the median value basing on the value in the very middle and filtered
// out values exceeding its range of 1/8 and 8 times. Returned is a structure
// that shows the median and also the lower and upper value used for filtering.
inline PassFilter<int> GetPeakRange(const int* window, int* replica, size_t size)
{
// This calculation does more-less the following:
Expand Down Expand Up @@ -909,6 +913,9 @@ inline PassFilter<int> GetPeakRange(const int* window, int* replica, size_t size
return filter;
}

// This function sums up all values in the array (from p to end),
// except those that don't fit in the low- and high-pass filter.
// Returned is the sum and the number of elements taken into account.
inline std::pair<int, int> AccumulatePassFilter(const int* p, const int* end, PassFilter<int> filter)
{
int count = 0;
Expand All @@ -926,6 +933,13 @@ inline std::pair<int, int> AccumulatePassFilter(const int* p, const int* end, Pa
return std::make_pair(sum, count);
}

// This function sums up all values in the array (from p to end)
// and simultaneously elements from `para`, stated it points to
// an array of the same size. The first array is used as a driver
// for which elements to include and which to skip, and this is done
// for both arrays at particular index position. Returner is the sum
// of the elements passed from the first array and from the `para`
// array, as well as the number of included elements.
template <class IntCount, class IntParaCount>
inline void AccumulatePassFilterParallel(const int* p, const int* end, PassFilter<int> filter,
const int* para,
Expand Down
71 changes: 13 additions & 58 deletions srtcore/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ void srt::CPktTimeWindowTools::initializeWindowArrays(int* r_pktWindow, int* r_p
}


int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, const int* abytes, size_t asize, size_t hdr_size, int& bytesps)
int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, const int* abytes, size_t asize, size_t hdr_size, int& w_bytesps)
{
PassFilter<int> filter = GetPeakRange(window, replica, asize);

unsigned count = 0;
int sum = 0;

bytesps = 0;
w_bytesps = 0;
unsigned long bytes = 0;
// // (explicit specialization due to problems on MSVC 2013 and 2015)
AccumulatePassFilterParallel<unsigned, unsigned long>(window, window + asize, filter, abytes,
Expand All @@ -175,72 +175,27 @@ int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica,
if (count > (asize >> 1))
{
bytes += (hdr_size * count); //Add protocol headers to bytes received
bytesps = (int)ceil(1000000.0 / (double(sum) / double(bytes)));
w_bytesps = (int)ceil(1000000.0 / (double(sum) / double(bytes)));
return (int)ceil(1000000.0 / (sum / count));
}
else
{
bytesps = 0;
w_bytesps = 0;
return 0;
}
}

int srt::CPktTimeWindowTools::getBandwidth_in(const int* window, int* replica, size_t psize)
{
// XXX REPLACE ->
// int count;
// int sum;
// Tie2(sum, count) = AccumulatePassFilter(window, window + psize, filter);
// count += 1;
// sum += filter.median;

// This calculation does more-less the following:
//
// 1. Having example window:
// - 50, 51, 100, 55, 80, 1000, 600, 1500, 1200, 10, 90
// 2. This window is now sorted, but we only know the value in the middle:
// - 10, 50, 51, 55, 80, [[90]], 100, 600, 1000, 1200, 1500
// 3. Now calculate:
// - lower: 90/8 = 11.25
// - upper: 90*8 = 720
// 4. Now calculate the arithmetic median from all these values,
// but drop those from outside the <lower, upper> range:
// - 10, (11<) [ 50, 51, 55, 80, 90, 100, 600, ] (>720) 1000, 1200, 1500
// 5. Calculate the median from the extracted range,
// NOTE: the median is actually repeated once, so size is +1.
//
// values = { 50, 51, 55, 80, 90, 100, 600 };
// sum = 90 + accumulate(values); ==> 1026
// median = sum/(1 + values.size()); ==> 147
//
// For comparison: the overall arithmetic median from this window == 430
//
// 6. Returned value = 1M/median

// get median value, but cannot change the original value order in the window
std::copy(window, window + psize - 1, replica);
std::nth_element(replica, replica + (psize / 2), replica + psize - 1);
//std::sort(replica, replica + psize); <--- was used for debug, just leave it as a mark
int median = replica[psize / 2];

int count = 1;
int sum = median;
int upper = median << 3; // median*8
int lower = median >> 3; // median/8

// median filtering
const int* p = window;
for (int i = 0, n = (int)psize; i < n; ++ i)
{
if ((*p < upper) && (*p > lower))
{
++ count;
sum += *p;
}
++ p;
}
// XXX <-
return (int)ceil(1000000.0 / (double(sum) / double(count)));
PassFilter<int> filter = GetPeakRange(window, replica, psize);

int count;
int sum;
Tie2(sum, count) = AccumulatePassFilter(window, window + psize, filter);
count += 1;
sum += filter.median;

return (int)ceil(1000000.0 / (double(sum) / double(count)));
}


0 comments on commit 1a06628

Please sign in to comment.