#include <RTPAVProfilePayload32Sender.h>
Protected Member Functions | |
virtual void | initialize () |
virtual void | initializeSenderModule (RTPInnerPacket *rinpIn) |
virtual bool | sendPacket () |
Protected Attributes | |
double | _initialDelay |
double | _framesPerSecond |
double | _frameNumber |
void RTPAVProfilePayload32Sender::initialize | ( | ) | [protected, virtual] |
Initializes the module. It sets the values for clock rate and payload type.
Reimplemented from RTPPayloadSender.
00034 { 00035 00036 RTPPayloadSender::initialize(); 00037 00038 _clockRate = 90000; 00039 _payloadType = 32; 00040 };
void RTPAVProfilePayload32Sender::initializeSenderModule | ( | RTPInnerPacket * | rinpIn | ) | [protected, virtual] |
The main method. This method reads the gdf file header.
Reimplemented from RTPPayloadSender.
00115 { 00116 ev << "initializeSenderModule Enter"<<endl; 00117 char line[100]; 00118 char unit[100]; 00119 char description[100]; 00120 00121 RTPPayloadSender::initializeSenderModule(rinpIn); 00122 00123 // first line: fps unit description 00124 _inputFileStream.get(line, 100, '\n'); 00125 00126 float fps; 00127 sscanf(line, "%f %s %s", &fps, unit, description); 00128 _framesPerSecond = fps; 00129 00130 _frameNumber = 0; 00131 00132 // get new line character 00133 char c; 00134 _inputFileStream.get(c); 00135 00136 // second line: initial delay unit description 00137 _inputFileStream.get(line, 100, '\n'); 00138 00139 float delay; 00140 sscanf(line, "%f %s %s", &delay, unit, description); 00141 00142 _initialDelay = delay; 00143 00144 // wait initial delay 00145 // cPacket *reminderMessage = new cMessage("next frame"); 00146 // scheduleAt(simTime() + _initialDelay, reminderMessage); 00147 ev << "initializeSenderModule Exit"<<endl; 00148 };
bool RTPAVProfilePayload32Sender::sendPacket | ( | ) | [protected, virtual] |
This method sends one mpeg frame. It sends one or more rtp data packet. Returns false if there were no more frames.
Reimplemented from RTPPayloadSender.
00152 { 00153 ev << "sendPacket() "<< endl; 00154 // read next frame line 00155 int bits; 00156 char unit[100]; 00157 char description[100]; 00158 00159 _inputFileStream >> bits; 00160 _inputFileStream >> unit; 00161 _inputFileStream.get(description, 100, '\n'); 00162 00163 int pictureType = 0; 00164 00165 if (strchr(description, 'I')) { 00166 pictureType = 1; 00167 } 00168 else if (strchr(description, 'P')) { 00169 pictureType = 2; 00170 } 00171 else if (strchr(description, 'B')) { 00172 pictureType = 3; 00173 } 00174 else if (strchr(description, 'D')) { 00175 pictureType = 4; 00176 }; 00177 00178 int bytesRemaining = bits / 8; 00179 00180 if (!_inputFileStream.eof()) { 00181 while (bytesRemaining > 0) { 00182 RTPPacket *rtpPacket = new RTPPacket("RTPPacket"); 00183 RTPMpegPacket *mpegPacket = new RTPMpegPacket("MpegPacket"); 00184 00185 // the only mpeg information we know is the picture type 00186 mpegPacket->setPictureType(pictureType); 00187 00188 // the maximum number of real data bytes 00189 int maxDataSize = _mtu - rtpPacket->getBitLength() - mpegPacket->getBitLength(); 00190 00191 if (bytesRemaining > maxDataSize) { 00192 00193 // we do not know where slices in the 00194 // mpeg picture begin 00195 // so we simulate by assuming a slice 00196 // has a length of 64 bytes 00197 int slicedDataSize = (maxDataSize / 64) * 64; 00198 00199 mpegPacket->addBitLength(slicedDataSize); 00200 00201 00202 rtpPacket->encapsulate(mpegPacket); 00203 00204 bytesRemaining = bytesRemaining - slicedDataSize; 00205 } 00206 else { 00207 mpegPacket->addBitLength(bytesRemaining); 00208 rtpPacket->encapsulate(mpegPacket); 00209 // set marker because this is 00210 // the last packet of the frame 00211 rtpPacket->setMarker(1); 00212 bytesRemaining = 0; 00213 } 00214 00215 rtpPacket->setPayloadType(_payloadType); 00216 rtpPacket->setSequenceNumber(_sequenceNumber); 00217 _sequenceNumber++; 00218 00219 00220 rtpPacket->setTimeStamp(_timeStampBase + (_initialDelay + (1 / _framesPerSecond) * (double)_frameNumber) * _clockRate); 00221 rtpPacket->setSSRC(_ssrc); 00222 00223 00224 RTPInnerPacket *rinpOut = new RTPInnerPacket("dataOut()"); 00225 00226 00227 rinpOut->dataOut(rtpPacket); 00228 00229 send(rinpOut, "toProfile"); 00230 00231 }; 00232 _frameNumber++; 00233 00234 _reminderMessage = new cMessage("nextFrame"); 00235 scheduleAt(simTime() + 1.0 / _framesPerSecond, _reminderMessage); 00236 return true; 00237 } 00238 else { 00239 std::cout <<"LastSequenceNumber "<< _sequenceNumber << endl; 00240 return false; 00241 } 00242 ev << "sendPacket() Exit"<< endl; 00243 };
double RTPAVProfilePayload32Sender::_initialDelay [protected] |
The initial delay of the mpeg video.
Referenced by initializeSenderModule(), and sendPacket().
double RTPAVProfilePayload32Sender::_framesPerSecond [protected] |
The number of frames per second of the mpeg video.
Referenced by initializeSenderModule(), and sendPacket().
double 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().