#include <RTP.h>
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.
Definition at line 36 of file RTP.h.
void RTP::connectRet | ( | ) | [protected, virtual] |
Called when the socket layer has connected a socket.
Definition at line 316 of file RTP.cc.
Referenced by createSocket().
{ initializeRTCP(); }
void RTP::createProfile | ( | ) | [protected, virtual] |
Creates the profile module.
Definition at line 354 of file RTP.cc.
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] |
Definition at line 182 of file RTP.cc.
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.
Definition at line 374 of file RTP.cc.
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.
Definition at line 266 of file RTP.cc.
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] |
Definition at line 193 of file RTP.cc.
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.
Definition at line 149 of file RTP.cc.
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.
Definition at line 49 of file RTP.cc.
{ 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.
Definition at line 73 of file RTP.cc.
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.
Definition at line 97 of file RTP.cc.
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.
Definition at line 125 of file RTP.cc.
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.
Definition at line 139 of file RTP.cc.
Referenced by handleMessage().
{ readRet(msg); }
void RTP::initialize | ( | ) | [protected, virtual] |
Initializes variables.
Definition at line 41 of file RTP.cc.
{ _socketFdIn = -1;//UDPSocket::generateSocketId(); _socketFdOut = -1; _leaveSession = false; }
void RTP::initializeProfile | ( | ) | [protected, virtual] |
Initializes the profile module.
Definition at line 402 of file RTP.cc.
Referenced by enterSession().
{ RTPInnerPacket *rinp = new RTPInnerPacket("initializeProfile()"); rinp->initializeProfile(_mtu); send(rinp, "profileOut"); }
void RTP::initializeRTCP | ( | ) | [protected, virtual] |
Initializes the rtcp module-.
Definition at line 410 of file RTP.cc.
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.
Definition at line 169 of file RTP.cc.
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.
Definition at line 213 of file RTP.cc.
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.
Definition at line 322 of file RTP.cc.
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.
Definition at line 343 of file RTP.cc.
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.
Definition at line 291 of file RTP.cc.
Referenced by handleMessageFromRTCP().
{ RTPInterfacePacket *rifp = new RTPInterfacePacket("sessionEntered()"); rifp->sessionEntered(rinp->getSSRC()); send(rifp, "appOut"); delete rinp; }
void RTP::senderModuleControl | ( | RTPInterfacePacket * | rifp | ) | [protected, virtual] |
Definition at line 203 of file RTP.cc.
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] |
Definition at line 229 of file RTP.cc.
Referenced by handleMessageFromProfile().
{ RTPInterfacePacket *rifp = new RTPInterfacePacket("senderModuleCreated()"); rifp->senderModuleCreated(rinp->getSSRC()); send(rifp, "appOut"); delete rinp; }
void RTP::senderModuleDeleted | ( | RTPInnerPacket * | rinp | ) | [protected, virtual] |
Definition at line 239 of file RTP.cc.
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] |
Definition at line 250 of file RTP.cc.
Referenced by handleMessageFromProfile().
{
send(rinp, "rtcpOut");
}
void RTP::senderModuleStatus | ( | RTPInnerPacket * | rinp | ) | [protected, virtual] |
Definition at line 256 of file RTP.cc.
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.
Definition at line 301 of file RTP.cc.
Referenced by handleMessageFromRTCP().
{ RTPInterfacePacket *rifp = new RTPInterfacePacket("sessionLeft()"); rifp->sessionLeft(); send(rifp, "appOut"); delete rinp; }
void RTP::socketRet | ( | ) | [protected, virtual] |
int RTP::_bandwidth [protected] |
The available bandwidth for this session.
Definition at line 130 of file RTP.h.
Referenced by enterSession(), and initializeRTCP().
const char* RTP::_commonName [protected] |
The CNAME of this end system.
Definition at line 120 of file RTP.h.
Referenced by enterSession(), and initializeRTCP().
IPAddress RTP::_destinationAddress [protected] |
The destination address.
Definition at line 135 of file RTP.h.
Referenced by createSocket(), dataOut(), enterSession(), initializeRTCP(), and readRet().
bool RTP::_leaveSession [protected] |
True when this end system is about to leave the session.
Definition at line 165 of file RTP.h.
Referenced by initialize(), leaveSession(), and readRet().
int RTP::_mtu [protected] |
The maximum size of a packet.
Definition at line 145 of file RTP.h.
Referenced by enterSession(), initializeProfile(), and initializeRTCP().
int RTP::_port [protected] |
The rtp port.
Definition at line 140 of file RTP.h.
Referenced by createSocket(), dataOut(), enterSession(), initializeRTCP(), profileInitialized(), and readRet().
const char* RTP::_profileName [protected] |
The name of the profile used in this session.
Definition at line 125 of file RTP.h.
Referenced by createProfile(), and enterSession().
int RTP::_rtcpPercentage [protected] |
The percentage of the bandwidth used for rtcp.
Definition at line 150 of file RTP.h.
Referenced by initializeRTCP(), and profileInitialized().
int RTP::_socketFdIn [protected] |
The rtp server socket file descriptor.
Definition at line 155 of file RTP.h.
Referenced by createSocket(), and initialize().
int RTP::_socketFdOut [protected] |
The rtp client socket file descriptor.
Definition at line 160 of file RTP.h.
Referenced by createSocket(), and initialize().