INET Framework for OMNeT++/OMNEST
RTP Class Reference

#include <RTP.h>

List of all members.

Protected Member Functions

virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void handleMessageFromApp (cMessage *msg)
virtual void handleMessageFromProfile (cMessage *msg)
virtual void handleMessageFromRTCP (cMessage *msg)
virtual void handleMessagefromUDP (cMessage *msg)
virtual void enterSession (RTPInterfacePacket *rifp)
virtual void leaveSession (RTPInterfacePacket *rifp)
virtual void createSenderModule (RTPInterfacePacket *rifp)
virtual void deleteSenderModule (RTPInterfacePacket *rifp)
virtual void senderModuleControl (RTPInterfacePacket *rifp)
virtual void profileInitialized (RTPInnerPacket *rinp)
virtual void senderModuleCreated (RTPInnerPacket *rinp)
virtual void senderModuleDeleted (RTPInnerPacket *rinp)
virtual void senderModuleInitialized (RTPInnerPacket *rinp)
virtual void senderModuleStatus (RTPInnerPacket *rinp)
virtual void dataOut (RTPInnerPacket *rinp)
virtual void rtcpInitialized (RTPInnerPacket *rinp)
virtual void sessionLeft (RTPInnerPacket *rinp)
virtual void createProfile ()
virtual void createSocket ()
virtual void socketRet ()
virtual void connectRet ()
virtual void readRet (cMessage *sifp)
virtual void initializeProfile ()
virtual void initializeRTCP ()
virtual int resolveMTU ()

Protected Attributes

const char * _commonName
const char * _profileName
int _bandwidth
IPAddress _destinationAddress
int _port
int _mtu
int _rtcpPercentage
int _socketFdIn
int _socketFdOut
bool _leaveSession

Detailed Description

An RTP is the center of the rtp layer of an endsystem. It creates the profile module, sends and receives rtp data packets and forwards messages. It also communicates with the application.


Member Function Documentation

void RTP::connectRet ( ) [protected, virtual]

Called when the socket layer has connected a socket.

Referenced by createSocket().

void RTP::createProfile ( ) [protected, virtual]

Creates the profile module.

Referenced by enterSession().

{
    cModuleType *moduleType = cModuleType::find(_profileName);
    if (moduleType == NULL)
        error("Profile type `%s' not found", _profileName);

    RTPProfile *profile = check_and_cast<RTPProfile *>(moduleType->create("Profile", this));
    profile->finalizeParameters();

    profile->setGateSize("payloadReceiverOut", 30);
    profile->setGateSize("payloadReceiverIn", 30);

    this->gate("profileOut")->connectTo(profile->gate("rtpIn"));
    profile->gate("rtpOut")->connectTo(this->gate("profileIn"));

    profile->callInitialize();
    profile->scheduleStart(simTime());
}
void RTP::createSenderModule ( RTPInterfacePacket rifp) [protected, virtual]

Referenced by handleMessageFromApp().

{
    RTPInnerPacket *rinp = new RTPInnerPacket("createSenderModule()");
    ev << rifp->getSSRC()<<endl;
    rinp->createSenderModule(rifp->getSSRC(), rifp->getPayloadType(), rifp->getFileName());
    send(rinp, "profileOut");

    delete rifp;
}
void RTP::createSocket ( ) [protected, virtual]

Requests a server socket from the UDP layer.

Referenced by profileInitialized().

{
    // TODO UDPAppBase should be ported to use UDPSocket sometime, but for now
    // we just manage the UDP socket by hand...
    if (_socketFdIn == -1) {
        _socketFdIn = UDPSocket::generateSocketId();

        UDPControlInfo *ctrl = new UDPControlInfo();

        IPAddress ipaddr(_destinationAddress);

        if (ipaddr.isMulticast()) {
            ctrl->setSrcAddr(IPAddress(_destinationAddress));
            ctrl->setSrcPort(_port);
        }
        else {
             ctrl->setSrcPort(_port);
             ctrl->setSockId(_socketFdOut);
        }
        ctrl->setSockId((int)_socketFdIn);
        cMessage *msg = new cMessage("UDP_C_BIND", UDP_C_BIND);
        msg->setControlInfo(ctrl);
        send(msg,"udpOut");

        connectRet();
    }
}
void RTP::dataOut ( RTPInnerPacket rinp) [protected, virtual]

Sends a rtp data packet to the UDP layer and a copy of it to the rtcp module.

Referenced by handleMessageFromProfile().

{
    RTPPacket *msg = check_and_cast<RTPPacket *>(rinp->decapsulate());

    // send message to UDP, with the appropriate control info attached
    msg->setKind(UDP_C_DATA);

    UDPControlInfo *ctrl = new UDPControlInfo();
    ctrl->setDestAddr(_destinationAddress);
    ctrl->setDestPort(_port);
    msg->setControlInfo(ctrl);

//     ev << "Sending packet: ";msg->dump();
    send(msg, "udpOut");

    // RTCP module must be informed about sent rtp data packet

    RTPInnerPacket *rinpOut = new RTPInnerPacket(*rinp);
    rinpOut->encapsulate(new RTPPacket(*msg));
    send(rinpOut, "rtcpOut");

    delete rinp;
}
void RTP::deleteSenderModule ( RTPInterfacePacket rifp) [protected, virtual]

Referenced by handleMessageFromApp().

{
    RTPInnerPacket *rinp = new RTPInnerPacket("deleteSenderModule()");
    rinp->deleteSenderModule(rifp->getSSRC());
    send(rinp, "profileOut");

    delete rifp;
}
void RTP::enterSession ( RTPInterfacePacket rifp) [protected, virtual]

Creates the profile module and initializes it.

Referenced by handleMessageFromApp().

{
    _profileName = rifp->getProfileName();
    _commonName = rifp->getCommonName();
    _bandwidth = rifp->getBandwidth();
    _destinationAddress = rifp->getDestinationAddress();

    _port = rifp->getPort();
    if (_port % 2 != 0) {
        _port = _port - 1;
    }

    _mtu = resolveMTU();

    createProfile();
    initializeProfile();
    delete rifp;
}
void RTP::handleMessage ( cMessage *  msg) [protected, virtual]

Handles incoming messages.

{
    if (msg->getArrivalGateId() == findGate("appIn")) {
        handleMessageFromApp(msg);
    }
    else if (msg->getArrivalGateId() == findGate("profileIn")) {
        handleMessageFromProfile(msg);
    }
    else if (msg->getArrivalGateId() == findGate("rtcpIn")) {
        handleMessageFromRTCP(msg);
    }
    else if (msg->getArrivalGateId() == findGate("udpIn")) {
        handleMessagefromUDP(msg);
    }
    else {
        error("Message from unknown gate");
    }
}
void RTP::handleMessageFromApp ( cMessage *  msg) [protected, virtual]

Handles messages received from the applicaiton.

Referenced by handleMessage().

{
    RTPInterfacePacket *rifp = check_and_cast<RTPInterfacePacket *>(msg);
    if (rifp->getType() == RTPInterfacePacket::RTP_IFP_ENTER_SESSION) {
        enterSession(rifp);
    }
    else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_CREATE_SENDER_MODULE) {
        createSenderModule(rifp);
    }
    else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_DELETE_SENDER_MODULE) {
        deleteSenderModule(rifp);
    }
    else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_SENDER_CONTROL) {
        senderModuleControl(rifp);
    }
    else if (rifp->getType() == RTPInterfacePacket::RTP_IFP_LEAVE_SESSION) {
        leaveSession(rifp);
    }
    else {
        error("unknown RTPInterfacePacket type from application");
    }
}
void RTP::handleMessageFromProfile ( cMessage *  msg) [protected, virtual]

Handles messages received from the profile module.

Referenced by handleMessage().

{
    RTPInnerPacket *rinp = check_and_cast<RTPInnerPacket *>(msg);
    if (rinp->getType() == RTPInnerPacket::RTP_INP_PROFILE_INITIALIZED) {
        profileInitialized(rinp);
    }
    else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_CREATED) {
        senderModuleCreated(rinp);
    }
    else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_DELETED) {
        senderModuleDeleted(rinp);
    }
    else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_INITIALIZED) {
        senderModuleInitialized(rinp);
    }
    else if (rinp->getType() == RTPInnerPacket::RTP_INP_SENDER_MODULE_STATUS) {
        senderModuleStatus(rinp);
    }
    else if (rinp->getType() == RTPInnerPacket::RTP_INP_DATA_OUT) {
        dataOut(rinp);
    }
    else {
        delete msg;
    }
    ev << "handleMessageFromProfile(cMessage *msg) Exit"<<endl;
}
void RTP::handleMessageFromRTCP ( cMessage *  msg) [protected, virtual]

Handles messages received from the rtcp module.

Referenced by handleMessage().

{
    RTPInnerPacket *rinp = check_and_cast<RTPInnerPacket *>(msg);
    if (rinp->getType() == RTPInnerPacket::RTP_INP_RTCP_INITIALIZED) {
        rtcpInitialized(rinp);
    }
    else if (rinp->getType() == RTPInnerPacket::RTP_INP_SESSION_LEFT) {
        sessionLeft(rinp);
    }
    else {
        error("Unknown RTPInnerPacket type %d from rtcp", rinp->getType());
    }
}
void RTP::handleMessagefromUDP ( cMessage *  msg) [protected, virtual]

Handles messages received from the UDP layer.

Referenced by handleMessage().

{
    readRet(msg);
}
void RTP::initialize ( ) [protected, virtual]

Initializes variables.

{
    _socketFdIn = -1;//UDPSocket::generateSocketId();
    _socketFdOut = -1;
    _leaveSession = false;
}
void RTP::initializeProfile ( ) [protected, virtual]

Initializes the profile module.

Referenced by enterSession().

{
    RTPInnerPacket *rinp = new RTPInnerPacket("initializeProfile()");
    rinp->initializeProfile(_mtu);
    send(rinp, "profileOut");
}
void RTP::initializeRTCP ( ) [protected, virtual]

Initializes the rtcp module-.

Referenced by connectRet().

{
    RTPInnerPacket *rinp = new RTPInnerPacket("initializeRTCP()");
    int rtcpPort = _port + 1;
    rinp->initializeRTCP(opp_strdup(_commonName), _mtu, _bandwidth, _rtcpPercentage, _destinationAddress, rtcpPort);
    send(rinp, "rtcpOut");
}
void RTP::leaveSession ( RTPInterfacePacket rifp) [protected, virtual]

Destroys the profile module and orders the rtcp module to send an rtcp bye packet.

Referenced by handleMessageFromApp().

{
    cModule *profileModule = gate("profileOut")->getNextGate()->getOwnerModule();
    profileModule->deleteModule();
    _leaveSession = true;
    RTPInnerPacket *rinp = new RTPInnerPacket("leaveSession()");
    rinp->leaveSession();
    send(rinp,"rtcpOut");

    delete rifp;
}
void RTP::profileInitialized ( RTPInnerPacket rinp) [protected, virtual]

Called when the profile module is initialized.

Referenced by handleMessageFromProfile().

{
    _rtcpPercentage = rinp->getRtcpPercentage();
    if (_port == PORT_UNDEF) {
        _port = rinp->getPort();
        if (_port % 2 != 0) {
            _port = _port - 1;
        }
    }

    delete rinp;

    createSocket();
}
void RTP::readRet ( cMessage *  sifp) [protected, virtual]

Called when data from the socket layer has been received.

Referenced by handleMessagefromUDP().

{
    if ( ! _leaveSession)
    {
         RTPPacket *msg = check_and_cast<RTPPacket *>(sifp);

         msg->dump();
         RTPInnerPacket *rinp1 = new RTPInnerPacket("dataIn1()");
         rinp1->dataIn(new RTPPacket(*msg), IPAddress(_destinationAddress), _port);

         RTPInnerPacket *rinp2 = new RTPInnerPacket(*rinp1);
         send(rinp2, "rtcpOut");
         //delete rinp2;
         send(rinp1, "profileOut");
         //delete rinp1;
    }

    delete sifp;
}
int RTP::resolveMTU ( ) [protected, virtual]

Determines the maximum transmission unit that can be uses for rtp. This implementation assumes that we use an ethernet with 1500 bytes mtu. The returned value is 1500 bytes minus header sizes for ip and udp.

Referenced by enterSession().

{
    // this is not what it should be
    // do something like mtu path discovery
    // for the simulation we can use this example value
    // it's 1500 bytes (ethernet) minus ip
    // and udp headers
    return 1500 - 20 - 8;
}
void RTP::rtcpInitialized ( RTPInnerPacket rinp) [protected, virtual]

Informs the application that the session is entered.

Referenced by handleMessageFromRTCP().

{
    RTPInterfacePacket *rifp = new RTPInterfacePacket("sessionEntered()");
    rifp->sessionEntered(rinp->getSSRC());
    send(rifp, "appOut");

    delete rinp;
}
void RTP::senderModuleControl ( RTPInterfacePacket rifp) [protected, virtual]

Referenced by handleMessageFromApp().

{
    RTPInnerPacket *rinp = new RTPInnerPacket("senderModuleControl()");
    rinp->senderModuleControl(rinp->getSSRC(), (RTPSenderControlMessage *)(rifp->decapsulate()));
    send(rinp, "profileOut");

    delete rifp;
}
void RTP::senderModuleCreated ( RTPInnerPacket rinp) [protected, virtual]

Referenced by handleMessageFromProfile().

{
    RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleCreated()");
    rifp->senderModuleCreated(rinp->getSSRC());
    send(rifp, "appOut");

    delete rinp;
}
void RTP::senderModuleDeleted ( RTPInnerPacket rinp) [protected, virtual]

Referenced by handleMessageFromProfile().

{
    RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleDeleted()");
    rifp->senderModuleDeleted(rinp->getSSRC());
    send(rifp, "appOut");

    // perhaps we should send a message to rtcp module
    delete rinp;
}
void RTP::senderModuleInitialized ( RTPInnerPacket rinp) [protected, virtual]

Referenced by handleMessageFromProfile().

{
    send(rinp, "rtcpOut");
}
void RTP::senderModuleStatus ( RTPInnerPacket rinp) [protected, virtual]

Referenced by handleMessageFromProfile().

{
    RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleStatus()");
    rifp->senderModuleStatus(rinp->getSSRC(), (RTPSenderStatusMessage *)(rinp->decapsulate()));
    send(rifp, "appOut");

    delete rinp;
}
void RTP::sessionLeft ( RTPInnerPacket rinp) [protected, virtual]

Informs the application that this end system has left the rtp session.

Referenced by handleMessageFromRTCP().

{
    RTPInterfacePacket *rifp = new RTPInterfacePacket("sessionLeft()");
    rifp->sessionLeft();
    send(rifp, "appOut");

    delete rinp;
}
void RTP::socketRet ( ) [protected, virtual]

Called when the socket layer returns a socket.

{
}

Member Data Documentation

int RTP::_bandwidth [protected]

The available bandwidth for this session.

Referenced by enterSession(), and initializeRTCP().

const char* RTP::_commonName [protected]

The CNAME of this end system.

Referenced by enterSession(), and initializeRTCP().

The destination address.

Referenced by createSocket(), dataOut(), enterSession(), initializeRTCP(), and readRet().

bool RTP::_leaveSession [protected]

True when this end system is about to leave the session.

Referenced by initialize(), leaveSession(), and readRet().

int RTP::_mtu [protected]

The maximum size of a packet.

Referenced by enterSession(), initializeProfile(), and initializeRTCP().

int RTP::_port [protected]
const char* RTP::_profileName [protected]

The name of the profile used in this session.

Referenced by createProfile(), and enterSession().

int RTP::_rtcpPercentage [protected]

The percentage of the bandwidth used for rtcp.

Referenced by initializeRTCP(), and profileInitialized().

int RTP::_socketFdIn [protected]

The rtp server socket file descriptor.

Referenced by createSocket(), and initialize().

int RTP::_socketFdOut [protected]

The rtp client socket file descriptor.

Referenced by createSocket(), and initialize().


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