RINASim  October 2016
Documentation of framework for OMNeT++
AEVideo.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "AEVideo.h"
17 
18 namespace AEVideo {
19 
21 
22 int Stream::nextId = 0;
23 
25  id = nextId++;
26  wt = 0.03;
27  brt = 8.0;
28  varFrameS = 0.0;
29  //rng = &uniform;
30 }
31 
32 void Stream::setFps(double val) {
33  wt = 1/val;
34 }
35 
36 void Stream::setBrt(double val) {
37  brt = val*1024;
38 }
39 
40 void Stream::setVarFrameS(double val){
41  varFrameS = val;
42 }
43 
45  rng = val;
46 }
47 
48 
50  return id;
51 }
52 
53 double Stream::getWt() {
54  return wt;
55 }
56 
58  return (int) rng(minFrameS, maxFrameS,0);
59 }
60 
62  double packetSize = brt*wt;
63  minFrameS = ceil(packetSize*(1-varFrameS));
64  maxFrameS = ceil(packetSize*(1+varFrameS));
65 }
66 
68  streamId = id;
69 }
70 
71 void AEVideo::doIni() {
72  startVar = par("startVar");
73 
74 
75  cXMLElement* slXml = NULL;
76  if (par("streamList").xmlValue() != NULL && par("streamList").xmlValue()->hasChildren()){
77  slXml = par("streamList").xmlValue();
78  } else {
79  error("streamList parameter not initialized!");
80  }
81 
82  cXMLElementList streamsXML = slXml->getChildrenByTagName("Stream");
83  for (cXMLElementList::iterator it = streamsXML.begin(); it != streamsXML.end(); ++it) {
84  cXMLElement* m = *it;
85 
86  std::string streamType = "";
87  if (m->getAttribute("type")) {
88  streamType = m->getAttribute("type");
89  }
90 
91  Stream st;
92  if(streamType == "LR" || streamType == "1"){
93  st.setFps(15.0);
94  st.setBrt(128.0);
95  } else if(streamType == "SD" || streamType == "2"){
96  st.setFps(30.0);
97  st.setBrt(400.0);
98  } else if(streamType == "HD" || streamType == "3"){
99  st.setFps(30.0);
100  st.setBrt(1228.8);
101  }
102 
103  cXMLElementList attrs = m->getChildren();
104  for (cXMLElementList::iterator jt = attrs.begin(); jt != attrs.end(); ++jt) {
105  cXMLElement* n = *jt;
106  if ( !strcmp(n->getTagName(), "fps") ) {
107  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
108  if (v > 0) { st.setFps(v); }
109  } else if ( !strcmp(n->getTagName(), "brt") ) {
110  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
111  if (v > 0) { st.setBrt(v); }
112  } else if ( !strcmp(n->getTagName(), "varFr") ) {
113  double v = n->getNodeValue() ? atof(n->getNodeValue()) : 0;
114  if (v >= 0 && v <= 1) { st.setVarFrameS(v); }
115  } else if ( !strcmp(n->getTagName(), "rng") ) {
116  string nodeVal = n->getNodeValue();
117  if(nodeVal == "uniform"){
118  //st.setRNG(&uniform);
119  } else if(nodeVal == "normal"){
120  st.setRNG(&minMaxNormal);
121  }
122  }
123  }
124  st.compute();
125 
126  streams.push_back(st);
127  }
128 }
129 
130 void AEVideo::doFin(){
131  EV << k <<endl;
132  EV << maxSize <<endl;
133 }
134 
135 void AEVideo::iniCom(){
136  for(sVecIt it = streams.begin(); it != streams.end(); it++){
137  scheduleAt(uniform(simTime(), simTime()+startVar), new Stream_Timer(it->getid()) );
138  }
139 }
140 
141 void AEVideo::processMsg(_AESInt_self * msg){
142  Stream_Timer * st = dynamic_cast<Stream_Timer*>(msg);
143  if(inTime && st){
144  Stream *s = &streams[st->streamId];
145  int data = s->getNextFrame();
146  while(data > 0){
147  sendMsg(new _PingMsg(), min(data, maxSize));
148  data -= maxSize;
149  }
150  scheduleAt(simTime()+s->getWt(), new Stream_Timer(st->streamId) );
151  }
152  delete msg;
153 }
154 
155 }
int getNextFrame()
Definition: AEVideo.cc:57
double minMaxNormal(double a, double b, int rng)
Definition: AESInt.cc:30
void setBrt(double)
Definition: AEVideo.cc:36
double getWt()
Definition: AEVideo.cc:53
void setRNG(RNG_function)
Definition: AEVideo.cc:44
double varFrameS
Definition: AEVideo.h:50
double minFrameS
Definition: AEVideo.h:51
RNG_function rng
Definition: AEVideo.h:53
void setVarFrameS(double)
Definition: AEVideo.cc:40
double(* RNG_function)(double, double, int rng)
Definition: AEVideo.h:26
double maxFrameS
Definition: AEVideo.h:51
sVec::iterator sVecIt
Definition: AEVideo.h:57
void compute()
Definition: AEVideo.cc:61
double brt
Definition: AEVideo.h:48
static int nextId
Definition: AEVideo.h:45
Define_Module(AEVideo)
double wt
Definition: AEVideo.h:48
void setFps(double)
Definition: AEVideo.cc:32