Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

RTPPayloadSender Class Reference

#include <RTPPayloadSender.h>

Inheritance diagram for RTPPayloadSender:
RTPAVProfilePayload32Sender

List of all members.

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

Detailed Description

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.

Definition at line 37 of file RTPPayloadSender.h.


Member Enumeration Documentation

A sender module's transmission can be in different states.

Enumerator:
STOPPED 
PLAYING 

Data is being sent.

Definition at line 63 of file RTPPayloadSender.h.

                          {
            STOPPED, //< No transmission.
            PLAYING  
        };


Constructor & Destructor Documentation

RTPPayloadSender::RTPPayloadSender (  )  [inline]

Constructor, with activity() stack size.

Definition at line 45 of file RTPPayloadSender.h.

: cSimpleModule(32768) {}

RTPPayloadSender::~RTPPayloadSender (  )  [virtual]

Cleaning up. Calls closeSourceFile.

Definition at line 29 of file RTPPayloadSender.cc.


Member Function Documentation

void RTPPayloadSender::activity (  )  [virtual]

Definition at line 49 of file RTPPayloadSender.cc.

{
    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.

Definition at line 125 of file RTPPayloadSender.cc.

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().

Definition at line 195 of file RTPPayloadSender.cc.

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.

Definition at line 35 of file RTPPayloadSender.cc.

Referenced by RTPProfile::createSenderModule().

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.

Definition at line 100 of file RTPPayloadSender.cc.

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.

Definition at line 116 of file RTPPayloadSender.cc.

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.

Definition at line 159 of file RTPPayloadSender.cc.

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.

Definition at line 131 of file RTPPayloadSender.cc.

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.

Definition at line 153 of file RTPPayloadSender.cc.

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.

Definition at line 147 of file RTPPayloadSender.cc.

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.

Definition at line 177 of file RTPPayloadSender.cc.

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.

Definition at line 171 of file RTPPayloadSender.cc.

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.

Definition at line 206 of file RTPPayloadSender.cc.

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.

Definition at line 183 of file RTPPayloadSender.cc.

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");
}


Member Data Documentation

The clock rate in ticks per second this sender uses.

Definition at line 93 of file RTPPayloadSender.h.

Referenced by initialize(), RTPAVProfilePayload32Sender::initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().

std::ifstream RTPPayloadSender::_inputFileStream [protected]

The input file stream for the data file.

Definition at line 73 of file RTPPayloadSender.h.

Referenced by closeSourceFile(), RTPAVProfilePayload32Sender::initializeSenderModule(), openSourceFile(), and RTPAVProfilePayload32Sender::sendPacket().

int RTPPayloadSender::_mtu [protected]

The maximum size of an RTPPacket.

Definition at line 78 of file RTPPayloadSender.h.

Referenced by initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().

The payload type this sender creates.

Definition at line 88 of file RTPPayloadSender.h.

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.

Definition at line 127 of file RTPPayloadSender.h.

Referenced by pause(), RTPAVProfilePayload32Sender::sendPacket(), and stop().

The current sequence number.

Definition at line 115 of file RTPPayloadSender.h.

Referenced by initialize(), and RTPAVProfilePayload32Sender::sendPacket().

The first sequence number used for created rtp data packets. The value is chosen randomly.

Definition at line 110 of file RTPPayloadSender.h.

Referenced by initialize(), and initializeSenderModule().

uint32 RTPPayloadSender::_ssrc [protected]

The ssrc identifier of this sender module.

Definition at line 83 of file RTPPayloadSender.h.

Referenced by endOfFile(), initialize(), initializeSenderModule(), pause(), play(), RTPAVProfilePayload32Sender::sendPacket(), and stop().

The current state of data transmission.

Definition at line 120 of file RTPPayloadSender.h.

Referenced by endOfFile(), initializeSenderModule(), pause(), play(), and stop().

uint32 RTPPayloadSender::_timeStamp [protected]

The current rtp time stamp.

Definition at line 104 of file RTPPayloadSender.h.

Referenced by initialize(), and play().

The first rtp time stamp used for created rtp data packets. The value is chosen randomly.

Definition at line 99 of file RTPPayloadSender.h.

Referenced by initialize(), initializeSenderModule(), and RTPAVProfilePayload32Sender::sendPacket().


The documentation for this class was generated from the following files: