UDPVideoStreamCli.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2005 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 
00019 //
00020 // based on the video streaming app of the similar name by Johnny Lai
00021 //
00022 
00023 #include "UDPVideoStreamCli.h"
00024 #include "IPAddressResolver.h"
00025 
00026 
00027 Define_Module(UDPVideoStreamCli);
00028 
00029 
00030 void UDPVideoStreamCli::initialize()
00031 {
00032     eed.setName("video stream eed");
00033     simtime_t startTime = par("startTime");
00034 
00035     if (startTime>=0)
00036         scheduleAt(startTime, new cMessage("UDPVideoStreamStart"));
00037 }
00038 
00039 void UDPVideoStreamCli::finish()
00040 {
00041 }
00042 
00043 void UDPVideoStreamCli::handleMessage(cMessage* msg)
00044 {
00045     if (msg->isSelfMessage())
00046     {
00047         delete msg;
00048         requestStream();
00049     }
00050     else
00051     {
00052         receiveStream(PK(msg));
00053     }
00054 }
00055 
00056 void UDPVideoStreamCli::requestStream()
00057 {
00058     int svrPort = par("serverPort");
00059     int localPort = par("localPort");
00060     const char *address = par("serverAddress");
00061     IPvXAddress svrAddr = IPAddressResolver().resolve(address);
00062     if (svrAddr.isUnspecified())
00063     {
00064         EV << "Server address is unspecified, skip sending video stream request\n";
00065         return;
00066     }
00067 
00068     EV << "Requesting video stream from " << svrAddr << ":" << svrPort << "\n";
00069 
00070     bindToPort(localPort);
00071 
00072     cPacket *msg = new cPacket("VideoStrmReq");
00073     sendToUDP(msg, localPort, svrAddr, svrPort);
00074 }
00075 
00076 void UDPVideoStreamCli::receiveStream(cPacket *msg)
00077 {
00078     EV << "Video stream packet:\n";
00079     printPacket(msg);
00080     eed.record(simTime() - msg->getCreationTime());
00081     delete msg;
00082 }
00083