INET Framework for OMNeT++/OMNEST
|
#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 |
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.
void RTPAVProfilePayload32Sender::initialize | ( | ) | [protected, virtual] |
Initializes the module. It sets the values for clock rate and payload type.
Reimplemented from RTPPayloadSender.
{ RTPPayloadSender::initialize(); _clockRate = 90000; _payloadType = 32; }
void RTPAVProfilePayload32Sender::initializeSenderModule | ( | RTPInnerPacket * | rinpIn | ) | [protected, virtual] |
The main method. This method reads the gdf file header.
Reimplemented from RTPPayloadSender.
{ ev << "initializeSenderModule Enter"<<endl; char line[100]; char unit[100]; char description[100]; RTPPayloadSender::initializeSenderModule(rinpIn); // first line: fps unit description _inputFileStream.get(line, 100, '\n'); float fps; sscanf(line, "%f %s %s", &fps, unit, description); _framesPerSecond = fps; _frameNumber = 0; // get new line character char c; _inputFileStream.get(c); // second line: initial delay unit description _inputFileStream.get(line, 100, '\n'); float delay; sscanf(line, "%f %s %s", &delay, unit, description); _initialDelay = delay; // wait initial delay // cPacket *reminderMessage = new cMessage("next frame"); // scheduleAt(simTime() + _initialDelay, reminderMessage); ev << "initializeSenderModule Exit"<<endl; }
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.
{ ev << "sendPacket() "<< endl; // read next frame line int bits; char unit[100]; char description[100]; _inputFileStream >> bits; _inputFileStream >> unit; _inputFileStream.get(description, 100, '\n'); int pictureType = 0; if (strchr(description, 'I')) { pictureType = 1; } else if (strchr(description, 'P')) { pictureType = 2; } else if (strchr(description, 'B')) { pictureType = 3; } else if (strchr(description, 'D')) { pictureType = 4; } int bytesRemaining = bits / 8; if (!_inputFileStream.eof()) { while (bytesRemaining > 0) { RTPPacket *rtpPacket = new RTPPacket("RTPPacket"); RTPMpegPacket *mpegPacket = new RTPMpegPacket("MpegPacket"); // the only mpeg information we know is the picture type mpegPacket->setPictureType(pictureType); // the maximum number of real data bytes int maxDataSize = _mtu - rtpPacket->getBitLength() - mpegPacket->getBitLength(); if (bytesRemaining > maxDataSize) { // we do not know where slices in the // mpeg picture begin // so we simulate by assuming a slice // has a length of 64 bytes int slicedDataSize = (maxDataSize / 64) * 64; mpegPacket->addBitLength(slicedDataSize); rtpPacket->encapsulate(mpegPacket); bytesRemaining = bytesRemaining - slicedDataSize; } else { mpegPacket->addBitLength(bytesRemaining); rtpPacket->encapsulate(mpegPacket); // set marker because this is // the last packet of the frame rtpPacket->setMarker(1); bytesRemaining = 0; } rtpPacket->setPayloadType(_payloadType); rtpPacket->setSequenceNumber(_sequenceNumber); _sequenceNumber++; rtpPacket->setTimeStamp(_timeStampBase + (_initialDelay + (1 / _framesPerSecond) * (double)_frameNumber) * _clockRate); rtpPacket->setSSRC(_ssrc); RTPInnerPacket *rinpOut = new RTPInnerPacket("dataOut()"); rinpOut->dataOut(rtpPacket); send(rinpOut, "profileOut"); } _frameNumber++; _reminderMessage = new cMessage("nextFrame"); scheduleAt(simTime() + 1.0 / _framesPerSecond, _reminderMessage); return true; } else { std::cout <<"LastSequenceNumber "<< _sequenceNumber << endl; return false; } ev << "sendPacket() Exit"<< endl; }
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().
double RTPAVProfilePayload32Sender::_framesPerSecond [protected] |
The number of frames per second of the mpeg video.
Referenced by initializeSenderModule(), and sendPacket().
double RTPAVProfilePayload32Sender::_initialDelay [protected] |
The initial delay of the mpeg video.
Referenced by initializeSenderModule(), and sendPacket().