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_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...
 

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

◆ initialize()

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

Initializes the module.

It sets the values for clock rate and payload type.

Reimplemented from inet::rtp::RtpPayloadSender.

◆ initializeSenderModule()

void inet::rtp::RtpAvProfilePayload32Sender::initializeSenderModule ( RtpInnerPacket rinpIn)
overrideprotectedvirtual

The main method.

This method reads the gdf file header.

Reimplemented from inet::rtp::RtpPayloadSender.

75 {
76  EV_TRACE << "sendPacket() " << endl;
77  // read next frame line
78  int bits;
79  char unit[100];
80  char description[100];
81  bool ret;
82 
83  _inputFileStream >> bits;

◆ sendPacket()

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.

92  {
93  case 'I':
94  pictureType = 1;
95  break;
96 
97  case 'P':
98  pictureType = 2;
99  break;
100 
101  case 'B':
102  pictureType = 3;
103  break;
104 
105  case 'D':
106  pictureType = 4;
107  break;
108 
109  default:
110  pictureType = 0;
111  break;
112  }
113 
114  int bytesRemaining = bits / 8;
115 
116  if (!_inputFileStream.eof()) {
117  while (bytesRemaining > 0) {
118  Packet *packet = new Packet("RtpPacket");
119  const auto& rtpHeader = makeShared<RtpHeader>();
120  const auto& mpegHeader = makeShared<RtpMpegHeader>();
121  const auto& mpegPayload = makeShared<ByteCountChunk>();
122 
123  // the only mpeg information we know is the picture type
124  mpegHeader->setPictureType(pictureType);
125 
126  // the maximum number of real data bytes
127  int maxDataSize = _mtu - B(rtpHeader->getChunkLength() + mpegHeader->getChunkLength()).get();
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  mpegHeader->setPayloadLength(slicedDataSize);
137  mpegPayload->setLength(B(slicedDataSize));
138 
139  bytesRemaining = bytesRemaining - slicedDataSize;
140  }
141  else {
142  mpegHeader->setPayloadLength(bytesRemaining);
143  mpegPayload->setLength(B(bytesRemaining));
144  // set marker because this is
145  // the last packet of the frame
146  rtpHeader->setMarker(1);
147  bytesRemaining = 0;
148  }
149 
150  rtpHeader->setPayloadType(_payloadType);
151  rtpHeader->setSequenceNumber(_sequenceNumber);
152  _sequenceNumber++;
153 
154  rtpHeader->setTimeStamp(_timeStampBase + (_initialDelay + (1 / _framesPerSecond) * (double)_frameNumber) * _clockRate);
155  rtpHeader->setSsrc(_ssrc);
156  packet->insertAtFront(rtpHeader);
157  packet->insertAtBack(mpegHeader);
158  packet->insertAtBack(mpegPayload);
159 
160  RtpInnerPacket *rinpOut = new RtpInnerPacket("dataOut()");
161  rinpOut->setDataOutPkt(packet);
162 
163  send(rinpOut, "profileOut");
164  }
165  _frameNumber++;
166 
167  _reminderMessage = new cMessage("nextFrame");
168  scheduleAfter(1.0 / _framesPerSecond, _reminderMessage);
169  ret = true;
170  }
171  else {
172  std::cout << "LastSequenceNumber " << _sequenceNumber << endl;
173  ret = false;
174  }
175  EV_TRACE << "sendPacket() Exit" << endl;
176  return ret;
177 }
178 
179 } // namespace rtp
180 
181 } // namespace inet
182 

Member Data Documentation

◆ _frameNumber

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.

◆ _framesPerSecond

double inet::rtp::RtpAvProfilePayload32Sender::_framesPerSecond
protected

The number of frames per second of the mpeg video.

◆ _initialDelay

double inet::rtp::RtpAvProfilePayload32Sender::_initialDelay
protected

The initial delay of the mpeg video.


The documentation for this class was generated from the following files:
inet::rtp::RtpAvProfilePayload32Sender::_framesPerSecond
double _framesPerSecond
The number of frames per second of the mpeg video.
Definition: RtpAvProfilePayload32Sender.h:81
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::_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::_sequenceNumber
uint16_t _sequenceNumber
The current sequence number.
Definition: RtpPayloadSender.h:186
inet::rtp::RtpAvProfilePayload32Sender::_frameNumber
double _frameNumber
The number of the current mpeg frame.
Definition: RtpAvProfilePayload32Sender.h:87
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::rtp::RtpPayloadSender::_clockRate
int _clockRate
The clock rate in ticks per second this sender uses.
Definition: RtpPayloadSender.h:164
inet::rtp::RtpPayloadSender::_inputFileStream
std::ifstream _inputFileStream
The input file stream for the data file.
Definition: RtpPayloadSender.h:144
inet::units::unit
pow< internal::none, 0 > unit
Definition: Units.h:72
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::RtpAvProfilePayload32Sender::_initialDelay
double _initialDelay
The initial delay of the mpeg video.
Definition: RtpAvProfilePayload32Sender.h:76