#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 |
RTPPayloadSender::RTPPayloadSender | ( | ) | [inline] |
RTPPayloadSender::~RTPPayloadSender | ( | ) | [virtual] |
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(), and RTPAVProfilePayload32Sender::initialize().
00034 { 00035 cSimpleModule::initialize(); 00036 _mtu = 0; 00037 _ssrc = 0; 00038 _payloadType = 0; 00039 _clockRate = 0; 00040 _timeStampBase = intrand(65535); 00041 _timeStamp = _timeStampBase; 00042 _sequenceNumberBase = intrand(0x7fffffff); 00043 _sequenceNumber = _sequenceNumberBase; 00044 };
void RTPPayloadSender::activity | ( | ) | [virtual] |
00047 { 00048 const char *command; 00049 while (true) { 00050 cMessage *msg = receive(); 00051 if (msg->getArrivalGateId() == findGate("fromProfile")) { 00052 RTPInnerPacket *rinpIn = (RTPInnerPacket *)msg; 00053 if (rinpIn->getType() == RTPInnerPacket::RTP_INP_INITIALIZE_SENDER_MODULE) { 00054 initializeSenderModule(rinpIn); 00055 } 00056 else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) { 00057 RTPSenderControlMessage *rscm = (RTPSenderControlMessage *)(rinpIn->decapsulate()); 00058 delete rinpIn; 00059 command = rscm->getCommand(); 00060 if (!opp_strcmp(command, "PLAY")) { 00061 play(); 00062 } 00063 else if (!opp_strcmp(command, "PLAY_UNTIL_TIME")) { 00064 playUntilTime(rscm->getCommandParameter1()); 00065 } 00066 else if (!opp_strcmp(command, "PLAY_UNTIL_BYTE")) { 00067 playUntilByte(rscm->getCommandParameter1()); 00068 } 00069 else if (!opp_strcmp(command, "PAUSE")) { 00070 pause(); 00071 } 00072 else if (!opp_strcmp(command, "STOP")) { 00073 stop(); 00074 } 00075 else if (!opp_strcmp(command, "SEEK_TIME")) { 00076 seekTime(rscm->getCommandParameter1()); 00077 } 00078 else if (!opp_strcmp(command, "SEEK_BYTE")) { 00079 seekByte(rscm->getCommandParameter1()); 00080 } 00081 else { 00082 error("unknown sender control message"); 00083 }; 00084 delete rscm; 00085 } 00086 } 00087 else { 00088 if (!sendPacket()) { 00089 endOfFile(); 00090 } 00091 delete msg; 00092 } 00093 } 00094 };
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(), and RTPAVProfilePayload32Sender::initializeSenderModule().
00097 { 00098 ev << "initializeSenderModule Enter" << endl; 00099 _mtu = rinpIn->getMTU(); 00100 _ssrc = rinpIn->getSSRC(); 00101 const char *fileName = rinpIn->getFileName(); 00102 openSourceFile(fileName); 00103 delete rinpIn; 00104 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleInitialized()"); 00105 rinpOut->senderModuleInitialized(_ssrc, _payloadType, _clockRate, _timeStampBase, _sequenceNumberBase); 00106 send(rinpOut, "toProfile"); 00107 _status = STOPPED; 00108 ev << "initializeSenderModule Exit" << endl; 00109 };
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().
00112 { 00113 _inputFileStream.open(fileName); 00114 if (!_inputFileStream) { 00115 opp_error("sender module: error open data file"); 00116 } 00117 };
void RTPPayloadSender::closeSourceFile | ( | ) | [protected, virtual] |
This method is called by the destructor and closes the data file.
Referenced by ~RTPPayloadSender().
00120 { 00121 _inputFileStream.close(); 00122 };
void RTPPayloadSender::play | ( | ) | [protected, virtual] |
Starts data transmission. Every sender module must implement this method.
Referenced by activity().
00125 { 00126 _status = PLAYING; 00127 RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("PLAYING"); 00128 rssm->setStatus("PLAYING"); 00129 rssm->setTimeStamp(_timeStamp); 00130 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PLAYING)"); 00131 rinpOut->senderModuleStatus(_ssrc, rssm); 00132 send(rinpOut, "toProfile"); 00133 00134 if (!sendPacket()) { 00135 endOfFile(); 00136 } 00137 };
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().
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().
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().
00150 { 00151 cancelEvent(_reminderMessage); 00152 _status = STOPPED; 00153 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PAUSED)"); 00154 RTPSenderStatusMessage *rsim = new RTPSenderStatusMessage(); 00155 rsim->setStatus("PAUSED"); 00156 rinpOut->senderModuleStatus(_ssrc, rsim); 00157 send(rinpOut, "toProfile"); 00158 };
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().
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().
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().
00171 { 00172 cancelEvent(_reminderMessage); 00173 _status = STOPPED; 00174 RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("STOPPED"); 00175 rssm->setStatus("STOPPED"); 00176 RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleStatus(STOPPED)"); 00177 rinp->senderModuleStatus(_ssrc, rssm); 00178 send(rinp, "toProfile"); 00179 };
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().
00182 { 00183 _status = STOPPED; 00184 RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage(); 00185 rssm->setStatus("FINISHED"); 00186 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(FINISHED)"); 00187 rinpOut->senderModuleStatus(_ssrc, rssm); 00188 send(rinpOut, "toProfile"); 00189 };
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().
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().
uint32 RTPPayloadSender::_ssrc [protected] |
The ssrc identifier of this sender module.
Referenced by endOfFile(), initialize(), initializeSenderModule(), pause(), play(), RTPAVProfilePayload32Sender::sendPacket(), and stop().
int RTPPayloadSender::_payloadType [protected] |
The payload type this sender creates.
Referenced by initialize(), RTPAVProfilePayload32Sender::initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().
int RTPPayloadSender::_clockRate [protected] |
The clock rate in ticks per second this sender uses.
Referenced by initialize(), RTPAVProfilePayload32Sender::initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().
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().
uint32 RTPPayloadSender::_timeStamp [protected] |
The current rtp time stamp.
Referenced by initialize(), and play().
uint16 RTPPayloadSender::_sequenceNumberBase [protected] |
The first sequence number used for created rtp data packets. The value is chosen randomly.
Referenced by initialize(), and initializeSenderModule().
uint16 RTPPayloadSender::_sequenceNumber [protected] |
The current sequence number.
Referenced by initialize(), and RTPAVProfilePayload32Sender::sendPacket().
SenderStatus RTPPayloadSender::_status [protected] |
The current state of data transmission.
Referenced by endOfFile(), initializeSenderModule(), pause(), play(), and stop().
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().