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

Stream VBR video streams to clients. More...

#include <UdpVideoStreamServer.h>

Inheritance diagram for inet::UdpVideoStreamServer:
inet::ApplicationBase inet::UdpSocket::ICallback inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Classes

struct  VideoStreamData
 

Public Member Functions

 UdpVideoStreamServer ()
 
virtual ~UdpVideoStreamServer ()
 
- Public Member Functions inherited from inet::ApplicationBase
 ApplicationBase ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::UdpSocket::ICallback
virtual ~ICallback ()
 

Protected Types

typedef std::map< long int, VideoStreamDataVideoStreamMap
 
- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Protected Member Functions

virtual void processStreamRequest (Packet *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 void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
virtual void socketDataArrived (UdpSocket *socket, Packet *packet) override
 Notifies about data arrival, packet ownership is transferred to the callee. More...
 
virtual void socketErrorArrived (UdpSocket *socket, Indication *indication) override
 Notifies about error indication arrival, indication ownership is transferred to the callee. More...
 
virtual void socketClosed (UdpSocket *socket) override
 Notifies about socket closed, indication ownership is transferred to the callee. More...
 
- Protected Member Functions inherited from inet::ApplicationBase
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

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::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Static Protected Attributes

static simsignal_t reqStreamBytesSignal = registerSignal("reqStreamBytes")
 

Detailed Description

Stream VBR video streams to clients.

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

Member Typedef Documentation

◆ VideoStreamMap

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

Constructor & Destructor Documentation

◆ UdpVideoStreamServer()

inet::UdpVideoStreamServer::UdpVideoStreamServer ( )
inline
77 {}

◆ ~UdpVideoStreamServer()

inet::UdpVideoStreamServer::~UdpVideoStreamServer ( )
virtual
34 {
35  for (auto& elem : streams)
36  cancelAndDelete(elem.second.timer);
37 }

Member Function Documentation

◆ clearStreams()

void inet::UdpVideoStreamServer::clearStreams ( )
protectedvirtual
147 {
148  for (auto& elem : streams)
149  cancelAndDelete(elem.second.timer);
150  streams.clear();
151 }

Referenced by handleCrashOperation(), and handleStopOperation().

◆ finish()

void inet::UdpVideoStreamServer::finish ( )
overrideprotectedvirtual
58 {
59 }

◆ handleCrashOperation()

void inet::UdpVideoStreamServer::handleCrashOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

181 {
182  clearStreams();
183  if (operation->getRootModule() != getContainingNode(this)) // closes socket when the application crashed only
184  socket.destroy(); // TODO in real operating systems, program crash detected by OS and OS closes sockets of crashed programs.
185  socket.setCallback(nullptr);
186 }

◆ handleMessageWhenUp()

void inet::UdpVideoStreamServer::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

62 {
63  if (msg->isSelfMessage()) {
64  // timer for a particular video stream expired, send packet
65  sendStreamData(msg);
66  }
67  else
69 }

◆ handleStartOperation()

void inet::UdpVideoStreamServer::handleStartOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

154 {
155  socket.setOutputGate(gate("socketOut"));
156  socket.setCallback(this);
158 
159  int timeToLive = par("timeToLive");
160  if (timeToLive != -1)
161  socket.setTimeToLive(timeToLive);
162 
163  int dscp = par("dscp");
164  if (dscp != -1)
165  socket.setDscp(dscp);
166 
167  int tos = par("tos");
168  if (tos != -1)
169  socket.setTos(tos);
170 }

◆ handleStopOperation()

void inet::UdpVideoStreamServer::handleStopOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

173 {
174  clearStreams();
175  socket.setCallback(nullptr);
176  socket.close();
177  delayActiveOperationFinish(par("stopOperationTimeout"));
178 }

◆ initialize()

void inet::UdpVideoStreamServer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

40 {
42 
43  if (stage == INITSTAGE_LOCAL) {
44  sendInterval = &par("sendInterval");
45  packetLen = &par("packetLen");
46  videoSize = &par("videoSize");
47  localPort = par("localPort");
48 
49  // statistics
50  numStreams = 0;
51  numPkSent = 0;
52 
53  WATCH_MAP(streams);
54  }
55 }

◆ numInitStages()

virtual int inet::UdpVideoStreamServer::numInitStages ( ) const
inlineoverrideprotectedvirtual
61 { return NUM_INIT_STAGES; }

◆ processStreamRequest()

void inet::UdpVideoStreamServer::processStreamRequest ( Packet msg)
protectedvirtual
90 {
91  // register video stream...
92  cMessage *timer = new cMessage("VideoStreamTmr");
93  VideoStreamData *d = &streams[timer->getId()];
94  d->timer = timer;
95  d->clientAddr = msg->getTag<L3AddressInd>()->getSrcAddress();
96  d->clientPort = msg->getTag<L4PortInd>()->getSrcPort();
97  d->videoSize = (*videoSize);
98  d->bytesLeft = d->videoSize;
99  d->numPkSent = 0;
100  ASSERT(d->videoSize > 0);
101  delete msg;
102 
103  numStreams++;
104  emit(reqStreamBytesSignal, d->videoSize);
105 
106  // ... then transmit first packet right away
107  sendStreamData(timer);
108 }

Referenced by socketDataArrived().

◆ sendStreamData()

void inet::UdpVideoStreamServer::sendStreamData ( cMessage *  timer)
protectedvirtual
111 {
112  auto it = streams.find(timer->getId());
113  if (it == streams.end())
114  throw cRuntimeError("Model error: Stream not found for timer");
115 
116  VideoStreamData *d = &(it->second);
117 
118  // generate and send a packet
119  Packet *pkt = new Packet("VideoStrmPk");
120  long pktLen = *packetLen;
121 
122  if (pktLen > d->bytesLeft)
123  pktLen = d->bytesLeft;
124  const auto& payload = makeShared<ByteCountChunk>(B(pktLen));
125  payload->addTag<CreationTimeTag>()->setCreationTime(simTime());
126  pkt->insertAtBack(payload);
127 
128  emit(packetSentSignal, pkt);
129  socket.sendTo(pkt, d->clientAddr, d->clientPort);
130 
131  d->bytesLeft -= pktLen;
132  d->numPkSent++;
133  numPkSent++;
134 
135  // reschedule timer if there's bytes left to send
136  if (d->bytesLeft > 0) {
137  simtime_t interval = (*sendInterval);
138  scheduleAfter(interval, timer);
139  }
140  else {
141  streams.erase(it);
142  delete timer;
143  }
144 }

Referenced by handleMessageWhenUp(), and processStreamRequest().

◆ socketClosed()

void inet::UdpVideoStreamServer::socketClosed ( UdpSocket socket)
overrideprotectedvirtual

Notifies about socket closed, indication ownership is transferred to the callee.

Implements inet::UdpSocket::ICallback.

84 {
85  if (operationalState == State::STOPPING_OPERATION)
86  startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime"));
87 }

◆ socketDataArrived()

void inet::UdpVideoStreamServer::socketDataArrived ( UdpSocket socket,
Packet packet 
)
overrideprotectedvirtual

Notifies about data arrival, packet ownership is transferred to the callee.

Implements inet::UdpSocket::ICallback.

72 {
73  // process incoming packet
74  processStreamRequest(packet);
75 }

◆ socketErrorArrived()

void inet::UdpVideoStreamServer::socketErrorArrived ( UdpSocket socket,
Indication indication 
)
overrideprotectedvirtual

Notifies about error indication arrival, indication ownership is transferred to the callee.

Implements inet::UdpSocket::ICallback.

78 {
79  EV_WARN << "Ignoring UDP error report " << indication->getName() << endl;
80  delete indication;
81 }

Member Data Documentation

◆ localPort

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

Referenced by handleStartOperation(), and initialize().

◆ numPkSent

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

Referenced by initialize(), and sendStreamData().

◆ numStreams

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

Referenced by initialize(), and processStreamRequest().

◆ packetLen

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

Referenced by initialize(), and sendStreamData().

◆ reqStreamBytesSignal

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

Referenced by processStreamRequest().

◆ sendInterval

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

Referenced by initialize().

◆ socket

UdpSocket inet::UdpVideoStreamServer::socket
protected

◆ streams

VideoStreamMap inet::UdpVideoStreamServer::streams
protected

◆ videoSize

cPar* inet::UdpVideoStreamServer::videoSize = nullptr
protected

Referenced by initialize().


The documentation for this class was generated from the following files:
inet::UdpSocket::setOutputGate
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UdpSocket.h:117
inet::UdpSocket::setDscp
void setDscp(short dscp)
Sets the Ipv4 / Ipv6 dscp fields of packets sent from the UDP socket.
Definition: UdpSocket.cc:121
inet::UdpSocket::setTimeToLive
void setTimeToLive(int ttl)
Set the TTL (Ipv6: Hop Limit) field on sent packets.
Definition: UdpSocket.cc:112
inet::UdpVideoStreamServer::sendStreamData
virtual void sendStreamData(cMessage *timer)
Definition: UdpVideoStreamServer.cc:110
inet::OperationalMixin< cSimpleModule >::operationalState
State operationalState
Definition: OperationalMixin.h:23
inet::UdpSocket::bind
void bind(int localPort)
Bind the socket to a local port number.
Definition: UdpSocket.cc:34
inet::UdpSocket::sendTo
void sendTo(Packet *msg, L3Address destAddr, int destPort)
Sends a data packet to the given address and port.
Definition: UdpSocket.cc:69
inet::UdpVideoStreamServer::streams
VideoStreamMap streams
Definition: UdpVideoStreamServer.h:44
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::UdpSocket::destroy
virtual void destroy() override
Notify the protocol that the owner of ISocket has destroyed the socket.
Definition: UdpSocket.cc:98
L3AddressInd
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
inet::packetSentSignal
simsignal_t packetSentSignal
Definition: Simsignals.cc:96
inet::UdpVideoStreamServer::processStreamRequest
virtual void processStreamRequest(Packet *msg)
Definition: UdpVideoStreamServer.cc:89
inet::UdpVideoStreamServer::reqStreamBytesSignal
static simsignal_t reqStreamBytesSignal
Definition: UdpVideoStreamServer.h:56
inet::UdpSocket::setCallback
void setCallback(ICallback *cb)
Sets a callback object, to be used with processMessage().
Definition: UdpSocket.cc:338
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::UdpVideoStreamServer::numStreams
unsigned int numStreams
Definition: UdpVideoStreamServer.h:54
inet::UdpVideoStreamServer::videoSize
cPar * videoSize
Definition: UdpVideoStreamServer.h:51
inet::UdpVideoStreamServer::packetLen
cPar * packetLen
Definition: UdpVideoStreamServer.h:50
inet::UdpSocket::processMessage
virtual void processMessage(cMessage *msg) override
Examines the message, takes ownership, and updates socket state.
Definition: UdpSocket.cc:343
inet::UdpVideoStreamServer::sendInterval
cPar * sendInterval
Definition: UdpVideoStreamServer.h:49
inet::UdpVideoStreamServer::socket
UdpSocket socket
Definition: UdpVideoStreamServer.h:45
inet::UdpVideoStreamServer::localPort
int localPort
Definition: UdpVideoStreamServer.h:48
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::UdpSocket::close
virtual void close() override
Unbinds the socket.
Definition: UdpSocket.cc:87
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::UdpVideoStreamServer::numPkSent
unsigned long numPkSent
Definition: UdpVideoStreamServer.h:55
L4PortInd
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L4PortInd
Definition: IUdp-gates.txt:20
inet::OperationalMixin< cSimpleModule >::delayActiveOperationFinish
virtual void delayActiveOperationFinish(simtime_t timeout)
Definition: OperationalMixinImpl.h:161
inet::OperationalMixin< cSimpleModule >::startActiveOperationExtraTimeOrFinish
virtual void startActiveOperationExtraTimeOrFinish(simtime_t extraTime)
Definition: OperationalMixinImpl.h:179
inet::UdpVideoStreamServer::clearStreams
virtual void clearStreams()
Definition: UdpVideoStreamServer.cc:146
inet::UdpSocket::setTos
void setTos(short tos)
Sets the Ipv4 Type of Service / Ipv6 Traffic Class fields of packets sent from the UDP socket.
Definition: UdpSocket.cc:130