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

The class RtpPayloadSender is the base class for all modules creating RTP data packets. More...

#include <RtpPayloadSender.h>

Inheritance diagram for inet::rtp::RtpPayloadSender:
inet::rtp::RtpAvProfilePayload32Sender

Public Member Functions

 RtpPayloadSender ()
 Constructor. More...
 
virtual ~RtpPayloadSender ()
 Destructor. More...
 

Protected Types

enum  SenderStatus { STOPPED, PLAYING }
 A sender module's transmission can be in different states. More...
 

Protected Member Functions

virtual void initialize () override
 Chooses sequence number and time stamp base values and reads the omnet parameter "mtu". More...
 
virtual void handleMessage (cMessage *msg) override
 
virtual void initializeSenderModule (RtpInnerPacket *)
 This method is called when a newly create sender module received its initialization message from profile module. More...
 
virtual void openSourceFile (const char *fileName)
 This method is called by initializeSenderModule and opens the source data file as an inputFileStream stored in member variable _inputFileStream. More...
 
virtual void closeSourceFile ()
 This method is called by the destructor and closes the data file. More...
 
virtual void play ()
 Starts data transmission. More...
 
virtual void playUntilTime (simtime_t moment)
 Starts transmission from the current file position and plays until given time (relative to start of file) is reached. More...
 
virtual void playUntilByte (int position)
 Starts transmission from the current file position and plays until given byte position (excluding file header) is reached. More...
 
virtual void pause ()
 When data is being transmitted this methods suspends till a new PLAY command. More...
 
virtual void seekTime (simtime_t moment)
 When the data transmission is paused the current position is changed to this time (relative to start of file). More...
 
virtual void seekByte (int position)
 When the data transmission is paused the current position is changed to this byte position (excluding file header). More...
 
virtual void stop ()
 This method stop data transmission and resets the sender module so that a following PLAY command would start the transmission at the beginning again. More...
 
virtual void endOfFile ()
 This method gets called when the sender module reaches the end of file. More...
 
virtual bool sendPacket ()
 This method gets called when one (or more) rtp data packets have to be sent. More...
 

Protected Attributes

std::ifstream _inputFileStream
 The input file stream for the data file. More...
 
int _mtu = 0
 The maximum size of an RtpPacket. More...
 
uint32_t _ssrc = 0
 The ssrc identifier of this sender module. More...
 
int _payloadType = -1
 The payload type this sender creates. More...
 
int _clockRate = 0
 The clock rate in ticks per second this sender uses. More...
 
uint32_t _timeStampBase = 0
 The first rtp time stamp used for created rtp data packets. More...
 
uint32_t _timeStamp = 0
 The current rtp time stamp. More...
 
uint16_t _sequenceNumberBase = 0
 The first sequence number used for created rtp data packets. More...
 
uint16_t _sequenceNumber = 0
 The current sequence number. More...
 
SenderStatus _status = static_cast<SenderStatus>(-1)
 The current state of data transmission. More...
 
cMessage * _reminderMessage = nullptr
 A self message used as timer for the moment the next packet must be sent. More...
 

Detailed Description

The class RtpPayloadSender is the base class for all modules creating RTP data packets.

It provides functionality needed by every RTP data packet sender like opening and closing the data file and choosing sequence number and time stamp start values.

Member Enumeration Documentation

◆ SenderStatus

A sender module's transmission can be in different states.

Enumerator
STOPPED 
PLAYING 

Data is being sent.

52  {
53  STOPPED, // < No transmission.
54  PLAYING
55  };

Constructor & Destructor Documentation

◆ RtpPayloadSender()

inet::rtp::RtpPayloadSender::RtpPayloadSender ( )

Constructor.

19 {
20 }

◆ ~RtpPayloadSender()

inet::rtp::RtpPayloadSender::~RtpPayloadSender ( )
virtual

Destructor.

Calls closeSourceFile.

23 {
25  cancelAndDelete(_reminderMessage);
26 }

Member Function Documentation

◆ closeSourceFile()

void inet::rtp::RtpPayloadSender::closeSourceFile ( )
protectedvirtual

This method is called by the destructor and closes the data file.

123 {
124  _inputFileStream.close();
125 }

Referenced by ~RtpPayloadSender().

◆ endOfFile()

void inet::rtp::RtpPayloadSender::endOfFile ( )
protectedvirtual

This method gets called when the sender module reaches the end of file.

For the transmission it has the same effect like stop().

187 {
188  _status = STOPPED;
189  RtpSenderStatusMessage *rssm = new RtpSenderStatusMessage("FINISHED");
190  rssm->setStatus(RTP_SENDER_STATUS_FINISHED);
191  RtpInnerPacket *rinpOut = new RtpInnerPacket("senderModuleStatus(FINISHED)");
192  rinpOut->setSenderModuleStatusPkt(_ssrc, rssm);
193  send(rinpOut, "profileOut");
194 }

Referenced by handleMessage(), and play().

◆ handleMessage()

void inet::rtp::RtpPayloadSender::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
43 {
44  if (msg == _reminderMessage) {
45  delete msg;
46  _reminderMessage = nullptr;
47  if (!sendPacket()) {
48  endOfFile();
49  }
50  }
51  else if (msg->getArrivalGateId() == findGate("profileIn")) {
52  RtpInnerPacket *rinpIn = check_and_cast<RtpInnerPacket *>(msg);
53  if (rinpIn->getType() == RTP_INP_INITIALIZE_SENDER_MODULE) {
54  initializeSenderModule(rinpIn);
55  }
56  else if (rinpIn->getType() == RTP_INP_SENDER_MODULE_CONTROL) {
57  RtpSenderControlMessage *rscm = check_and_cast<RtpSenderControlMessage *>(rinpIn->decapsulate());
58  delete rinpIn;
59  switch (rscm->getCommand()) {
60  case RTP_CONTROL_PLAY:
61  play();
62  break;
63 
65  playUntilTime(rscm->getCommandParameter1());
66  break;
67 
69  playUntilByte(rscm->getCommandParameter1());
70  break;
71 
72  case RTP_CONTROL_PAUSE:
73  pause();
74  break;
75 
76  case RTP_CONTROL_STOP:
77  stop();
78  break;
79 
81  seekTime(rscm->getCommandParameter1());
82  break;
83 
85  seekByte(rscm->getCommandParameter1());
86  break;
87 
88  default:
89  throw cRuntimeError("unknown sender control message");
90  break;
91  }
92  delete rscm;
93  }
94  }
95  else {
96  throw cRuntimeError("Unknown message!");
97  }
98 }

◆ initialize()

void inet::rtp::RtpPayloadSender::initialize ( )
overrideprotectedvirtual

Chooses sequence number and time stamp base values and reads the omnet parameter "mtu".

Reimplemented in inet::rtp::RtpAvProfilePayload32Sender.

29 {
30  cSimpleModule::initialize();
31  _mtu = 0;
32  _ssrc = 0;
33  _payloadType = 0;
34  _clockRate = 0;
35  _timeStampBase = intrand(65535);
37  _sequenceNumberBase = intrand(0x7fffffff);
39  _reminderMessage = nullptr;
40 }

◆ initializeSenderModule()

void inet::rtp::RtpPayloadSender::initializeSenderModule ( RtpInnerPacket rinpIn)
protectedvirtual

This method is called when a newly create sender module received its initialization message from profile module.

It returns an RTP_INP_SENDER_MODULE_INITIALIZED message which

Reimplemented in inet::rtp::RtpAvProfilePayload32Sender.

101 {
102  EV_TRACE << "initializeSenderModule Enter" << endl;
103  _mtu = rinpIn->getMtu();
104  _ssrc = rinpIn->getSsrc();
105  const char *fileName = rinpIn->getFileName();
106  openSourceFile(fileName);
107  delete rinpIn;
108  RtpInnerPacket *rinpOut = new RtpInnerPacket("senderModuleInitialized()");
109  rinpOut->setSenderModuleInitializedPkt(_ssrc, _payloadType, _clockRate, _timeStampBase, _sequenceNumberBase);
110  send(rinpOut, "profileOut");
111  _status = STOPPED;
112  EV_TRACE << "initializeSenderModule Exit" << endl;
113 }

Referenced by handleMessage().

◆ openSourceFile()

void inet::rtp::RtpPayloadSender::openSourceFile ( const char *  fileName)
protectedvirtual

This method is called by initializeSenderModule and opens the source data file as an inputFileStream stored in member variable _inputFileStream.

Most data formats can use this method directly, but when using a library for a certain data format which offers an own open routine this method must be overwritten.

116 {
117  _inputFileStream.open(fileName);
118  if (!_inputFileStream)
119  throw cRuntimeError("Error opening data file '%s'", fileName);
120 }

Referenced by initializeSenderModule().

◆ pause()

void inet::rtp::RtpPayloadSender::pause ( )
protectedvirtual

When data is being transmitted this methods suspends till a new PLAY command.

Implementation in sender modules is optional.

153 {
154  cancelAndDelete(_reminderMessage);
155  _reminderMessage = nullptr;
156  _status = STOPPED;
157  RtpInnerPacket *rinpOut = new RtpInnerPacket("senderModuleStatus(PAUSED)");
158  RtpSenderStatusMessage *rsim = new RtpSenderStatusMessage();
159  rsim->setStatus(RTP_SENDER_STATUS_PAUSED);
160  rinpOut->setSenderModuleStatusPkt(_ssrc, rsim);
161  send(rinpOut, "profileOut");
162 }

Referenced by handleMessage().

◆ play()

void inet::rtp::RtpPayloadSender::play ( )
protectedvirtual

Starts data transmission.

Every sender module must implement this method.

128 {
129  _status = PLAYING;
130  RtpSenderStatusMessage *rssm = new RtpSenderStatusMessage("PLAYING");
131  rssm->setStatus(RTP_SENDER_STATUS_PLAYING);
132  rssm->setTimeStamp(_timeStamp);
133  RtpInnerPacket *rinpOut = new RtpInnerPacket("senderModuleStatus(PLAYING)");
134  rinpOut->setSenderModuleStatusPkt(_ssrc, rssm);
135  send(rinpOut, "profileOut");
136 
137  if (!sendPacket()) {
138  endOfFile();
139  }
140 }

Referenced by handleMessage().

◆ playUntilByte()

void inet::rtp::RtpPayloadSender::playUntilByte ( int  position)
protectedvirtual

Starts transmission from the current file position and plays until given byte position (excluding file header) is reached.

Implementation in sender modules is optional.

148 {
149  throw cRuntimeError("playUntilByte() not implemented");
150 }

Referenced by handleMessage().

◆ playUntilTime()

void inet::rtp::RtpPayloadSender::playUntilTime ( simtime_t  moment)
protectedvirtual

Starts transmission from the current file position and plays until given time (relative to start of file) is reached.

Implementation in sender modules is optional.

143 {
144  throw cRuntimeError("playUntilTime() not implemented");
145 }

Referenced by handleMessage().

◆ seekByte()

void inet::rtp::RtpPayloadSender::seekByte ( int  position)
protectedvirtual

When the data transmission is paused the current position is changed to this byte position (excluding file header).

Implementation in sender modules is optional.

170 {
171  throw cRuntimeError("seekByte() not implemented");
172 }

Referenced by handleMessage().

◆ seekTime()

void inet::rtp::RtpPayloadSender::seekTime ( simtime_t  moment)
protectedvirtual

When the data transmission is paused the current position is changed to this time (relative to start of file).

Implementation in sender modules is optional.

165 {
166  throw cRuntimeError("seekTime() not implemented");
167 }

Referenced by handleMessage().

◆ sendPacket()

bool inet::rtp::RtpPayloadSender::sendPacket ( )
protectedvirtual

This method gets called when one (or more) rtp data packets have to be sent.

Subclasses must overwrite this method to do something useful. This implementation doesn't send packets it just returns

Reimplemented in inet::rtp::RtpAvProfilePayload32Sender.

197 {
198  throw cRuntimeError("sendPacket() not implemented");
199  return false;
200 }

Referenced by handleMessage(), and play().

◆ stop()

void inet::rtp::RtpPayloadSender::stop ( )
protectedvirtual

This method stop data transmission and resets the sender module so that a following PLAY command would start the transmission at the beginning again.

175 {
176  cancelAndDelete(_reminderMessage);
177  _reminderMessage = nullptr;
178  _status = STOPPED;
179  RtpSenderStatusMessage *rssm = new RtpSenderStatusMessage("STOPPED");
180  rssm->setStatus(RTP_SENDER_STATUS_STOPPED);
181  RtpInnerPacket *rinp = new RtpInnerPacket("senderModuleStatus(STOPPED)");
182  rinp->setSenderModuleStatusPkt(_ssrc, rssm);
183  send(rinp, "profileOut");
184 }

Referenced by handleMessage().

Member Data Documentation

◆ _clockRate

int inet::rtp::RtpPayloadSender::_clockRate = 0
protected

The clock rate in ticks per second this sender uses.

Referenced by initialize(), and initializeSenderModule().

◆ _inputFileStream

std::ifstream inet::rtp::RtpPayloadSender::_inputFileStream
protected

The input file stream for the data file.

Referenced by closeSourceFile(), and openSourceFile().

◆ _mtu

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

The maximum size of an RtpPacket.

Referenced by initialize(), and initializeSenderModule().

◆ _payloadType

int inet::rtp::RtpPayloadSender::_payloadType = -1
protected

The payload type this sender creates.

Referenced by initialize(), and initializeSenderModule().

◆ _reminderMessage

cMessage* inet::rtp::RtpPayloadSender::_reminderMessage = nullptr
protected

A self message used as timer for the moment the next packet must be sent.

It's a member variable because when playing gets paused or stopped the timer must be cancelled.

Referenced by handleMessage(), initialize(), pause(), stop(), and ~RtpPayloadSender().

◆ _sequenceNumber

uint16_t inet::rtp::RtpPayloadSender::_sequenceNumber = 0
protected

The current sequence number.

Referenced by initialize().

◆ _sequenceNumberBase

uint16_t inet::rtp::RtpPayloadSender::_sequenceNumberBase = 0
protected

The first sequence number used for created rtp data packets.

The value is chosen randomly.

Referenced by initialize(), and initializeSenderModule().

◆ _ssrc

uint32_t inet::rtp::RtpPayloadSender::_ssrc = 0
protected

The ssrc identifier of this sender module.

Referenced by endOfFile(), initialize(), initializeSenderModule(), pause(), play(), and stop().

◆ _status

SenderStatus inet::rtp::RtpPayloadSender::_status = static_cast<SenderStatus>(-1)
protected

The current state of data transmission.

Referenced by endOfFile(), initializeSenderModule(), pause(), play(), and stop().

◆ _timeStamp

uint32_t inet::rtp::RtpPayloadSender::_timeStamp = 0
protected

The current rtp time stamp.

Referenced by initialize(), and play().

◆ _timeStampBase

uint32_t inet::rtp::RtpPayloadSender::_timeStampBase = 0
protected

The first rtp time stamp used for created rtp data packets.

The value is chosen randomly.

Referenced by initialize(), and initializeSenderModule().


The documentation for this class was generated from the following files:
inet::rtp::RtpPayloadSender::seekByte
virtual void seekByte(int position)
When the data transmission is paused the current position is changed to this byte position (excluding...
Definition: RtpPayloadSender.cc:169
inet::rtp::RtpPayloadSender::_sequenceNumberBase
uint16_t _sequenceNumberBase
The first sequence number used for created rtp data packets.
Definition: RtpPayloadSender.h:181
inet::rtp::RtpPayloadSender::play
virtual void play()
Starts data transmission.
Definition: RtpPayloadSender.cc:127
inet::rtp::RtpPayloadSender::playUntilTime
virtual void playUntilTime(simtime_t moment)
Starts transmission from the current file position and plays until given time (relative to start of f...
Definition: RtpPayloadSender.cc:142
inet::rtp::RTP_SENDER_STATUS_FINISHED
@ RTP_SENDER_STATUS_FINISHED
Definition: RtpSenderStatusMessage_m.h:67
inet::rtp::RTP_CONTROL_SEEK_TIME
@ RTP_CONTROL_SEEK_TIME
Definition: RtpSenderControlMessage_m.h:83
inet::rtp::RTP_CONTROL_PLAY_UNTIL_BYTE
@ RTP_CONTROL_PLAY_UNTIL_BYTE
Definition: RtpSenderControlMessage_m.h:80
inet::rtp::RTP_SENDER_STATUS_PLAYING
@ RTP_SENDER_STATUS_PLAYING
Definition: RtpSenderStatusMessage_m.h:66
inet::rtp::RtpPayloadSender::PLAYING
@ PLAYING
Data is being sent.
Definition: RtpPayloadSender.h:54
inet::rtp::RtpPayloadSender::stop
virtual void stop()
This method stop data transmission and resets the sender module so that a following PLAY command woul...
Definition: RtpPayloadSender.cc:174
inet::rtp::RtpPayloadSender::initializeSenderModule
virtual void initializeSenderModule(RtpInnerPacket *)
This method is called when a newly create sender module received its initialization message from prof...
Definition: RtpPayloadSender.cc:100
inet::rtp::RtpPayloadSender::closeSourceFile
virtual void closeSourceFile()
This method is called by the destructor and closes the data file.
Definition: RtpPayloadSender.cc:122
inet::rtp::RTP_INP_INITIALIZE_SENDER_MODULE
@ RTP_INP_INITIALIZE_SENDER_MODULE
Definition: RtpInnerPacket_m.h:95
inet::rtp::RTP_INP_SENDER_MODULE_CONTROL
@ RTP_INP_SENDER_MODULE_CONTROL
Definition: RtpInnerPacket_m.h:97
inet::rtp::RtpPayloadSender::_ssrc
uint32_t _ssrc
The ssrc identifier of this sender module.
Definition: RtpPayloadSender.h:154
inet::rtp::RtpPayloadSender::_timeStampBase
uint32_t _timeStampBase
The first rtp time stamp used for created rtp data packets.
Definition: RtpPayloadSender.h:170
inet::rtp::RtpPayloadSender::STOPPED
@ STOPPED
Definition: RtpPayloadSender.h:53
inet::rtp::RTP_CONTROL_PAUSE
@ RTP_CONTROL_PAUSE
Definition: RtpSenderControlMessage_m.h:81
inet::rtp::RtpPayloadSender::_reminderMessage
cMessage * _reminderMessage
A self message used as timer for the moment the next packet must be sent.
Definition: RtpPayloadSender.h:198
inet::rtp::RtpPayloadSender::_timeStamp
uint32_t _timeStamp
The current rtp time stamp.
Definition: RtpPayloadSender.h:175
inet::rtp::RtpPayloadSender::pause
virtual void pause()
When data is being transmitted this methods suspends till a new PLAY command.
Definition: RtpPayloadSender.cc:152
inet::rtp::RtpPayloadSender::_sequenceNumber
uint16_t _sequenceNumber
The current sequence number.
Definition: RtpPayloadSender.h:186
inet::rtp::RtpPayloadSender::seekTime
virtual void seekTime(simtime_t moment)
When the data transmission is paused the current position is changed to this time (relative to start ...
Definition: RtpPayloadSender.cc:164
inet::rtp::RTP_CONTROL_SEEK_BYTE
@ RTP_CONTROL_SEEK_BYTE
Definition: RtpSenderControlMessage_m.h:84
inet::rtp::RTP_CONTROL_PLAY
@ RTP_CONTROL_PLAY
Definition: RtpSenderControlMessage_m.h:78
inet::rtp::RtpPayloadSender::_clockRate
int _clockRate
The clock rate in ticks per second this sender uses.
Definition: RtpPayloadSender.h:164
inet::rtp::RTP_CONTROL_STOP
@ RTP_CONTROL_STOP
Definition: RtpSenderControlMessage_m.h:82
inet::rtp::RTP_SENDER_STATUS_PAUSED
@ RTP_SENDER_STATUS_PAUSED
Definition: RtpSenderStatusMessage_m.h:69
inet::rtp::RtpPayloadSender::_status
SenderStatus _status
The current state of data transmission.
Definition: RtpPayloadSender.h:191
inet::rtp::RtpPayloadSender::_inputFileStream
std::ifstream _inputFileStream
The input file stream for the data file.
Definition: RtpPayloadSender.h:144
inet::rtp::RtpPayloadSender::openSourceFile
virtual void openSourceFile(const char *fileName)
This method is called by initializeSenderModule and opens the source data file as an inputFileStream ...
Definition: RtpPayloadSender.cc:115
inet::rtp::RTP_SENDER_STATUS_STOPPED
@ RTP_SENDER_STATUS_STOPPED
Definition: RtpSenderStatusMessage_m.h:68
inet::rtp::RtpPayloadSender::endOfFile
virtual void endOfFile()
This method gets called when the sender module reaches the end of file.
Definition: RtpPayloadSender.cc:186
inet::rtp::RtpPayloadSender::playUntilByte
virtual void playUntilByte(int position)
Starts transmission from the current file position and plays until given byte position (excluding fil...
Definition: RtpPayloadSender.cc:147
inet::rtp::RtpPayloadSender::sendPacket
virtual bool sendPacket()
This method gets called when one (or more) rtp data packets have to be sent.
Definition: RtpPayloadSender.cc:196
inet::rtp::RtpPayloadSender::_mtu
int _mtu
The maximum size of an RtpPacket.
Definition: RtpPayloadSender.h:149
inet::rtp::RtpPayloadSender::_payloadType
int _payloadType
The payload type this sender creates.
Definition: RtpPayloadSender.h:159
inet::rtp::RTP_CONTROL_PLAY_UNTIL_TIME
@ RTP_CONTROL_PLAY_UNTIL_TIME
Definition: RtpSenderControlMessage_m.h:79