INET Framework for OMNeT++/OMNEST
App_voice.cc
Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2011 Martin Danko
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU 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 General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00019 
00020 #include <omnetpp.h>
00021 #include "App_voice.h"
00022 
00023 
00024 Register_Class(voice);
00025 
00026 /*
00027  * loadConfig(): 
00028  * Funkcia nacita konfiguraciu aplikacie zo XML suboru 
00029  * @param appConfig     - XML blok s konfiguraciu generovanej aplikacie 
00030  * @return - Vrati true bola konfiguracia spravne nacitana
00031  */
00032 bool voice::loadConfig(const cXMLElement& appConfig)
00033 {
00034   
00035   cXMLElement* element;
00036 
00037   element = appConfig.getFirstChildWithTag("codec");
00038   if(element != NULL)
00039   {// pouzity kodek
00040     std::string codec = element->getNodeValue();
00041     if(codec == "g711" || codec == "G.711")
00042       codecRate = 64000;
00043     else if(codec == "g729" || codec == "G.729")
00044       codecRate = 8000;
00045   }
00046   
00047   element = appConfig.getFirstChildWithTag("codec_rate");
00048   if(element != NULL) // explicitne definavana bitova rychlost
00049     codecRate =  atoi(element->getNodeValue());
00050     
00051   element = appConfig.getFirstChildWithTag("packets_per_second");
00052   if(element != NULL)
00053   {
00054     std::string ppsString = element->getNodeValue();
00055     if(ppsString == "default")
00056       pps = 50.0;
00057     else
00058       pps = atof(element->getNodeValue());
00059   }
00060     
00061   element = appConfig.getFirstChildWithTag("vad");
00062   if(element != NULL)
00063   { // technologia VAD bude pouzita
00064     std::string vadString = element->getNodeValue();
00065     if(vadString == "true" || vadString == "True" || vadString == "TRUE")
00066       vad = true;
00067   }
00068   
00069   if(pps == 0.0 || codecRate == 0)
00070     return false; // chyba nacitania
00071   
00072   return true;
00073 }
00074 
00075 /*
00076  * getDefaultPort(): 
00077  * Funkcia vracia hodnotu implicitneho portu aplikacie  
00078  * @return - Vrati implicitny port VoIP
00079  */ 
00080 int voice::getDefaultPort()
00081 {
00082   return 16384;
00083 }
00084 
00085 /*
00086  * getNextPacketTime(): 
00087  * Funkcia vrati velkost hlaviciek nad ramec transportneho protokolu
00088  * U VoIP je to velkost RTP hlavicky   
00089  * @return - Vrati velkost RTP hlavicky
00090  */ 
00091 int voice::anotherEncapsulationOverhead()
00092 {
00093   return 12;  // rtp hlavicka
00094 }
00095 
00096 /*
00097  * getNextPacketTime(): 
00098  * Funkcia na zaklade poctu paketov za sekundu uci cas za aky
00099  * sa bude generovat dalsi paket  
00100  * @return - Vrati cas genetovania dalsieho paketu
00101  */  
00102 double voice::getNextPacketTime()
00103 {
00104   if(vad)
00105   { // VAD sposobi, ze je generovanych len 70% paketov 
00106     double time = 1.0/pps;
00107     while(intuniform(0, 10) > 7)
00108       time += 1.0/pps;
00109     
00110     return time;
00111   }
00112   return 1.0/pps; 
00113 }
00114 
00115 /*
00116  * getPacketSize(): 
00117  * Funkcia na zaklade kodeku a poctu paketov za sekundu urci velkost 
00118  * generovaneho paketu 
00119  * @return - Vrati velkost vygenerovaneho paketu
00120  */    
00121 int voice::getPacketSize()
00122 {
00123   return  codecRate/(8 * pps);
00124 }
00125