INET Framework for OMNeT++/OMNEST
inet::rtp::RTPProfile Class Reference

The class RTPProfile is a module which handles RTPPayloadSender and RTPPayloadReceiver modules. More...

#include <RTPProfile.h>

Inheritance diagram for inet::rtp::RTPProfile:
inet::rtp::RTPAVProfile

Classes

class  SSRCGate
 

Public Member Functions

 RTPProfile ()
 

Protected Types

typedef std::map< uint32, SSRCGate * > SSRCGateMap
 Stores information to which gate rtp data packets from a ssrc must be forwarded. More...
 

Protected Member Functions

virtual void initialize () override
 Initializes variables. More...
 
virtual ~RTPProfile ()
 
virtual void handleMessage (cMessage *msg) override
 Creates and removes payload sender and receiver modules on demand. More...
 
virtual void handleMessageFromRTP (cMessage *msg)
 Handles messages received from the rtp module. More...
 
virtual void handleMessageFromPayloadSender (cMessage *msg)
 Handles messages coming from the sender module. More...
 
virtual void handleMessageFromPayloadReceiver (cMessage *msg)
 Handles messages coming from a receiver module. More...
 
virtual void initializeProfile (RTPInnerPacket *rinp)
 Initialization message received from rtp module. More...
 
virtual void createSenderModule (RTPInnerPacket *rinp)
 This method is called when the application issued the creation of an rtp payload sender module to transmit data. More...
 
virtual void deleteSenderModule (RTPInnerPacket *rinp)
 When a sender module is no longer needed it can be deleted by the profile module. More...
 
virtual void senderModuleControl (RTPInnerPacket *rinp)
 The profile module forwards sender control messages to the sender module. More...
 
virtual void dataIn (RTPInnerPacket *rinp)
 Handles incoming data packets: If there isn't a receiver module for this sender it creates one. More...
 
virtual void senderModuleInitialized (RTPInnerPacket *rinp)
 The sender module returns a senderModuleInitialized message after being initialized. More...
 
virtual void senderModuleStatus (RTPInnerPacket *rinp)
 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. More...
 
virtual void dataOut (RTPInnerPacket *rinp)
 Handles outgoing data packets: Calls processOutgoingPacket and forwards the packet to the rtp module. More...
 
virtual void processIncomingPacket (RTPInnerPacket *rinp)
 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. More...
 
virtual void processOutgoingPacket (RTPInnerPacket *rinp)
 Simular to the procedure for incoming packets, this adds profile specific extensions to outgoing rtp packets. More...
 
virtual SSRCGatefindSSRCGate (uint32 ssrc)
 Finds the gate of the receiver module for rtp data packets from this ssrc. More...
 
virtual SSRCGatenewSSRCGate (uint32 ssrc)
 Creates a new association ssrc/gateId for this ssrc. More...
 

Protected Attributes

const char * _profileName = nullptr
 The name of this profile. More...
 
int _maxReceivers = 0
 The maximum number of incoming data streams this profile module can handle. More...
 
SSRCGateMap _ssrcGates
 
int _rtcpPercentage = 0
 The percentage of the available bandwidth to be used for rtcp. More...
 
int _preferredPort = -1
 The rtp port this profile uses if no port is given. More...
 
int _mtu = 0
 The maximum size an RTPPacket can have. More...
 
bool _autoOutputFileNames = false
 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. More...
 

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

Member Typedef Documentation

typedef std::map<uint32, SSRCGate *> inet::rtp::RTPProfile::SSRCGateMap
protected

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

Constructor & Destructor Documentation

inet::rtp::RTPProfile::RTPProfile ( )
33 {
34 }
inet::rtp::RTPProfile::~RTPProfile ( )
protectedvirtual
51 {
52  for (auto & elem : _ssrcGates)
53  delete elem.second;
54 }
SSRCGateMap _ssrcGates
Definition: RTPProfile.h:193

Member Function Documentation

void inet::rtp::RTPProfile::createSenderModule ( RTPInnerPacket rinp)
protectedvirtual

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().

150 {
151  EV_TRACE << "createSenderModule Enter" << endl;
152  int ssrc = rinp->getSsrc();
153  int payloadType = rinp->getPayloadType();
154  char moduleName[100];
155 
156  EV_INFO << "ProfileName: " << _profileName << " payloadType: " << payloadType << endl;
157  const char *pkgPrefix = "inet.transportlayer.rtp."; //FIXME hardcoded string
158  sprintf(moduleName, "%sRTP%sPayload%iSender", pkgPrefix, _profileName, payloadType);
159 
160  cModuleType *moduleType = cModuleType::find(moduleName);
161  if (moduleType == nullptr)
162  throw cRuntimeError("RTPProfile: payload sender module '%s' not found", moduleName);
163 
164  RTPPayloadSender *rtpPayloadSender = (RTPPayloadSender *)(moduleType->create(moduleName, this));
165  rtpPayloadSender->finalizeParameters();
166 
167  gate("payloadSenderOut")->connectTo(rtpPayloadSender->gate("profileIn"));
168  rtpPayloadSender->gate("profileOut")->connectTo(gate("payloadSenderIn"));
169 
170  rtpPayloadSender->callInitialize();
171  rtpPayloadSender->scheduleStart(simTime());
172 
173  RTPInnerPacket *rinpOut1 = new RTPInnerPacket("senderModuleCreated()");
174  rinpOut1->setSenderModuleCreatedPkt(ssrc);
175  send(rinpOut1, "rtpOut");
176 
177  RTPInnerPacket *rinpOut2 = new RTPInnerPacket("initializeSenderModule()");
178  rinpOut2->setInitializeSenderModulePkt(ssrc, rinp->getFileName(), _mtu);
179  send(rinpOut2, "payloadSenderOut");
180 
181  delete rinp;
182  EV_TRACE << "createSenderModule Exit" << endl;
183 }
const char * _profileName
The name of this profile.
Definition: RTPProfile.h:179
int _mtu
The maximum size an RTPPacket can have.
Definition: RTPProfile.h:208
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::rtp::RTPProfile::dataIn ( RTPInnerPacket rinp)
protectedvirtual

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().

203 {
204  EV_TRACE << "dataIn(RTPInnerPacket *rinp) Enter" << endl;
205  processIncomingPacket(rinp);
206 
207  RTPPacket *packet = check_and_cast<RTPPacket *>(rinp->getEncapsulatedPacket());
208 
209  uint32 ssrc = packet->getSsrc();
210 
211  SSRCGate *ssrcGate = findSSRCGate(ssrc);
212 
213  if (!ssrcGate) {
214  ssrcGate = newSSRCGate(ssrc);
215  char payloadReceiverName[100];
216  const char *pkgPrefix = "inet.transportlayer.rtp."; //FIXME hardcoded string
217  sprintf(payloadReceiverName, "%sRTP%sPayload%iReceiver",
218  pkgPrefix, _profileName, packet->getPayloadType());
219 
220  cModuleType *moduleType = cModuleType::find(payloadReceiverName);
221  if (moduleType == nullptr)
222  throw cRuntimeError("Receiver module type %s not found", payloadReceiverName);
223  else {
224  RTPPayloadReceiver *receiverModule =
225  (RTPPayloadReceiver *)(moduleType->create(payloadReceiverName, this));
226  if (_autoOutputFileNames) {
227  char outputFileName[100];
228  sprintf(outputFileName, "id%i.sim", receiverModule->getId());
229  receiverModule->par("outputFileName") = outputFileName;
230  }
231  receiverModule->finalizeParameters();
232 
233  this->gate(ssrcGate->getGateId())->connectTo(receiverModule->gate("profileIn"));
234  receiverModule->gate("profileOut")->connectTo(this->gate(ssrcGate->getGateId()
235  - findGate("payloadReceiverOut", 0) + findGate("payloadReceiverIn", 0)));
236 
237  for (int i = 0; receiverModule->callInitialize(i); i++)
238  ;
239 
240  receiverModule->scheduleStart(simTime());
241  }
242  }
243 
244  send(rinp, ssrcGate->getGateId());
245  EV_TRACE << "dataIn(RTPInnerPacket *rinp) Exit" << endl;
246 }
bool _autoOutputFileNames
If this is set true the RTPProfile automatically sets the output file name for payload receiver modul...
Definition: RTPProfile.h:215
const char * _profileName
The name of this profile.
Definition: RTPProfile.h:179
virtual SSRCGate * newSSRCGate(uint32 ssrc)
Creates a new association ssrc/gateId for this ssrc.
Definition: RTPProfile.cc:284
uint32_t uint32
Definition: Compat.h:30
virtual void processIncomingPacket(RTPInnerPacket *rinp)
Every time a rtp packet is received it it pre-processed by this method to remove profile specific ext...
Definition: RTPProfile.cc:266
virtual SSRCGate * findSSRCGate(uint32 ssrc)
Finds the gate of the receiver module for rtp data packets from this ssrc.
Definition: RTPProfile.cc:276
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::rtp::RTPProfile::dataOut ( RTPInnerPacket rinp)
protectedvirtual

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

Referenced by handleMessageFromPayloadSender().

249 {
250  processOutgoingPacket(rinp);
251  send(rinp, "rtpOut");
252 }
virtual void processOutgoingPacket(RTPInnerPacket *rinp)
Simular to the procedure for incoming packets, this adds profile specific extensions to outgoing rtp ...
Definition: RTPProfile.cc:271
void inet::rtp::RTPProfile::deleteSenderModule ( RTPInnerPacket rinp)
protectedvirtual

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

Referenced by handleMessageFromRTP().

186 {
187  cModule *senderModule = gate("payloadSenderOut")->getNextGate()->getOwnerModule();
188  senderModule->deleteModule();
189 
190  RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleDeleted()");
191  rinpOut->setSenderModuleDeletedPkt(rinpIn->getSsrc());
192  delete rinpIn;
193 
194  send(rinpOut, "rtpOut");
195 }
RTPProfile::SSRCGate * inet::rtp::RTPProfile::findSSRCGate ( uint32  ssrc)
protectedvirtual

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

Referenced by dataIn().

277 {
278  auto objectIndex = _ssrcGates.find(ssrc);
279  if (objectIndex == _ssrcGates.end())
280  return nullptr;
281  return objectIndex->second;
282 }
SSRCGateMap _ssrcGates
Definition: RTPProfile.h:193
void inet::rtp::RTPProfile::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Creates and removes payload sender and receiver modules on demand.

57 {
58  if (msg->getArrivalGateId() == findGate("rtpIn")) {
60  }
61  else if (msg->getArrivalGateId() == findGate("payloadSenderIn")) {
63  }
64  else if (msg->getArrivalGateId() >= findGate("payloadReceiverIn")
65  && msg->getArrivalGateId() < findGate("payloadReceiverIn") + _maxReceivers)
66  {
68  }
69  else {
70  throw cRuntimeError("message coming from unknown gate");
71  }
72 }
virtual void handleMessageFromRTP(cMessage *msg)
Handles messages received from the rtp module.
Definition: RTPProfile.cc:74
virtual void handleMessageFromPayloadSender(cMessage *msg)
Handles messages coming from the sender module.
Definition: RTPProfile.cc:109
virtual void handleMessageFromPayloadReceiver(cMessage *msg)
Handles messages coming from a receiver module.
Definition: RTPProfile.cc:132
int _maxReceivers
The maximum number of incoming data streams this profile module can handle.
Definition: RTPProfile.h:186
void inet::rtp::RTPProfile::handleMessageFromPayloadReceiver ( cMessage *  msg)
protectedvirtual

Handles messages coming from a receiver module.

Referenced by handleMessage().

133 {
134  // currently payload receiver modules don't send messages
135  delete msg;
136 }
void inet::rtp::RTPProfile::handleMessageFromPayloadSender ( cMessage *  msg)
protectedvirtual

Handles messages coming from the sender module.

Referenced by handleMessage().

110 {
111  RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);
112 
113  switch (rinpIn->getType()) {
114  case RTP_INP_DATA_OUT:
115  dataOut(rinpIn);
116  break;
117 
119  senderModuleInitialized(rinpIn);
120  break;
121 
123  senderModuleStatus(rinpIn);
124  break;
125 
126  default:
127  throw cRuntimeError("Profile received RTPInnerPacket from sender module with wrong type: %d", rinpIn->getType());
128  break;
129  }
130 }
virtual void senderModuleStatus(RTPInnerPacket *rinp)
After having received a sender module control message the sender module returns a sender status messa...
Definition: RTPProfile.cc:260
virtual void dataOut(RTPInnerPacket *rinp)
Handles outgoing data packets: Calls processOutgoingPacket and forwards the packet to the rtp module...
Definition: RTPProfile.cc:248
Definition: RTPInnerPacket_m.h:85
Definition: RTPInnerPacket_m.h:88
Definition: RTPInnerPacket_m.h:83
virtual void senderModuleInitialized(RTPInnerPacket *rinp)
The sender module returns a senderModuleInitialized message after being initialized.
Definition: RTPProfile.cc:254
void inet::rtp::RTPProfile::handleMessageFromRTP ( cMessage *  msg)
protectedvirtual

Handles messages received from the rtp module.

Referenced by handleMessage().

75 {
76  EV_TRACE << "handleMessageFromRTP Enter " << endl;
77 
78  RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);
79 
80  switch (rinpIn->getType()) {
82  initializeProfile(rinpIn);
83  break;
84 
86  createSenderModule(rinpIn);
87  break;
88 
90  deleteSenderModule(rinpIn);
91  break;
92 
94  senderModuleControl(rinpIn);
95  break;
96 
97  case RTP_INP_DATA_IN:
98  dataIn(rinpIn);
99  break;
100 
101  default:
102  throw cRuntimeError("RTPInnerPacket from RTPModule has wrong type: %d", rinpIn->getType());
103  break;
104  }
105 
106  EV_TRACE << "handleMessageFromRTP Exit " << endl;
107 }
virtual void dataIn(RTPInnerPacket *rinp)
Handles incoming data packets: If there isn&#39;t a receiver module for this sender it creates one...
Definition: RTPProfile.cc:202
virtual void createSenderModule(RTPInnerPacket *rinp)
This method is called when the application issued the creation of an rtp payload sender module to tra...
Definition: RTPProfile.cc:149
virtual void initializeProfile(RTPInnerPacket *rinp)
Initialization message received from rtp module.
Definition: RTPProfile.cc:138
virtual void deleteSenderModule(RTPInnerPacket *rinp)
When a sender module is no longer needed it can be deleted by the profile module. ...
Definition: RTPProfile.cc:185
Definition: RTPInnerPacket_m.h:78
Definition: RTPInnerPacket_m.h:80
Definition: RTPInnerPacket_m.h:89
Definition: RTPInnerPacket_m.h:84
Definition: RTPInnerPacket_m.h:74
virtual void senderModuleControl(RTPInnerPacket *rinp)
The profile module forwards sender control messages to the sender module.
Definition: RTPProfile.cc:197
void inet::rtp::RTPProfile::initialize ( )
overrideprotectedvirtual

Initializes variables.

Must be overwritten by subclasses.

Reimplemented in inet::rtp::RTPAVProfile.

Referenced by inet::rtp::RTPAVProfile::initialize().

37 {
38  EV_TRACE << "initialize() Enter" << endl;
39  _profileName = "Profile";
40  _rtcpPercentage = 5;
42 
43  // how many gates to payload receivers do we have
44  _maxReceivers = gateSize("payloadReceiverOut");
45  _ssrcGates.clear();
46  _autoOutputFileNames = par("autoOutputFileNames").boolValue();
47  EV_TRACE << "initialize() Exit" << endl;
48 }
bool _autoOutputFileNames
If this is set true the RTPProfile automatically sets the output file name for payload receiver modul...
Definition: RTPProfile.h:215
int _preferredPort
The rtp port this profile uses if no port is given.
Definition: RTPProfile.h:203
const char * _profileName
The name of this profile.
Definition: RTPProfile.h:179
const short PORT_UNDEF
TCP/UDP port numbers.
Definition: IPv4Address.h:39
int _rtcpPercentage
The percentage of the available bandwidth to be used for rtcp.
Definition: RTPProfile.h:198
SSRCGateMap _ssrcGates
Definition: RTPProfile.h:193
int _maxReceivers
The maximum number of incoming data streams this profile module can handle.
Definition: RTPProfile.h:186
void inet::rtp::RTPProfile::initializeProfile ( RTPInnerPacket rinp)
protectedvirtual

Initialization message received from rtp module.

Referenced by handleMessageFromRTP().

139 {
140  EV_TRACE << "initializeProfile Enter" << endl;
141  _mtu = rinp->getMTU();
142  delete rinp;
143  RTPInnerPacket *rinpOut = new RTPInnerPacket("profileInitialized()");
144  rinpOut->setProfileInitializedPkt(_rtcpPercentage, _preferredPort);
145  send(rinpOut, "rtpOut");
146  EV_TRACE << "initializeProfile Exit" << endl;
147 }
int _preferredPort
The rtp port this profile uses if no port is given.
Definition: RTPProfile.h:203
int _rtcpPercentage
The percentage of the available bandwidth to be used for rtcp.
Definition: RTPProfile.h:198
int _mtu
The maximum size an RTPPacket can have.
Definition: RTPProfile.h:208
RTPProfile::SSRCGate * inet::rtp::RTPProfile::newSSRCGate ( uint32  ssrc)
protectedvirtual

Creates a new association ssrc/gateId for this ssrc.

Referenced by dataIn().

285 {
286  SSRCGate *ssrcGate = new SSRCGate(ssrc);
287  bool assigned = false;
288  int receiverGateId = findGate("payloadReceiverOut", 0);
289  for (int i = receiverGateId; i < receiverGateId + _maxReceivers && !assigned; i++) {
290  if (!gate(i)->isConnected()) {
291  ssrcGate->setGateId(i);
292  assigned = true;
293  }
294  }
295 
296  if (!assigned)
297  throw cRuntimeError("Can't manage more senders");
298 
299  _ssrcGates[ssrc] = ssrcGate;
300  return ssrcGate;
301 }
SSRCGateMap _ssrcGates
Definition: RTPProfile.h:193
int _maxReceivers
The maximum number of incoming data streams this profile module can handle.
Definition: RTPProfile.h:186
void inet::rtp::RTPProfile::processIncomingPacket ( RTPInnerPacket rinp)
protectedvirtual

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().

267 {
268  // do nothing with the packet
269 }
void inet::rtp::RTPProfile::processOutgoingPacket ( RTPInnerPacket rinp)
protectedvirtual

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

Referenced by dataOut().

272 {
273  // do nothing with the packet
274 }
void inet::rtp::RTPProfile::senderModuleControl ( RTPInnerPacket rinp)
protectedvirtual

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

Referenced by handleMessageFromRTP().

198 {
199  send(rinp, "payloadSenderOut");
200 }
void inet::rtp::RTPProfile::senderModuleInitialized ( RTPInnerPacket rinp)
protectedvirtual

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().

255 {
256  EV_TRACE << "senderModuleInitialized" << endl;
257  send(rinp, "rtpOut");
258 }
void inet::rtp::RTPProfile::senderModuleStatus ( RTPInnerPacket rinp)
protectedvirtual

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().

261 {
262  EV_TRACE << "senderModuleStatus" << endl;
263  send(rinp, "rtpOut");
264 }

Member Data Documentation

bool inet::rtp::RTPProfile::_autoOutputFileNames = false
protected

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().

int inet::rtp::RTPProfile::_maxReceivers = 0
protected

The maximum number of incoming data streams this profile module can handle.

It is set to the gate size of "payloadReceiverOut", "payloadReceiverIn".

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

int inet::rtp::RTPProfile::_mtu = 0
protected

The maximum size an RTPPacket can have.

Referenced by createSenderModule(), and initializeProfile().

int inet::rtp::RTPProfile::_preferredPort = -1
protected

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

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

const char* inet::rtp::RTPProfile::_profileName = nullptr
protected

The name of this profile.

Needed for dynamic creating of sender and receiver modules.

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

int inet::rtp::RTPProfile::_rtcpPercentage = 0
protected

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

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

SSRCGateMap inet::rtp::RTPProfile::_ssrcGates
protected

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