#include <rtp.h>
Public Member Functions | |
RTPAgent () | |
virtual void | 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_ |
Definition at line 398 of file rtp.h.
RTPAgent::RTPAgent | ( | ) |
constructor initializes the RTPAgent intance
Definition at line 66 of file rtp.cc.
References interval_, maxpkts_, random_, seqno_, and timestamp_.
00066 : Agent(PT_RTP), session_(0), lastpkttime_(-1e6), 00067 running_(0), rtp_timer_(this) 00068 { 00069 bind("seqno_", &seqno_); 00070 bind_time("interval_", &interval_); 00071 bind("packetSize_", &size_); 00072 bind("maxpkts_", &maxpkts_); 00073 bind("random_", &random_); 00074 timestamp_ = 0; 00075 00076 }
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 132 of file rtp.cc.
References interval_, RTPSession::localsrc_update(), RTPSession::localsrc_update_nbytes(), random_, rtp_timer_, running_, sendpkt(), and session_.
Referenced by RTPTimer::expire().
00133 { 00134 if (running_) { 00135 sendpkt(); 00136 if (session_) 00137 session_->localsrc_update(size_); 00138 session_->localsrc_update_nbytes(size_); 00139 00140 double t = interval_; 00141 if (random_) 00142 /* add some zero-mean white noise */ 00143 t += interval_ * Random::uniform(-0.5, 0.5); 00144 rtp_timer_.resched(t); 00145 } 00146 }
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 173 of file rtp.cc.
References RTPSession::recv(), and session_.
int RTPAgent::command | ( | int | argc, | |
const char *const * | argv | |||
) | [virtual] |
Definition at line 181 of file rtp.cc.
References advanceby(), rate_change(), seqno_, session_, start(), and stop().
00182 { 00183 if (argc == 2) { 00184 if (strcmp(argv[1], "rate-change") == 0) { 00185 rate_change(); 00186 return (TCL_OK); 00187 } else if (strcmp(argv[1], "start") == 0) { 00188 start(); 00189 return (TCL_OK); 00190 } else if (strcmp(argv[1], "stop") == 0) { 00191 stop(); 00192 return (TCL_OK); 00193 } 00194 } else if (argc == 3) { 00195 if (strcmp(argv[1], "session") == 0) { 00196 session_ = (RTPSession*)TclObject::lookup(argv[2]); 00197 return (TCL_OK); 00198 } else if (strcmp(argv[1], "advance") == 0) { 00199 int newseq = atoi(argv[2]); 00200 advanceby(newseq - seqno_); 00201 return (TCL_OK); 00202 } else if (strcmp(argv[1], "advanceby") == 0) { 00203 advanceby(atoi(argv[2])); 00204 return (TCL_OK); 00205 } 00206 } 00207 return (Agent::command(argc, argv)); 00208 }
void RTPAgent::advanceby | ( | int | delta | ) |
void RTPAgent::sendmsg | ( | int | nbytes, | |
const char * | flags = 0 | |||
) | [virtual] |
sends the packets
Definition at line 94 of file rtp.cc.
References hdr_rtp::access(), finish(), maxpkts_, hdr_rtp::seqno(), seqno_, and start().
00095 { 00096 Packet *p; 00097 int n; 00098 00099 assert (size_ > 0); 00100 00101 if (++seqno_ < maxpkts_) { 00102 n = nbytes / size_; 00103 00104 if (nbytes == -1) { 00105 start(); 00106 return; 00107 } 00108 while (n-- > 0) { 00109 p = allocpkt(); 00110 hdr_rtp* rh = hdr_rtp::access(p); 00111 rh->seqno() = seqno_; 00112 target_->recv(p); 00113 } 00114 n = nbytes % size_; 00115 if (n > 0) { 00116 p = allocpkt(); 00117 hdr_rtp* rh = hdr_rtp::access(p); 00118 rh->seqno() = seqno_; 00119 target_->recv(p); 00120 } 00121 idle(); 00122 } else { 00123 finish(); 00124 // xxx: should we deschedule the timer here? */ 00125 }; 00126 }
void RTPAgent::sendpkt | ( | ) | [protected, virtual] |
allocates the RTP packet that has to be sent
Definition at line 231 of file rtp.cc.
References lastpkttime_, makepkt(), and timestamp_.
Referenced by rate_change(), start(), and timeout().
00232 { 00233 Packet* p = allocpkt(); 00234 lastpkttime_ = Scheduler::instance().clock(); 00235 timestamp_ = lastpkttime_; 00236 makepkt(p); 00237 target_->recv(p, (Handler*)0); 00238 }
void RTPAgent::makepkt | ( | Packet * | p | ) | [protected, virtual] |
creates the RTP packet and fills in the packet header fields
Definition at line 240 of file rtp.cc.
References hdr_rtp::access(), hdr_rtp::seqno(), seqno_, session_, RTPSession::srcid(), hdr_rtp::srcid(), hdr_rtp::timestamp(), and timestamp_.
Referenced by sendpkt().
00241 { 00242 00243 hdr_rtp *rh = hdr_rtp::access(p); 00244 /* Fill in srcid_ and seqno */ 00245 rh->seqno() = seqno_++; 00246 rh->srcid() = session_ ? session_->srcid() : 0; 00247 rh->timestamp()= timestamp_; 00248 00249 00250 }
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 216 of file rtp.cc.
References interval_, lastpkttime_, rtp_timer_, and sendpkt().
Referenced by command().
00217 { 00218 rtp_timer_.force_cancel(); 00219 00220 double t = lastpkttime_ + interval_; 00221 00222 double now = Scheduler::instance().clock(); 00223 if ( t > now) 00224 rtp_timer_.resched(t - now); 00225 else { 00226 sendpkt(); 00227 rtp_timer_.resched(interval_); 00228 } 00229 }
void RTPAgent::start | ( | ) | [protected, virtual] |
starts the RTP Agent
Definition at line 78 of file rtp.cc.
References interval_, rtp_timer_, running_, and sendpkt().
Referenced by advanceby(), command(), and sendmsg().
00079 { 00080 running_ = 1; 00081 sendpkt(); 00082 rtp_timer_.resched(interval_); 00083 }
void RTPAgent::stop | ( | ) | [protected, virtual] |
stops the RTP Agent
Definition at line 86 of file rtp.cc.
References finish(), and rtp_timer_.
Referenced by command().
00087 { 00088 // printf("inside stop localsrc_ %d\n", session_->localsrc_->srcid()); 00089 rtp_timer_.force_cancel(); 00090 finish(); 00091 }
void RTPAgent::finish | ( | ) | [protected, virtual] |
RTPSession* RTPAgent::session_ [protected] |
double RTPAgent::lastpkttime_ [protected] |
int RTPAgent::seqno_ [protected] |
Definition at line 415 of file rtp.h.
Referenced by advanceby(), command(), makepkt(), RTPAgent(), and sendmsg().
int RTPAgent::running_ [protected] |
int RTPAgent::random_ [protected] |
int RTPAgent::maxpkts_ [protected] |
double RTPAgent::interval_ [protected] |
Definition at line 419 of file rtp.h.
Referenced by rate_change(), RTPAgent(), start(), and timeout().
RTPTimer RTPAgent::rtp_timer_ [protected] |
double RTPAgent::timestamp_ [protected] |