User Manual, Developers Guide and API Documentation

Video.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <APPLICATIONS/session/server/wimax/Video.hpp>
00029 
00030 using namespace applications::session::server::wimax;
00031 
00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::server::wimax::Video,
00033                      applications::session::Session,
00034                      "server.WiMAXVideo", wns::PyConfigViewCreator);
00035 
00036 
00037 using namespace applications::session::server::wimax;
00038 
00039 Video::Video(const wns::pyconfig::View& _pyco) :
00040   Session(_pyco),
00041   framePacketCounter(0),
00042   firstPacketNumber(true)
00043 {
00044   wns::pyconfig::View pSDConfig(_pyco, "packetSize");
00045   std::string pSDName = pSDConfig.get<std::string>("__plugin__");
00046   packetSizeDistribution = wns::distribution::DistributionFactory::creator(pSDName)->create(pSDConfig);
00047 
00048   wns::pyconfig::View iATConfig(_pyco, "packetIat");
00049   std::string iATName = iATConfig.get<std::string>("__plugin__");
00050   packetIatDistribution = wns::distribution::DistributionFactory::creator(iATName)->create(iATConfig);
00051 
00052   settlingTime = _pyco.get<wns::simulator::Time>("settlingTime");
00053 
00054   videoFrameRate = _pyco.get<double>("frameRate");
00055   videoFrameIat = 1 / double(videoFrameRate);
00056   numberOfPacketsPerFrame = _pyco.get<double>("numberOfPacketsPerFrame");
00057 
00058   MESSAGE_BEGIN(NORMAL, logger, m, "APPL: Starting new session with: ");
00059   m << "videoFrameRate = " << videoFrameRate;
00060   m << ", videoFrameIat = " << videoFrameIat;
00061   m << ", numberOfPackets = " << numberOfPacketsPerFrame;
00062   MESSAGE_END();
00063 
00064   state = idle;
00065 
00066   /* only for probing */
00067   sessionType = wimaxvideo;
00068 
00069   packetFrom = "server.WiMAXVideo";
00070 }
00071 
00072 Video::~Video()
00073 {
00074   if(packetSizeDistribution != NULL)
00075     delete packetSizeDistribution;
00076   packetSizeDistribution = NULL;
00077 
00078   if(packetIatDistribution != NULL)
00079     delete packetIatDistribution;
00080   packetIatDistribution = NULL;
00081 }
00082 
00083 void
00084 Video::onData(const wns::osi::PDUPtr& _pdu)
00085 {
00086   state = running;
00087 
00088   assureType(_pdu.getPtr(), applications::session::PDU*);
00089 
00090   receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber();
00091 
00092   MESSAGE_SINGLE(NORMAL, logger, "APPL: receivedPacketNumber = " << receivedPacketNumber << ".");
00093 
00094   applications::session::Session::incomingProbesCalculation(_pdu);
00095 
00096   onTimeout(frametimeout);
00097 }
00098 
00099 void
00100 Video::onTimeout(const Timeout& _t)
00101 {
00102   if(_t == statetimeout)
00103     {
00104       if(framePacketCounter < numberOfPacketsPerFrame)
00105     {
00106       framePacketCounter += 1;
00107 
00108       packetSize = (*packetSizeDistribution)();
00109       /* The distributed value is in byte, so it has to be converted to bit. */
00110       packetSize *= 8.0;
00111 
00112       MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending video packet!");
00113 
00114       applications::session::Session::iatProbesCalculation();
00115 
00116       applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco);
00117       applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime());
00118 
00119       if(firstPacketNumber == true)
00120         {
00121           packetNumber = 1;
00122           applicationPDU->setPacketNumber(packetNumber, packetFrom);
00123           MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << ".");
00124 
00125           firstPacketNumber = false;
00126         }
00127       else
00128         {
00129           ++packetNumber;
00130           applicationPDU->setPacketNumber(packetNumber, packetFrom);
00131           MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << ".");
00132         }
00133 
00134       wns::osi::PDUPtr pdu(applicationPDU);
00135       applications::session::Session::outgoingProbesCalculation(pdu);
00136 
00137       connection->sendData(pdu);
00138 
00139       iat = (*packetIatDistribution)();
00140       /* The distributed value is in ms, so it has to be converted to sec. */
00141       iat /= 1000.0;
00142 
00143       setTimeout(statetimeout, iat);
00144     }
00145       else
00146     {
00147       framePacketCounter = 0;
00148     }
00149     }
00150   else if(_t == frametimeout)
00151     {
00152       /* Starting new frame! */
00153       setTimeout(frametimeout, videoFrameIat);
00154       onTimeout(statetimeout);
00155     }
00156   else if(_t == probetimeout)
00157     {
00158       applications::session::Session::onTimeout(_t);
00159     }
00160   else
00161     {
00162       assure(false, "APPL: Unknown timout type =" << _t);
00163     }
00164 }

Generated on Sun May 27 03:32:16 2012 for openWNS by  doxygen 1.5.5