![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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/client/wimax/VideoTelephony.hpp> 00029 00030 using namespace applications::session::client::wimax; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::client::wimax::VideoTelephony, 00033 applications::session::Session, 00034 "client.WiMAXVideoTelephony", wns::PyConfigViewCreator); 00035 00036 VideoTelephony::VideoTelephony(const wns::pyconfig::View& _pyco) : 00037 applications::session::client::Session(_pyco), 00038 stateTransitionDistribution(NULL), 00039 iFramePacketSizeDistribution(NULL), 00040 bFramePacketSizeDistribution(NULL), 00041 pFramePacketSizeDistribution(NULL), 00042 bFrameCounter(1), 00043 gopCounter(1), 00044 newGOP(true), 00045 cnCounter(0) 00046 { 00047 wns::pyconfig::View sTVConfig(_pyco, "stateTransition"); 00048 std::string sTVName = sTVConfig.get<std::string>("__plugin__"); 00049 stateTransitionDistribution = wns::distribution::DistributionFactory::creator(sTVName)->create(sTVConfig); 00050 00051 wns::pyconfig::View iPSConfig(_pyco, "iFramePacketSize"); 00052 std::string iPSName = iPSConfig.get<std::string>("__plugin__"); 00053 iFramePacketSizeDistribution = wns::distribution::DistributionFactory::creator(iPSName)->create(iPSConfig); 00054 00055 wns::pyconfig::View bPSConfig(_pyco, "bFramePacketSize"); 00056 std::string bPSName = bPSConfig.get<std::string>("__plugin__"); 00057 bFramePacketSizeDistribution = wns::distribution::DistributionFactory::creator(bPSName)->create(bPSConfig); 00058 00059 wns::pyconfig::View pPSConfig(_pyco, "pFramePacketSize"); 00060 std::string pPSName = pPSConfig.get<std::string>("__plugin__"); 00061 pFramePacketSizeDistribution = wns::distribution::DistributionFactory::creator(pPSName)->create(pPSConfig); 00062 00063 settlingTime = _pyco.get<wns::simulator::Time>("settlingTime"); 00064 00065 voicePacketIat = _pyco.get<wns::simulator::Time>("voicePacketIat"); 00066 voicePacketSize = _pyco.get<Bit>("voicePacketSize"); 00067 /* Packet size includes 12 bytes RTP header. */ 00068 voicePacketSize = voicePacketSize + 96; 00069 00070 comfortNoisePacketSize = _pyco.get<Bit>("comfortNoisePacketSize"); 00071 /* Packet size includes 12 bytes RTP header. */ 00072 comfortNoisePacketSize = comfortNoisePacketSize + 96; 00073 00074 comfortNoise = _pyco.get<bool>("comfortNoise"); 00075 00076 MESSAGE_BEGIN(NORMAL, logger, m, "APPL: Starting new session with voiceparameters: "); 00077 m << "voicePacketSize = " << voicePacketSize; 00078 m << ", voicePacketIat = " << voicePacketIat; 00079 m << ", comfortNoisePacketSize = " << comfortNoisePacketSize; 00080 MESSAGE_END(); 00081 00082 videoFrameRate = _pyco.get<int>("frameRate"); 00083 videoPacketIat = 1 / double(videoFrameRate); 00084 shiftI = _pyco.get<double>("shiftI"); 00085 00086 MESSAGE_BEGIN(NORMAL, logger, m, "APPL: Starting new session with videoparameters: "); 00087 m << "videoFrameRate = " << videoFrameRate; 00088 m << ", videoPacketIat = " << videoPacketIat; 00089 MESSAGE_END(); 00090 00091 state = running; 00092 00093 /* only for probing */ 00094 sessionType = wimaxvideotelephony; 00095 00096 sessionDelay = (*sessionDelayDistribution)(); 00097 MESSAGE_SINGLE(NORMAL, logger, "APPL: Delay before session starts: " << sessionDelay << ".\n"); 00098 00099 setTimeout(connectiontimeout, 0.07); 00100 setTimeout(probetimeout, windowSize); 00101 } 00102 00103 00104 VideoTelephony::~VideoTelephony() 00105 { 00106 if (stateTransitionDistribution != NULL) 00107 delete stateTransitionDistribution; 00108 stateTransitionDistribution = NULL; 00109 00110 if(iFramePacketSizeDistribution != NULL) 00111 delete iFramePacketSizeDistribution; 00112 iFramePacketSizeDistribution = NULL; 00113 00114 if(bFramePacketSizeDistribution != NULL) 00115 delete bFramePacketSizeDistribution; 00116 bFramePacketSizeDistribution = NULL; 00117 00118 if(pFramePacketSizeDistribution != NULL) 00119 delete pFramePacketSizeDistribution; 00120 pFramePacketSizeDistribution = NULL; 00121 } 00122 00123 void 00124 VideoTelephony::onData(const wns::osi::PDUPtr& _pdu) 00125 { 00126 assureType(_pdu.getPtr(), applications::session::PDU*); 00127 00128 receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber(); 00129 00130 MESSAGE_SINGLE(NORMAL, logger, "APPL: receivedPacketNumber = " << receivedPacketNumber << "."); 00131 00132 applications::session::Session::incomingProbesCalculation(_pdu); 00133 00134 if((receivedPacketNumber == 1) && (state != sessionended)) 00135 { 00136 /* Voice */ 00137 onTimeout(sendtimeout); 00138 00139 /* Video */ 00140 onTimeout(frametimeout); 00141 voiceState = active; 00142 setTimeout(statetransitiontimeout, 0.02); 00143 00144 state = running; 00145 } 00146 } 00147 00148 void 00149 VideoTelephony::onTimeout(const Timeout& _t) 00150 { 00151 /* Voice */ 00152 if(_t == sendtimeout) 00153 { 00154 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending voicepacket!"); 00155 00156 applications::session::Session::iatProbesCalculation(); 00157 00158 packetSize = voicePacketSize; 00159 00160 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(voicePacketSize), pyco); 00161 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00162 00163 ++packetNumber; 00164 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00165 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00166 00167 wns::osi::PDUPtr pdu(applicationPDU); 00168 applications::session::Session::outgoingProbesCalculation(pdu); 00169 00170 connection->sendData(pdu); 00171 } 00172 else if(_t == receivetimeout) 00173 { 00174 /* Comfort noise packets will be send to fill the silence */ 00175 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending comfort noise packet!"); 00176 00177 applications::session::Session::iatProbesCalculation(); 00178 00179 packetSize = comfortNoisePacketSize; 00180 00181 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(comfortNoisePacketSize), pyco); 00182 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00183 00184 ++packetNumber; 00185 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00186 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00187 00188 wns::osi::PDUPtr pdu(applicationPDU); 00189 applications::session::Session::outgoingProbesCalculation(pdu); 00190 00191 connection->sendData(pdu); 00192 } 00193 else if(_t == statetransitiontimeout) 00194 { 00195 /* Transition between active (speech) state and inactive (silent/pause) state. */ 00196 double stateTransitionValue = (*stateTransitionDistribution)(); 00197 00198 MESSAGE_SINGLE(NORMAL, logger, "APPL: State transition. TransitionValue = " << stateTransitionValue << "."); 00199 00200 if(stateTransitionValue <= 0.01 && voiceState == inactive) 00201 { 00202 cnCounter = 0; 00203 onTimeout(sendtimeout); 00204 00205 voiceState = active; 00206 } 00207 else if(stateTransitionValue > 0.01 && voiceState == inactive) 00208 { 00209 if(cnCounter == 8) 00210 { 00211 cnCounter = 1; 00212 onTimeout(receivetimeout); 00213 } 00214 else 00215 { 00216 cnCounter += 1; 00217 } 00218 } 00219 else if(stateTransitionValue <= 0.01 && voiceState == active) 00220 { 00221 cnCounter = 1; 00222 onTimeout(receivetimeout); 00223 00224 voiceState = inactive; 00225 } 00226 else if(stateTransitionValue > 0.01 && voiceState == active) 00227 { 00228 onTimeout(sendtimeout); 00229 } 00230 00231 setTimeout(statetransitiontimeout, 0.02); 00232 } 00233 /* Video */ 00234 else if(_t == frametimeout) 00235 { 00236 if(newGOP == false) 00237 { 00238 if(bFrameCounter <= 2) 00239 { 00240 /* B-Frame */ 00241 MESSAGE_SINGLE(NORMAL, logger, "APPL: B-FRAME!"); 00242 00243 // applications::session::Session::iatProbesCalculation(); 00244 00245 bFrameCounter += 1; 00246 00247 packetSize = (*bFramePacketSizeDistribution)(); 00248 /* The distributed value is in byte, so it has to be converted to bit. */ 00249 packetSize *= 8.0; 00250 00251 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00252 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00253 00254 packetSize = voicePacketSize; 00255 00256 ++packetNumber; 00257 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00258 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00259 00260 wns::osi::PDUPtr pdu(applicationPDU); 00261 applications::session::Session::outgoingProbesCalculation(pdu); 00262 00263 connection->sendData(pdu); 00264 00265 setTimeout(frametimeout, videoPacketIat); 00266 00267 } 00268 else 00269 { 00270 /* P-Frame */ 00271 bFrameCounter = 1; 00272 00273 if(gopCounter < 4) 00274 { 00275 MESSAGE_SINGLE(NORMAL, logger, "APPL: P-FRAME!"); 00276 00277 // applications::session::Session::iatProbesCalculation(); 00278 00279 packetSize = (*pFramePacketSizeDistribution)(); 00280 /* The distributed value is in byte, so it has to be converted to bit. */ 00281 packetSize *= 8.0; 00282 00283 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00284 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00285 00286 ++packetNumber; 00287 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00288 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00289 00290 wns::osi::PDUPtr pdu(applicationPDU); 00291 applications::session::Session::outgoingProbesCalculation(pdu); 00292 00293 connection->sendData(pdu); 00294 00295 gopCounter += 1; 00296 setTimeout(frametimeout, videoPacketIat); 00297 } 00298 else 00299 { 00300 gopCounter = 1; 00301 newGOP = true; 00302 onTimeout(frametimeout); 00303 } 00304 } 00305 } 00306 else 00307 { 00308 /* I-Frame */ 00309 MESSAGE_SINGLE(NORMAL, logger, "APPL: I-FRAME!"); 00310 00311 // applications::session::Session::iatProbesCalculation(); 00312 00313 packetSize = (*iFramePacketSizeDistribution)(); 00314 /* This value has to be shifted. */ 00315 packetSize += shiftI; 00316 /* The distributed value is in byte, so it has to be converted to bit. */ 00317 packetSize *= 8.0; 00318 00319 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00320 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00321 00322 ++packetNumber; 00323 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00324 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00325 00326 wns::osi::PDUPtr pdu(applicationPDU); 00327 applications::session::Session::outgoingProbesCalculation(pdu); 00328 00329 connection->sendData(pdu); 00330 00331 newGOP = false; 00332 setTimeout(frametimeout, videoPacketIat); 00333 } 00334 } 00335 else if(_t == connectiontimeout) 00336 { 00337 packetFrom = "client.WiMAXVideoTelephony"; 00338 00339 /* Open connection */ 00340 binding->initBinding(); 00341 } 00342 else if(_t == probetimeout) 00343 { 00344 applications::session::Session::onTimeout(_t); 00345 } 00346 else if(_t == statetimeout) 00347 { 00348 /* Start with calling the server. */ 00349 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(comfortNoisePacketSize), pyco); 00350 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00351 00352 packetSize = comfortNoisePacketSize; 00353 00354 packetNumber = 1; 00355 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00356 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00357 00358 wns::osi::PDUPtr pdu(applicationPDU); 00359 applications::session::Session::outgoingProbesCalculation(pdu); 00360 00361 connection->sendData(pdu); 00362 00363 state = idle; 00364 } 00365 else 00366 { 00367 assure(false, "APPL: Unknown timout type =" << _t); 00368 } 00369 } 00370
1.5.5