#include <rtp.h>
Public Member Functions | |
RTPAgent () | |
virtual void | timeout (int) |
void | join_timeout (int) |
virtual void | recv (Packet *p, Handler *) |
virtual int | command (int argc, const char *const *argv) |
void | advanceby (int delta) |
virtual void | sendmsg (int nbytes, const char *flags=0) |
Protected Member Functions | |
virtual void | sendpkt () |
virtual void | makepkt (Packet *) |
void | rate_change () |
virtual void | start () |
virtual void | stop () |
virtual void | finish () |
Protected Attributes | |
RTPSession * | session_ |
double | lastpkttime_ |
int | seqno_ |
int | running_ |
int | random_ |
int | maxpkts_ |
double | interval_ |
RTPTimer | rtp_timer_ |
double | timestamp_ |
JoinTimer | join_timer_ |
int | join_flag_ |
Definition at line 458 of file rtp.h.
RTPAgent::RTPAgent | ( | ) |
constructor initializes the RTPAgent intance
Definition at line 68 of file rtp.cc.
References interval_, join_flag_, maxpkts_, random_, seqno_, and timestamp_.
00068 : Agent(PT_RTP), session_(0), lastpkttime_(-1e6), 00069 running_(0), rtp_timer_(this),join_timer_(this) 00070 { 00071 bind("seqno_", &seqno_); 00072 bind_time("interval_", &interval_); 00073 bind("packetSize_", &size_); 00074 bind("maxpkts_", &maxpkts_); 00075 bind("random_", &random_); 00076 timestamp_ = 0; 00077 join_flag_ = 0; 00078 00079 00080 }
void RTPAgent::timeout | ( | int | ) | [virtual] |
when the RTPTimer times out the RTP Agent sends an RTP packet when there is a session (multicast session) the sending source is apdating the number of RTP packets that sends
Definition at line 141 of file rtp.cc.
References interval_, RTPSession::localsrc_update(), RTPSession::localsrc_update_nbytes(), random_, rtp_timer_, running_, sendpkt(), and session_.
Referenced by RTPTimer::expire().
00142 { 00143 if (running_) { 00144 sendpkt(); 00145 if (session_) 00146 session_->localsrc_update(size_); 00147 session_->localsrc_update_nbytes(size_); 00148 00149 00150 double t = interval_; 00151 if (random_) 00152 /* add some zero-mean white noise */ 00153 t += interval_ * Random::uniform(-0.5, 0.5); 00154 rtp_timer_.resched(t); 00155 } 00156 }
void RTPAgent::join_timeout | ( | int | ) |
Definition at line 158 of file rtp.cc.
References join_flag_, join_timer_, running_, and TIMEOUT.
Referenced by JoinTimer::expire().
00159 { 00160 if (running_) { 00161 if(join_flag_ == 0) join_flag_ = 1; 00162 join_timer_.resched(TIMEOUT); 00163 } 00164 }
void RTPAgent::recv | ( | Packet * | p, | |
Handler * | ||||
) | [virtual] |
the receive method for RTP packets. It simples passes the packet to the instance of the RTPSession class. Ottherwise the mothod does nothing
Definition at line 192 of file rtp.cc.
References RTPSession::recv(), and session_.
int RTPAgent::command | ( | int | argc, | |
const char *const * | argv | |||
) | [virtual] |
Definition at line 200 of file rtp.cc.
References advanceby(), rate_change(), seqno_, session_, start(), and stop().
00201 { 00202 if (argc == 2) { 00203 if (strcmp(argv[1], "rate-change") == 0) { 00204 rate_change(); 00205 return (TCL_OK); 00206 } else if (strcmp(argv[1], "start") == 0) { 00207 start(); 00208 return (TCL_OK); 00209 } else if (strcmp(argv[1], "stop") == 0) { 00210 stop(); 00211 return (TCL_OK); 00212 } 00213 } else if (argc == 3) { 00214 if (strcmp(argv[1], "session") == 0) { 00215 session_ = (RTPSession*)TclObject::lookup(argv[2]); 00216 return (TCL_OK); 00217 } else if (strcmp(argv[1], "advance") == 0) { 00218 int newseq = atoi(argv[2]); 00219 advanceby(newseq - seqno_); 00220 return (TCL_OK); 00221 } else if (strcmp(argv[1], "advanceby") == 0) { 00222 advanceby(atoi(argv[2])); 00223 return (TCL_OK); 00224 } 00225 } 00226 return (Agent::command(argc, argv)); 00227 }
void RTPAgent::advanceby | ( | int | delta | ) |
void RTPAgent::sendmsg | ( | int | nbytes, | |
const char * | flags = 0 | |||
) | [virtual] |
sends the packets
Definition at line 103 of file rtp.cc.
References hdr_rtp::access(), finish(), maxpkts_, hdr_rtp::seqno(), seqno_, and start().
00104 { 00105 Packet *p; 00106 int n; 00107 00108 assert (size_ > 0); 00109 00110 if (++seqno_ < maxpkts_) { 00111 n = nbytes / size_; 00112 00113 if (nbytes == -1) { 00114 start(); 00115 return; 00116 } 00117 while (n-- > 0) { 00118 p = allocpkt(); 00119 hdr_rtp* rh = hdr_rtp::access(p); 00120 rh->seqno() = seqno_; 00121 target_->recv(p); 00122 } 00123 n = nbytes % size_; 00124 if (n > 0) { 00125 p = allocpkt(); 00126 hdr_rtp* rh = hdr_rtp::access(p); 00127 rh->seqno() = seqno_; 00128 target_->recv(p); 00129 } 00130 idle(); 00131 } else { 00132 finish(); 00133 // xxx: should we deschedule the timer here? */ 00134 }; 00135 }
void RTPAgent::sendpkt | ( | ) | [protected, virtual] |
allocates the RTP packet that has to be sent
Definition at line 250 of file rtp.cc.
References lastpkttime_, makepkt(), and timestamp_.
Referenced by rate_change(), start(), and timeout().
00251 { 00252 Packet* p = allocpkt(); 00253 lastpkttime_ = Scheduler::instance().clock(); 00254 timestamp_ = lastpkttime_; 00255 makepkt(p); 00256 target_->recv(p, (Handler*)0); 00257 }
void RTPAgent::makepkt | ( | Packet * | p | ) | [protected, virtual] |
creates the RTP packet and fills in the packet header fields
Definition at line 259 of file rtp.cc.
References hdr_rtp::access(), join_flag_, hdr_rtp::seqno(), seqno_, session_, RTPSession::srcid(), hdr_rtp::srcid(), hdr_rtp::T_epoch(), hdr_rtp::timestamp(), and timestamp_.
Referenced by sendpkt().
00260 { 00261 00262 hdr_rtp *rh = hdr_rtp::access(p); 00263 /* Fill in srcid_ and seqno */ 00264 rh->seqno() = seqno_++; 00265 rh->srcid() = session_ ? session_->srcid() : 0; 00266 rh->timestamp()= timestamp_; 00267 if(join_flag_ == 1 ) { 00268 rh->T_epoch() = 1; 00269 join_flag_ = 0; 00270 } else rh->T_epoch() = 0; 00271 00272 00273 }
void RTPAgent::rate_change | ( | ) | [protected] |
We modify the rate in this way to get a faster reaction to the a rate change since a rate change from a very low rate to a very fast rate may take an undesireably long time if we have to wait for timeout at the old rate before we can send at the new (faster) rate.
Definition at line 235 of file rtp.cc.
References interval_, lastpkttime_, rtp_timer_, and sendpkt().
Referenced by command().
00236 { 00237 rtp_timer_.force_cancel(); 00238 00239 double t = lastpkttime_ + interval_; 00240 00241 double now = Scheduler::instance().clock(); 00242 if ( t > now) 00243 rtp_timer_.resched(t - now); 00244 else { 00245 sendpkt(); 00246 rtp_timer_.resched(interval_); 00247 } 00248 }
void RTPAgent::start | ( | ) | [protected, virtual] |
starts the RTP Agent
Definition at line 82 of file rtp.cc.
References INITIAL_TIMEOUT, interval_, join_timer_, rtp_timer_, running_, sendpkt(), session_, and RTPSession::start_timer().
Referenced by advanceby(), command(), and sendmsg().
00083 { 00084 running_ = 1; 00085 join_timer_.resched(INITIAL_TIMEOUT); 00086 sendpkt(); 00087 rtp_timer_.resched(interval_); 00088 if (session_) { 00089 session_->start_timer(); 00090 } 00091 }
void RTPAgent::stop | ( | ) | [protected, virtual] |
stops the RTP Agent
Definition at line 94 of file rtp.cc.
References finish(), rtp_timer_, session_, and RTPSession::stop_timer().
Referenced by command().
00095 { 00096 session_->stop_timer(); 00097 rtp_timer_.force_cancel(); 00098 // join_timer_.force_cansel(); 00099 finish(); 00100 }
void RTPAgent::finish | ( | ) | [protected, virtual] |
RTPSession* RTPAgent::session_ [protected] |
double RTPAgent::lastpkttime_ [protected] |
int RTPAgent::seqno_ [protected] |
Definition at line 476 of file rtp.h.
Referenced by advanceby(), command(), makepkt(), RTPAgent(), and sendmsg().
int RTPAgent::running_ [protected] |
Definition at line 477 of file rtp.h.
Referenced by advanceby(), finish(), join_timeout(), start(), and timeout().
int RTPAgent::random_ [protected] |
int RTPAgent::maxpkts_ [protected] |
double RTPAgent::interval_ [protected] |
Definition at line 480 of file rtp.h.
Referenced by rate_change(), RTPAgent(), start(), and timeout().
RTPTimer RTPAgent::rtp_timer_ [protected] |
double RTPAgent::timestamp_ [protected] |
JoinTimer RTPAgent::join_timer_ [protected] |
int RTPAgent::join_flag_ [protected] |