RTPPayloadSender.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           RTPPayloadSender.cc  -  description
00003                              -------------------
00004     (C) 2007 Ahmed Ayadi  <ahmed.ayadi@sophia.inria.fr>
00005     (C) 2001 Matthias Oppitz, Arndt Buschmann <Matthias.Oppitz@gmx.de> <a.buschmann@gmx.de>
00006 
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00023 #include "RTPPayloadSender.h"
00024 
00025 
00026 Define_Module(RTPPayloadSender);
00027 
00028 
00029 RTPPayloadSender::~RTPPayloadSender()
00030 {
00031     closeSourceFile();
00032 }
00033 
00034 
00035 void RTPPayloadSender::initialize()
00036 {
00037     cSimpleModule::initialize();
00038     _mtu = 0;
00039     _ssrc = 0;
00040     _payloadType = 0;
00041     _clockRate = 0;
00042     _timeStampBase = intrand(65535);
00043     _timeStamp = _timeStampBase;
00044     _sequenceNumberBase = intrand(0x7fffffff);
00045     _sequenceNumber = _sequenceNumberBase;
00046 }
00047 
00048 
00049 void RTPPayloadSender::activity()
00050 {
00051     const char *command;
00052     while (true) {
00053         cMessage *msg = receive();
00054         if (msg->getArrivalGateId() == findGate("profileIn")) {
00055             RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);
00056             if (rinpIn->getType() == RTPInnerPacket::RTP_INP_INITIALIZE_SENDER_MODULE) {
00057                 initializeSenderModule(rinpIn);
00058             }
00059             else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) {
00060                 RTPSenderControlMessage *rscm = (RTPSenderControlMessage *)(rinpIn->decapsulate());
00061                 delete rinpIn;
00062                 command = rscm->getCommand();
00063                 if (!opp_strcmp(command, "PLAY")) {
00064                     play();
00065                 }
00066                 else if (!opp_strcmp(command, "PLAY_UNTIL_TIME")) {
00067                     playUntilTime(rscm->getCommandParameter1());
00068                 }
00069                 else if (!opp_strcmp(command, "PLAY_UNTIL_BYTE")) {
00070                     playUntilByte(rscm->getCommandParameter1());
00071                 }
00072                 else if (!opp_strcmp(command, "PAUSE")) {
00073                     pause();
00074                 }
00075                 else if (!opp_strcmp(command, "STOP")) {
00076                     stop();
00077                 }
00078                 else if (!opp_strcmp(command, "SEEK_TIME")) {
00079                     seekTime(rscm->getCommandParameter1());
00080                 }
00081                 else if (!opp_strcmp(command, "SEEK_BYTE")) {
00082                     seekByte(rscm->getCommandParameter1());
00083                 }
00084                 else {
00085                     error("unknown sender control message");
00086                 }
00087                 delete rscm;
00088             }
00089         }
00090         else {
00091             if (!sendPacket()) {
00092                 endOfFile();
00093             }
00094             delete msg;
00095         }
00096     }
00097 }
00098 
00099 
00100 void RTPPayloadSender::initializeSenderModule(RTPInnerPacket *rinpIn)
00101 {
00102     ev << "initializeSenderModule Enter" << endl;
00103     _mtu = rinpIn->getMTU();
00104     _ssrc = rinpIn->getSSRC();
00105     const char *fileName = rinpIn->getFileName();
00106     openSourceFile(fileName);
00107     delete rinpIn;
00108     RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleInitialized()");
00109     rinpOut->senderModuleInitialized(_ssrc, _payloadType, _clockRate, _timeStampBase, _sequenceNumberBase);
00110     send(rinpOut, "profileOut");
00111     _status = STOPPED;
00112     ev << "initializeSenderModule Exit" << endl;
00113 }
00114 
00115 
00116 void RTPPayloadSender::openSourceFile(const char *fileName)
00117 {
00118     _inputFileStream.open(fileName);
00119     if (!_inputFileStream) {
00120         opp_error("sender module: error open data file");
00121     }
00122 }
00123 
00124 
00125 void RTPPayloadSender::closeSourceFile()
00126 {
00127     _inputFileStream.close();
00128 }
00129 
00130 
00131 void RTPPayloadSender::play()
00132 {
00133     _status = PLAYING;
00134     RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("PLAYING");
00135     rssm->setStatus("PLAYING");
00136     rssm->setTimeStamp(_timeStamp);
00137     RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PLAYING)");
00138     rinpOut->senderModuleStatus(_ssrc, rssm);
00139     send(rinpOut, "profileOut");
00140 
00141     if (!sendPacket()) {
00142         endOfFile();
00143     }
00144 }
00145 
00146 
00147 void RTPPayloadSender::playUntilTime(simtime_t moment)
00148 {
00149     error("playUntilTime() not implemented");
00150 }
00151 
00152 
00153 void RTPPayloadSender::playUntilByte(int position)
00154 {
00155     error("playUntilByte() not implemented");
00156 }
00157 
00158 
00159 void RTPPayloadSender::pause()
00160 {
00161     cancelEvent(_reminderMessage);
00162     _status = STOPPED;
00163     RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(PAUSED)");
00164     RTPSenderStatusMessage *rsim = new RTPSenderStatusMessage();
00165     rsim->setStatus("PAUSED");
00166     rinpOut->senderModuleStatus(_ssrc, rsim);
00167     send(rinpOut, "profileOut");
00168 }
00169 
00170 
00171 void RTPPayloadSender::seekTime(simtime_t moment)
00172 {
00173     error("seekTime() not implemented");
00174 }
00175 
00176 
00177 void RTPPayloadSender::seekByte(int position)
00178 {
00179     error("seekByte() not implemented");
00180 }
00181 
00182 
00183 void RTPPayloadSender::stop()
00184 {
00185     cancelEvent(_reminderMessage);
00186     _status = STOPPED;
00187     RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage("STOPPED");
00188     rssm->setStatus("STOPPED");
00189     RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleStatus(STOPPED)");
00190     rinp->senderModuleStatus(_ssrc, rssm);
00191     send(rinp, "profileOut");
00192 }
00193 
00194 
00195 void RTPPayloadSender::endOfFile()
00196 {
00197     _status = STOPPED;
00198     RTPSenderStatusMessage *rssm = new RTPSenderStatusMessage();
00199     rssm->setStatus("FINISHED");
00200     RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleStatus(FINISHED)");
00201     rinpOut->senderModuleStatus(_ssrc, rssm);
00202     send(rinpOut, "profileOut");
00203 }
00204 
00205 
00206 bool RTPPayloadSender::sendPacket()
00207 {
00208     error("sendPacket() not implemented");
00209     return false;
00210 }