INET Framework for OMNeT++/OMNEST
|
#include <RTPPayloadSender.h>
Public Types | |
enum | SenderStatus { STOPPED, PLAYING } |
Public Member Functions | |
RTPPayloadSender () | |
virtual | ~RTPPayloadSender () |
virtual void | initialize () |
virtual void | activity () |
Protected Member Functions | |
virtual void | initializeSenderModule (RTPInnerPacket *) |
virtual void | openSourceFile (const char *fileName) |
virtual void | closeSourceFile () |
virtual void | play () |
virtual void | playUntilTime (simtime_t moment) |
virtual void | playUntilByte (int position) |
virtual void | pause () |
virtual void | seekTime (simtime_t moment) |
virtual void | seekByte (int position) |
virtual void | stop () |
virtual void | endOfFile () |
virtual bool | sendPacket () |
Protected Attributes | |
std::ifstream | _inputFileStream |
int | _mtu |
uint32 | _ssrc |
int | _payloadType |
int | _clockRate |
uint32 | _timeStampBase |
uint32 | _timeStamp |
uint16 | _sequenceNumberBase |
uint16 | _sequenceNumber |
SenderStatus | _status |
cMessage * | _reminderMessage |
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.
RTPPayloadSender::RTPPayloadSender | ( | ) | [inline] |
Constructor, with activity() stack size.
: cSimpleModule(32768) {}
RTPPayloadSender::~RTPPayloadSender | ( | ) | [virtual] |
Cleaning up. Calls closeSourceFile.
{ closeSourceFile(); }
void RTPPayloadSender::activity | ( | ) | [virtual] |
{ const char *command; while (true) { cMessage *msg = receive(); if (msg->getArrivalGateId() == findGate("profileIn")) { RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg); if (rinpIn->getType() == RTPInnerPacket::RTP_INP_INITIALIZE_SENDER_MODULE) { initializeSenderModule(rinpIn); } else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) { RTPSenderControlMessage *rscm = (RTPSenderControlMessage *)(rinpIn->decapsulate()); delete rinpIn; command = rscm->getCommand(); if (!opp_strcmp(command, "PLAY")) { play(); } else if (!opp_strcmp(command, "PLAY_UNTIL_TIME")) { playUntilTime(rscm->getCommandParameter1()); } else if (!opp_strcmp(command, "PLAY_UNTIL_BYTE")) { playUntilByte(rscm->getCommandParameter1()); } else if (!opp_strcmp(command, "PAUSE")) { pause(); } else if (!opp_strcmp(command, "STOP")) { stop(); } else if (!opp_strcmp(command, "SEEK_TIME")) { seekTime(rscm->getCommandParameter1()); } else if (!opp_strcmp(command, "SEEK_BYTE")) { seekByte(rscm->getCommandParameter1()); } else { error("unknown sender control message"); } delete rscm; } } else { if (!sendPacket()) { endOfFile(); } delete msg; } } }
void RTPPayloadSender::closeSourceFile | ( | ) | [protected, virtual] |
This method is called by the destructor and closes the data file.
Referenced by ~RTPPayloadSender().
{ _inputFileStream.close(); }
void RTPPayloadSender::endOfFile | ( | ) | [protected, virtual] |
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 activity(), and play().
{ _status = STOPPED; RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage(); rssm->setStatus("FINISHED"); RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(FINISHED)"); rinpOut->senderModuleStatus(_ssrc, rssm); send(rinpOut, "profileOut"); }
void RTPPayloadSender::initialize | ( | ) | [virtual] |
Chooses sequence number and time stamp base values and reads the omnet parameter "mtu".
Reimplemented in RTPAVProfilePayload32Sender.
Referenced by RTPProfile::createSenderModule().
{ cSimpleModule::initialize(); _mtu = 0; _ssrc = 0; _payloadType = 0; _clockRate = 0; _timeStampBase = intrand(65535); _timeStamp = _timeStampBase; _sequenceNumberBase = intrand(0x7fffffff); _sequenceNumber = _sequenceNumberBase; }
void RTPPayloadSender::initializeSenderModule | ( | RTPInnerPacket * | rinpIn | ) | [protected, virtual] |
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 RTPAVProfilePayload32Sender.
Referenced by activity().
{ ev << "initializeSenderModule Enter" << endl; _mtu = rinpIn->getMTU(); _ssrc = rinpIn->getSSRC(); const char *fileName = rinpIn->getFileName(); openSourceFile(fileName); delete rinpIn; RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleInitialized()"); rinpOut->senderModuleInitialized(_ssrc, _payloadType, _clockRate, _timeStampBase, _sequenceNumberBase); send(rinpOut, "profileOut"); _status = STOPPED; ev << "initializeSenderModule Exit" << endl; }
void RTPPayloadSender::openSourceFile | ( | const char * | fileName | ) | [protected, virtual] |
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().
{ _inputFileStream.open(fileName); if (!_inputFileStream) { opp_error("sender module: error open data file"); } }
void RTPPayloadSender::pause | ( | ) | [protected, virtual] |
When data is being transmitted this methods suspends till a new PLAY command. Implementation in sender modules is optional.
Referenced by activity().
{ cancelEvent(_reminderMessage); _status = STOPPED; RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PAUSED)"); RTPSenderStatusMessage *rsim = new RTPSenderStatusMessage(); rsim->setStatus("PAUSED"); rinpOut->senderModuleStatus(_ssrc, rsim); send(rinpOut, "profileOut"); }
void RTPPayloadSender::play | ( | ) | [protected, virtual] |
Starts data transmission. Every sender module must implement this method.
Referenced by activity().
{ _status = PLAYING; RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("PLAYING"); rssm->setStatus("PLAYING"); rssm->setTimeStamp(_timeStamp); RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PLAYING)"); rinpOut->senderModuleStatus(_ssrc, rssm); send(rinpOut, "profileOut"); if (!sendPacket()) { endOfFile(); } }
void RTPPayloadSender::playUntilByte | ( | int | position | ) | [protected, virtual] |
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 activity().
{
error("playUntilByte() not implemented");
}
void RTPPayloadSender::playUntilTime | ( | simtime_t | moment | ) | [protected, virtual] |
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 activity().
{
error("playUntilTime() not implemented");
}
void RTPPayloadSender::seekByte | ( | int | position | ) | [protected, virtual] |
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 activity().
{
error("seekByte() not implemented");
}
void RTPPayloadSender::seekTime | ( | simtime_t | moment | ) | [protected, virtual] |
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 activity().
{
error("seekTime() not implemented");
}
bool RTPPayloadSender::sendPacket | ( | ) | [protected, virtual] |
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 RTPAVProfilePayload32Sender.
Referenced by activity(), and play().
{ error("sendPacket() not implemented"); return false; }
void RTPPayloadSender::stop | ( | ) | [protected, virtual] |
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 activity().
{ cancelEvent(_reminderMessage); _status = STOPPED; RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("STOPPED"); rssm->setStatus("STOPPED"); RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleStatus(STOPPED)"); rinp->senderModuleStatus(_ssrc, rssm); send(rinp, "profileOut"); }
int RTPPayloadSender::_clockRate [protected] |
The clock rate in ticks per second this sender uses.
Referenced by initialize(), RTPAVProfilePayload32Sender::initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().
std::ifstream RTPPayloadSender::_inputFileStream [protected] |
The input file stream for the data file.
Referenced by closeSourceFile(), RTPAVProfilePayload32Sender::initializeSenderModule(), openSourceFile(), and RTPAVProfilePayload32Sender::sendPacket().
int RTPPayloadSender::_mtu [protected] |
The maximum size of an RTPPacket.
Referenced by initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().
int RTPPayloadSender::_payloadType [protected] |
The payload type this sender creates.
Referenced by initialize(), RTPAVProfilePayload32Sender::initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().
cMessage* RTPPayloadSender::_reminderMessage [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 pause(), RTPAVProfilePayload32Sender::sendPacket(), and stop().
uint16 RTPPayloadSender::_sequenceNumber [protected] |
The current sequence number.
Referenced by initialize(), and RTPAVProfilePayload32Sender::sendPacket().
uint16 RTPPayloadSender::_sequenceNumberBase [protected] |
The first sequence number used for created rtp data packets. The value is chosen randomly.
Referenced by initialize(), and initializeSenderModule().
uint32 RTPPayloadSender::_ssrc [protected] |
The ssrc identifier of this sender module.
Referenced by endOfFile(), initialize(), initializeSenderModule(), pause(), play(), RTPAVProfilePayload32Sender::sendPacket(), and stop().
SenderStatus RTPPayloadSender::_status [protected] |
The current state of data transmission.
Referenced by endOfFile(), initializeSenderModule(), pause(), play(), and stop().
uint32 RTPPayloadSender::_timeStamp [protected] |
The current rtp time stamp.
Referenced by initialize(), and play().
uint32 RTPPayloadSender::_timeStampBase [protected] |
The first rtp time stamp used for created rtp data packets. The value is chosen randomly.
Referenced by initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().