RTPSession Class Reference

#include <rtp.h>

List of all members.

Public Member Functions

 RTPSession ()
 ~RTPSession ()
virtual void recv (Packet *p, Handler *)
virtual void recv_ctrl (Packet *p)
int command (int argc, const char *const *argv)
u_int32_t srcid ()
int build_report (int bye)
void localsrc_update (int)
void update_rate ()
void pass_sr (sender_report *)
void localsrc_update_nbytes (int n)
void smooth_rate (double rate)
int build_sdes ()
int build_bye ()
hdr_rtpaccess_hdr_rtp ()
void print_rcv ()

Public Attributes

RTPSourceallsrcs_
RTPSourcelocalsrc_
RTPReceiverreceivers_
int last_np_
int enableFlowControl_
double rx_recv_
double jitter_
double smooth_rate_

Protected Member Functions

RTPSourcelookup (u_int32_t)
RTPReceiverlookup_rcv (u_int32_t)
void enter (RTPSource *)
void enter_rcv (RTPReceiver *)
void calculate_RTT ()
void increase_rate (int a)
void measure_smooth_loss (double n)
void calculateR_tcp (int a)
void initial_rate (double a)
void remove_receiver (RTPReceiver *)
void calculate_alpha (double value)
void evaluate_jitter (double value)
void remove_sender (RTPSource *)

Protected Attributes

list< double > lst
double T_one_way_
hdr_rtprh_
int we_sent
double RTT_
double weight [8]
double pkt_loss_history [8]
double smooth_loss_
int last_pkts_lost_
int last_ehsr_
double tx_rate_
double time_elapsed_
double last_time_report_
double alpha
double smooth_factor
list< double > jitter_lst
double z_score


Detailed Description

the session class is the heart of the RTP protocol. all main functions can be found here. Any extension to the RTP code should reference this class

Definition at line 271 of file rtp.h.


Constructor & Destructor Documentation

RTPSession::RTPSession (  ) 

zero argument constructor

Definition at line 77 of file session-rtp.cc.

References alpha, enableFlowControl_, jitter_, last_time_report_, NOW, RTT_, rx_recv_, smooth_factor, smooth_loss_, smooth_rate_, weight, and z_score.

00078         : allsrcs_(0), localsrc_(0), receivers_(0),last_np_(0), T_one_way_(0),rh_(0),
00079         we_sent(0),last_pkts_lost_(0),last_ehsr_(-1),tx_rate_(0), time_elapsed_(0)
00080 {
00081         bind("enableFlowControl_", &enableFlowControl_);
00082         bind("rx_recv_",&rx_recv_);
00083         bind("jitter_",&jitter_);
00084         bind("RTT_",&RTT_);
00085         bind("z_score",&z_score);
00086         bind("smooth_loss_",&smooth_loss_);
00087         smooth_rate_ = 0;
00088         alpha = 1;
00089         smooth_factor = 0.1;
00090         last_time_report_ = NOW;
00091         weight[0] = 1;
00092         weight[1] = 1;
00093         weight[2] = 1;
00094         weight[3] = 1;
00095         weight[4] = 0.8;
00096         weight[5] = 0.6;
00097         weight[6] = 0.4;
00098         weight[7] = 0.2;
00099 }

RTPSession::~RTPSession (  ) 

destructor

Definition at line 104 of file session-rtp.cc.

References allsrcs_, localsrc_, lst, RTPReceiver::next, RTPSource::next, and receivers_.

00105 {
00106         while (allsrcs_ != 0) {
00107                 RTPSource* p = allsrcs_;
00108                 allsrcs_ = allsrcs_->next;
00109                 delete p;
00110         }
00111         delete localsrc_;
00112         while (receivers_ != 0) {
00113                 RTPReceiver* p = receivers_;
00114                 receivers_ = receivers_->next;
00115                 delete p;
00116         }
00117         lst.~list<double>();
00118         
00119 }


Member Function Documentation

void RTPSession::recv ( Packet *  p,
Handler *   
) [virtual]

this method accesses the RTP packets it adds a newly heard source, which is the originator of the RTP packet, calculates the one way trip time and calls the calculate_RTT(T_one_way_ , eff_rtt) method for the RTT calculation. It measures also the delay jitter time of the RTP packets. Use this method to update any wished field of the Source class instances

Parameters:
p the RTP packet that just received by the RTP Agent
 

Definition at line 288 of file session-rtp.cc.

References hdr_rtp::access(), RTPSource::cum_pkts_lost(), RTPSource::ehsr(), evaluate_jitter(), RTPSource::jitter(), jitter_, localsrc_, lookup(), RTPSource::nbytes(), NOW, RTPSource::np(), RTPSource::ps(), hdr_rtp::seqno(), RTPSource::srcid(), hdr_rtp::srcid(), T_one_way_, hdr_rtp::timestamp(), and RTPSource::transit().

Referenced by RTPAgent::recv().

00289 {
00290         hdr_cmn* mh = hdr_cmn::access(p);
00291         hdr_rtp* rh = hdr_rtp::access(p);
00292         RTPSource* s = lookup(rh->srcid());
00293 
00294         if (s == 0) {
00295                 if(rh->srcid()!=localsrc_->srcid()){
00296                         Tcl& tcl = Tcl::instance();
00297                         tcl.evalf("%s new-source %d", name(),rh->srcid());
00298                         s = (RTPSource*)TclObject::lookup(tcl.result());
00299                 }
00300         }
00301         if(rh->srcid()!=localsrc_->srcid())
00302         {
00303                 // calculate one way trip time
00304                 T_one_way_ = NOW - rh->timestamp();
00305                 // count packet losses
00306                 int pkts_lost = 0;
00307                 int difference =  rh->seqno() - s->ehsr();  
00308                 if (difference <= 1) { // to deal with the first RTP packet in which s->ehrs() = -1
00309                         pkts_lost = 0;
00310                         
00311                 }
00312                 
00313                 if (difference > 1) {
00314                         pkts_lost = difference -1;
00315                         
00316                 }
00317                 // calculate delay jitter, see RFC 3550 Appendix A8
00318                 double transit = NOW - rh->timestamp();
00319                 double d = transit - s->transit();
00320                 s->transit(transit);
00321                 if (d < 0) d = -d;
00322                 s->jitter( s->jitter() + (1./16.) * (d - s->jitter()));
00323                 evaluate_jitter(s->jitter());
00324                 jitter_ = s->jitter();
00325 //              printf("jitter %f \n",s->jitter());
00326                 s->np(1); // counts the packets that I have received from sender s
00327                 s->cum_pkts_lost(pkts_lost);// counts the packets that I have lost from sender s
00328                 s->ehsr(rh->seqno());// the first ehsr = -1
00329                 s->nbytes(mh->size()); // counts the number of bytes that I have lost from sender s
00330                 s->ps(mh->size());// the packet size in bytes
00331         }
00332         Packet::free(p);
00333 }

void RTPSession::recv_ctrl ( Packet *  p  )  [virtual]

the function that accesses and exploits the SR and RR here is where the sender calculates the effective RTT time based on the receiver's RR. The sender also updates its transmission rate based on the receivers' RR. We don't exploit the SR in this implementation but a third party eg a network controller can exploit both SR and RR, witout in fact joining the session

Parameters:
p the RTCP packet

Definition at line 497 of file session-rtp.cc.

References hdr_rtp::access(), receiver_report::bye(), calculate_alpha(), receiver_report::DLSR(), RTPReceiver::eff_rtt(), sr_extensions::eff_rtt(), enableFlowControl_, enter_rcv(), RTPSource::is_sender(), localsrc_, lookup(), lookup_rcv(), receiver_report::LSR(), RTPSource::LSR(), RTPReceiver::next, sr_extensions::next, NOW, receiver_report::R_tcp(), RTPReceiver::rate(), receivers_, remove_receiver(), hdr_rtp::rr_, sender_report::s_ext_, sender_report::sender_srcid(), hdr_rtp::sr_, RTPReceiver::srcid(), sr_extensions::srcid(), hdr_rtp::srcid(), RTPSource::srcid(), RTPSource::SRT(), hdr_rtp::timestamp(), and update_rate().

Referenced by RTCPAgent::recv().

00498 {
00499         hdr_cmn* mh = hdr_cmn::access(p);
00500         hdr_rtp* rh = hdr_rtp::access(p);
00501         u_int32_t local_src = localsrc_->srcid();
00502         
00503         if(rh->srcid() != local_src) {
00504         
00505                 if (rh->sr_ != 0) { // get the Sender report
00506                         RTPSource* source = lookup(rh->sr_->sender_srcid());
00507                         if (source != 0 && source->srcid()!= local_src) {
00508                                 source->LSR(rh->timestamp());
00509                                 source->SRT(NOW);
00510                                 
00511                                 if(rh->sr_->s_ext_ != 0) {
00512                                 sr_extensions* se = new sr_extensions;
00513                                 for (se = rh->sr_->s_ext_; se != 0; se = se->next) {
00514 
00515                                         if(se->srcid()==localsrc_->srcid()) {
00516                                         
00517                                                 if(se->eff_rtt() == 0) {
00518                                                         calculate_alpha(0);
00519                                                 } else calculate_alpha(se->eff_rtt());
00520                                         }
00521                                                 
00522                                 }// end for
00523                                 }
00524                                 
00525                         }
00526                 }
00527 
00528                 if(localsrc_->is_sender()){ // get the Receiver report
00529 
00530                                 if(rh->rr_ != 0){
00531                                         RTPReceiver* s = lookup_rcv(rh->srcid());
00532                                                 
00533                                                 if (s != 0) {
00534                                                         for (s = receivers_; s!= 0; s = s->next) {
00535                 
00536                                                                 if(rh->srcid() == s->srcid()) {
00537                                                                         
00538                                                                         double eff_rtt = 0.0;
00539                                                                 
00540                                                                         if(rh->rr_->LSR()!=0) {
00541                                                                         eff_rtt = NOW - rh->rr_->LSR() - rh->rr_->DLSR();
00542                                                                         }
00543                                                                         s->eff_rtt(eff_rtt);
00544                                                                         s->rate(rh->rr_->R_tcp());
00545                                                                         if(rh->rr_->bye() == 1) {
00546                                                                                 remove_receiver(s);
00547                                                                         }
00548                                                                         
00549                                                                 }       
00550 
00551                                                         } // end for loop
00552                                                         if(enableFlowControl_ == 1 && receivers_) {
00553                                                                 update_rate();
00554                                                                 } else {
00555                                                                         printf("TIME: %f Sender %d NOT HAVING RECEIVERS \n", NOW,localsrc_->srcid());
00556                                                                 //      slow_start();
00557                                                                         
00558                                                                         }
00559                                                 } //end if
00560                                                 else {
00561                                                         s = new RTPReceiver(rh->srcid());
00562                                                         enter_rcv(s);
00563                                                 }
00564                                                 
00565                                         }
00566                                 }
00567         }
00568 
00569         Tcl::instance().evalf("%s sample-size %d", name(), mh->size());
00570         Packet::free(p);
00571 }

int RTPSession::command ( int  argc,
const char *const *  argv 
)

the command function that handles TCL commands

Definition at line 767 of file session-rtp.cc.

References enter(), initial_rate(), and localsrc_.

00768 {
00769         if (argc == 3) {
00770                 if (strcmp(argv[1], "enter") == 0) {
00771                         RTPSource* s = (RTPSource*)TclObject::lookup(argv[2]);
00772                         enter(s);
00773                         return (TCL_OK);
00774                 }
00775                 if (strcmp(argv[1], "localsrc") == 0) {
00776                         localsrc_ = (RTPSource*)TclObject::lookup(argv[2]);
00777                         enter(localsrc_);
00778                         return (TCL_OK);
00779                 }
00780                 if (strcmp(argv[1], "rate") == 0) {
00781                         initial_rate(atoi(argv[2]));
00782                         return(TCL_OK);
00783                 }
00784         }
00785 
00786         return (TclObject::command(argc, argv));
00787 }

u_int32_t RTPSession::srcid (  )  [inline]

Definition at line 282 of file rtp.h.

References localsrc_, and RTPSource::srcid().

Referenced by RTPAgent::makepkt(), and RTCPAgent::sendpkt().

00282 { return (localsrc_->srcid()); }

int RTPSession::build_report ( int  bye  ) 

the method for creating the SR and RR reports the "heart" of the RTCP protocol

Parameters:
bye if there is a bye event
Returns:
the length of this report in bytes

Definition at line 155 of file session-rtp.cc.

References allsrcs_, build_bye(), build_sdes(), receiver_report::bye(), calculate_RTT(), calculateR_tcp(), receiver_report::cum_pkts_lost(), receiver_report::DLSR(), RTPReceiver::eff_rtt(), sr_extensions::eff_rtt(), increase_rate(), receiver_report::jitter(), last_ehsr_, last_np_, last_time_report_, localsrc_, receiver_report::LSR(), measure_smooth_loss(), RTPSource::nbytes(), RTPSource::next, sr_extensions::next, RTPReceiver::next, NOW, RTPSource::np(), sender_report::octets_sent(), sender_report::pkts_sent(), receiver_report::R_tcp(), receivers_, remove_sender(), rh_, hdr_rtp::rr_, RTCP_HDRSIZE, RTCP_RR_SIZE, RTCP_SR_SIZE, rx_recv_, sender_report::s_ext_, sender_report::sender_srcid(), smooth_rate_, hdr_rtp::sr_, RTPReceiver::srcid(), sr_extensions::srcid(), RTPSource::srcid(), time_elapsed_, and we_sent.

Referenced by RTCPAgent::command(), and RTCPAgent::timeout().

00156 {
00157         rh_ = new hdr_rtp;
00158         rh_->rr_ = 0;
00159         rh_->sr_ = 0;
00160         int nsrc = 0;
00161         int nrr = 0;
00162         int len = RTCP_HDRSIZE;
00163         we_sent = 0;
00164         double fraction = 0.0;
00165         time_elapsed_ = NOW - last_time_report_;
00166         last_time_report_ = NOW;
00167         if (localsrc_->np() != last_np_) {
00168                 last_np_ = localsrc_->np();
00169                 we_sent = 1;
00170                 len += RTCP_SR_SIZE;
00171                 //add sender report
00172                 sender_report* sr;
00173                 //fill the report
00174                 sr = new sender_report;
00175                 sr->s_ext_ = 0;
00176                 sr->sender_srcid()= localsrc_->srcid();
00177                 sr->pkts_sent() = localsrc_->np();
00178                 sr->octets_sent() = localsrc_->nbytes();
00179                 RTPReceiver *p;
00180                 for (p = receivers_; p != 0; p = p->next) {
00181                         sr_extensions* se = new sr_extensions;
00182                         se->srcid()=p->srcid();
00183                         se->eff_rtt()=p->eff_rtt();
00184                         se->next = sr->s_ext_;
00185                         sr->s_ext_ = se;
00186                 }
00187              
00188                 //store the report
00189                 rh_->sr_ = sr;
00190         }
00191         for (RTPSource* sp = allsrcs_; sp != 0; sp = sp->next) {
00192                 ++nsrc;
00193                 int received = sp->np() - sp->snp();
00194 
00195                 if (received == 0) {
00196 
00197                         continue;
00198                 }
00199                 if(localsrc_->srcid() != sp->srcid()) {
00200                 int bytes = received * (sp->ps());
00201                 rx_recv_ = ( 8 * (double)bytes)/time_elapsed_;
00202                 sp->snp(sp->np());
00203                 len += RTCP_RR_SIZE;
00204                 // calculate loss fraction since previous report
00205                 int expected_interval  = sp->ehsr() - last_ehsr_;
00206                 last_ehsr_ = sp->ehsr();
00207                 int lost_interval = expected_interval -  received;
00208 
00209 
00210                 if (lost_interval <= 0 || expected_interval == 0 ) {
00211                          fraction = 0;
00212 
00213                 } else fraction = ((double)lost_interval  / (double)expected_interval);
00214                 calculate_RTT();
00215                 // Update the R_tcp according to fraction value
00216                 if( sp->np() >= 1) {// I have already received RTP packets from the source
00217                         if(fraction == 0) {
00218                                 increase_rate(sp->ps());
00219 
00220                         }       else /*if(fraction != 0)*/ {
00221                                         measure_smooth_loss(fraction);
00222                                         calculateR_tcp(sp->ps());
00223                                 }
00224                 }
00225                 //add receiver report
00226                 receiver_report* rr;
00227                 rr = new receiver_report;
00228                 //fill the report
00229                 rr->cum_pkts_lost() = sp->cum_pkts_lost();
00230                 rr->LSR() = sp->LSR();
00231                 rr->DLSR()= Scheduler::instance().clock() - sp->SRT();
00232                 rr->R_tcp() = smooth_rate_;
00233                 rr->jitter() = sp->jitter();
00234                 if(bye) {
00235                 printf ("TIME for BYE %f \n", NOW);
00236                 rr->bye()= 1;
00237                 remove_sender(sp);
00238                 } else rr->bye() = 0;
00239                 rh_->rr_ = rr;
00240 
00241                 if (++nrr >= 31)
00242                         break;
00243                 } // end if
00244 
00245         }// end for loop
00246 
00247 
00248         if (bye) {
00249                 len += build_bye();
00250                 }
00251         else
00252                 len += build_sdes();
00253 
00254         Tcl::instance().evalf("%s adapt-timer %d %d %d", name(),
00255                               nsrc, nrr, we_sent);
00256         Tcl::instance().evalf("%s sample-size %d", name(), len);
00257 
00258         return (len);
00259 }

void RTPSession::localsrc_update ( int   ) 

it is called when the RTPAgent sends a RTP packet and updates the number of packets (np) field of the originator of the RTP packet

Parameters:
int the packet to be added

Definition at line 127 of file session-rtp.cc.

References RTPSource::is_sender(), localsrc_, and RTPSource::np().

Referenced by RTPAgent::timeout().

00128 {
00129         localsrc_->np(1);
00130         localsrc_->is_sender(true);
00131 }

void RTPSession::update_rate (  ) 

this method compares the reported TCP friendly bandwidth by the receivers and calls the session_bw and transmit methods in session-rtp.tcl class to adjust the sender's transmission rate The adjustment in the transmission rate occures after the sender receives reports from all the receivers. r_tcp, is the receiver estimation of the TCP friendly bandwidth

Definition at line 581 of file session-rtp.cc.

References localsrc_, lst, RTPReceiver::next, NOW, RTPReceiver::rate(), receivers_, RTPSource::srcid(), and tx_rate_.

Referenced by recv_ctrl().

00582 {
00583         RTPReceiver* s;
00584         for (s = receivers_; s!= 0; s = s->next) {
00585                 if(s->rate() !=0) {
00586                         lst.push_front(s->rate());
00587                 }
00588         }
00589         lst.sort();
00590         double inst_tx =lst.front();
00591         lst.clear();
00592         if(inst_tx != tx_rate_) {
00593                 // we do not let the transmission rate to drop below tx_rate_/2
00594                 if(inst_tx < (tx_rate_/2)) {
00595                         tx_rate_ = tx_rate_/2;
00596                 } else tx_rate_ = inst_tx;
00597         printf("Time:%f Sender:%d ...Rate change to:%f \n", NOW,localsrc_->srcid(),8*tx_rate_);
00598         Tcl::instance().evalf("%s session_bw %fb/s",name(),8*tx_rate_);
00599         Tcl::instance().evalf("%s transmit %fb/s",name(),8*tx_rate_);
00600         }
00601         
00602 }

void RTPSession::pass_sr ( sender_report  ) 

void RTPSession::localsrc_update_nbytes ( int  n  ) 

it is called when the RTPAgent sends a RTP packet and updates the number of number of bytes (nbytes) field of the originator of the RTP packet

Parameters:
n the bytes to be added

Definition at line 139 of file session-rtp.cc.

References localsrc_, and RTPSource::nbytes().

Referenced by RTPAgent::timeout().

00140 {
00141         localsrc_->nbytes(n);
00142         
00143 }

void RTPSession::smooth_rate ( double  inst_tx  ) 

this is the filter function for the smooth transmission rate measurement

Parameters:
inst_tx the current transmission rate estimation by the RTP receiver

Definition at line 481 of file session-rtp.cc.

References smooth_factor, and smooth_rate_.

Referenced by calculateR_tcp(), and increase_rate().

00482 {
00483         smooth_rate_ = smooth_factor * inst_tx + smooth_rate_ * (1 - smooth_factor);
00484 }

int RTPSession::build_sdes (  ) 

not implemented yet. It only returns 20 bytes that are to be added to the RTCP report

Definition at line 272 of file session-rtp.cc.

Referenced by build_report().

00273 {
00274 
00275         /* XXX We'll get to this later... */
00276         return (20);
00277 }

int RTPSession::build_bye (  ) 

it is called upon a bye event returns 8 bytes length

Definition at line 264 of file session-rtp.cc.

Referenced by build_report().

00265 {
00266         
00267         return (8);
00268 }

hdr_rtp * RTPSession::access_hdr_rtp (  ) 

accesses the RTP packet header

Returns:
, the

Definition at line 608 of file session-rtp.cc.

References rh_.

Referenced by RTCPAgent::sendpkt().

00609 {
00610         return rh_;
00611 }

void RTPSession::print_rcv (  ) 

for debugging, prints all the receivers that a source serves

Definition at line 651 of file session-rtp.cc.

References RTPReceiver::next, receivers_, and RTPReceiver::srcid().

00652 {
00653 
00654         RTPReceiver *p;
00655         for (p = receivers_; p != 0; p = p->next)
00656         {
00657             printf("Receiver:%d\n", p->srcid());
00658         }
00659 }

RTPSource * RTPSession::lookup ( u_int32_t  srcid  )  [protected]

it checks if the source has heard

Parameters:
srcid the source id of this source
Returns:
the source of the RTP packet if it exists, zero otherwise

Definition at line 619 of file session-rtp.cc.

References allsrcs_, RTPSource::next, and RTPSource::srcid().

Referenced by recv(), and recv_ctrl().

00620 {
00621         RTPSource *p;
00622         for (p = allsrcs_; p != 0; p = p->next)
00623         {       
00624                 if (p->srcid() == srcid)
00625                         return (p);
00626         }
00627         return (0);
00628 }

RTPReceiver * RTPSession::lookup_rcv ( u_int32_t  srcid  )  [protected]

Check if the receiver exists in the sender's list

Parameters:
srcid the source id of this receiver
Returns:
the receiver if it exists, zero otherwise

Definition at line 636 of file session-rtp.cc.

References RTPReceiver::next, receivers_, and RTPReceiver::srcid().

Referenced by recv_ctrl().

00637 {
00638 
00639         RTPReceiver *p;
00640         for (p = receivers_; p != 0; p = p->next)
00641         {
00642                 if (p->srcid() == srcid)
00643                         return (p);
00644         }
00645         return (0);
00646 }

void RTPSession::enter ( RTPSource s  )  [protected]

enter a new source

Parameters:
s the new RTPSource

Definition at line 665 of file session-rtp.cc.

References allsrcs_, localsrc_, RTPSource::next, NOW, and RTPSource::srcid().

Referenced by command().

00666 {
00667         if(s->srcid() != localsrc_->srcid() ) {
00668         printf("Time:%f Receiver:%d ...I add sender %d \n", NOW,localsrc_->srcid(), s->srcid());
00669         s->next = allsrcs_;
00670         allsrcs_ = s;
00671         }
00672 }

void RTPSession::enter_rcv ( RTPReceiver s  )  [protected]

enter a new receiver

Parameters:
s the new RTPReceiver

Definition at line 678 of file session-rtp.cc.

References localsrc_, RTPReceiver::next, NOW, receivers_, RTPReceiver::srcid(), and RTPSource::srcid().

Referenced by recv_ctrl().

00679 {
00680         printf("Time:%f Sender:%d ...I add receiver %d \n", NOW,localsrc_->srcid(), s->srcid());
00681         s->next = receivers_;
00682         receivers_ = s;
00683 }

void RTPSession::calculate_RTT (  )  [protected]

calculates the RTT time one_way is the one way trip time eff is the effective RTT time measured and reported by the sender of the RTP packets

Parameters:
eff,the effective RTT time measured by the sender

Definition at line 398 of file session-rtp.cc.

References alpha, RTT_, and T_one_way_.

Referenced by build_report().

00399 {
00400         double temp=(1+alpha) * T_one_way_;
00401  //     RTT_ = temp * 0.5 + 0.5 * RTT_;
00402         RTT_ = temp * 0.1 + 0.9 * RTT_;   //taken from RFC 3448
00403 }

void RTPSession::increase_rate ( int  ps  )  [protected]

the estimation made by the receiver of the transmission rate when fraction loss is zero. The increase is not higher than 1 RTP packet/current rate in bytes/sec sample_tx is the current estimation of the RTP receiver. We pass this value from the filter

Parameters:
ps,the packet size of the RTP packet

Definition at line 413 of file session-rtp.cc.

References RTT_, smooth_rate(), and smooth_rate_.

Referenced by build_report().

00414 {
00415         double sample_tx = smooth_rate_ +  (double)ps/RTT_;
00416         // pass sample_tx from the filter
00417         smooth_rate(sample_tx);
00418 }

void RTPSession::measure_smooth_loss ( double  fraction  )  [protected]

measure_smooth_loss is called when the last measured by the receiver loss fraction is not zero.

Parameters:
fraction the fraction of lost RTP packets/expected RTP packets since last RR

Definition at line 426 of file session-rtp.cc.

References pkt_loss_history, smooth_loss_, and weight.

Referenced by build_report().

00427 {
00428         
00429         double I_tot0 = 0;
00430         double I_tot1 = 0;
00431         double W_tot = 0;
00432         for (int i=0; i<7; i++) {
00433         pkt_loss_history[i+1]= pkt_loss_history[i];
00434         }
00435         pkt_loss_history[0] = fraction;
00436 
00437         for (int i=0; i<7; i++) {
00438         I_tot0 = I_tot0+ (pkt_loss_history[i] * weight[i]);
00439         W_tot = W_tot +  weight[i];
00440         }
00441 
00442         for (int i=1; i<8; i++) {
00443         I_tot1 = I_tot1 + (pkt_loss_history[i] * weight[i-1]);
00444         }
00445         double I_tot =0;
00446         if( I_tot0 > I_tot1) {
00447         I_tot = I_tot0;
00448         } else {
00449         I_tot = I_tot1;
00450         }
00451         double  I_mean = I_tot/W_tot;
00452 
00453         smooth_loss_= I_mean;
00454 }

void RTPSession::calculateR_tcp ( int  ps  )  [protected]

calculates the TCP friendly bandwidth share

Parameters:
ps is the size of the RTP packet

Definition at line 460 of file session-rtp.cc.

References localsrc_, NOW, RTT_, smooth_loss_, smooth_rate(), and RTPSource::srcid().

Referenced by build_report().

00461 {
00462 
00463         double min =0;
00464         double fraction = 3 * sqrt((3 * smooth_loss_) / 8);
00465         if(fraction <  1 ){
00466                 min = fraction;
00467         }       else min =1;
00468         // TCP friendly BW share equation
00469         double sample_tx = (double)ps / (RTT_ *  (sqrt(2 * smooth_loss_ /3)) + 4 * (RTT_ * min * smooth_loss_) * (1 + (32 * pow(smooth_loss_,2))));
00470         printf("Time:%f Receiver:%d smooth_loss_:%f \n", NOW,localsrc_->srcid(),smooth_loss_);
00471         // pass sample_tx from the filter
00472         smooth_rate(sample_tx);
00473 }

void RTPSession::initial_rate ( double  a  )  [protected]

it's good for the receiver to have a rough knowledge of the session rate

Parameters:
a the initial session rate

Definition at line 756 of file session-rtp.cc.

References smooth_rate_, and tx_rate_.

Referenced by command().

00757 {
00758         tx_rate_ =(double)a/8;
00759         smooth_rate_ = tx_rate_;
00760         
00761 }

void RTPSession::remove_receiver ( RTPReceiver p  )  [protected]

remove a receiver from a sender's list

Parameters:
p the RTPReceiver to be removed

Definition at line 689 of file session-rtp.cc.

References localsrc_, RTPReceiver::next, NOW, receivers_, RTPReceiver::srcid(), and RTPSource::srcid().

Referenced by recv_ctrl().

00690 {
00691 
00692         printf("Time:%f Sender:%d ...I remove receiver %d \n", NOW,localsrc_->srcid(),p->srcid());
00693         RTPReceiver* s;
00694         RTPReceiver* q;
00695         if (receivers_==p)
00696         {
00697                 q = receivers_;
00698                 receivers_=receivers_->next;
00699                 delete q;
00700         }
00701         else
00702         {
00703                 for (s = receivers_; s!=0; s=s->next)
00704                 {
00705                         if (s->next==p)
00706                         {
00707                                 q = s->next;
00708                                 s->next=q->next;
00709                                 delete q; 
00710                         }       
00711                 }
00712         }
00713 
00714 }

void RTPSession::calculate_alpha ( double  value  )  [protected]

the function that calculate the A value

Parameters:
value the effective RTT that is measured by the RTP sender

Definition at line 382 of file session-rtp.cc.

References alpha, and T_one_way_.

Referenced by recv_ctrl().

00383 {
00384         if( value == 0) {
00385                 alpha = 1;
00386         } else
00387         alpha = (value/T_one_way_) -1;
00388 }

void RTPSession::evaluate_jitter ( double  value  )  [protected]

This is a core function. It tunes our congestion controller based on network statistical information. We evaluate upcoming congestion by checking how far the new jitter value falls from the jitter stab=ndard deviation

Parameters:
value the newly measured jitter value

Definition at line 341 of file session-rtp.cc.

References CONGESTED, DELTA, jitter_, jitter_lst, LOADED, smooth_factor, UNLOADED, and z_score.

Referenced by recv().

00342 {
00343         jitter_ = 0.8 * value - 0.2 * jitter_;
00344         jitter_lst.push_front(jitter_);
00345         list<double> temp_lst;
00346         temp_lst = jitter_lst;
00347         int size = jitter_lst.size();
00348         double temp_array[size];
00349         double dev_array[size];
00350         double mean =0;
00351         double count =0;
00352         double std_dev =0;
00353         
00354         if (size >1) {
00355                 for (int i=0; i<size; i++) {
00356                         temp_array[i]=jitter_lst.front();
00357                         count += temp_array[i];
00358                         jitter_lst.pop_front();
00359                 }
00360                 mean = count/size;
00361                 count =0;
00362                 for (int j =0; j<size; j++) {
00363                         dev_array[j]=temp_array[j]-mean;
00364                         count+=pow(dev_array[j],2);
00365                 }
00366                 std_dev = sqrt(count/(size-1));
00367                 double temp = temp_lst.front();
00368                 z_score = (temp - mean)/std_dev;
00369                 jitter_lst = temp_lst;
00370                 if(-DELTA < z_score < DELTA) {
00371                          smooth_factor = LOADED;
00372                 } else if ( z_score <= -DELTA) {
00373                          smooth_factor = UNLOADED;
00374                 } else smooth_factor = CONGESTED;
00375         }
00376 }

void RTPSession::remove_sender ( RTPSource p  )  [protected]

we remove this sender from the list upon a bye event

Parameters:
p the sender that has to be removed from our sources' list

Definition at line 720 of file session-rtp.cc.

References allsrcs_, jitter_, localsrc_, RTPSource::next, NOW, rx_recv_, and RTPSource::srcid().

Referenced by build_report().

00721 {
00722         printf("Time:%f Receiver:%d ...I remove sender %d \n", NOW,localsrc_->srcid(), p->srcid());
00723         if(p->srcid() != localsrc_->srcid()) {
00724         RTPSource* s;
00725         RTPSource* q;
00726         if (allsrcs_==p)
00727         {
00728                 q = allsrcs_;
00729                 allsrcs_= allsrcs_->next;
00730                 delete q;
00731         }
00732         else
00733         {
00734                 for (s = allsrcs_; s!=0; s=s->next)
00735                 {
00736                         if (s->next==p)
00737                         {
00738                                 q = s->next;
00739                                 s->next=q->next;
00740                                 delete q; 
00741                         }       
00742                 }
00743         }       
00744         
00745         }
00746         rx_recv_= 0;
00747         jitter_=0;
00748 }


Member Data Documentation

Definition at line 295 of file rtp.h.

Referenced by build_report(), enter(), lookup(), remove_sender(), and ~RTPSession().

the last packet number

Definition at line 299 of file rtp.h.

Referenced by build_report().

zero by default

Definition at line 309 of file rtp.h.

Referenced by recv_ctrl(), and RTPSession().

the receiveing rate as it measured by the RTP receiver

Definition at line 311 of file rtp.h.

Referenced by build_report(), remove_sender(), and RTPSession().

the jitter delay as is it measured by the RTP receiver

Definition at line 313 of file rtp.h.

Referenced by evaluate_jitter(), recv(), remove_sender(), and RTPSession().

the smooth transmission rate

Definition at line 315 of file rtp.h.

Referenced by build_report(), increase_rate(), initial_rate(), RTPSession(), and smooth_rate().

list<double> RTPSession::lst [protected]

a list to store values

Definition at line 324 of file rtp.h.

Referenced by update_rate(), and ~RTPSession().

double RTPSession::T_one_way_ [protected]

the one-way trip time

Definition at line 340 of file rtp.h.

Referenced by calculate_alpha(), calculate_RTT(), and recv().

hdr_rtp* RTPSession::rh_ [protected]

the rtp header

Definition at line 342 of file rtp.h.

Referenced by access_hdr_rtp(), and build_report().

int RTPSession::we_sent [protected]

true if the RTP sender sent packets since the last RTP SR

Definition at line 346 of file rtp.h.

Referenced by build_report().

double RTPSession::RTT_ [protected]

the RTT time

Definition at line 348 of file rtp.h.

Referenced by calculate_RTT(), calculateR_tcp(), increase_rate(), and RTPSession().

double RTPSession::weight[8] [protected]

weights for the smooth loss raton calculation

Definition at line 350 of file rtp.h.

Referenced by measure_smooth_loss(), and RTPSession().

double RTPSession::pkt_loss_history[8] [protected]

the array to keep the packet loss history

Definition at line 352 of file rtp.h.

Referenced by measure_smooth_loss().

double RTPSession::smooth_loss_ [protected]

the smooth loss ratio

Definition at line 354 of file rtp.h.

Referenced by calculateR_tcp(), measure_smooth_loss(), and RTPSession().

int RTPSession::last_pkts_lost_ [protected]

keeps the number of the last packets losts since the beginning of the session

Definition at line 356 of file rtp.h.

int RTPSession::last_ehsr_ [protected]

keeps the highest expected RTP sequence number

Definition at line 358 of file rtp.h.

Referenced by build_report().

double RTPSession::tx_rate_ [protected]

the transmission rate that is measured by the receiver

Definition at line 360 of file rtp.h.

Referenced by initial_rate(), and update_rate().

double RTPSession::time_elapsed_ [protected]

time elapsed since the last RR (receiver report)

Definition at line 362 of file rtp.h.

Referenced by build_report().

double RTPSession::last_time_report_ [protected]

the time when the last RR was sent

Definition at line 364 of file rtp.h.

Referenced by build_report(), and RTPSession().

double RTPSession::alpha [protected]

the value A

Definition at line 366 of file rtp.h.

Referenced by calculate_alpha(), calculate_RTT(), and RTPSession().

double RTPSession::smooth_factor [protected]

defines the responsiveness of the protocol

Definition at line 372 of file rtp.h.

Referenced by evaluate_jitter(), RTPSession(), and smooth_rate().

list<double> RTPSession::jitter_lst [protected]

list to keep all jitter delay measurements

Definition at line 374 of file rtp.h.

Referenced by evaluate_jitter().

double RTPSession::z_score [protected]

z score for statistical measurements

Definition at line 376 of file rtp.h.

Referenced by evaluate_jitter(), and RTPSession().


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

Generated on Mon Jun 2 11:25:26 2008 for ASMP by  doxygen 1.5.5