RtVideoStreamingSender.h Source File

Simu5G: RtVideoStreamingSender.h Source File
Simu5G
RtVideoStreamingSender.h
1//
2// Simu5G
3//
4// Copyright (C) 2019-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef APPS_MEC_RTVIDEOSTREAMINGSENDER_H_
14#define APPS_MEC_RTVIDEOSTREAMINGSENDER_H_
15
16#include <inet/common/ModuleRefByPar.h>
17#include <inet/common/geometry/common/Coord.h>
18#include <inet/common/geometry/common/EulerAngles.h>
19#include <inet/mobility/contract/IMobility.h>
20#include <inet/networklayer/common/L3Address.h>
21#include <inet/networklayer/common/L3AddressResolver.h>
22#include <inet/transportlayer/contract/udp/UdpSocket.h>
23
24#include "simu5g/common/binder/Binder.h"
25#include "simu5g/apps/mec/WarningAlert/packets/WarningAlertPacket_m.h"
26#include "simu5g/mec/platform/MeAppPacket_Types.h"
27
28namespace simu5g {
29
30using namespace omnetpp;
31
32struct FragmentedFrameStatus {
33 int frameNumber;
34 int frameSize;
35 int remainingFragments;
36 int numberOfFragments;
37 int bytesPerPacket;
38 int pictureType;
39 uint32_t rtpTimestamp;
40
41 int remainingFrameBytes;
42 int remainingFramesSlices;
43};
44
49
50class RtVideoStreamingSender : public cSimpleModule, public inet::UdpSocket::ICallback
51{
52 //communication to device app and MEC app
53 inet::UdpSocket socket;
54
55 int size_;
56 simtime_t lifeCyclePeriod_;
57 int localPort_;
58 int deviceAppPort_;
59 inet::L3Address deviceAppAddress_;
60
61 // MEC application endPoint (returned by the device app)
62 inet::L3Address mecAppAddress_;
63 int mecAppPort_;
64
65 std::string mecAppName;
66
67 //scheduling
68 enum MsgKind {
69 KIND_SELF_RT_VIDEO_STREAMING_APP_START = 1000,
70 KIND_SELF_RT_VIDEO_STREAMING_APP_STOP,
71 KIND_SELF_MEC_APP_START,
72 KIND_SELF_MEC_APP_STOP,
73 KIND_SELF_SESSION_START,
74 KIND_SELF_SESSION_STOP,
75 KIND_SELF_NEXT_FRAME,
76 KIND_SELF_MOBILITY_STATS,
77 };
78
79 cMessage *selfRTVideoStreamingAppStart_ = nullptr;
80 cMessage *selfRTVideoStreamingAppStop_ = nullptr;
81
82 cMessage *selfMecAppStart_ = nullptr;
83 cMessage *selfMecAppStop_ = nullptr;
84
85 cMessage *selfSessionStart_ = nullptr;
86 cMessage *selfSessionStop_ = nullptr;
87
88 inet::UdpSocket videoStreamSocket_;
89
90 const char *fileName;
94 std::ifstream _inputFileStream;
95
96 int mtu_;
97 cMessage *_nextFrame = nullptr;
98
102 double _initialDelay;
103
107 double _framesPerSecond;
108
113 unsigned long _frameNumber = 0;
114 unsigned long _sequenceNumber = 0;
115
116 int sessionId_ = 0;
117
118 bool sendAllOnOneTime_;
119
120 // mobility information
121 opp_component_ptr<cModule> ue;
122 inet::ModuleRefByPar<inet::IMobility> mobility;
123 inet::Coord position;
124 cMessage *mobilityStats_ = nullptr;
125
126 static simsignal_t positionSignalXSignal_;
127 static simsignal_t positionSignalYSignal_;
128 static simsignal_t positionSignalZSignal_;
129
130 static simsignal_t velocitySignal_;
131 double mobilityUpdateInterval_; // send position and speed info
132
133 FragmentedFrameStatus fragFrameStatus_;
134
135 public:
136 ~RtVideoStreamingSender() override;
137
138 protected:
139
140 int numInitStages() const override { return inet::NUM_INIT_STAGES; }
141 void initialize(int stage) override;
142 void handleMessage(cMessage *msg) override;
143
144 // communication with device app
145 void sendStartMecApp();
146 void sendStopMecApp();
147 // communication with MEC app
148 void sendMessage();
149 void sendStartMessage();
150 void sendStopMessage();
151 void sendSessionStopMessage();
152 void sendSessionStartMessage();
153
154 // handlers
155 void handleStartAck(inet::Packet *packet);
156 void handleStartNack(inet::Packet *packet);
157
158 void handleStopAck(inet::Packet *packet);
159 void handleStopNack(inet::Packet *packet);
160
161 void handleStartSessionAck(inet::Packet *packet);
162 void handleStartSessionNack(inet::Packet *packet);
163
164 void handleStopSessionAck(inet::Packet *packet);
165 void handleStopSessionNack(inet::Packet *packet);
166
167 void handleAckStartMecApp(inet::Packet *packet);
168 void handleInfoMecApp(inet::Packet *packet);
169 void handleAckStopMecApp(inet::Packet *packet);
170
171 // UdpSocket::ICallback methods
172 void socketDataArrived(inet::UdpSocket *socket, inet::Packet *packet) override;
173 void socketErrorArrived(inet::UdpSocket *socket, inet::Indication *indication) override;
174 void socketClosed(inet::UdpSocket *socket) override;
175
176 void openFileStream();
177 void initializeVideoStream();
178};
179
180} //namespace
181
182#endif /* APPS_MEC_RTVIDEOSTREAMINGSENDER_H_ */
183
Definition RtVideoStreamingSender.h:51
Definition AlertReceiver.h:24