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 _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 _timeStampBase = 0
 The first rtp time stamp used for created rtp data packets. More...
 
uint32 _timeStamp = 0
 The current rtp time stamp. More...
 
uint16 _sequenceNumberBase = 0
 The first sequence number used for created rtp data packets. More...
 
uint16 _sequenceNumber = 0
 The current sequence number. More...
 
SenderStatus _status = (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

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

Enumerator
STOPPED 
PLAYING 

Data is being sent.

63  {
64  STOPPED, //< No transmission.
65  PLAYING
66  };
Data is being sent.
Definition: RTPPayloadSender.h:65
Definition: RTPPayloadSender.h:64

Constructor & Destructor Documentation

inet::rtp::RTPPayloadSender::RTPPayloadSender ( )

Constructor.

30 {
31 }
inet::rtp::RTPPayloadSender::~RTPPayloadSender ( )
virtual

Destructor.

Calls closeSourceFile.

34 {
36  cancelAndDelete(_reminderMessage);
37 }
cMessage * _reminderMessage
A self message used as timer for the moment the next packet must be sent.
Definition: RTPPayloadSender.h:209
virtual void closeSourceFile()
This method is called by the destructor and closes the data file.
Definition: RTPPayloadSender.cc:133

Member Function Documentation

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

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

Referenced by ~RTPPayloadSender().

134 {
135  _inputFileStream.close();
136 }
std::ifstream _inputFileStream
The input file stream for the data file.
Definition: RTPPayloadSender.h:155
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().

Referenced by handleMessage(), and play().

198 {
199  _status = STOPPED;
200  RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("FINISHED");
201  rssm->setStatus(RTP_SENDER_STATUS_FINISHED);
202  RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(FINISHED)");
203  rinpOut->setSenderModuleStatusPkt(_ssrc, rssm);
204  send(rinpOut, "profileOut");
205 }
SenderStatus _status
The current state of data transmission.
Definition: RTPPayloadSender.h:202
Definition: RTPSenderStatusMessage_m.h:61
uint32 _ssrc
The ssrc identifier of this sender module.
Definition: RTPPayloadSender.h:165
Definition: RTPPayloadSender.h:64
void inet::rtp::RTPPayloadSender::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
54 {
55  if (msg == _reminderMessage) {
56  delete msg;
57  _reminderMessage = nullptr;
58  if (!sendPacket()) {
59  endOfFile();
60  }
61  }
62  else if (msg->getArrivalGateId() == findGate("profileIn")) {
63  RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);
64  if (rinpIn->getType() == RTP_INP_INITIALIZE_SENDER_MODULE) {
65  initializeSenderModule(rinpIn);
66  }
67  else if (rinpIn->getType() == RTP_INP_SENDER_MODULE_CONTROL) {
68  RTPSenderControlMessage *rscm = (RTPSenderControlMessage *)(rinpIn->decapsulate());
69  delete rinpIn;
70  switch (rscm->getCommand()) {
71  case RTP_CONTROL_PLAY:
72  play();
73  break;
74 
76  playUntilTime(rscm->getCommandParameter1());
77  break;
78 
80  playUntilByte(rscm->getCommandParameter1());
81  break;
82 
83  case RTP_CONTROL_PAUSE:
84  pause();
85  break;
86 
87  case RTP_CONTROL_STOP:
88  stop();
89  break;
90 
92  seekTime(rscm->getCommandParameter1());
93  break;
94 
96  seekByte(rscm->getCommandParameter1());
97  break;
98 
99  default:
100  throw cRuntimeError("unknown sender control message");
101  break;
102  }
103  delete rscm;
104  }
105  }
106  else {
107  throw cRuntimeError("Unknown message!");
108  }
109 }
virtual void seekByte(int position)
When the data transmission is paused the current position is changed to this byte position (excluding...
Definition: RTPPayloadSender.cc:180
virtual bool sendPacket()
This method gets called when one (or more) rtp data packets have to be sent.
Definition: RTPPayloadSender.cc:207
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:175
cMessage * _reminderMessage
A self message used as timer for the moment the next packet must be sent.
Definition: RTPPayloadSender.h:209
virtual void pause()
When data is being transmitted this methods suspends till a new PLAY command.
Definition: RTPPayloadSender.cc:163
Definition: RTPInnerPacket_m.h:82
Definition: RTPSenderControlMessage_m.h:72
virtual void stop()
This method stop data transmission and resets the sender module so that a following PLAY command woul...
Definition: RTPPayloadSender.cc:185
virtual void initializeSenderModule(RTPInnerPacket *)
This method is called when a newly create sender module received its initialization message from prof...
Definition: RTPPayloadSender.cc:111
virtual void play()
Starts data transmission.
Definition: RTPPayloadSender.cc:138
Definition: RTPSenderControlMessage_m.h:73
Definition: RTPSenderControlMessage_m.h:78
virtual void endOfFile()
This method gets called when the sender module reaches the end of file.
Definition: RTPPayloadSender.cc:197
Definition: RTPInnerPacket_m.h:84
Definition: RTPSenderControlMessage_m.h:76
Definition: RTPSenderControlMessage_m.h:75
Definition: RTPSenderControlMessage_m.h:77
virtual void playUntilByte(int position)
Starts transmission from the current file position and plays until given byte position (excluding fil...
Definition: RTPPayloadSender.cc:158
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:153
Definition: RTPSenderControlMessage_m.h:74
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.

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

40 {
41  cSimpleModule::initialize();
42  _mtu = 0;
43  _ssrc = 0;
44  _payloadType = 0;
45  _clockRate = 0;
46  _timeStampBase = intrand(65535);
48  _sequenceNumberBase = intrand(0x7fffffff);
50  _reminderMessage = nullptr;
51 }
int _payloadType
The payload type this sender creates.
Definition: RTPPayloadSender.h:170
cMessage * _reminderMessage
A self message used as timer for the moment the next packet must be sent.
Definition: RTPPayloadSender.h:209
uint32 _timeStampBase
The first rtp time stamp used for created rtp data packets.
Definition: RTPPayloadSender.h:181
uint32 _ssrc
The ssrc identifier of this sender module.
Definition: RTPPayloadSender.h:165
int _mtu
The maximum size of an RTPPacket.
Definition: RTPPayloadSender.h:160
uint16 _sequenceNumberBase
The first sequence number used for created rtp data packets.
Definition: RTPPayloadSender.h:192
uint16 _sequenceNumber
The current sequence number.
Definition: RTPPayloadSender.h:197
int _clockRate
The clock rate in ticks per second this sender uses.
Definition: RTPPayloadSender.h:175
uint32 _timeStamp
The current rtp time stamp.
Definition: RTPPayloadSender.h:186
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.

Referenced by handleMessage(), and inet::rtp::RTPAVProfilePayload32Sender::initializeSenderModule().

112 {
113  EV_TRACE << "initializeSenderModule Enter" << endl;
114  _mtu = rinpIn->getMTU();
115  _ssrc = rinpIn->getSsrc();
116  const char *fileName = rinpIn->getFileName();
117  openSourceFile(fileName);
118  delete rinpIn;
119  RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleInitialized()");
120  rinpOut->setSenderModuleInitializedPkt(_ssrc, _payloadType, _clockRate, _timeStampBase, _sequenceNumberBase);
121  send(rinpOut, "profileOut");
122  _status = STOPPED;
123  EV_TRACE << "initializeSenderModule Exit" << endl;
124 }
int _payloadType
The payload type this sender creates.
Definition: RTPPayloadSender.h:170
SenderStatus _status
The current state of data transmission.
Definition: RTPPayloadSender.h:202
uint32 _timeStampBase
The first rtp time stamp used for created rtp data packets.
Definition: RTPPayloadSender.h:181
virtual void openSourceFile(const char *fileName)
This method is called by initializeSenderModule and opens the source data file as an inputFileStream ...
Definition: RTPPayloadSender.cc:126
uint32 _ssrc
The ssrc identifier of this sender module.
Definition: RTPPayloadSender.h:165
int _mtu
The maximum size of an RTPPacket.
Definition: RTPPayloadSender.h:160
Definition: RTPPayloadSender.h:64
uint16 _sequenceNumberBase
The first sequence number used for created rtp data packets.
Definition: RTPPayloadSender.h:192
int _clockRate
The clock rate in ticks per second this sender uses.
Definition: RTPPayloadSender.h:175
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.

Referenced by initializeSenderModule().

127 {
128  _inputFileStream.open(fileName);
129  if (!_inputFileStream)
130  throw cRuntimeError("Error opening data file '%s'", fileName);
131 }
std::ifstream _inputFileStream
The input file stream for the data file.
Definition: RTPPayloadSender.h:155
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.

Referenced by handleMessage().

164 {
165  cancelAndDelete(_reminderMessage);
166  _reminderMessage = nullptr;
167  _status = STOPPED;
168  RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PAUSED)");
169  RTPSenderStatusMessage *rsim = new RTPSenderStatusMessage();
170  rsim->setStatus(RTP_SENDER_STATUS_PAUSED);
171  rinpOut->setSenderModuleStatusPkt(_ssrc, rsim);
172  send(rinpOut, "profileOut");
173 }
SenderStatus _status
The current state of data transmission.
Definition: RTPPayloadSender.h:202
cMessage * _reminderMessage
A self message used as timer for the moment the next packet must be sent.
Definition: RTPPayloadSender.h:209
Definition: RTPSenderStatusMessage_m.h:63
uint32 _ssrc
The ssrc identifier of this sender module.
Definition: RTPPayloadSender.h:165
Definition: RTPPayloadSender.h:64
void inet::rtp::RTPPayloadSender::play ( )
protectedvirtual

Starts data transmission.

Every sender module must implement this method.

Referenced by handleMessage().

139 {
140  _status = PLAYING;
141  RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("PLAYING");
142  rssm->setStatus(RTP_SENDER_STATUS_PLAYING);
143  rssm->setTimeStamp(_timeStamp);
144  RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PLAYING)");
145  rinpOut->setSenderModuleStatusPkt(_ssrc, rssm);
146  send(rinpOut, "profileOut");
147 
148  if (!sendPacket()) {
149  endOfFile();
150  }
151 }
virtual bool sendPacket()
This method gets called when one (or more) rtp data packets have to be sent.
Definition: RTPPayloadSender.cc:207
SenderStatus _status
The current state of data transmission.
Definition: RTPPayloadSender.h:202
Data is being sent.
Definition: RTPPayloadSender.h:65
uint32 _ssrc
The ssrc identifier of this sender module.
Definition: RTPPayloadSender.h:165
virtual void endOfFile()
This method gets called when the sender module reaches the end of file.
Definition: RTPPayloadSender.cc:197
Definition: RTPSenderStatusMessage_m.h:60
uint32 _timeStamp
The current rtp time stamp.
Definition: RTPPayloadSender.h:186
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.

Referenced by handleMessage().

159 {
160  throw cRuntimeError("playUntilByte() not implemented");
161 }
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.

Referenced by handleMessage().

154 {
155  throw cRuntimeError("playUntilTime() not implemented");
156 }
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.

Referenced by handleMessage().

181 {
182  throw cRuntimeError("seekByte() not implemented");
183 }
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.

Referenced by handleMessage().

176 {
177  throw cRuntimeError("seekTime() not implemented");
178 }
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.

Referenced by handleMessage(), and play().

208 {
209  throw cRuntimeError("sendPacket() not implemented");
210  return false;
211 }
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.

Referenced by handleMessage().

186 {
187  cancelAndDelete(_reminderMessage);
188  _reminderMessage = nullptr;
189  _status = STOPPED;
190  RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("STOPPED");
191  rssm->setStatus(RTP_SENDER_STATUS_STOPPED);
192  RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleStatus(STOPPED)");
193  rinp->setSenderModuleStatusPkt(_ssrc, rssm);
194  send(rinp, "profileOut");
195 }
SenderStatus _status
The current state of data transmission.
Definition: RTPPayloadSender.h:202
cMessage * _reminderMessage
A self message used as timer for the moment the next packet must be sent.
Definition: RTPPayloadSender.h:209
Definition: RTPSenderStatusMessage_m.h:62
uint32 _ssrc
The ssrc identifier of this sender module.
Definition: RTPPayloadSender.h:165
Definition: RTPPayloadSender.h:64

Member Data Documentation

int inet::rtp::RTPPayloadSender::_clockRate = 0
protected
std::ifstream inet::rtp::RTPPayloadSender::_inputFileStream
protected
int inet::rtp::RTPPayloadSender::_mtu = 0
protected
int inet::rtp::RTPPayloadSender::_payloadType = -1
protected
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(), inet::rtp::RTPAVProfilePayload32Sender::sendPacket(), stop(), and ~RTPPayloadSender().

uint16 inet::rtp::RTPPayloadSender::_sequenceNumber = 0
protected

The current sequence number.

Referenced by initialize(), and inet::rtp::RTPAVProfilePayload32Sender::sendPacket().

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

uint32 inet::rtp::RTPPayloadSender::_ssrc = 0
protected
SenderStatus inet::rtp::RTPPayloadSender::_status = (SenderStatus)-1
protected

The current state of data transmission.

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

uint32 inet::rtp::RTPPayloadSender::_timeStamp = 0
protected

The current rtp time stamp.

Referenced by initialize(), and play().

uint32 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(), initializeSenderModule(), and inet::rtp::RTPAVProfilePayload32Sender::sendPacket().


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