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

A "Realtime" VideoStream client application. More...

#include <UDPVideoStreamCli.h>

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

Public Member Functions

 UDPVideoStreamCli ()
 
virtual ~UDPVideoStreamCli ()
 
- 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 Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void finish () override
 
virtual void handleMessageWhenUp (cMessage *msg) override
 
virtual void requestStream ()
 
virtual void receiveStream (cPacket *msg)
 
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

UDPSocket socket
 
cMessage * selfMsg = nullptr
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Static Protected Attributes

static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 

Detailed Description

A "Realtime" VideoStream client application.

Basic video stream application. Clients connect to server and get a stream of video back.

Constructor & Destructor Documentation

inet::UDPVideoStreamCli::UDPVideoStreamCli ( )
inline
62 { }
virtual inet::UDPVideoStreamCli::~UDPVideoStreamCli ( )
inlinevirtual
63 { cancelAndDelete(selfMsg); }
cMessage * selfMsg
Definition: UDPVideoStreamCli.h:42

Member Function Documentation

void inet::UDPVideoStreamCli::finish ( )
overrideprotectedvirtual
41 {
42  ApplicationBase::finish();
43 }
void inet::UDPVideoStreamCli::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalBase.

46 {
47  if (msg->isSelfMessage()) {
48  requestStream();
49  }
50  else if (msg->getKind() == UDP_I_DATA) {
51  // process incoming packet
52  receiveStream(PK(msg));
53  }
54  else if (msg->getKind() == UDP_I_ERROR) {
55  EV_WARN << "Ignoring UDP error report\n";
56  delete msg;
57  }
58  else {
59  throw cRuntimeError("Unrecognized message (%s)%s", msg->getClassName(), msg->getName());
60  }
61 }
virtual void receiveStream(cPacket *msg)
Definition: UDPVideoStreamCli.cc:85
Definition: UDPControlInfo_m.h:83
Definition: UDPControlInfo_m.h:84
virtual void requestStream()
Definition: UDPVideoStreamCli.cc:63
#define PK(msg)
Definition: INETDefs.h:92
void inet::UDPVideoStreamCli::handleNodeCrash ( )
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

108 {
109  cancelEvent(selfMsg);
110 }
cMessage * selfMsg
Definition: UDPVideoStreamCli.h:42
bool inet::UDPVideoStreamCli::handleNodeShutdown ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

101 {
102  cancelEvent(selfMsg);
103  //TODO if(socket.isOpened()) socket.close();
104  return true;
105 }
cMessage * selfMsg
Definition: UDPVideoStreamCli.h:42
bool inet::UDPVideoStreamCli::handleNodeStart ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

93 {
94  simtime_t startTimePar = par("startTime");
95  simtime_t startTime = std::max(startTimePar, simTime());
96  scheduleAt(startTime, selfMsg);
97  return true;
98 }
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
cMessage * selfMsg
Definition: UDPVideoStreamCli.h:42
void inet::UDPVideoStreamCli::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

32 {
34 
35  if (stage == INITSTAGE_LOCAL) {
36  selfMsg = new cMessage("UDPVideoStreamStart");
37  }
38 }
Local initializations.
Definition: InitStages.h:35
virtual void initialize(int stage) override
Definition: OperationalBase.cc:32
cMessage * selfMsg
Definition: UDPVideoStreamCli.h:42
virtual int inet::UDPVideoStreamCli::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::OperationalBase.

48 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::UDPVideoStreamCli::receiveStream ( cPacket *  msg)
protectedvirtual

Referenced by handleMessageWhenUp().

86 {
87  EV_INFO << "Video stream packet: " << UDPSocket::getReceivedPacketInfo(pk) << endl;
88  emit(rcvdPkSignal, pk);
89  delete pk;
90 }
static std::string getReceivedPacketInfo(cPacket *pk)
Utility function: returns a line of information about a packet received via UDP.
Definition: UDPSocket.cc:324
static simsignal_t rcvdPkSignal
Definition: UDPVideoStreamCli.h:45
void inet::UDPVideoStreamCli::requestStream ( )
protectedvirtual

Referenced by handleMessageWhenUp().

64 {
65  int svrPort = par("serverPort");
66  int localPort = par("localPort");
67  const char *address = par("serverAddress");
68  L3Address svrAddr = L3AddressResolver().resolve(address);
69 
70  if (svrAddr.isUnspecified()) {
71  EV_ERROR << "Server address is unspecified, skip sending video stream request\n";
72  return;
73  }
74 
75  EV_INFO << "Requesting video stream from " << svrAddr << ":" << svrPort << "\n";
76 
77  socket.setOutputGate(gate("udpOut"));
78  socket.bind(localPort);
79 
80  cPacket *pk = new cPacket("VideoStrmReq");
81  pk->setByteLength(1); //FIXME set packet length
82  socket.sendTo(pk, svrAddr, svrPort);
83 }
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
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UDPSocket.h:110
UDPSocket socket
Definition: UDPVideoStreamCli.h:41
void bind(int localPort)
Bind the socket to a local port number.
Definition: UDPSocket.cc:53

Member Data Documentation

simsignal_t inet::UDPVideoStreamCli::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by receiveStream().

cMessage* inet::UDPVideoStreamCli::selfMsg = nullptr
protected
UDPSocket inet::UDPVideoStreamCli::socket
protected

Referenced by requestStream().


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