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

The class Rtcp is responsible for creating, receiving and processing of rtcp packets. More...

#include <Rtcp.h>

Inheritance diagram for inet::rtp::Rtcp:
inet::LifecycleUnsupported inet::ILifecycle

Public Member Functions

 Rtcp ()
 
virtual ~Rtcp ()
 
- Public Member Functions inherited from inet::LifecycleUnsupported
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void initialize (int stage) override
 Initializes variables. More...
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 Message handling. More...
 
virtual void handleMessageFromRTP (cMessage *msg)
 Handles messages from the Rtp module. More...
 
virtual void handleMessageFromUDP (cMessage *msg)
 Handles messages coming from the socket layer. More...
 
virtual void handleSelfMessage (cMessage *msg)
 Handles self messages. More...
 
virtual void handleInitializeRTCP (RtpInnerPacket *rinp)
 Initializes the rtcp module when the session is started. More...
 
virtual void handleSenderModuleInitialized (RtpInnerPacket *rinp)
 Stores information about the new transmission. More...
 
virtual void handleDataOut (RtpInnerPacket *packet)
 Stores information about an outgoing Rtp data packet. More...
 
virtual void handleDataIn (RtpInnerPacket *rinp)
 Stores information about an outgoing Rtp data packet. More...
 
virtual void handleLeaveSession (RtpInnerPacket *rinp)
 Makes the rtcp module send an RtcpByePacket in the next RtcpCompoundPacket to tell other participants in the Rtp session that this end system leaves. More...
 
virtual void connectRet ()
 Called when the socket layer has finished a connect. More...
 
virtual void readRet (Packet *sifpIn)
 Called when this rtcp module receives data from the socket layer. More...
 
virtual void createSocket ()
 Request a server socket from the socket layer. More...
 
virtual void chooseSSRC ()
 Chooses the ssrc identifier for this end system. More...
 
virtual void scheduleInterval ()
 Calculates the length of the next rtcp interval an issues a self message to remind itself. More...
 
virtual void createPacket ()
 Creates and sends an RtcpCompoundPacket. More...
 
virtual void processOutgoingRTPPacket (Packet *packet)
 Extracts information of a sent RtpPacket. More...
 
virtual void processIncomingRTPPacket (Packet *packet, Ipv4Address address, int port)
 Extracts information of a received RtpPacket. More...
 
virtual void processIncomingRTCPPacket (Packet *packet, Ipv4Address address, int port)
 Extracts information of a received RtcpCompoundPacket. More...
 
void processIncomingRTCPSenderReportPacket (const Ptr< const RtcpSenderReportPacket > &rtcpSenderReportPacket, Ipv4Address address, int port)
 
void processIncomingRTCPReceiverReportPacket (const Ptr< const RtcpReceiverReportPacket > &rtcpReceiverReportPacket, Ipv4Address address, int port)
 
void processIncomingRTCPSDESPacket (const Ptr< const RtcpSdesPacket > &rtcpSDESPacket, Ipv4Address address, int port, simtime_t arrivalTime)
 
void processIncomingRTCPByePacket (const Ptr< const RtcpByePacket > &rtcpByePacket, Ipv4Address address, int port)
 
virtual RtpParticipantInfofindParticipantInfo (uint32_t ssrc)
 Returns the RtpParticipantInfo object used for storing information about the Rtp end system with this ssrc identifier. More...
 
virtual void calculateAveragePacketSize (int size)
 Recalculates the average size of an RtcpCompoundPacket when one of this size has been sent or received. More...
 

Protected Attributes

int _mtu = 0
 The maximum size an RTCPCompundPacket can have. More...
 
int _bandwidth = 0
 The bandwidth for this Rtp session. More...
 
int _rtcpPercentage = 0
 The percentage of bandwidth for rtcp. More...
 
Ipv4Address _destinationAddress
 The destination address. More...
 
int _port = -1
 The rtcp port. More...
 
bool _ssrcChosen = false
 True when this end system has chosen its ssrc identifier. More...
 
bool _leaveSession = false
 True when this end system is about to leave the session. More...
 
RtpSenderInfo_senderInfo = nullptr
 The RtpSenderInfo about this end system. More...
 
cArray _participantInfos
 Information about all known Rtp end system participating in this Rtp session. More...
 
UdpSocket _udpSocket
 The UDP socket for sending/receiving rtcp packets. More...
 
int _packetsCalculated = 0
 The number of packets this rtcp module has calculated. More...
 
double _averagePacketSize = 0
 The average size of an RtcpCompoundPacket. More...
 

Detailed Description

The class Rtcp is responsible for creating, receiving and processing of rtcp packets.

It also keeps track of this and other Rtp end systems.

Constructor & Destructor Documentation

◆ Rtcp()

inet::rtp::Rtcp::Rtcp ( )
28 {
29 }

◆ ~Rtcp()

inet::rtp::Rtcp::~Rtcp ( )
virtual
56 {
57  if (!_ssrcChosen)
58  delete _senderInfo;
59 }

Member Function Documentation

◆ calculateAveragePacketSize()

void inet::rtp::Rtcp::calculateAveragePacketSize ( int  size)
protectedvirtual

Recalculates the average size of an RtcpCompoundPacket when one of this size has been sent or received.

503 {
504  // add size of ip and udp header to given size before calculating
505  double sumPacketSize = (double)(_packetsCalculated) * _averagePacketSize + (double)(size + 20 + 8);
506  _averagePacketSize = sumPacketSize / (double)(++_packetsCalculated);
507 }

Referenced by createPacket(), and processIncomingRTCPPacket().

◆ chooseSSRC()

void inet::rtp::Rtcp::chooseSSRC ( )
protectedvirtual

Chooses the ssrc identifier for this end system.

229 {
230  uint32_t ssrc = 0;
231  bool ssrcConflict = false;
232  do {
233  ssrc = intrand(0x7fffffff);
234  ssrcConflict = findParticipantInfo(ssrc) != nullptr;
235  } while (ssrcConflict);
236 
237  EV_INFO << "chooseSSRC" << ssrc;
238  _senderInfo->setSsrc(ssrc);
240  _ssrcChosen = true;
241 }

Referenced by handleSelfMessage().

◆ connectRet()

void inet::rtp::Rtcp::connectRet ( )
protectedvirtual

Called when the socket layer has finished a connect.

188 {
189  // schedule first rtcp packet
190  double intervalLength = 2.5 * (dblrand() + 0.5);
191  cMessage *reminderMessage = new cMessage("Interval");
192  scheduleAfter(intervalLength, reminderMessage);
193 }

Referenced by createSocket().

◆ createPacket()

void inet::rtp::Rtcp::createPacket ( )
protectedvirtual

Creates and sends an RtcpCompoundPacket.

244 {
245  // first packet in an rtcp compound packet must
246  // be a sender or receiver report
247  Ptr<RtcpReceiverReportPacket> reportPacket = nullptr;
248 
249  // if this rtcp end system is a sender (see SenderInformation::isSender() for
250  // details) insert a sender report
251  if (_senderInfo->isSender()) {
252  const auto& senderReportPacket = makeShared<RtcpSenderReportPacket>();
253  SenderReport *senderReport = _senderInfo->senderReport(simTime());
254  senderReportPacket->setSenderReport(*senderReport);
255  delete senderReport;
256  reportPacket = senderReportPacket;
257  }
258  else {
259  reportPacket = makeShared<RtcpReceiverReportPacket>();
260  }
261  reportPacket->setSsrc(_senderInfo->getSsrc());
262 
263  // insert receiver reports for packets from other sources
264  for (int i = 0; i < _participantInfos.size(); i++) {
265  if (_participantInfos.exist(i)) {
266  RtpParticipantInfo *participantInfo = check_and_cast<RtpParticipantInfo *>(_participantInfos.get(i));
267  if (participantInfo->getSsrc() != _senderInfo->getSsrc()) {
268  ReceptionReport *report = check_and_cast<RtpReceiverInfo *>(participantInfo)->receptionReport(simTime());
269  if (report != nullptr) {
270  reportPacket->addReceptionReport(report);
271  }
272  }
273  participantInfo->nextInterval(simTime());
274 
275  if (participantInfo->toBeDeleted(simTime())) {
276  _participantInfos.remove(participantInfo);
277  delete participantInfo;
278  // perhaps inform the profile
279  }
280  }
281  }
282  reportPacket->paddingAndSetLength();
283 
284  // insert source description items (at least common name)
285  const auto& sdesPacket = makeShared<RtcpSdesPacket>();
286 
287  SdesChunk *chunk = _senderInfo->getSDESChunk();
288  sdesPacket->addSDESChunk(chunk);
289  sdesPacket->paddingAndSetLength();
290 
291  Packet *compoundPacket = new Packet("RtcpCompoundPacket");
292 
293  compoundPacket->insertAtBack(reportPacket);
294  compoundPacket->insertAtBack(sdesPacket);
295 
296  // create rtcp app/bye packets if needed
297  if (_leaveSession) {
298  const auto& byePacket = makeShared<RtcpByePacket>();
299  byePacket->setSsrc(_senderInfo->getSsrc());
300  byePacket->paddingAndSetLength();
301  compoundPacket->insertAtBack(byePacket);
302  }
303 
304  calculateAveragePacketSize(compoundPacket->getByteLength());
305 
306  _udpSocket.sendTo(compoundPacket, _destinationAddress, _port);
307 
308  if (_leaveSession) {
309  RtpInnerPacket *rinp = new RtpInnerPacket("sessionLeft()");
310  rinp->setSessionLeftPkt();
311  send(rinp, "rtpOut");
312  }
313 }

Referenced by handleSelfMessage().

◆ createSocket()

void inet::rtp::Rtcp::createSocket ( )
protectedvirtual

Request a server socket from the socket layer.

202 {
203  _udpSocket.bind(_port); // TODO this will fail if this function is invoked multiple times; not sure that may (or is expected to) happen
204  MulticastGroupList mgl = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this)->collectMulticastGroups();
205  _udpSocket.joinLocalMulticastGroups(mgl); // TODO make it parameter-dependent
206  connectRet();
207 }

Referenced by handleInitializeRTCP().

◆ findParticipantInfo()

RtpParticipantInfo * inet::rtp::Rtcp::findParticipantInfo ( uint32_t  ssrc)
protectedvirtual

Returns the RtpParticipantInfo object used for storing information about the Rtp end system with this ssrc identifier.

Returns nullptr if this end system is unknown.

497 {
498  std::string ssrcString = RtpParticipantInfo::ssrcToName(ssrc);
499  return check_and_cast_nullable<RtpParticipantInfo *>(_participantInfos.get(ssrcString.c_str()));
500 }

Referenced by chooseSSRC(), processIncomingRTCPByePacket(), processIncomingRTCPReceiverReportPacket(), processIncomingRTCPSDESPacket(), processIncomingRTCPSenderReportPacket(), and processIncomingRTPPacket().

◆ handleDataIn()

void inet::rtp::Rtcp::handleDataIn ( RtpInnerPacket rinp)
protectedvirtual

Stores information about an outgoing Rtp data packet.

176 {
177  Packet *packet = check_and_cast<Packet *>(rinp->decapsulate());
178 // rtpPacket->dump();
179  processIncomingRTPPacket(packet, rinp->getAddress(), rinp->getPort());
180 }

Referenced by handleMessageFromRTP().

◆ handleDataOut()

void inet::rtp::Rtcp::handleDataOut ( RtpInnerPacket packet)
protectedvirtual

Stores information about an outgoing Rtp data packet.

170 {
171  Packet *packet = check_and_cast<Packet *>(innerPacket->decapsulate());
172  processOutgoingRTPPacket(packet);
173 }

Referenced by handleMessageFromRTP().

◆ handleInitializeRTCP()

void inet::rtp::Rtcp::handleInitializeRTCP ( RtpInnerPacket rinp)
protectedvirtual

Initializes the rtcp module when the session is started.

145 {
146  _mtu = rinp->getMtu();
147  _bandwidth = rinp->getBandwidth();
148  _rtcpPercentage = rinp->getRtcpPercentage();
149  _destinationAddress = rinp->getAddress();
150  _port = rinp->getPort();
151 
152  _senderInfo = new RtpSenderInfo();
153 
154  SdesItem *sdesItem = new SdesItem(SdesItem::SDES_CNAME, rinp->getCommonName());
155  _senderInfo->addSDESItem(sdesItem);
156 
157  // create server socket for receiving rtcp packets
158  createSocket();
159 }

Referenced by handleMessageFromRTP().

◆ handleLeaveSession()

void inet::rtp::Rtcp::handleLeaveSession ( RtpInnerPacket rinp)
protectedvirtual

Makes the rtcp module send an RtcpByePacket in the next RtcpCompoundPacket to tell other participants in the Rtp session that this end system leaves.

183 {
184  _leaveSession = true;
185 }

Referenced by handleMessageFromRTP().

◆ handleMessage()

void inet::rtp::Rtcp::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Message handling.

Dispatches messages by arrival gate.

62 {
63  // first distinguish incoming messages by arrival gate
64  if (msg->isSelfMessage()) {
65  handleSelfMessage(msg);
66  }
67  else if (msg->getArrivalGateId() == findGate("rtpIn")) {
69  }
70  else if (msg->getArrivalGateId() == findGate("udpIn")) {
72  }
73  else {
74  throw cRuntimeError("Message from unknown gate");
75  }
76 }

◆ handleMessageFromRTP()

void inet::rtp::Rtcp::handleMessageFromRTP ( cMessage *  msg)
protectedvirtual

Handles messages from the Rtp module.

83 {
84  // from the rtp module all messages are of type RtpInnerPacket
85  RtpInnerPacket *rinp = check_and_cast<RtpInnerPacket *>(msg);
86 
87  // distinguish by type
88  switch (rinp->getType()) {
91  break;
92 
95  break;
96 
97  case RTP_INP_DATA_OUT:
98  handleDataOut(rinp);
99  break;
100 
101  case RTP_INP_DATA_IN:
102  handleDataIn(rinp);
103  break;
104 
106  handleLeaveSession(rinp);
107  break;
108 
109  default:
110  throw cRuntimeError("Unknown RtpInnerPacket type");
111  }
112 
113  delete msg;
114 }

Referenced by handleMessage().

◆ handleMessageFromUDP()

void inet::rtp::Rtcp::handleMessageFromUDP ( cMessage *  msg)
protectedvirtual

Handles messages coming from the socket layer.

117 {
118  // from SocketLayer all message are of type cMessage
119  readRet(check_and_cast<Packet *>(msg));
120 }

Referenced by handleMessage().

◆ handleSelfMessage()

void inet::rtp::Rtcp::handleSelfMessage ( cMessage *  msg)
protectedvirtual

Handles self messages.

123 {
124  // it's time to create an rtcp packet
125  if (!_ssrcChosen) {
126  chooseSSRC();
127  RtpInnerPacket *rinp1 = new RtpInnerPacket("rtcpInitialized()");
128  rinp1->setRtcpInitializedPkt(_senderInfo->getSsrc());
129  send(rinp1, "rtpOut");
130  }
131 
132  createPacket();
133 
134  if (!_leaveSession) {
136  }
137  delete msg;
138 }

Referenced by handleMessage().

◆ handleSenderModuleInitialized()

void inet::rtp::Rtcp::handleSenderModuleInitialized ( RtpInnerPacket rinp)
protectedvirtual

Stores information about the new transmission.

162 {
163  _senderInfo->setStartTime(simTime());
164  _senderInfo->setClockRate(rinp->getClockRate());
165  _senderInfo->setTimeStampBase(rinp->getTimeStampBase());
166  _senderInfo->setSequenceNumberBase(rinp->getSequenceNumberBase());
167 }

Referenced by handleMessageFromRTP().

◆ initialize()

void inet::rtp::Rtcp::initialize ( int  stage)
overrideprotectedvirtual

Initializes variables.

32 {
33  cSimpleModule::initialize(stage);
34 
35  if (stage == INITSTAGE_LOCAL) {
36  // initialize variables
37  _ssrcChosen = false;
38  _leaveSession = false;
39  _udpSocket.setOutputGate(gate("udpOut"));
40 
42  _averagePacketSize = 0.0;
43 
44  _participantInfos.setName("ParticipantInfos");
45  }
46  else if (stage == INITSTAGE_TRANSPORT_LAYER) {
47  cModule *node = findContainingNode(this);
48  NodeStatus *nodeStatus = node ? check_and_cast_nullable<NodeStatus *>(node->getSubmodule("status")) : nullptr;
49  bool isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
50  if (!isOperational)
51  throw cRuntimeError("This module doesn't support starting in node DOWN state");
52  }
53 }

◆ numInitStages()

virtual int inet::rtp::Rtcp::numInitStages ( ) const
inlineoverrideprotectedvirtual
46 { return NUM_INIT_STAGES; }

◆ processIncomingRTCPByePacket()

void inet::rtp::Rtcp::processIncomingRTCPByePacket ( const Ptr< const RtcpByePacket > &  rtcpByePacket,
Ipv4Address  address,
int  port 
)
protected
482 {
483  uint32_t ssrc = rtcpByePacket->getSsrc();
484  RtpParticipantInfo *participantInfo = findParticipantInfo(ssrc);
485 
486  if (participantInfo != nullptr && participantInfo != _senderInfo) {
487  _participantInfos.remove(participantInfo);
488 
489  delete participantInfo;
490  // perhaps it would be useful to inform
491  // the profile to remove the corresponding
492  // receiver module
493  }
494 }

Referenced by processIncomingRTCPPacket().

◆ processIncomingRTCPPacket()

void inet::rtp::Rtcp::processIncomingRTCPPacket ( Packet packet,
Ipv4Address  address,
int  port 
)
protectedvirtual

Extracts information of a received RtcpCompoundPacket.

355 {
356  calculateAveragePacketSize(packet->getByteLength());
357  simtime_t arrivalTime = packet->getArrivalTime();
358 
359  for (int i = 0; packet->getByteLength() > 0; i++) {
360  // remove the rtcp packet from the rtcp compound packet
361  const auto& rtcpPacket = packet->popAtFront<RtcpPacket>();
362  if (rtcpPacket) {
363  switch (rtcpPacket->getPacketType()) {
364  case RTCP_PT_SR:
365  processIncomingRTCPSenderReportPacket(CHK(dynamicPtrCast<const RtcpSenderReportPacket>(rtcpPacket)), address, port);
366  break;
367 
368  case RTCP_PT_RR:
369  processIncomingRTCPReceiverReportPacket(CHK(dynamicPtrCast<const RtcpReceiverReportPacket>(rtcpPacket)), address, port);
370  break;
371 
372  case RTCP_PT_SDES:
373  processIncomingRTCPSDESPacket(CHK(dynamicPtrCast<const RtcpSdesPacket>(rtcpPacket)), address, port, arrivalTime);
374  break;
375 
376  case RTCP_PT_BYE:
377  processIncomingRTCPByePacket(CHK(dynamicPtrCast<const RtcpByePacket>(rtcpPacket)), address, port);
378  break;
379 
380  default:
381  throw cRuntimeError("unknown Rtcp packet type");
382  break;
383  }
384  }
385  }
386  delete packet;
387 }

Referenced by readRet().

◆ processIncomingRTCPReceiverReportPacket()

void inet::rtp::Rtcp::processIncomingRTCPReceiverReportPacket ( const Ptr< const RtcpReceiverReportPacket > &  rtcpReceiverReportPacket,
Ipv4Address  address,
int  port 
)
protected
424 {
425  uint32_t ssrc = rtcpReceiverReportPacket->getSsrc();
426  RtpParticipantInfo *participantInfo = findParticipantInfo(ssrc);
427  if (participantInfo == nullptr) {
428  participantInfo = new RtpReceiverInfo(ssrc);
429  participantInfo->setAddress(address);
430  participantInfo->setRTCPPort(port);
431  _participantInfos.add(participantInfo);
432  }
433  else {
434  if ((participantInfo->getAddress() == address) &&
435  (participantInfo->getRTCPPort() == PORT_UNDEF))
436  {
437  participantInfo->setRTCPPort(port);
438  }
439  else {
440  // check for ssrc conflict
441  }
442  }
443 
444  const cArray& receptionReports = rtcpReceiverReportPacket->getReceptionReports();
445  for (int j = 0; j < receptionReports.size(); j++) {
446  if (receptionReports.exist(j)) {
447  const ReceptionReport *receptionReport = check_and_cast<const ReceptionReport *>(receptionReports.get(j));
448  if (_senderInfo && (receptionReport->getSsrc() == _senderInfo->getSsrc())) {
449  _senderInfo->processReceptionReport(receptionReport, simTime());
450  }
451  }
452  }
453 }

Referenced by processIncomingRTCPPacket().

◆ processIncomingRTCPSDESPacket()

void inet::rtp::Rtcp::processIncomingRTCPSDESPacket ( const Ptr< const RtcpSdesPacket > &  rtcpSDESPacket,
Ipv4Address  address,
int  port,
simtime_t  arrivalTime 
)
protected
456 {
457  const cArray& sdesChunks = rtcpSDESPacket->getSdesChunks();
458 
459  for (int j = 0; j < sdesChunks.size(); j++) {
460  if (sdesChunks.exist(j)) {
461  // remove the sdes chunk from the cArray of sdes chunks
462  const SdesChunk *sdesChunk = check_and_cast<const SdesChunk *>(sdesChunks.get(j));
463  // this is needed to avoid seg faults
464 // sdesChunk->setOwner(this);
465  uint32_t ssrc = sdesChunk->getSsrc();
466  RtpParticipantInfo *participantInfo = findParticipantInfo(ssrc);
467  if (participantInfo == nullptr) {
468  participantInfo = new RtpReceiverInfo(ssrc);
469  participantInfo->setAddress(address);
470  participantInfo->setRTCPPort(port);
471  _participantInfos.add(participantInfo);
472  }
473  else {
474  // check for ssrc conflict
475  }
476  participantInfo->processSDESChunk(sdesChunk, arrivalTime);
477  }
478  }
479 }

Referenced by processIncomingRTCPPacket().

◆ processIncomingRTCPSenderReportPacket()

void inet::rtp::Rtcp::processIncomingRTCPSenderReportPacket ( const Ptr< const RtcpSenderReportPacket > &  rtcpSenderReportPacket,
Ipv4Address  address,
int  port 
)
protected
390 {
391  uint32_t ssrc = rtcpSenderReportPacket->getSsrc();
392  RtpParticipantInfo *participantInfo = findParticipantInfo(ssrc);
393 
394  if (participantInfo == nullptr) {
395  participantInfo = new RtpReceiverInfo(ssrc);
396  participantInfo->setAddress(address);
397  participantInfo->setRTCPPort(port);
398  _participantInfos.add(participantInfo);
399  }
400  else {
401  if ((participantInfo->getAddress() == address) &&
402  (participantInfo->getRTCPPort() == PORT_UNDEF))
403  {
404  participantInfo->setRTCPPort(port);
405  }
406  else {
407  // check for ssrc conflict
408  }
409  }
410  participantInfo->processSenderReport(rtcpSenderReportPacket->getSenderReport(), simTime());
411 
412  const cArray& receptionReports = rtcpSenderReportPacket->getReceptionReports();
413  for (int j = 0; j < receptionReports.size(); j++) {
414  if (receptionReports.exist(j)) {
415  const ReceptionReport *receptionReport = check_and_cast<const ReceptionReport *>(receptionReports.get(j));
416  if (_senderInfo && (receptionReport->getSsrc() == _senderInfo->getSsrc())) {
417  _senderInfo->processReceptionReport(receptionReport, simTime());
418  }
419  }
420  }
421 }

Referenced by processIncomingRTCPPacket().

◆ processIncomingRTPPacket()

void inet::rtp::Rtcp::processIncomingRTPPacket ( Packet packet,
Ipv4Address  address,
int  port 
)
protectedvirtual

Extracts information of a received RtpPacket.

321 {
322  bool good = false;
323  const auto& rtpHeader = packet->peekAtFront<RtpHeader>();
324  uint32_t ssrc = rtpHeader->getSsrc();
325  RtpParticipantInfo *participantInfo = findParticipantInfo(ssrc);
326  if (participantInfo == nullptr) {
327  participantInfo = new RtpParticipantInfo(ssrc);
328  participantInfo->setAddress(address);
329  participantInfo->setRTPPort(port);
330  _participantInfos.add(participantInfo);
331  good = true;
332  }
333  else {
334  // check for ssrc conflict
335  if (participantInfo->getAddress() == address) {
336  if (participantInfo->getRTPPort() == port) {
337  good = true;
338  }
339  else if (participantInfo->getRTPPort() == PORT_UNDEF) {
340  participantInfo->setRTPPort(port);
341  good = true;
342  }
343  }
344  }
345  if (good) {
346  participantInfo->processRTPPacket(packet, getId(), packet->getArrivalTime());
347  }
348  else {
349  EV_INFO << "Incoming packet address/port conflict, packet dropped.\n";
350  delete packet;
351  }
352 }

Referenced by handleDataIn().

◆ processOutgoingRTPPacket()

void inet::rtp::Rtcp::processOutgoingRTPPacket ( Packet packet)
protectedvirtual

Extracts information of a sent RtpPacket.

316 {
317  _senderInfo->processRTPPacket(packet, getId(), simTime());
318 }

Referenced by handleDataOut().

◆ readRet()

void inet::rtp::Rtcp::readRet ( Packet sifpIn)
protectedvirtual

Called when this rtcp module receives data from the socket layer.

196 {
197  emit(packetReceivedSignal, sifpIn);
198  processIncomingRTCPPacket(sifpIn, Ipv4Address(_destinationAddress), _port);
199 }

Referenced by handleMessageFromUDP().

◆ scheduleInterval()

void inet::rtp::Rtcp::scheduleInterval ( )
protectedvirtual

Calculates the length of the next rtcp interval an issues a self message to remind itself.

210 {
211  simtime_t intervalLength = _averagePacketSize * (simtime_t)(_participantInfos.size())
212  / (simtime_t)(_bandwidth * _rtcpPercentage * (_senderInfo->isSender() ? 1.0 : 0.75) / 100.0);
213 
214  // interval length must be at least 5 seconds
215  if (intervalLength < 5.0)
216  intervalLength = 5.0;
217 
218  // to avoid rtcp packet bursts multiply calculated interval length
219  // with a random number between 0.5 and 1.5
220  intervalLength = intervalLength * (0.5 + dblrand());
221 
222  intervalLength /= (double)(2.71828 - 1.5); // [RFC 3550] , by Ahmed ayadi
223 
224  cMessage *reminderMessage = new cMessage("Interval");
225  scheduleAfter(intervalLength, reminderMessage);
226 }

Referenced by handleSelfMessage().

Member Data Documentation

◆ _averagePacketSize

double inet::rtp::Rtcp::_averagePacketSize = 0
protected

The average size of an RtcpCompoundPacket.

Referenced by calculateAveragePacketSize(), initialize(), and scheduleInterval().

◆ _bandwidth

int inet::rtp::Rtcp::_bandwidth = 0
protected

The bandwidth for this Rtp session.

Referenced by handleInitializeRTCP(), and scheduleInterval().

◆ _destinationAddress

Ipv4Address inet::rtp::Rtcp::_destinationAddress
protected

The destination address.

Referenced by createPacket(), handleInitializeRTCP(), and readRet().

◆ _leaveSession

bool inet::rtp::Rtcp::_leaveSession = false
protected

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

Referenced by createPacket(), handleLeaveSession(), handleSelfMessage(), and initialize().

◆ _mtu

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

The maximum size an RTCPCompundPacket can have.

Referenced by handleInitializeRTCP().

◆ _packetsCalculated

int inet::rtp::Rtcp::_packetsCalculated = 0
protected

The number of packets this rtcp module has calculated.

Referenced by calculateAveragePacketSize(), and initialize().

◆ _participantInfos

◆ _port

int inet::rtp::Rtcp::_port = -1
protected

The rtcp port.

Referenced by createPacket(), createSocket(), handleInitializeRTCP(), and readRet().

◆ _rtcpPercentage

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

The percentage of bandwidth for rtcp.

Referenced by handleInitializeRTCP(), and scheduleInterval().

◆ _senderInfo

◆ _ssrcChosen

bool inet::rtp::Rtcp::_ssrcChosen = false
protected

True when this end system has chosen its ssrc identifier.

Referenced by chooseSSRC(), handleSelfMessage(), initialize(), and ~Rtcp().

◆ _udpSocket

UdpSocket inet::rtp::Rtcp::_udpSocket
protected

The UDP socket for sending/receiving rtcp packets.

Referenced by createPacket(), createSocket(), and initialize().


The documentation for this class was generated from the following files:
inet::UdpSocket::setOutputGate
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UdpSocket.h:117
CHK
#define CHK(x)
Definition: INETDefs.h:87
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::rtp::RTCP_PT_RR
@ RTCP_PT_RR
Definition: RtcpPacket_m.h:85
inet::rtp::RtpParticipantInfo::getSDESChunk
virtual SdesChunk * getSDESChunk() const
Returns a copy of the sdes chunk used for storing source description items about this system.
Definition: RtpParticipantInfo.cc:87
inet::rtp::Rtcp::findParticipantInfo
virtual RtpParticipantInfo * findParticipantInfo(uint32_t ssrc)
Returns the RtpParticipantInfo object used for storing information about the Rtp end system with this...
Definition: Rtcp.cc:496
inet::UdpSocket::bind
void bind(int localPort)
Bind the socket to a local port number.
Definition: UdpSocket.cc:34
inet::UdpSocket::sendTo
void sendTo(Packet *msg, L3Address destAddr, int destPort)
Sends a data packet to the given address and port.
Definition: UdpSocket.cc:69
inet::rtp::Rtcp::processIncomingRTCPSDESPacket
void processIncomingRTCPSDESPacket(const Ptr< const RtcpSdesPacket > &rtcpSDESPacket, Ipv4Address address, int port, simtime_t arrivalTime)
Definition: Rtcp.cc:455
inet::PORT_UNDEF
const short PORT_UNDEF
TCP/UDP port numbers.
Definition: Ipv4Address.h:28
inet::rtp::Rtcp::_destinationAddress
Ipv4Address _destinationAddress
The destination address.
Definition: Rtcp.h:178
inet::rtp::Rtcp::_averagePacketSize
double _averagePacketSize
The average size of an RtcpCompoundPacket.
Definition: Rtcp.h:220
inet::rtp::Rtcp::_rtcpPercentage
int _rtcpPercentage
The percentage of bandwidth for rtcp.
Definition: Rtcp.h:173
inet::rtp::Rtcp::processIncomingRTCPPacket
virtual void processIncomingRTCPPacket(Packet *packet, Ipv4Address address, int port)
Extracts information of a received RtcpCompoundPacket.
Definition: Rtcp.cc:354
inet::rtp::RtpSenderInfo::setTimeStampBase
virtual void setTimeStampBase(uint32_t timeStampBase)
Sets the initial rtp time stamp.
Definition: RtpSenderInfo.cc:107
inet::rtp::Rtcp::_bandwidth
int _bandwidth
The bandwidth for this Rtp session.
Definition: Rtcp.h:168
inet::rtp::RTP_INP_INITIALIZE_RTCP
@ RTP_INP_INITIALIZE_RTCP
Definition: RtpInnerPacket_m.h:89
inet::rtp::Rtcp::_packetsCalculated
int _packetsCalculated
The number of packets this rtcp module has calculated.
Definition: Rtcp.h:215
inet::rtp::RTP_INP_DATA_IN
@ RTP_INP_DATA_IN
Definition: RtpInnerPacket_m.h:102
inet::rtp::Rtcp::_ssrcChosen
bool _ssrcChosen
True when this end system has chosen its ssrc identifier.
Definition: Rtcp.h:188
inet::rtp::RTCP_PT_BYE
@ RTCP_PT_BYE
Definition: RtcpPacket_m.h:87
inet::rtp::Rtcp::processIncomingRTCPReceiverReportPacket
void processIncomingRTCPReceiverReportPacket(const Ptr< const RtcpReceiverReportPacket > &rtcpReceiverReportPacket, Ipv4Address address, int port)
Definition: Rtcp.cc:423
inet::rtp::RTP_INP_SENDER_MODULE_INITIALIZED
@ RTP_INP_SENDER_MODULE_INITIALIZED
Definition: RtpInnerPacket_m.h:96
inet::rtp::Rtcp::processIncomingRTCPSenderReportPacket
void processIncomingRTCPSenderReportPacket(const Ptr< const RtcpSenderReportPacket > &rtcpSenderReportPacket, Ipv4Address address, int port)
Definition: Rtcp.cc:389
inet::rtp::Rtcp::createPacket
virtual void createPacket()
Creates and sends an RtcpCompoundPacket.
Definition: Rtcp.cc:243
inet::rtp::RtpSenderInfo::setStartTime
virtual void setStartTime(simtime_t startTime)
Sets the time (simTime) when this endsystem has started sending rtp packets.
Definition: RtpSenderInfo.cc:97
inet::rtp::Rtcp::processIncomingRTPPacket
virtual void processIncomingRTPPacket(Packet *packet, Ipv4Address address, int port)
Extracts information of a received RtpPacket.
Definition: Rtcp.cc:320
inet::rtp::SdesItem::SDES_CNAME
@ SDES_CNAME
Definition: Sdes.h:31
inet::rtp::RtpSenderInfo::senderReport
virtual SenderReport * senderReport(simtime_t now) override
Returns a SenderReport for this rtp endsystem.
Definition: RtpSenderInfo.cc:77
inet::rtp::Rtcp::handleDataOut
virtual void handleDataOut(RtpInnerPacket *packet)
Stores information about an outgoing Rtp data packet.
Definition: Rtcp.cc:169
inet::rtp::Rtcp::readRet
virtual void readRet(Packet *sifpIn)
Called when this rtcp module receives data from the socket layer.
Definition: Rtcp.cc:195
inet::rtp::RTP_INP_DATA_OUT
@ RTP_INP_DATA_OUT
Definition: RtpInnerPacket_m.h:101
inet::rtp::Rtcp::connectRet
virtual void connectRet()
Called when the socket layer has finished a connect.
Definition: Rtcp.cc:187
inet::rtp::Rtcp::createSocket
virtual void createSocket()
Request a server socket from the socket layer.
Definition: Rtcp.cc:201
inet::packetReceivedSignal
simsignal_t packetReceivedSignal
Definition: Simsignals.cc:97
inet::rtp::Rtcp::chooseSSRC
virtual void chooseSSRC()
Chooses the ssrc identifier for this end system.
Definition: Rtcp.cc:228
inet::UdpSocket::joinLocalMulticastGroups
void joinLocalMulticastGroups(MulticastGroupList mgl)
Joins the socket to each multicast group that are registered with any of the interfaces.
Definition: UdpSocket.cc:265
inet::rtp::RtpParticipantInfo::addSDESItem
virtual void addSDESItem(SdesItem *sdesItem)
Adds this sdes item to the sdes chunk of this participant.
Definition: RtpParticipantInfo.cc:92
inet::rtp::RTCP_PT_SR
@ RTCP_PT_SR
Definition: RtcpPacket_m.h:84
inet::rtp::RtpSenderInfo::processRTPPacket
virtual void processRTPPacket(Packet *packet, int id, simtime_t arrivalTime) override
Stores information about this outgoing RtpPacket.
Definition: RtpSenderInfo.cc:61
inet::INITSTAGE_TRANSPORT_LAYER
INET_API InitStage INITSTAGE_TRANSPORT_LAYER
Initialization of transport-layer protocols.
inet::rtp::Rtcp::handleSelfMessage
virtual void handleSelfMessage(cMessage *msg)
Handles self messages.
Definition: Rtcp.cc:122
inet::MulticastGroupList
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:26
inet::rtp::Rtcp::processIncomingRTCPByePacket
void processIncomingRTCPByePacket(const Ptr< const RtcpByePacket > &rtcpByePacket, Ipv4Address address, int port)
Definition: Rtcp.cc:481
inet::rtp::Rtcp::_port
int _port
The rtcp port.
Definition: Rtcp.h:183
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::rtp::RtpParticipantInfo::getSsrc
virtual uint32_t getSsrc() const override
Returns the ssrc identifier of the RTP endsystem.
Definition: RtpParticipantInfo.cc:122
inet::rtp::Rtcp::handleInitializeRTCP
virtual void handleInitializeRTCP(RtpInnerPacket *rinp)
Initializes the rtcp module when the session is started.
Definition: Rtcp.cc:144
inet::rtp::Rtcp::handleDataIn
virtual void handleDataIn(RtpInnerPacket *rinp)
Stores information about an outgoing Rtp data packet.
Definition: Rtcp.cc:175
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::rtp::RtpSenderInfo::setClockRate
virtual void setClockRate(int clockRate)
Sets the clock rate (in ticks per second) this sender increases the rtp time stamp.
Definition: RtpSenderInfo.cc:102
inet::rtp::Rtcp::handleMessageFromUDP
virtual void handleMessageFromUDP(cMessage *msg)
Handles messages coming from the socket layer.
Definition: Rtcp.cc:116
inet::rtp::Rtcp::_participantInfos
cArray _participantInfos
Information about all known Rtp end system participating in this Rtp session.
Definition: Rtcp.h:204
inet::rtp::Rtcp::processOutgoingRTPPacket
virtual void processOutgoingRTPPacket(Packet *packet)
Extracts information of a sent RtpPacket.
Definition: Rtcp.cc:315
inet::NodeStatus::UP
@ UP
Definition: NodeStatus.h:28
inet::rtp::RTP_INP_LEAVE_SESSION
@ RTP_INP_LEAVE_SESSION
Definition: RtpInnerPacket_m.h:99
inet::rtp::Rtcp::_udpSocket
UdpSocket _udpSocket
The UDP socket for sending/receiving rtcp packets.
Definition: Rtcp.h:209
inet::rtp::Rtcp::handleLeaveSession
virtual void handleLeaveSession(RtpInnerPacket *rinp)
Makes the rtcp module send an RtcpByePacket in the next RtcpCompoundPacket to tell other participants...
Definition: Rtcp.cc:182
inet::rtp::Rtcp::calculateAveragePacketSize
virtual void calculateAveragePacketSize(int size)
Recalculates the average size of an RtcpCompoundPacket when one of this size has been sent or receive...
Definition: Rtcp.cc:502
inet::rtp::Rtcp::_leaveSession
bool _leaveSession
True when this end system is about to leave the session.
Definition: Rtcp.h:193
inet::rtp::RtpParticipantInfo::ssrcToName
static std::string ssrcToName(uint32_t ssrc)
This method returns the given 32 bit ssrc identifier as an 8 character hexadecimal number which is us...
Definition: RtpParticipantInfo.cc:137
inet::rtp::RtpSenderInfo::processReceptionReport
virtual void processReceptionReport(const ReceptionReport *report, simtime_t arrivalTime)
Processes an incoming ReceptionReport for this sender.
Definition: RtpSenderInfo.cc:73
inet::rtp::RtpParticipantInfo::setSsrc
virtual void setSsrc(uint32_t ssrc) override
Sets the ssrc identifier.
Definition: RtpParticipantInfo.cc:127
inet::rtp::RTCP_PT_SDES
@ RTCP_PT_SDES
Definition: RtcpPacket_m.h:86
inet::rtp::Rtcp::handleSenderModuleInitialized
virtual void handleSenderModuleInitialized(RtpInnerPacket *rinp)
Stores information about the new transmission.
Definition: Rtcp.cc:161
inet::rtp::Rtcp::handleMessageFromRTP
virtual void handleMessageFromRTP(cMessage *msg)
Handles messages from the Rtp module.
Definition: Rtcp.cc:82
inet::rtp::Rtcp::scheduleInterval
virtual void scheduleInterval()
Calculates the length of the next rtcp interval an issues a self message to remind itself.
Definition: Rtcp.cc:209
inet::rtp::Rtcp::_mtu
int _mtu
The maximum size an RTCPCompundPacket can have.
Definition: Rtcp.h:163
inet::rtp::RtpParticipantInfo::isSender
virtual bool isSender() const
Returns true if this endsystem has sent at least one RTP data packet during the last two rtcp interva...
Definition: RtpParticipantInfo.cc:97
inet::rtp::RtpSenderInfo::setSequenceNumberBase
virtual void setSequenceNumberBase(uint16_t sequenceNumberBase)
Sets the initial sequence number.
Definition: RtpSenderInfo.cc:112
inet::rtp::Rtcp::_senderInfo
RtpSenderInfo * _senderInfo
The RtpSenderInfo about this end system.
Definition: Rtcp.h:198