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

virtual void initialize ()
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 RTPSSRCGatefindSSRCGate (u_int32 ssrc)
virtual RTPSSRCGatenewSSRCGate (u_int32 ssrc)

Public Attributes

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


Member Function Documentation

void RTPProfile::createSenderModule ( RTPInnerPacket rinp  )  [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.

00143                                                         {
00144 
00145     int ssrc = rinp->ssrc();
00146     int payloadType = rinp->payloadType();
00147     char moduleName[100];
00148     sprintf(moduleName, "RTP%sPayload%iSender", _profileName, payloadType);
00149 
00150     cModuleType *moduleType = findModuleType(moduleName);
00151 
00152     if (moduleType == NULL) {
00153         opp_error("RTPProfile: payload sender module \"", moduleName, "\" not found !");
00154     };
00155     RTPPayloadSender *rtpPayloadSender = (RTPPayloadSender *)(moduleType->create(moduleName, this));
00156 
00157     connect(this, findGate("toPayloadSender"), NULL, rtpPayloadSender, rtpPayloadSender->findGate("fromProfile"));
00158     connect(rtpPayloadSender, rtpPayloadSender->findGate("toProfile"), NULL, this, findGate("fromPayloadSender"));
00159 
00160     rtpPayloadSender->initialize();
00161     rtpPayloadSender->scheduleStart(simTime());
00162 
00163     RTPInnerPacket *rinpOut1 = new RTPInnerPacket("senderModuleCreated()");
00164     rinpOut1->senderModuleCreated(ssrc);
00165     send(rinpOut1, "toRTP");
00166 
00167     RTPInnerPacket *rinpOut2 = new RTPInnerPacket("initializeSenderModule()");
00168     rinpOut2->initializeSenderModule(ssrc, rinp->fileName(), _mtu);
00169     send(rinpOut2, "toPayloadSender");
00170 
00171     delete rinp;
00172 };

void RTPProfile::dataIn ( RTPInnerPacket rinp  )  [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.

00192                                             {
00193 
00194     processIncomingPacket(rinp);
00195 
00196     RTPPacket *packet = (RTPPacket *)(rinp->encapsulatedMsg());
00197 
00198     u_int32 ssrc = packet->ssrc();
00199 
00200     RTPSSRCGate *ssrcGate = findSSRCGate(ssrc);
00201 
00202     if (!ssrcGate) {
00203         ssrcGate = newSSRCGate(ssrc);
00204         char payloadReceiverName[100];
00205         sprintf(payloadReceiverName, "RTP%sPayload%iReceiver", _profileName, packet->payloadType());
00206 
00207         cModuleType *moduleType = findModuleType(payloadReceiverName);
00208         if (moduleType == NULL) {
00209             opp_error("Receiver module %s not found !", payloadReceiverName);
00210         }
00211         else {
00212             RTPPayloadReceiver *receiverModule = (RTPPayloadReceiver *)(moduleType->create(payloadReceiverName, this));
00213             if (_autoOutputFileNames) {
00214                 char outputFileName[100];
00215                 sprintf(outputFileName, "id%i.sim", receiverModule->id());
00216                 receiverModule->par("outputFileName") = outputFileName;
00217             }
00218             connect(this, ssrcGate->gateId(), NULL, receiverModule, receiverModule->findGate("fromProfile"));
00219             connect(receiverModule, receiverModule->findGate("toProfile"), NULL, this,  ssrcGate->gateId() - findGate("toPayloadReceiver") + findGate("fromPayloadReceiver"));
00220             receiverModule->callInitialize(0);
00221             receiverModule->scheduleStart(simTime());
00222         }
00223     };
00224 
00225     send(rinp, ssrcGate->gateId());
00226 };

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

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

00229                                              {
00230     processOutgoingPacket(rinp);
00231     send(rinp, "toRTP");
00232 };

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

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

00175                                                           {
00176     cModule *senderModule = gate("toPayloadSender")->toGate()->ownerModule();
00177     senderModule->deleteModule();
00178 
00179     RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleDeleted()");
00180     rinpOut->senderModuleDeleted(rinpIn->ssrc());
00181     delete rinpIn;
00182 
00183     send(rinpOut, "toRTP");
00184 };

RTPSSRCGate * RTPProfile::findSSRCGate ( u_int32  ssrc  )  [virtual]

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

00255                                                   {
00256     const char *name = RTPParticipantInfo::ssrcToName(ssrc);
00257     int objectIndex = _ssrcGates->find(name);
00258     if (objectIndex == -1) {
00259         return NULL;
00260     }
00261     else {
00262         cObject *co = (_ssrcGates->get(objectIndex));
00263         return (RTPSSRCGate *)co;
00264     };
00265 };

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

Creates and removes payload sender and receiver modules on demand.

00049                                             {
00050 
00051     if (msg->arrivalGateId() == findGate("fromRTP")) {
00052         handleMessageFromRTP(msg);
00053     }
00054 
00055     else if (msg->arrivalGateId() == findGate("fromPayloadSender")) {
00056         handleMessageFromPayloadSender(msg);
00057     }
00058 
00059     else if (msg->arrivalGateId() >= findGate("fromPayloadReceiver") && msg->arrivalGateId() < findGate("fromPayloadReceiver") + _maxReceivers) {
00060         handleMessageFromPayloadReceiver(msg);
00061     }
00062 
00063     else {
00064         // this shouldn't happen
00065         EV << "RTPProfile: message coming from unknown gate" << endl;
00066     }
00067 
00068 };

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

Handles messages coming from a receiver module.

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

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

Handles messages coming from the sender module.

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

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

Handles messages received from the rtp module.

00071                                                    {
00072 
00073     if (opp_strcmp(msg->className(), "RTPInnerPacket"))
00074         error("RTPProfile: message received from RTPModule is not an RTPInnerPacket !");
00075 
00076         RTPInnerPacket *rinpIn = (RTPInnerPacket *)msg;
00077 
00078         if (rinpIn->type() == RTPInnerPacket::RTP_INP_INITIALIZE_PROFILE) {
00079             initializeProfile(rinpIn);
00080         }
00081 
00082         else if (rinpIn->type() == RTPInnerPacket::RTP_INP_CREATE_SENDER_MODULE) {
00083             createSenderModule(rinpIn);
00084         }
00085 
00086         else if (rinpIn->type() == RTPInnerPacket::RTP_INP_DELETE_SENDER_MODULE) {
00087             deleteSenderModule(rinpIn);
00088         }
00089 
00090         else if (rinpIn->type() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) {
00091             senderModuleControl(rinpIn);
00092         }
00093 
00094         else if (rinpIn->type() == RTPInnerPacket::RTP_INP_DATA_IN) {
00095             dataIn(rinpIn);
00096         }
00097 
00098         else {
00099             EV << "RTPProfile: RTPInnerPacket from RTPModule has wrong type !"<< endl;
00100         }
00101 
00102 }

void RTPProfile::initialize (  )  [virtual]

Initializes variables. Must be overwritten by subclasses.

Reimplemented in RTPAVProfile.

00036                             {
00037 
00038     _profileName = "Profile";
00039     _rtcpPercentage = 5;
00040     _preferredPort = IPSuite_PORT_UNDEF;
00041 
00042     // how many gates to payload receivers do we have
00043     _maxReceivers = gate("toPayloadReceiver")->size();
00044     _ssrcGates = new cArray("SSRCGates");
00045     _autoOutputFileNames = par("autoOutputFileNames").boolValue();
00046 }

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

Initialization message received from rtp module.

00134                                                        {
00135     _mtu = rinp->mtu();
00136     delete rinp;
00137     RTPInnerPacket *rinpOut = new RTPInnerPacket("profileInitialized()");
00138     rinpOut->profileInitialized(_rtcpPercentage, _preferredPort);
00139     send(rinpOut, "toRTP");
00140 }

RTPSSRCGate * RTPProfile::newSSRCGate ( u_int32  ssrc  )  [virtual]

Creates a new association ssrc/gateId for this ssrc.

00268                                                  {
00269     RTPSSRCGate *ssrcGate = new RTPSSRCGate(ssrc);
00270     bool assigned = false;
00271     int receiverGateId = findGate("toPayloadReceiver");
00272     for (int i = receiverGateId; i < receiverGateId + _maxReceivers && !assigned; i++) {
00273         if (!gate(i)->isConnected()) {
00274             ssrcGate->setGateId(i);
00275             assigned = true;
00276         };
00277     };
00278     if (!assigned) {
00279         opp_error("Can't manage more senders !");
00280     };
00281     _ssrcGates->add(ssrcGate);
00282     return ssrcGate;
00283 };

void RTPProfile::processIncomingPacket ( RTPInnerPacket rinp  )  [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.

00245                                                            {
00246     // do nothing with the packet
00247 };

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

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

00250                                                            {
00251     // do nothing with the packet
00252 };

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

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

00187                                                          {
00188     send(rinp, "toPayloadSender");
00189 };

void RTPProfile::senderModuleInitialized ( RTPInnerPacket rinp  )  [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.

00235                                                              {
00236     send(rinp, "toRTP");
00237 };

void RTPProfile::senderModuleStatus ( RTPInnerPacket rinp  )  [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.

00240                                                         {
00241     send(rinp, "toRTP");
00242 };


Member Data Documentation

bool RTPProfile::_autoOutputFileNames

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.

int RTPProfile::_maxReceivers

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

int RTPProfile::_mtu

The maximum size an RTPPacket can have.

IN_Port RTPProfile::_preferredPort

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

const char* RTPProfile::_profileName

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

int RTPProfile::_rtcpPercentage

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

cArray* RTPProfile::_ssrcGates

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


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:24 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7