#include <RTPPayloadSender.h>
Inheritance diagram for RTPPayloadSender:
Public Types | |
STOPPED | |
PLAYING | |
Data is being sent. | |
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 |
u_int32 | _ssrc |
int | _payloadType |
int | _clockRate |
u_int32 | _timeStampBase |
u_int32 | _timeStamp |
u_int16 | _sequenceNumberBase |
u_int16 | _sequenceNumber |
SenderStatus | _status |
cMessage * | _reminderMessage |
RTPPayloadSender::RTPPayloadSender | ( | ) | [inline] |
RTPPayloadSender::~RTPPayloadSender | ( | ) | [virtual] |
void RTPPayloadSender::activity | ( | ) | [virtual] |
00048 { 00049 const char *command; 00050 while (true) { 00051 cMessage *msg = receive(); 00052 if (msg->arrivalGateId() == findGate("fromProfile")) { 00053 RTPInnerPacket *rinpIn = (RTPInnerPacket *)msg; 00054 if (rinpIn->type() == RTPInnerPacket::RTP_INP_INITIALIZE_SENDER_MODULE) { 00055 initializeSenderModule(rinpIn); 00056 } 00057 else if (rinpIn->type() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) { 00058 RTPSenderControlMessage *rscm = (RTPSenderControlMessage *)(rinpIn->decapsulate()); 00059 delete rinpIn; 00060 command = rscm->command(); 00061 if (!opp_strcmp(command, "PLAY")) { 00062 play(); 00063 } 00064 else if (!opp_strcmp(command, "PLAY_UNTIL_TIME")) { 00065 playUntilTime(rscm->commandParameter1()); 00066 } 00067 else if (!opp_strcmp(command, "PLAY_UNTIL_BYTE")) { 00068 playUntilByte(rscm->commandParameter1()); 00069 } 00070 else if (!opp_strcmp(command, "PAUSE")) { 00071 pause(); 00072 } 00073 else if (!opp_strcmp(command, "STOP")) { 00074 stop(); 00075 } 00076 else if (!opp_strcmp(command, "SEEK_TIME")) { 00077 seekTime(rscm->commandParameter1()); 00078 } 00079 else if (!opp_strcmp(command, "SEEK_BYTE")) { 00080 seekByte(rscm->commandParameter1()); 00081 } 00082 else { 00083 EV << "sender module: unknown sender control message" << endl; 00084 }; 00085 delete rscm; 00086 } 00087 } 00088 else { 00089 if (!sendPacket()) { 00090 endOfFile(); 00091 } 00092 delete msg; 00093 } 00094 } 00095 };
void RTPPayloadSender::closeSourceFile | ( | ) | [protected, virtual] |
This method is called by the destructor and closes the data file.
Reimplemented in RTPAVProfileSampleBasedAudioSender.
00119 { 00120 _inputFileStream.close(); 00121 };
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().
00181 { 00182 _status = STOPPED; 00183 RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage(); 00184 rssm->setStatus("FINISHED"); 00185 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(FINISHED)"); 00186 rinpOut->senderModuleStatus(_ssrc, rssm); 00187 send(rinpOut, "toProfile"); 00188 };
void RTPPayloadSender::initialize | ( | ) | [virtual] |
Chooses sequence number and time stamp base values and reads the omnet parameter "mtu".
Reimplemented in RTPAVProfilePayload10Sender, and RTPAVProfilePayload32Sender.
00035 { 00036 cSimpleModule::initialize(); 00037 _mtu = 0; 00038 _ssrc = 0; 00039 _payloadType = 0; 00040 _clockRate = 0; 00041 _timeStampBase = intrand(65535); 00042 _timeStamp = _timeStampBase; 00043 _sequenceNumberBase = intrand(0x7fffffff); 00044 _sequenceNumber = _sequenceNumberBase; 00045 };
void RTPPayloadSender::initializeSenderModule | ( | RTPInnerPacket * | ) | [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, and RTPAVProfileSampleBasedAudioSender.
00098 { 00099 _mtu = rinpIn->mtu(); 00100 _ssrc = rinpIn->ssrc(); 00101 const char *fileName = rinpIn->fileName(); 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 };
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.
Reimplemented in RTPAVProfileSampleBasedAudioSender.
00111 { 00112 _inputFileStream.open(fileName); 00113 if (!_inputFileStream) { 00114 opp_error("sender module: error open data file"); 00115 } 00116 };
void RTPPayloadSender::pause | ( | ) | [protected, virtual] |
When data is being transmitted this methods suspends till a new PLAY command. Implementation in sender modules is optional.
00149 { 00150 cancelEvent(_reminderMessage); 00151 _status = STOPPED; 00152 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PAUSED)"); 00153 RTPSenderStatusMessage *rsim = new RTPSenderStatusMessage(); 00154 rsim->setStatus("PAUSED"); 00155 rinpOut->senderModuleStatus(_ssrc, rsim); 00156 send(rinpOut, "toProfile"); 00157 };
void RTPPayloadSender::play | ( | ) | [protected, virtual] |
Starts data transmission. Every sender module must implement this method.
Reimplemented in RTPAVProfileSampleBasedAudioSender.
00124 { 00125 _status = PLAYING; 00126 RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("PLAYING"); 00127 rssm->setStatus("PLAYING"); 00128 rssm->setTimeStamp(_timeStamp); 00129 RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PLAYING)"); 00130 rinpOut->senderModuleStatus(_ssrc, rssm); 00131 send(rinpOut, "toProfile"); 00132 00133 if (!sendPacket()) { 00134 endOfFile(); 00135 } 00136 };
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.
00144 { 00145 EV << "sender module: playUntilByte() not implemented" << endl; 00146 };
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.
00139 { 00140 EV << "sender module: playUntilTime() not implemented" << endl; 00141 };
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.
Reimplemented in RTPAVProfileSampleBasedAudioSender.
00165 { 00166 EV << "sender module: seekByte() not implemented" << endl; 00167 };
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.
Reimplemented in RTPAVProfileSampleBasedAudioSender.
00160 { 00161 EV << "sender module: seekTime() not implemented" << endl; 00162 };
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, and RTPAVProfileSampleBasedAudioSender.
00191 { 00192 EV << "sender module: sendPacket() not implemented" << endl; 00193 return false; 00194 };
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.
Reimplemented in RTPAVProfileSampleBasedAudioSender.
00170 { 00171 cancelEvent(_reminderMessage); 00172 _status = STOPPED; 00173 RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("STOPPED"); 00174 rssm->setStatus("STOPPED"); 00175 RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleStatus(STOPPED)"); 00176 rinp->senderModuleStatus(_ssrc, rssm); 00177 send(rinp, "toProfile"); 00178 };
int RTPPayloadSender::_clockRate [protected] |
The clock rate in ticks per second this sender uses.
std::ifstream RTPPayloadSender::_inputFileStream [protected] |
The input file stream for the data file.
int RTPPayloadSender::_mtu [protected] |
The maximum size of an RTPPacket.
int RTPPayloadSender::_payloadType [protected] |
The payload type this sender creates.
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.
u_int16 RTPPayloadSender::_sequenceNumber [protected] |
The current sequence number.
u_int16 RTPPayloadSender::_sequenceNumberBase [protected] |
The first sequence number used for created rtp data packets. The value is chosen randomly.
u_int32 RTPPayloadSender::_ssrc [protected] |
The ssrc identifier of this sender module.
SenderStatus RTPPayloadSender::_status [protected] |
The current state of data transmission.
u_int32 RTPPayloadSender::_timeStamp [protected] |
The current rtp time stamp.
u_int32 RTPPayloadSender::_timeStampBase [protected] |
The first rtp time stamp used for created rtp data packets. The value is chosen randomly.