RTPTime RTCPScheduler::CalculateBYETransmissionInterval() { if (!byescheduled) return RTPTime(0,0); if (sendbyenow) return RTPTime(0,0); double C,n; C = ((double)avgbyepacketsize)/((1.0-schedparams.GetSenderBandwidthFraction())*schedparams.GetRTCPBandwidth()); n = (double)byemembers; RTPTime Tmin = schedparams.GetMinimumTransmissionInterval(); double tmin = Tmin.GetDouble(); if (schedparams.GetUseHalfAtStartup()) tmin /= 2.0; double ntimesC = n*C; double Td = (tmin>ntimesC)?tmin:ntimesC; double mul = rtprand.GetRandomDouble()+0.5; // gives random value between 0.5 and 1.5 double T = (Td*mul)/1.21828; // see RFC 3550 p 30 return RTPTime(T); }
void RTPPollThread::Stop() { if (!IsRunning()) return; stopmutex.Lock(); stop = true; stopmutex.Unlock(); if (transmitter) transmitter->AbortWait(); RTPTime thetime = RTPTime::CurrentTime(); bool done = false; while (JThread::IsRunning() && !done) { // wait max 5 sec RTPTime curtime = RTPTime::CurrentTime(); if ((curtime.GetDouble()-thetime.GetDouble()) > 5.0) done = true; RTPTime::Wait(RTPTime(0,10000)); } if (JThread::IsRunning()) { #ifndef _WIN32_WCE std::cerr << "RTPPollThread: Warning! Having to kill thread!" << std::endl; #endif // _WIN32_WCE JThread::Kill(); } stop = false; transmitter = 0; }
RTPTime RTCPScheduler::CalculateDeterministicInterval(bool sender /* = false */) { int numsenders = sources.GetSenderCount(); int numtotal = sources.GetActiveMemberCount(); // std::cout << "CalculateDeterministicInterval" << std::endl; // std::cout << " numsenders: " << numsenders << std::endl; // std::cout << " numtotal: " << numtotal << std::endl; // Try to avoid division by zero: if (numtotal == 0) numtotal++; double sfraction = ((double)numsenders)/((double)numtotal); double C,n; if (sfraction <= schedparams.GetSenderBandwidthFraction()) { if (sender) { C = ((double)avgrtcppacksize)/(schedparams.GetSenderBandwidthFraction()*schedparams.GetRTCPBandwidth()); n = (double)numsenders; } else { C = ((double)avgrtcppacksize)/((1.0-schedparams.GetSenderBandwidthFraction())*schedparams.GetRTCPBandwidth()); n = (double)(numtotal-numsenders); } } else { C = ((double)avgrtcppacksize)/schedparams.GetRTCPBandwidth(); n = (double)numtotal; } RTPTime Tmin = schedparams.GetMinimumTransmissionInterval(); double tmin = Tmin.GetDouble(); if (!hassentrtcp && schedparams.GetUseHalfAtStartup()) tmin /= 2.0; double ntimesC = n*C; double Td = (tmin>ntimesC)?tmin:ntimesC; // TODO: for debugging // std::cout << " Td: " << Td << std::endl; return RTPTime(Td); }
RTPTime RTCPScheduler::CalculateTransmissionInterval(bool sender) { RTPTime Td = CalculateDeterministicInterval(sender); double td,mul,T; // std::cout << "CalculateTransmissionInterval" << std::endl; td = Td.GetDouble(); mul = rtprand.GetRandomDouble()+0.5; // gives random value between 0.5 and 1.5 T = (td*mul)/1.21828; // see RFC 3550 p 30 // std::cout << " Td: " << td << std::endl; // std::cout << " mul: " << mul << std::endl; // std::cout << " T: " << T << std::endl; return RTPTime(T); }
int RTCPSchedulerParams::SetMinimumTransmissionInterval(const RTPTime &t) { double t2 = t.GetDouble(); if (t2 < RTCPSCHED_MININTERVAL) return ERR_RTP_SCHEDPARAMS_BADMINIMUMINTERVAL; mininterval = t; return 0; }