Classes | Public Member Functions | Protected Member Functions | Protected Attributes

RTPProfile Class Reference

#include <RTPProfile.h>

Inheritance diagram for RTPProfile:
RTPAVProfile

List of all members.

Classes

class  SSRCGate

Public Member Functions

 RTPProfile ()

Protected Member Functions

virtual void initialize ()
virtual ~RTPProfile ()
virtual void handleMessage (cMessage *msg)
virtual void handleMessageFromRTP (cMessage *msg)
virtual void handleMessageFromPayloadSender (cMessage *msg)
virtual void handleMessageFromPayloadReceiver (cMessage *msg)
virtual void initializeProfile (RTPInnerPacket *rinp)
virtual void createSenderModule (RTPInnerPacket *rinp)
virtual void deleteSenderModule (RTPInnerPacket *rinp)
virtual void senderModuleControl (RTPInnerPacket *rinp)
virtual void dataIn (RTPInnerPacket *rinp)
virtual void senderModuleInitialized (RTPInnerPacket *rinp)
virtual void senderModuleStatus (RTPInnerPacket *rinp)
virtual void dataOut (RTPInnerPacket *rinp)
virtual void processIncomingPacket (RTPInnerPacket *rinp)
virtual void processOutgoingPacket (RTPInnerPacket *rinp)
virtual SSRCGatefindSSRCGate (uint32 ssrc)
virtual SSRCGatenewSSRCGate (uint32 ssrc)

Protected Attributes

const char * _profileName
int _maxReceivers
cArray * _ssrcGates
int _rtcpPercentage
int _preferredPort
int _mtu
bool _autoOutputFileNames

Detailed Description

The class RTPProfile is a module which handles RTPPayloadSender and RTPPayloadReceiver modules. It creates them dynamically on demand. This class offers all functionality for the above tasks, subclasses just need to set variables like profile name, rtcp percentage and preferred port in their initialize() method. The dynamically created sender and receiver modules must have have following class names: RTP<profileName>Payload<payloadType>Sender RTP<profileName>Payload<payloadType>Receiver

Definition at line 40 of file RTPProfile.h.


Constructor & Destructor Documentation

RTPProfile::RTPProfile (  ) 

Definition at line 32 of file RTPProfile.cc.

{
    _ssrcGates = NULL;
}

RTPProfile::~RTPProfile (  )  [protected, virtual]

Definition at line 51 of file RTPProfile.cc.

{
    delete _ssrcGates;
}


Member Function Documentation

void RTPProfile::createSenderModule ( RTPInnerPacket rinp  )  [protected, virtual]

This method is called when the application issued the creation of an rtp payload sender module to transmit data. It creates a new sender module and connects it. The profile module informs the rtp module of having finished this task. Then it initializes the newly create sender module with a inititalizeSenderModule message.

Definition at line 147 of file RTPProfile.cc.

Referenced by handleMessageFromRTP().

{
    ev << "createSenderModule Enter"<<endl;
    int ssrc = rinp->getSSRC();
    int payloadType = rinp->getPayloadType();
    char moduleName[100];

    ev << "ProfileName: " << _profileName << " payloadType: " << payloadType<<endl;
    const char *pkgPrefix = "inet.transport.rtp."; //FIXME hardcoded string
    sprintf(moduleName, "%sRTP%sPayload%iSender", pkgPrefix, _profileName, payloadType);

    cModuleType *moduleType = cModuleType::find(moduleName);
    if (moduleType == NULL)
        opp_error("RTPProfile: payload sender module '%s' not found", moduleName);

    RTPPayloadSender *rtpPayloadSender = (RTPPayloadSender *)(moduleType->create(moduleName, this));
    rtpPayloadSender->finalizeParameters();

    gate("payloadSenderOut")->connectTo(rtpPayloadSender->gate("profileIn"));
    rtpPayloadSender->gate("profileOut")->connectTo(gate("payloadSenderIn"));

    rtpPayloadSender->initialize();
    rtpPayloadSender->scheduleStart(simTime());

    RTPInnerPacket *rinpOut1 = new RTPInnerPacket("senderModuleCreated()");
    rinpOut1->senderModuleCreated(ssrc);
    send(rinpOut1, "rtpOut");

    RTPInnerPacket *rinpOut2 = new RTPInnerPacket("initializeSenderModule()");
    rinpOut2->initializeSenderModule(ssrc, rinp->getFileName(), _mtu);
    send(rinpOut2, "payloadSenderOut");

    delete rinp;
    ev << "createSenderModule Exit"<<endl;
}

void RTPProfile::dataIn ( RTPInnerPacket rinp  )  [protected, virtual]

Handles incoming data packets: If there isn't a receiver module for this sender it creates one. The data packet is forwarded to the receiver module after calling processIncomingPacket.

Definition at line 203 of file RTPProfile.cc.

Referenced by handleMessageFromRTP().

{
    ev << "dataIn(RTPInnerPacket *rinp) Enter"<<endl;
    processIncomingPacket(rinp);

    RTPPacket *packet = check_and_cast<RTPPacket *>(rinp->getEncapsulatedMsg());

    uint32 ssrc = packet->getSSRC();

    SSRCGate *ssrcGate = findSSRCGate(ssrc);

    if (!ssrcGate) {
        ssrcGate = newSSRCGate(ssrc);
        char payloadReceiverName[100];
        const char *pkgPrefix = "inet.transport.rtp."; //FIXME hardcoded string
        sprintf(payloadReceiverName, "%sRTP%sPayload%iReceiver", pkgPrefix, _profileName, packet->getPayloadType());

        cModuleType *moduleType = cModuleType::find(payloadReceiverName);
        if (moduleType == NULL)
            opp_error("Receiver module type %s not found", payloadReceiverName);

        else {
            RTPPayloadReceiver *receiverModule = (RTPPayloadReceiver *)(moduleType->create(payloadReceiverName, this));
            if (_autoOutputFileNames) {
                char outputFileName[100];
                sprintf(outputFileName, "id%i.sim", receiverModule->getId());
                receiverModule->par("outputFileName") = outputFileName;
            }
            receiverModule->finalizeParameters();

            this->gate(ssrcGate->getGateId())->connectTo(receiverModule->gate("profileIn"));
            receiverModule->gate("profileOut")->connectTo(this->gate(ssrcGate->getGateId() - findGate("payloadReceiverOut",0) + findGate("payloadReceiverIn",0)));

            receiverModule->callInitialize(0);
            receiverModule->scheduleStart(simTime());
        }
    }

    send(rinp, ssrcGate->getGateId());
    ev << "dataIn(RTPInnerPacket *rinp) Exit"<<endl;
}

void RTPProfile::dataOut ( RTPInnerPacket rinp  )  [protected, virtual]

Handles outgoing data packets: Calls processOutgoingPacket and forwards the packet to the rtp module.

Definition at line 246 of file RTPProfile.cc.

Referenced by handleMessageFromPayloadSender().

{
    processOutgoingPacket(rinp);
    send(rinp, "rtpOut");
}

void RTPProfile::deleteSenderModule ( RTPInnerPacket rinp  )  [protected, virtual]

When a sender module is no longer needed it can be deleted by the profile module.

Definition at line 184 of file RTPProfile.cc.

Referenced by handleMessageFromRTP().

{
    cModule *senderModule = gate("payloadSenderOut")->getNextGate()->getOwnerModule();
    senderModule->deleteModule();

    RTPInnerPacket *rinpOut = new RTPInnerPacket("senderModuleDeleted()");
    rinpOut->senderModuleDeleted(rinpIn->getSSRC());
    delete rinpIn;

    send(rinpOut, "rtpOut");
}

RTPProfile::SSRCGate * RTPProfile::findSSRCGate ( uint32  ssrc  )  [protected, virtual]

Finds the gate of the receiver module for rtp data packets from this ssrc.

Definition at line 279 of file RTPProfile.cc.

Referenced by dataIn().

{
    const char *name = RTPParticipantInfo::ssrcToName(ssrc);
    int objectIndex = _ssrcGates->find(name);
    if (objectIndex == -1) {
        return NULL;
    }
    else {
        cObject *co = (_ssrcGates->get(objectIndex));
        return (SSRCGate *)co;
    }
}

void RTPProfile::handleMessage ( cMessage *  msg  )  [protected, virtual]

Creates and removes payload sender and receiver modules on demand.

Definition at line 57 of file RTPProfile.cc.

{
    if (msg->getArrivalGateId() == findGate("rtpIn")) {
        handleMessageFromRTP(msg);
    }

    else if (msg->getArrivalGateId() == findGate("payloadSenderIn")) {
        handleMessageFromPayloadSender(msg);
    }

    else if (msg->getArrivalGateId() >= findGate("payloadReceiverIn") && msg->getArrivalGateId() < findGate("payloadReceiverIn") + _maxReceivers) {
        handleMessageFromPayloadReceiver(msg);
    }

    else {
        error("message coming from unknown gate");
    }

}

void RTPProfile::handleMessageFromPayloadReceiver ( cMessage *  msg  )  [protected, virtual]

Handles messages coming from a receiver module.

Definition at line 128 of file RTPProfile.cc.

Referenced by handleMessage().

{
    // currently payload receiver modules don't send messages
    delete msg;
}

void RTPProfile::handleMessageFromPayloadSender ( cMessage *  msg  )  [protected, virtual]

Handles messages coming from the sender module.

Definition at line 107 of file RTPProfile.cc.

Referenced by handleMessage().

{

    RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);

    if (rinpIn->getType() == RTPInnerPacket::RTP_INP_DATA_OUT) {
        dataOut(rinpIn);
    }
    else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_INITIALIZED) {
        senderModuleInitialized(rinpIn);
    }
    else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_STATUS) {
        senderModuleStatus(rinpIn);
    }
    else {
        error("Profile received RTPInnerPacket from sender module with wrong type");
    }

}

void RTPProfile::handleMessageFromRTP ( cMessage *  msg  )  [protected, virtual]

Handles messages received from the rtp module.

Definition at line 78 of file RTPProfile.cc.

Referenced by handleMessage().

{
    ev << "handleMessageFromRTP Enter "<<endl;

    RTPInnerPacket *rinpIn = check_and_cast<RTPInnerPacket *>(msg);

    if (rinpIn->getType() == RTPInnerPacket::RTP_INP_INITIALIZE_PROFILE) {
        initializeProfile(rinpIn);
    }
    else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_CREATE_SENDER_MODULE) {
        createSenderModule(rinpIn);
    }
    else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_DELETE_SENDER_MODULE) {
        deleteSenderModule(rinpIn);
    }
    else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CONTROL) {
        senderModuleControl(rinpIn);
    }
    else if (rinpIn->getType() == RTPInnerPacket::RTP_INP_DATA_IN) {
        dataIn(rinpIn);
    }
    else {
        error("RTPInnerPacket from RTPModule has wrong type");
    }

    ev << "handleMessageFromRTP Exit "<<endl;
}

void RTPProfile::initialize (  )  [protected, virtual]

Initializes variables. Must be overwritten by subclasses.

Reimplemented in RTPAVProfile.

Definition at line 37 of file RTPProfile.cc.

{
    ev << "initialize() Enter"<<endl;
    _profileName = "Profile";
    _rtcpPercentage = 5;
    _preferredPort = PORT_UNDEF;

    // how many gates to payload receivers do we have
    _maxReceivers = gateSize("payloadReceiverOut");
    _ssrcGates = new cArray("SSRCGates");
    _autoOutputFileNames = par("autoOutputFileNames").boolValue();
    ev << "initialize() Exit"<<endl;
}

void RTPProfile::initializeProfile ( RTPInnerPacket rinp  )  [protected, virtual]

Initialization message received from rtp module.

Definition at line 135 of file RTPProfile.cc.

Referenced by handleMessageFromRTP().

{
    ev << "initializeProfile Enter"<<endl;
    _mtu = rinp->getMTU();
    delete rinp;
    RTPInnerPacket *rinpOut = new RTPInnerPacket("profileInitialized()");
    rinpOut->profileInitialized(_rtcpPercentage, _preferredPort);
    send(rinpOut, "rtpOut");
    ev << "initializeProfile Exit"<<endl;
}

RTPProfile::SSRCGate * RTPProfile::newSSRCGate ( uint32  ssrc  )  [protected, virtual]

Creates a new association ssrc/gateId for this ssrc.

Definition at line 293 of file RTPProfile.cc.

Referenced by dataIn().

{
    SSRCGate *ssrcGate = new SSRCGate(ssrc);
    bool assigned = false;
    int receiverGateId = findGate("payloadReceiverOut",0);
    for (int i = receiverGateId; i < receiverGateId + _maxReceivers && !assigned; i++) {
        if (!gate(i)->isConnected()) {
            ssrcGate->setGateId(i);
            assigned = true;
        }
    }

    if (!assigned)
        opp_error("Can't manage more senders");

    _ssrcGates->add(ssrcGate);
    return ssrcGate;
}

void RTPProfile::processIncomingPacket ( RTPInnerPacket rinp  )  [protected, virtual]

Every time a rtp packet is received it it pre-processed by this method to remove profile specific extension which are not handled by the payload receiver module. In this implementation the packet isn't changed. Important: This method works with RTPInnerPacket. So the rtp packet must be decapsulated, changed and encapsulated again.

Definition at line 267 of file RTPProfile.cc.

Referenced by dataIn().

{
    // do nothing with the packet
}

void RTPProfile::processOutgoingPacket ( RTPInnerPacket rinp  )  [protected, virtual]

Simular to the procedure for incoming packets, this adds profile specific extensions to outgoing rtp packets.

Definition at line 273 of file RTPProfile.cc.

Referenced by dataOut().

{
    // do nothing with the packet
}

void RTPProfile::senderModuleControl ( RTPInnerPacket rinp  )  [protected, virtual]

The profile module forwards sender control messages to the sender module.

Definition at line 197 of file RTPProfile.cc.

Referenced by handleMessageFromRTP().

{
    send(rinp, "payloadSenderOut");
}

void RTPProfile::senderModuleInitialized ( RTPInnerPacket rinp  )  [protected, virtual]

The sender module returns a senderModuleInitialized message after being initialized. The profile module forwards this message to the rtp module which delivers it to its destination, the rtcp module.

Definition at line 253 of file RTPProfile.cc.

Referenced by handleMessageFromPayloadSender().

{
    ev << "senderModuleInitialized"<<endl;
    send(rinp, "rtpOut");
}

void RTPProfile::senderModuleStatus ( RTPInnerPacket rinp  )  [protected, virtual]

After having received a sender module control message the sender module returns a sender status message to inform the application what it's doing at the moment.

Definition at line 260 of file RTPProfile.cc.

Referenced by handleMessageFromPayloadSender().

{
    ev << "senderModuleStatus"<<endl;
    send(rinp, "rtpOut");
}


Member Data Documentation

If this is set true the RTPProfile automatically sets the output file name for payload receiver modules so the user is not bothered to set them manually during simulation runtime.

Definition at line 212 of file RTPProfile.h.

Referenced by dataIn(), and initialize().

int RTPProfile::_maxReceivers [protected]

The maximum number of incoming data streams this profile module can handle. It is set to the gate size of "payloadReceiverOut", "payloadReceiverIn".

Definition at line 184 of file RTPProfile.h.

Referenced by handleMessage(), initialize(), and newSSRCGate().

int RTPProfile::_mtu [protected]

The maximum size an RTPPacket can have.

Definition at line 205 of file RTPProfile.h.

Referenced by createSenderModule(), and initializeProfile().

int RTPProfile::_preferredPort [protected]

The rtp port this profile uses if no port is given.

Definition at line 200 of file RTPProfile.h.

Referenced by initialize(), RTPAVProfile::initialize(), and initializeProfile().

const char* RTPProfile::_profileName [protected]

The name of this profile. Needed for dynamic creating of sender and receiver modules.

Definition at line 177 of file RTPProfile.h.

Referenced by createSenderModule(), dataIn(), initialize(), and RTPAVProfile::initialize().

int RTPProfile::_rtcpPercentage [protected]

The percentage of the available bandwidth to be used for rtcp.

Definition at line 195 of file RTPProfile.h.

Referenced by initialize(), RTPAVProfile::initialize(), and initializeProfile().

cArray* RTPProfile::_ssrcGates [protected]

Stores information to which gate rtp data packets from a ssrc must be forwarded.

Definition at line 190 of file RTPProfile.h.

Referenced by findSSRCGate(), initialize(), newSSRCGate(), RTPProfile(), and ~RTPProfile().


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