INET Framework for OMNeT++/OMNEST
inet::UDPVideoStreamSvr Class Reference

Stream VBR video streams to clients. More...

#include <UDPVideoStreamSvr.h>

Inheritance diagram for inet::UDPVideoStreamSvr:
inet::ApplicationBase inet::OperationalBase inet::ILifecycle

Classes

struct  VideoStreamData
 

Public Member Functions

 UDPVideoStreamSvr ()
 
virtual ~UDPVideoStreamSvr ()
 
- Public Member Functions inherited from inet::ApplicationBase
 ApplicationBase ()
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

typedef std::map< long int, VideoStreamDataVideoStreamMap
 

Protected Member Functions

virtual void processStreamRequest (cMessage *msg)
 
virtual void sendStreamData (cMessage *timer)
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void finish () override
 
virtual void handleMessageWhenUp (cMessage *msg) override
 
virtual void clearStreams ()
 
virtual bool handleNodeStart (IDoneCallback *doneCallback) override
 
virtual bool handleNodeShutdown (IDoneCallback *doneCallback) override
 
virtual void handleNodeCrash () override
 
- Protected Member Functions inherited from inet::ApplicationBase
virtual bool isInitializeStage (int stage) override
 
virtual bool isNodeStartStage (int stage) override
 
virtual bool isNodeShutdownStage (int stage) override
 
- Protected Member Functions inherited from inet::OperationalBase
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void setOperational (bool isOperational)
 

Protected Attributes

VideoStreamMap streams
 
UDPSocket socket
 
int localPort = -1
 
cPar * sendInterval = nullptr
 
cPar * packetLen = nullptr
 
cPar * videoSize = nullptr
 
unsigned int numStreams = 0
 
unsigned long numPkSent = 0
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Static Protected Attributes

static simsignal_t reqStreamBytesSignal = registerSignal("reqStreamBytes")
 
static simsignal_t sentPkSignal = registerSignal("sentPk")
 

Detailed Description

Stream VBR video streams to clients.

Cooperates with UDPVideoStreamCli. UDPVideoStreamCli requests a stream and UDPVideoStreamSvr starts streaming to them. Capable of handling streaming to multiple clients.

Member Typedef Documentation

typedef std::map<long int, VideoStreamData> inet::UDPVideoStreamSvr::VideoStreamMap
protected

Constructor & Destructor Documentation

inet::UDPVideoStreamSvr::UDPVideoStreamSvr ( )
inline
85 {}
inet::UDPVideoStreamSvr::~UDPVideoStreamSvr ( )
virtual
38 {
39  for (auto & elem : streams)
40  cancelAndDelete(elem.second.timer);
41 }
VideoStreamMap streams
Definition: UDPVideoStreamSvr.h:55

Member Function Documentation

void inet::UDPVideoStreamSvr::clearStreams ( )
protectedvirtual

Referenced by handleNodeCrash(), and handleNodeShutdown().

142 {
143  for (auto & elem : streams)
144  cancelAndDelete(elem.second.timer);
145  streams.clear();
146 }
VideoStreamMap streams
Definition: UDPVideoStreamSvr.h:55
void inet::UDPVideoStreamSvr::finish ( )
overrideprotectedvirtual
62 {
63 }
void inet::UDPVideoStreamSvr::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalBase.

66 {
67  if (msg->isSelfMessage()) {
68  // timer for a particular video stream expired, send packet
69  sendStreamData(msg);
70  }
71  else if (msg->getKind() == UDP_I_DATA) {
72  // start streaming
74  }
75  else if (msg->getKind() == UDP_I_ERROR) {
76  EV_WARN << "Ignoring UDP error report\n";
77  delete msg;
78  }
79  else {
80  throw cRuntimeError("Unrecognized message (%s)%s", msg->getClassName(), msg->getName());
81  }
82 }
Definition: UDPControlInfo_m.h:83
virtual void processStreamRequest(cMessage *msg)
Definition: UDPVideoStreamSvr.cc:84
virtual void sendStreamData(cMessage *timer)
Definition: UDPVideoStreamSvr.cc:107
Definition: UDPControlInfo_m.h:84
void inet::UDPVideoStreamSvr::handleNodeCrash ( )
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

164 {
165  clearStreams();
166 }
virtual void clearStreams()
Definition: UDPVideoStreamSvr.cc:141
bool inet::UDPVideoStreamSvr::handleNodeShutdown ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

157 {
158  clearStreams();
159  //TODO if(socket.isOpened()) socket.close();
160  return true;
161 }
virtual void clearStreams()
Definition: UDPVideoStreamSvr.cc:141
bool inet::UDPVideoStreamSvr::handleNodeStart ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

149 {
150  socket.setOutputGate(gate("udpOut"));
152 
153  return true;
154 }
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UDPSocket.h:110
UDPSocket socket
Definition: UDPVideoStreamSvr.h:56
void bind(int localPort)
Bind the socket to a local port number.
Definition: UDPSocket.cc:53
int localPort
Definition: UDPVideoStreamSvr.h:59
void inet::UDPVideoStreamSvr::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

44 {
46 
47  if (stage == INITSTAGE_LOCAL) {
48  sendInterval = &par("sendInterval");
49  packetLen = &par("packetLen");
50  videoSize = &par("videoSize");
51  localPort = par("localPort");
52 
53  // statistics
54  numStreams = 0;
55  numPkSent = 0;
56 
57  WATCH_MAP(streams);
58  }
59 }
cPar * packetLen
Definition: UDPVideoStreamSvr.h:61
cPar * sendInterval
Definition: UDPVideoStreamSvr.h:60
Local initializations.
Definition: InitStages.h:35
unsigned long numPkSent
Definition: UDPVideoStreamSvr.h:66
virtual void initialize(int stage) override
Definition: OperationalBase.cc:32
VideoStreamMap streams
Definition: UDPVideoStreamSvr.h:55
unsigned int numStreams
Definition: UDPVideoStreamSvr.h:65
cPar * videoSize
Definition: UDPVideoStreamSvr.h:62
int localPort
Definition: UDPVideoStreamSvr.h:59
virtual int inet::UDPVideoStreamSvr::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::OperationalBase.

73 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::UDPVideoStreamSvr::processStreamRequest ( cMessage *  msg)
protectedvirtual

Referenced by handleMessageWhenUp().

85 {
86  // register video stream...
87  UDPDataIndication *ctrl = check_and_cast<UDPDataIndication *>(msg->getControlInfo());
88 
89  cMessage *timer = new cMessage("VideoStreamTmr");
90  VideoStreamData *d = &streams[timer->getId()];
91  d->timer = timer;
92  d->clientAddr = ctrl->getSrcAddr();
93  d->clientPort = ctrl->getSrcPort();
94  d->videoSize = (*videoSize);
95  d->bytesLeft = d->videoSize;
96  d->numPkSent = 0;
97  ASSERT(d->videoSize > 0);
98  delete msg;
99 
100  numStreams++;
101  emit(reqStreamBytesSignal, d->videoSize);
102 
103  // ... then transmit first packet right away
104  sendStreamData(timer);
105 }
static simsignal_t reqStreamBytesSignal
Definition: UDPVideoStreamSvr.h:67
virtual void sendStreamData(cMessage *timer)
Definition: UDPVideoStreamSvr.cc:107
VideoStreamMap streams
Definition: UDPVideoStreamSvr.h:55
unsigned int numStreams
Definition: UDPVideoStreamSvr.h:65
void inet::UDPVideoStreamSvr::sendStreamData ( cMessage *  timer)
protectedvirtual

Referenced by handleMessageWhenUp(), and processStreamRequest().

108 {
109  auto it = streams.find(timer->getId());
110  if (it == streams.end())
111  throw cRuntimeError("Model error: Stream not found for timer");
112 
113  VideoStreamData *d = &(it->second);
114 
115  // generate and send a packet
116  cPacket *pkt = new cPacket("VideoStrmPk");
117  long pktLen = packetLen->longValue();
118 
119  if (pktLen > d->bytesLeft)
120  pktLen = d->bytesLeft;
121 
122  pkt->setByteLength(pktLen);
123  emit(sentPkSignal, pkt);
124  socket.sendTo(pkt, d->clientAddr, d->clientPort);
125 
126  d->bytesLeft -= pktLen;
127  d->numPkSent++;
128  numPkSent++;
129 
130  // reschedule timer if there's bytes left to send
131  if (d->bytesLeft > 0) {
132  simtime_t interval = (*sendInterval);
133  scheduleAt(simTime() + interval, timer);
134  }
135  else {
136  streams.erase(it);
137  delete timer;
138  }
139 }
void sendTo(cPacket *msg, L3Address destAddr, int destPort, const SendOptions *options=nullptr)
Sends a data packet to the given address and port.
Definition: UDPSocket.cc:88
cPar * packetLen
Definition: UDPVideoStreamSvr.h:61
static simsignal_t sentPkSignal
Definition: UDPVideoStreamSvr.h:68
UDPSocket socket
Definition: UDPVideoStreamSvr.h:56
unsigned long numPkSent
Definition: UDPVideoStreamSvr.h:66
VideoStreamMap streams
Definition: UDPVideoStreamSvr.h:55

Member Data Documentation

int inet::UDPVideoStreamSvr::localPort = -1
protected

Referenced by handleNodeStart(), and initialize().

unsigned long inet::UDPVideoStreamSvr::numPkSent = 0
protected

Referenced by initialize(), and sendStreamData().

unsigned int inet::UDPVideoStreamSvr::numStreams = 0
protected

Referenced by initialize(), and processStreamRequest().

cPar* inet::UDPVideoStreamSvr::packetLen = nullptr
protected

Referenced by initialize(), and sendStreamData().

simsignal_t inet::UDPVideoStreamSvr::reqStreamBytesSignal = registerSignal("reqStreamBytes")
staticprotected

Referenced by processStreamRequest().

cPar* inet::UDPVideoStreamSvr::sendInterval = nullptr
protected

Referenced by initialize().

simsignal_t inet::UDPVideoStreamSvr::sentPkSignal = registerSignal("sentPk")
staticprotected

Referenced by sendStreamData().

UDPSocket inet::UDPVideoStreamSvr::socket
protected

Referenced by handleNodeStart(), and sendStreamData().

VideoStreamMap inet::UDPVideoStreamSvr::streams
protected
cPar* inet::UDPVideoStreamSvr::videoSize = nullptr
protected

Referenced by initialize().


The documentation for this class was generated from the following files: