RTPProfile Class Reference

#include <RTPProfile.h>

Inheritance diagram for RTPProfile:

RTPAVProfile

List of all members.


Detailed Description

The class RTPProfile is a module which handles RTPPayloadSender and RTPPayloadReceiver modules. It creates them dynamically on demand. This class offers all functionality for the above tasks, subclasses just need to set variables like profile name, rtcp percentage and preferred port in their initialize() method. The dynamically created sender and receiver modules must have have following class names: RTP<profileName>Payload<payloadType>Sender RTP<profileName>Payload<payloadType>Receiver

Public Member Functions

 RTPProfile ()

Protected Member Functions

virtual void initialize ()
virtual ~RTPProfile ()
virtual void handleMessage (cMessage *msg)
virtual void handleMessageFromRTP (cMessage *msg)
virtual void handleMessageFromPayloadSender (cMessage *msg)
virtual void handleMessageFromPayloadReceiver (cMessage *msg)
virtual void initializeProfile (RTPInnerPacket *rinp)
virtual void createSenderModule (RTPInnerPacket *rinp)
virtual void deleteSenderModule (RTPInnerPacket *rinp)
virtual void senderModuleControl (RTPInnerPacket *rinp)
virtual void dataIn (RTPInnerPacket *rinp)
virtual void senderModuleInitialized (RTPInnerPacket *rinp)
virtual void senderModuleStatus (RTPInnerPacket *rinp)
virtual void dataOut (RTPInnerPacket *rinp)
virtual void processIncomingPacket (RTPInnerPacket *rinp)
virtual void processOutgoingPacket (RTPInnerPacket *rinp)
virtual SSRCGatefindSSRCGate (uint32 ssrc)
virtual SSRCGatenewSSRCGate (uint32 ssrc)

Protected Attributes

const char * _profileName
int _maxReceivers
cArray * _ssrcGates
int _rtcpPercentage
int _preferredPort
int _mtu
bool _autoOutputFileNames

Classes

class  SSRCGate

Constructor & Destructor Documentation

RTPProfile::RTPProfile (  ) 

00033 {
00034     _ssrcGates = NULL;
00035 }

RTPProfile::~RTPProfile (  )  [protected, virtual]

00052 {
00053     delete _ssrcGates;
00054 }


Member Function Documentation

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

Initializes variables. Must be overwritten by subclasses.

Reimplemented in RTPAVProfile.

Referenced by RTPAVProfile::initialize().

00038 {
00039     ev << "initialize() Enter"<<endl;
00040     _profileName = "Profile";
00041     _rtcpPercentage = 5;
00042     _preferredPort = PORT_UNDEF;
00043 
00044     // how many gates to payload receivers do we have
00045     _maxReceivers = gateSize("toPayloadReceiver");
00046     _ssrcGates = new cArray("SSRCGates");
00047     _autoOutputFileNames = par("autoOutputFileNames").boolValue();
00048     ev << "initialize() Exit"<<endl;
00049 }

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

Creates and removes payload sender and receiver modules on demand.

00058 {
00059     if (msg->getArrivalGateId() == findGate("fromRTP")) {
00060         handleMessageFromRTP(msg);
00061     }
00062 
00063     else if (msg->getArrivalGateId() == findGate("fromPayloadSender")) {
00064         handleMessageFromPayloadSender(msg);
00065     }
00066 
00067     else if (msg->getArrivalGateId() >= findGate("fromPayloadReceiver") && msg->getArrivalGateId() < findGate("fromPayloadReceiver") + _maxReceivers) {
00068         handleMessageFromPayloadReceiver(msg);
00069     }
00070 
00071     else {
00072         error("message coming from unknown gate");
00073     }
00074 
00075 };

void RTPProfile::handleMessageFromRTP ( cMessage *  msg  )  [protected, virtual]

Handles messages received from the rtp module.

Referenced by handleMessage().

00079 {
00080     ev << "handleMessageFromRTP Enter "<<endl;
00081 
00082     RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);
00083 
00084     if (rinpIn->getType() == RTPInnerPacket::RTP_INP_INITIALIZE_PROFILE) {
00085         initializeProfile(rinpIn);
00086     }
00087     else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_CREATE_SENDER_MODULE) {
00088         createSenderModule(rinpIn);
00089     }
00090     else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_DELETE_SENDER_MODULE) {
00091         deleteSenderModule(rinpIn);
00092     }
00093     else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) {
00094         senderModuleControl(rinpIn);
00095     }
00096     else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_DATA_IN) {
00097         dataIn(rinpIn);
00098     }
00099     else {
00100         error("RTPInnerPacket from RTPModule has wrong type");
00101     }
00102 
00103     ev << "handleMessageFromRTP Exit "<<endl;
00104 }

void RTPProfile::handleMessageFromPayloadSender ( cMessage *  msg  )  [protected, virtual]

Handles messages coming from the sender module.

Referenced by handleMessage().

00107                                                              {
00108 
00109     RTPInnerPacket *rinpIn = (RTPInnerPacket *)msg;
00110 
00111     if (rinpIn->getType() == RTPInnerPacket::RTP_INP_DATA_OUT) {
00112         dataOut(rinpIn);
00113     }
00114     else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_INITIALIZED) {
00115         senderModuleInitialized(rinpIn);
00116     }
00117     else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_STATUS) {
00118         senderModuleStatus(rinpIn);
00119     }
00120     else {
00121         error("Profile received RTPInnerPacket from sender module with wrong type");
00122     }
00123 
00124 }

void RTPProfile::handleMessageFromPayloadReceiver ( cMessage *  msg  )  [protected, virtual]

Handles messages coming from a receiver module.

Referenced by handleMessage().

00127                                                                {
00128     // currently payload receiver modules don't send messages
00129     delete msg;
00130 }

void RTPProfile::initializeProfile ( RTPInnerPacket rinp  )  [protected, virtual]

Initialization message received from rtp module.

Referenced by handleMessageFromRTP().

00134 {
00135     ev << "initializeProfile Enter"<<endl;
00136     _mtu = rinp->getMTU();
00137     delete rinp;
00138     RTPInnerPacket *rinpOut = new RTPInnerPacket("profileInitialized()");
00139     rinpOut->profileInitialized(_rtcpPercentage, _preferredPort);
00140     send(rinpOut, "toRTP");
00141     ev << "initializeProfile Exit"<<endl;
00142 }

void RTPProfile::createSenderModule ( RTPInnerPacket rinp  )  [protected, virtual]

This method is called when the application issued the creation of an rtp payload sender module to transmit data. It creates a new sender module and connects it. The profile module informs the rtp module of having finished this task. Then it initializes the newly create sender module with a inititalizeSenderModule message.

Referenced by handleMessageFromRTP().

00146 {
00147     ev << "createSenderModule Enter"<<endl;
00148     int ssrc = rinp->getSSRC();
00149     int payloadType = rinp->getPayloadType();
00150     char moduleName[100];
00151 
00152     ev << "ProfileName: " << _profileName << " payloadType: " << payloadType<<endl;
00153     const char *pkgPrefix = "inet.transport.rtp."; //FIXME hardcoded string
00154     sprintf(moduleName, "%sRTP%sPayload%iSender", pkgPrefix, _profileName, payloadType);
00155 
00156     cModuleType *moduleType = cModuleType::find(moduleName);
00157     if (moduleType == NULL)
00158         opp_error("RTPProfile: payload sender module '%s' not found", moduleName);
00159 
00160     RTPPayloadSender *rtpPayloadSender = (RTPPayloadSender *)(moduleType->create(moduleName, this));
00161     rtpPayloadSender->finalizeParameters();
00162 
00163     gate("toPayloadSender")->connectTo(rtpPayloadSender->gate("fromProfile"));
00164     rtpPayloadSender->gate("toProfile")->connectTo(gate("fromPayloadSender"));
00165 
00166     rtpPayloadSender->initialize();
00167     rtpPayloadSender->scheduleStart(simTime());
00168 
00169     RTPInnerPacket *rinpOut1 = new RTPInnerPacket("senderModuleCreated()");
00170     rinpOut1->senderModuleCreated(ssrc);
00171     send(rinpOut1, "toRTP");
00172 
00173     RTPInnerPacket *rinpOut2 = new RTPInnerPacket("initializeSenderModule()");
00174     rinpOut2->initializeSenderModule(ssrc, rinp->getFileName(), _mtu);
00175     send(rinpOut2, "toPayloadSender");
00176 
00177     delete rinp;
00178     ev << "createSenderModule Exit"<<endl;
00179 };

void RTPProfile::deleteSenderModule ( RTPInnerPacket rinp  )  [protected, virtual]

When a sender module is no longer needed it can be deleted by the profile module.

Referenced by handleMessageFromRTP().

00183 {
00184     cModule *senderModule = gate("toPayloadSender")->getNextGate()->getOwnerModule();
00185     senderModule->deleteModule();
00186 
00187     RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleDeleted()");
00188     rinpOut->senderModuleDeleted(rinpIn->getSSRC());
00189     delete rinpIn;
00190 
00191     send(rinpOut, "toRTP");
00192 };

void RTPProfile::senderModuleControl ( RTPInnerPacket rinp  )  [protected, virtual]

The profile module forwards sender control messages to the sender module.

Referenced by handleMessageFromRTP().

00196 {
00197     send(rinp, "toPayloadSender");
00198 };

void RTPProfile::dataIn ( RTPInnerPacket rinp  )  [protected, virtual]

Handles incoming data packets: If there isn't a receiver module for this sender it creates one. The data packet is forwarded to the receiver module after calling processIncomingPacket.

Referenced by handleMessageFromRTP().

00202 {
00203     ev << "dataIn(RTPInnerPacket *rinp) Enter"<<endl;
00204     processIncomingPacket(rinp);
00205 
00206     RTPPacket *packet = (RTPPacket *)(rinp->getEncapsulatedMsg());
00207 
00208     uint32 ssrc = packet->getSSRC();
00209 
00210     SSRCGate *ssrcGate = findSSRCGate(ssrc);
00211 
00212     if (!ssrcGate) {
00213         ssrcGate = newSSRCGate(ssrc);
00214         char payloadReceiverName[100];
00215         const char *pkgPrefix = "inet.transport.rtp."; //FIXME hardcoded string
00216         sprintf(payloadReceiverName, "%sRTP%sPayload%iReceiver", pkgPrefix, _profileName, packet->getPayloadType());
00217 
00218         cModuleType *moduleType = cModuleType::find(payloadReceiverName);
00219         if (moduleType == NULL)
00220             opp_error("Receiver module type %s not found", payloadReceiverName);
00221 
00222         else {
00223             RTPPayloadReceiver *receiverModule = (RTPPayloadReceiver *)(moduleType->create(payloadReceiverName, this));
00224             if (_autoOutputFileNames) {
00225                 char outputFileName[100];
00226                 sprintf(outputFileName, "id%i.sim", receiverModule->getId());
00227                 receiverModule->par("outputFileName") = outputFileName;
00228             }
00229             receiverModule->finalizeParameters();
00230 
00231             this->gate(ssrcGate->getGateId())->connectTo(receiverModule->gate("fromProfile"));
00232             receiverModule->gate("toProfile")->connectTo(this->gate(ssrcGate->getGateId() - findGate("toPayloadReceiver",0) + findGate("fromPayloadReceiver",0)));
00233 
00234             receiverModule->callInitialize(0);
00235             receiverModule->scheduleStart(simTime());
00236         }
00237     };
00238 
00239     send(rinp, ssrcGate->getGateId());
00240     ev << "dataIn(RTPInnerPacket *rinp) Exit"<<endl;
00241 };

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

The sender module returns a senderModuleInitialized message after being initialized. The profile module forwards this message to the rtp module which delivers it to its destination, the rtcp module.

Referenced by handleMessageFromPayloadSender().

00252 {
00253     ev << "senderModuleInitialized"<<endl;
00254     send(rinp, "toRTP");
00255 };

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

After having received a sender module control message the sender module returns a sender status message to inform the application what it's doing at the moment.

Referenced by handleMessageFromPayloadSender().

00259 {
00260     ev << "senderModuleStatus"<<endl;
00261     send(rinp, "toRTP");
00262 };

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

Handles outgoing data packets: Calls processOutgoingPacket and forwards the packet to the rtp module.

Referenced by handleMessageFromPayloadSender().

00245 {
00246     processOutgoingPacket(rinp);
00247     send(rinp, "toRTP");
00248 };

void RTPProfile::processIncomingPacket ( RTPInnerPacket rinp  )  [protected, virtual]

Every time a rtp packet is received it it pre-processed by this method to remove profile specific extension which are not handled by the payload receiver module. In this implementation the packet isn't changed. Important: This method works with RTPInnerPacket. So the rtp packet must be decapsulated, changed and encapsulated again.

Referenced by dataIn().

00266 {
00267     // do nothing with the packet
00268 };

void RTPProfile::processOutgoingPacket ( RTPInnerPacket rinp  )  [protected, virtual]

Simular to the procedure for incoming packets, this adds profile specific extensions to outgoing rtp packets.

Referenced by dataOut().

00272 {
00273     // do nothing with the packet
00274 };

RTPProfile::SSRCGate * RTPProfile::findSSRCGate ( uint32  ssrc  )  [protected, virtual]

Finds the gate of the receiver module for rtp data packets from this ssrc.

Referenced by dataIn().

00278 {
00279     const char *name = RTPParticipantInfo::ssrcToName(ssrc);
00280     int objectIndex = _ssrcGates->find(name);
00281     if (objectIndex == -1) {
00282         return NULL;
00283     }
00284     else {
00285         cObject *co = (_ssrcGates->get(objectIndex));
00286         return (SSRCGate *)co;
00287     };
00288 };

RTPProfile::SSRCGate * RTPProfile::newSSRCGate ( uint32  ssrc  )  [protected, virtual]

Creates a new association ssrc/gateId for this ssrc.

Referenced by dataIn().

00292 {
00293     SSRCGate *ssrcGate = new SSRCGate(ssrc);
00294     bool assigned = false;
00295     int receiverGateId = findGate("toPayloadReceiver",0);
00296     for (int i = receiverGateId; i < receiverGateId + _maxReceivers && !assigned; i++) {
00297         if (!gate(i)->isConnected()) {
00298             ssrcGate->setGateId(i);
00299             assigned = true;
00300         }
00301     }
00302 
00303     if (!assigned)
00304         opp_error("Can't manage more senders");
00305 
00306     _ssrcGates->add(ssrcGate);
00307     return ssrcGate;
00308 };


Member Data Documentation

const char* RTPProfile::_profileName [protected]

The name of this profile. Needed for dynamic creating of sender and receiver modules.

Referenced by createSenderModule(), dataIn(), initialize(), and RTPAVProfile::initialize().

int RTPProfile::_maxReceivers [protected]

The maximum number of incoming data streams this profile module can handle. It is set to the gate size of "toPayloadReceiver", "fromPayloadReceiver".

Referenced by handleMessage(), initialize(), and newSSRCGate().

cArray* RTPProfile::_ssrcGates [protected]

Stores information to which gate rtp data packets from a ssrc must be forwarded.

Referenced by findSSRCGate(), initialize(), newSSRCGate(), RTPProfile(), and ~RTPProfile().

int RTPProfile::_rtcpPercentage [protected]

The percentage of the available bandwidth to be used for rtcp.

Referenced by initialize(), RTPAVProfile::initialize(), and initializeProfile().

int RTPProfile::_preferredPort [protected]

The rtp port this profile uses if no port is given.

Referenced by initialize(), RTPAVProfile::initialize(), and initializeProfile().

int RTPProfile::_mtu [protected]

The maximum size an RTPPacket can have.

Referenced by createSenderModule(), and initializeProfile().

If this is set true the RTPProfile automatically sets the output file name for payload receiver modules so the user is not bothered to set them manually during simulation runtime.

Referenced by dataIn(), and initialize().


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

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