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

An RTPAVProfilePayload32Sender is a module for sending data of payload type 32 in the rtp audio/video profile, which is mpeg video. More...

#include <RTPAVProfilePayload32Sender.h>

Inheritance diagram for inet::rtp::RTPAVProfilePayload32Sender:
inet::rtp::RTPPayloadSender

Protected Member Functions

virtual void initialize () override
 Initializes the module. More...
 
virtual void initializeSenderModule (RTPInnerPacket *rinpIn) override
 The main method. More...
 
virtual bool sendPacket () override
 This method sends one mpeg frame. More...
 
- Protected Member Functions inherited from inet::rtp::RTPPayloadSender
virtual void handleMessage (cMessage *msg) override
 
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...
 

Protected Attributes

double _initialDelay
 The initial delay of the mpeg video. More...
 
double _framesPerSecond
 The number of frames per second of the mpeg video. More...
 
double _frameNumber
 The number of the current mpeg frame. More...
 
- Protected Attributes inherited from inet::rtp::RTPPayloadSender
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...
 

Additional Inherited Members

- Public Member Functions inherited from inet::rtp::RTPPayloadSender
 RTPPayloadSender ()
 Constructor. More...
 
virtual ~RTPPayloadSender ()
 Destructor. More...
 
- Protected Types inherited from inet::rtp::RTPPayloadSender
enum  SenderStatus { STOPPED, PLAYING }
 A sender module's transmission can be in different states. More...
 

Detailed Description

An RTPAVProfilePayload32Sender is a module for sending data of payload type 32 in the rtp audio/video profile, which is mpeg video.

This implementation doesn't send real mpeg data it just reads the gdf file created by Mpeg_Stat and sends rtp data packets which contain an RTPMpegPacket. The corresponding receiver module RTPAVProfilePayload32Receiver.

Member Function Documentation

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

Initializes the module.

It sets the values for clock rate and payload type.

Reimplemented from inet::rtp::RTPPayloadSender.

33 {
35 
36  _clockRate = 90000;
37  _payloadType = 32;
38 }
int _payloadType
The payload type this sender creates.
Definition: RTPPayloadSender.h:170
virtual void initialize() override
Chooses sequence number and time stamp base values and reads the omnet parameter "mtu".
Definition: RTPPayloadSender.cc:39
int _clockRate
The clock rate in ticks per second this sender uses.
Definition: RTPPayloadSender.h:175
void inet::rtp::RTPAVProfilePayload32Sender::initializeSenderModule ( RTPInnerPacket rinpIn)
overrideprotectedvirtual

The main method.

This method reads the gdf file header.

Reimplemented from inet::rtp::RTPPayloadSender.

41 {
42  EV_TRACE << "initializeSenderModule Enter" << endl;
43  char line[100];
44  char unit[100];
45  char description[100];
46 
48 
49  // first line: fps unit description
50  _inputFileStream.get(line, 100, '\n');
51 
52  float fps;
53  sscanf(line, "%f %s %s", &fps, unit, description);
54  _framesPerSecond = fps;
55 
56  _frameNumber = 0;
57 
58  // get new line character
59  char c;
60  _inputFileStream.get(c);
61 
62  // second line: initial delay unit description
63  _inputFileStream.get(line, 100, '\n');
64 
65  float delay;
66  sscanf(line, "%f %s %s", &delay, unit, description);
67 
68  _initialDelay = delay;
69 
70  // wait initial delay
71  // cPacket *reminderMessage = new cMessage("next frame");
72  // scheduleAt(simTime() + _initialDelay, reminderMessage);
73  EV_TRACE << "initializeSenderModule Exit" << endl;
74 }
double _frameNumber
The number of the current mpeg frame.
Definition: RTPAVProfilePayload32Sender.h:76
std::ifstream _inputFileStream
The input file stream for the data file.
Definition: RTPPayloadSender.h:155
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
double _framesPerSecond
The number of frames per second of the mpeg video.
Definition: RTPAVProfilePayload32Sender.h:70
virtual void initializeSenderModule(RTPInnerPacket *)
This method is called when a newly create sender module received its initialization message from prof...
Definition: RTPPayloadSender.cc:111
pow< internal::none, 0 > unit
Definition: Units.h:60
double _initialDelay
The initial delay of the mpeg video.
Definition: RTPAVProfilePayload32Sender.h:65
bool inet::rtp::RTPAVProfilePayload32Sender::sendPacket ( )
overrideprotectedvirtual

This method sends one mpeg frame.

It sends one or more rtp data packet. Returns false if there were no more frames.

Reimplemented from inet::rtp::RTPPayloadSender.

77 {
78  EV_TRACE << "sendPacket() " << endl;
79  // read next frame line
80  int bits;
81  char unit[100];
82  char description[100];
83  bool ret;
84 
85  _inputFileStream >> bits;
87  _inputFileStream.get(description, 100, '\n');
88 
89  int pictureType;
90  char *ptr;
91 
92  for (ptr = description; *ptr == ' ' || *ptr == '\t' ; ptr++)
93  ;
94  switch (*ptr) {
95  case 'I':
96  pictureType = 1;
97  break;
98 
99  case 'P':
100  pictureType = 2;
101  break;
102 
103  case 'B':
104  pictureType = 3;
105  break;
106 
107  case 'D':
108  pictureType = 4;
109  break;
110 
111  default:
112  pictureType = 0;
113  break;
114  }
115 
116  int bytesRemaining = bits / 8;
117 
118  if (!_inputFileStream.eof()) {
119  while (bytesRemaining > 0) {
120  RTPPacket *rtpPacket = new RTPPacket("RTPPacket");
121  RTPMpegPacket *mpegPacket = new RTPMpegPacket("MpegPacket");
122 
123  // the only mpeg information we know is the picture type
124  mpegPacket->setPictureType(pictureType);
125 
126  // the maximum number of real data bytes
127  int maxDataSize = _mtu - rtpPacket->getByteLength() - mpegPacket->getByteLength();
128 
129  if (bytesRemaining > maxDataSize) {
130  // we do not know where slices in the
131  // mpeg picture begin
132  // so we simulate by assuming a slice
133  // has a length of 64 bytes
134  int slicedDataSize = (maxDataSize / 64) * 64;
135 
136  mpegPacket->setPayloadLength(slicedDataSize);
137  mpegPacket->addByteLength(slicedDataSize);
138 
139  rtpPacket->encapsulate(mpegPacket);
140 
141  bytesRemaining = bytesRemaining - slicedDataSize;
142  }
143  else {
144  mpegPacket->setPayloadLength(bytesRemaining);
145  mpegPacket->addByteLength(bytesRemaining);
146  rtpPacket->encapsulate(mpegPacket);
147  // set marker because this is
148  // the last packet of the frame
149  rtpPacket->setMarker(1);
150  bytesRemaining = 0;
151  }
152 
153  rtpPacket->setPayloadType(_payloadType);
154  rtpPacket->setSequenceNumber(_sequenceNumber);
155  _sequenceNumber++;
156 
157  rtpPacket->setTimeStamp(_timeStampBase + (_initialDelay + (1 / _framesPerSecond) * (double)_frameNumber) * _clockRate);
158  rtpPacket->setSsrc(_ssrc);
159 
160  RTPInnerPacket *rinpOut = new RTPInnerPacket("dataOut()");
161 
162  rinpOut->setDataOutPkt(rtpPacket);
163 
164  send(rinpOut, "profileOut");
165  }
166  _frameNumber++;
167 
168  _reminderMessage = new cMessage("nextFrame");
169  scheduleAt(simTime() + 1.0 / _framesPerSecond, _reminderMessage);
170  ret = true;
171  }
172  else {
173  std::cout << "LastSequenceNumber " << _sequenceNumber << endl;
174  ret = false;
175  }
176  EV_TRACE << "sendPacket() Exit" << endl;
177  return ret;
178 }
double _frameNumber
The number of the current mpeg frame.
Definition: RTPAVProfilePayload32Sender.h:76
int _payloadType
The payload type this sender creates.
Definition: RTPPayloadSender.h:170
std::ifstream _inputFileStream
The input file stream for the data file.
Definition: RTPPayloadSender.h:155
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
double _framesPerSecond
The number of frames per second of the mpeg video.
Definition: RTPAVProfilePayload32Sender.h:70
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
pow< internal::none, 0 > unit
Definition: Units.h:60
double _initialDelay
The initial delay of the mpeg video.
Definition: RTPAVProfilePayload32Sender.h:65
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

Member Data Documentation

double inet::rtp::RTPAVProfilePayload32Sender::_frameNumber
protected

The number of the current mpeg frame.

Needed for calculating the rtp time stamp in the rtp data packets.

Referenced by initializeSenderModule(), and sendPacket().

double inet::rtp::RTPAVProfilePayload32Sender::_framesPerSecond
protected

The number of frames per second of the mpeg video.

Referenced by initializeSenderModule(), and sendPacket().

double inet::rtp::RTPAVProfilePayload32Sender::_initialDelay
protected

The initial delay of the mpeg video.

Referenced by initializeSenderModule(), and sendPacket().


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