RTP Class Reference

#include <RTP.h>

List of all members.


Detailed Description

An RTP is the center of the rtp layer of an endsystem. It creates the profile module, sends and receives rtp data packets and forwards messages. It also communicates with the application.

Protected Member Functions

virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void handleMessageFromApp (cMessage *msg)
virtual void handleMessageFromProfile (cMessage *msg)
virtual void handleMessageFromRTCP (cMessage *msg)
virtual void handleMessagefromUDP (cMessage *msg)
virtual void enterSession (RTPInterfacePacket *rifp)
virtual void leaveSession (RTPInterfacePacket *rifp)
virtual void createSenderModule (RTPInterfacePacket *rifp)
virtual void deleteSenderModule (RTPInterfacePacket *rifp)
virtual void senderModuleControl (RTPInterfacePacket *rifp)
virtual void profileInitialized (RTPInnerPacket *rinp)
virtual void senderModuleCreated (RTPInnerPacket *rinp)
virtual void senderModuleDeleted (RTPInnerPacket *rinp)
virtual void senderModuleInitialized (RTPInnerPacket *rinp)
virtual void senderModuleStatus (RTPInnerPacket *rinp)
virtual void dataOut (RTPInnerPacket *rinp)
virtual void rtcpInitialized (RTPInnerPacket *rinp)
virtual void sessionLeft (RTPInnerPacket *rinp)
virtual void createProfile ()
virtual void createSocket ()
virtual void socketRet ()
virtual void connectRet ()
virtual void readRet (cMessage *sifp)
virtual void initializeProfile ()
virtual void initializeRTCP ()
virtual int resolveMTU ()

Protected Attributes

const char * _commonName
const char * _profileName
int _bandwidth
IPAddress _destinationAddress
int _port
int _mtu
int _rtcpPercentage
int _socketFdIn
int _socketFdOut
bool _leaveSession

Member Function Documentation

void RTP::initialize (  )  [protected, virtual]

Initializes variables.

00042 {
00043     _socketFdIn = -1;//UDPSocket::generateSocketId();
00044     _socketFdOut = -1;
00045     _leaveSession = false;
00046 };

void RTP::handleMessage ( cMessage *  msg  )  [protected, virtual]

Handles incoming messages.

00050 {
00051     if (msg->getArrivalGateId() == findGate("fromApp")) {
00052         handleMessageFromApp(msg);
00053     }
00054     else if (msg->getArrivalGateId() == findGate("fromProfile")) {
00055         handleMessageFromProfile(msg);
00056     }
00057     else if (msg->getArrivalGateId() == findGate("fromRTCP")) {
00058         handleMessageFromRTCP(msg);
00059     }
00060     else if (msg->getArrivalGateId() == findGate("fromUDPLayer")) {
00061         handleMessagefromUDP(msg);
00062     }
00063     else {
00064         error("Message from unknown gate");
00065     }
00066 };

void RTP::handleMessageFromApp ( cMessage *  msg  )  [protected, virtual]

Handles messages received from the applicaiton.

Referenced by handleMessage().

00074 {
00075     RTPInterfacePacket *rifp = (RTPInterfacePacket *)msg;
00076     if (rifp->getType() == RTPInterfacePacket::RTP_IFP_ENTER_SESSION) {
00077         enterSession(rifp);
00078     }
00079     else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_CREATE_SENDER_MODULE) {
00080         createSenderModule(rifp);
00081     }
00082     else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_DELETE_SENDER_MODULE) {
00083         deleteSenderModule(rifp);
00084     }
00085     else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_SENDER_CONTROL) {
00086         senderModuleControl(rifp);
00087     }
00088     else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_LEAVE_SESSION) {
00089         leaveSession(rifp);
00090     }
00091     else {
00092         error("unknown RTPInterfacePacket type from application");
00093     }
00094 };

void RTP::handleMessageFromProfile ( cMessage *  msg  )  [protected, virtual]

Handles messages received from the profile module.

Referenced by handleMessage().

00098 {
00099     RTPInnerPacket *rinp = (RTPInnerPacket *)msg;
00100     if (rinp->getType() == RTPInnerPacket::RTP_INP_PROFILE_INITIALIZED) {
00101         profileInitialized(rinp);
00102     }
00103     else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CREATED) {
00104         senderModuleCreated(rinp);
00105     }
00106     else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_DELETED) {
00107         senderModuleDeleted(rinp);
00108     }
00109     else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_INITIALIZED) {
00110         senderModuleInitialized(rinp);
00111     }
00112     else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_STATUS) {
00113         senderModuleStatus(rinp);
00114     }
00115     else if (rinp->getType() == RTPInnerPacket::RTP_INP_DATA_OUT) {
00116         dataOut(rinp);
00117     }
00118     else {
00119         delete msg;
00120     }
00121     ev << "handleMessageFromProfile(cMessage *msg) Exit"<<endl;
00122 }

void RTP::handleMessageFromRTCP ( cMessage *  msg  )  [protected, virtual]

Handles messages received from the rtcp module.

Referenced by handleMessage().

00126 {
00127     RTPInnerPacket *rinp = (RTPInnerPacket *)msg;
00128     if (rinp->getType() == RTPInnerPacket::RTP_INP_RTCP_INITIALIZED) {
00129         rtcpInitialized(rinp);
00130     }
00131     else if (rinp->getType() == RTPInnerPacket::RTP_INP_SESSION_LEFT) {
00132         sessionLeft(rinp);
00133     }
00134     else {
00135         error("Unknown RTPInnerPacket type %d from rtcp", rinp->getType());
00136     }
00137 };

void RTP::handleMessagefromUDP ( cMessage *  msg  )  [protected, virtual]

Handles messages received from the UDP layer.

Referenced by handleMessage().

00140 {
00141     readRet(msg);
00142 };

void RTP::enterSession ( RTPInterfacePacket rifp  )  [protected, virtual]

Creates the profile module and initializes it.

Referenced by handleMessageFromApp().

00150 {
00151     _profileName = rifp->getProfileName();
00152     _commonName = rifp->getCommonName();
00153     _bandwidth = rifp->getBandwidth();
00154     _destinationAddress = rifp->getDestinationAddress();
00155 
00156     _port = rifp->getPort();
00157     if (_port % 2 != 0) {
00158         _port = _port - 1;
00159     }
00160 
00161     _mtu = resolveMTU();
00162 
00163     createProfile();
00164     initializeProfile();
00165     delete rifp;
00166 };

void RTP::leaveSession ( RTPInterfacePacket rifp  )  [protected, virtual]

Destroys the profile module and orders the rtcp module to send an rtcp bye packet.

Referenced by handleMessageFromApp().

00170 {
00171     cModule *profileModule = gate("toProfile")->getNextGate()->getOwnerModule();
00172     profileModule->deleteModule();
00173     _leaveSession = true;
00174     RTPInnerPacket *rinp = new RTPInnerPacket("leaveSession()");
00175     rinp->leaveSession();
00176     send(rinp,"toRTCP");
00177 
00178     delete rifp;
00179 };

void RTP::createSenderModule ( RTPInterfacePacket rifp  )  [protected, virtual]

Referenced by handleMessageFromApp().

00183 {
00184     RTPInnerPacket *rinp = new RTPInnerPacket("createSenderModule()");
00185     ev << rifp->getSSRC()<<endl;
00186     rinp->createSenderModule(rifp->getSSRC(), rifp->getPayloadType(), rifp->getFileName());
00187     send(rinp, "toProfile");
00188 
00189     delete rifp;
00190 };

void RTP::deleteSenderModule ( RTPInterfacePacket rifp  )  [protected, virtual]

Referenced by handleMessageFromApp().

00194 {
00195     RTPInnerPacket *rinp = new RTPInnerPacket("deleteSenderModule()");
00196     rinp->deleteSenderModule(rifp->getSSRC());
00197     send(rinp, "toProfile");
00198 
00199     delete rifp;
00200 };

void RTP::senderModuleControl ( RTPInterfacePacket rifp  )  [protected, virtual]

Referenced by handleMessageFromApp().

00204 {
00205     RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleControl()");
00206     rinp->senderModuleControl(rinp->getSSRC(), (RTPSenderControlMessage *)(rifp->decapsulate()));
00207     send(rinp, "toProfile");
00208 
00209     delete rifp;
00210 }

void RTP::profileInitialized ( RTPInnerPacket rinp  )  [protected, virtual]

Called when the profile module is initialized.

Referenced by handleMessageFromProfile().

00214 {
00215     _rtcpPercentage = rinp->getRtcpPercentage();
00216     if (_port == PORT_UNDEF) {
00217         _port = rinp->getPort();
00218         if (_port % 2 != 0) {
00219             _port = _port - 1;
00220         }
00221     }
00222 
00223     delete rinp;
00224 
00225     createSocket();
00226 };

void RTP::senderModuleCreated ( RTPInnerPacket rinp  )  [protected, virtual]

Referenced by handleMessageFromProfile().

00230 {
00231     RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleCreated()");
00232     rifp->senderModuleCreated(rinp->getSSRC());
00233     send(rifp, "toApp");
00234 
00235     delete rinp;
00236 };

void RTP::senderModuleDeleted ( RTPInnerPacket rinp  )  [protected, virtual]

Referenced by handleMessageFromProfile().

00240 {
00241     RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleDeleted()");
00242     rifp->senderModuleDeleted(rinp->getSSRC());
00243     send(rifp, "toApp");
00244 
00245     // perhaps we should send a message to rtcp module
00246     delete rinp;
00247 };

void RTP::senderModuleInitialized ( RTPInnerPacket rinp  )  [protected, virtual]

Referenced by handleMessageFromProfile().

00251 {
00252     send(rinp, "toRTCP");
00253 };

void RTP::senderModuleStatus ( RTPInnerPacket rinp  )  [protected, virtual]

Referenced by handleMessageFromProfile().

00257 {
00258     RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleStatus()");
00259     rifp->senderModuleStatus(rinp->getSSRC(), (RTPSenderStatusMessage *)(rinp->decapsulate()));
00260     send(rifp, "toApp");
00261 
00262     delete rinp;
00263 };

void RTP::dataOut ( RTPInnerPacket rinp  )  [protected, virtual]

Sends a rtp data packet to the UDP layer and a copy of it to the rtcp module.

Referenced by handleMessageFromProfile().

00267 {
00268     RTPPacket *msg = (RTPPacket *)(rinp->decapsulate());
00269 
00270     // send message to UDP, with the appropriate control info attached
00271     msg->setKind(UDP_C_DATA);
00272 
00273     UDPControlInfo *ctrl = new UDPControlInfo();
00274     ctrl->setDestAddr(_destinationAddress);
00275     ctrl->setDestPort(_port);
00276     msg->setControlInfo(ctrl);
00277 
00278 //     ev << "Sending packet: ";msg->dump();
00279     send(msg, "toUDPLayer");
00280 
00281     // RTCP module must be informed about sent rtp data packet
00282 
00283     RTPInnerPacket *rinpOut = new RTPInnerPacket(*rinp);
00284     rinpOut->encapsulate(new RTPPacket(*msg));
00285     send(rinpOut, "toRTCP");
00286 
00287     delete rinp;
00288 };

void RTP::rtcpInitialized ( RTPInnerPacket rinp  )  [protected, virtual]

Informs the application that the session is entered.

Referenced by handleMessageFromRTCP().

00292 {
00293     RTPInterfacePacket *rifp = new RTPInterfacePacket("sessionEntered()");
00294     rifp->sessionEntered(rinp->getSSRC());
00295     send(rifp, "toApp");
00296 
00297     delete rinp;
00298 };

void RTP::sessionLeft ( RTPInnerPacket rinp  )  [protected, virtual]

Informs the application that this end system has left the rtp session.

Referenced by handleMessageFromRTCP().

00302 {
00303     RTPInterfacePacket *rifp = new RTPInterfacePacket("sessionLeft()");
00304     rifp->sessionLeft();
00305     send(rifp, "toApp");
00306 
00307     delete rinp;
00308 };

void RTP::createProfile (  )  [protected, virtual]

Creates the profile module.

Referenced by enterSession().

00355 {
00356     cModuleType *moduleType = cModuleType::find(_profileName);
00357     if (moduleType == NULL)
00358         error("Profile type `%s' not found", _profileName);
00359 
00360     RTPProfile *profile = check_and_cast<RTPProfile *>(moduleType->create("Profile", this));
00361     profile->finalizeParameters();
00362 
00363     profile->setGateSize("toPayloadReceiver", 30);
00364     profile->setGateSize("fromPayloadReceiver", 30);
00365 
00366     this->gate("toProfile")->connectTo(profile->gate("fromRTP"));
00367     profile->gate("toRTP")->connectTo(this->gate("fromProfile"));
00368 
00369     profile->callInitialize();
00370     profile->scheduleStart(simTime());
00371 };

void RTP::createSocket (  )  [protected, virtual]

Requests a server socket from the UDP layer.

Referenced by profileInitialized().

00375 {
00376     // TODO UDPAppBase should be ported to use UDPSocket sometime, but for now
00377     // we just manage the UDP socket by hand...
00378     if (_socketFdIn == -1) {
00379     _socketFdIn = UDPSocket::generateSocketId();
00380 
00381     UDPControlInfo *ctrl = new UDPControlInfo();
00382 
00383     IPAddress ipaddr(_destinationAddress);
00384 
00385     if (ipaddr.isMulticast()) {
00386         ctrl->setSrcAddr(IPAddress(_destinationAddress));
00387         ctrl->setSrcPort(_port);
00388     }
00389     else {
00390          ctrl->setSrcPort(_port);
00391          ctrl->setSockId(_socketFdOut);
00392     }
00393     ctrl->setSockId((int)_socketFdIn);
00394     cMessage *msg = new cMessage("UDP_C_BIND", UDP_C_BIND);
00395     msg->setControlInfo(ctrl);
00396     send(msg,"toUDPLayer");
00397 
00398     connectRet();
00399     }
00400 };

void RTP::socketRet (  )  [protected, virtual]

Called when the socket layer returns a socket.

00312 {
00313 };

void RTP::connectRet (  )  [protected, virtual]

Called when the socket layer has connected a socket.

Referenced by createSocket().

00317 {
00318     initializeRTCP();
00319 };

void RTP::readRet ( cMessage *  sifp  )  [protected, virtual]

Called when data from the socket layer has been received.

Referenced by handleMessagefromUDP().

00323 {
00324     if ( ! _leaveSession)
00325     {
00326          RTPPacket *msg = (RTPPacket *)(sifp);
00327 
00328          msg->dump();
00329          RTPInnerPacket *rinp1 = new RTPInnerPacket("dataIn1()");
00330          rinp1->dataIn(new RTPPacket(*msg), IPAddress(_destinationAddress), _port);
00331 
00332          RTPInnerPacket *rinp2 = new RTPInnerPacket(*rinp1);
00333          send(rinp2, "toRTCP");
00334          //delete rinp2;
00335          send(rinp1, "toProfile");
00336          //delete rinp1;
00337     }
00338 
00339     delete sifp;
00340 };

void RTP::initializeProfile (  )  [protected, virtual]

Initializes the profile module.

Referenced by enterSession().

00403 {
00404     RTPInnerPacket *rinp = new RTPInnerPacket("initializeProfile()");
00405     rinp->initializeProfile(_mtu);
00406     send(rinp, "toProfile");
00407 };

void RTP::initializeRTCP (  )  [protected, virtual]

Initializes the rtcp module-.

Referenced by connectRet().

00411 {
00412     RTPInnerPacket *rinp = new RTPInnerPacket("initializeRTCP()");
00413     int rtcpPort = _port + 1;
00414     rinp->initializeRTCP(opp_strdup(_commonName), _mtu, _bandwidth, _rtcpPercentage, _destinationAddress, rtcpPort);
00415     send(rinp, "toRTCP");
00416 };

int RTP::resolveMTU (  )  [protected, virtual]

Determines the maximum transmission unit that can be uses for rtp. This implementation assumes that we use an ethernet with 1500 bytes mtu. The returned value is 1500 bytes minus header sizes for ip and udp.

Referenced by enterSession().

00344 {
00345     // this is not what it should be
00346     // do something like mtu path discovery
00347     // for the simulation we can use this example value
00348     // it's 1500 bytes (ethernet) minus ip
00349     // and udp headers
00350     return 1500 - 20 - 8;
00351 };


Member Data Documentation

const char* RTP::_commonName [protected]

The CNAME of this end system.

Referenced by enterSession(), and initializeRTCP().

const char* RTP::_profileName [protected]

The name of the profile used in this session.

Referenced by createProfile(), and enterSession().

int RTP::_bandwidth [protected]

The available bandwidth for this session.

Referenced by enterSession(), and initializeRTCP().

The destination address.

Referenced by createSocket(), dataOut(), enterSession(), initializeRTCP(), and readRet().

int RTP::_port [protected]

int RTP::_mtu [protected]

The maximum size of a packet.

Referenced by enterSession(), initializeProfile(), and initializeRTCP().

int RTP::_rtcpPercentage [protected]

The percentage of the bandwidth used for rtcp.

Referenced by initializeRTCP(), and profileInitialized().

int RTP::_socketFdIn [protected]

The rtp server socket file descriptor.

Referenced by createSocket(), and initialize().

int RTP::_socketFdOut [protected]

The rtp client socket file descriptor.

Referenced by createSocket(), and initialize().

bool RTP::_leaveSession [protected]

True when this end system is about to leave the session.

Referenced by initialize(), leaveSession(), and readRet().


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

Generated on Fri Mar 20 18:51:20 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5