-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.h
325 lines (263 loc) · 9.91 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* main.h
*
* H.323 call generator
*
* Copyright (c) 2001 Benny L. Prijono <[email protected]>
* Copyright (c) 2008-2018 Jan Willamowius <[email protected]>
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* https://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is CallGen323.
*
* The Initial Developer of the Original Code is Benny L. Prijono
*
* Contributor(s): Equivalence Pty. Ltd.
*
*/
#include <ptclib/delaychan.h>
#include <ptclib/pwavfile.h>
#include <h323.h>
#include <h323pdu.h>
#if !defined(P_USE_STANDARD_CXX_BOOL) && !defined(P_USE_INTEGER_BOOL)
typedef int PBoolean;
#endif
///////////////////////////////////////////////////////////////////////////////
class PlayMessage : public PDelayChannel
{
PCLASSINFO(PlayMessage, PDelayChannel);
public:
PlayMessage(const PString & filename, unsigned frameDelay, unsigned frameSize);
virtual PBoolean Read(void *, PINDEX);
virtual PBoolean Close();
protected:
PWAVFile wavFile;
};
///////////////////////////////////////////////////////////////////////////////
class RecordMessage : public PDelayChannel
{
PCLASSINFO(RecordMessage, PDelayChannel);
public:
RecordMessage(const PString & filename, unsigned frameDelay, unsigned frameSize);
virtual PBoolean Write(const void *, PINDEX);
virtual PBoolean Close();
protected:
PBoolean reallyClose;
};
///////////////////////////////////////////////////////////////////////////////
class MyH323EndPoint;
class RTPFuzzingChannel : public H323_ExternalRTPChannel
{
PCLASSINFO(RTPFuzzingChannel, H323_ExternalRTPChannel);
public:
RTPFuzzingChannel(MyH323EndPoint & ep, H323Connection & connection, const H323Capability & capability, Directions direction, unsigned sessionID, WORD rtpPort, WORD rtcpPort);
virtual ~RTPFuzzingChannel();
virtual PBoolean Start();
PDECLARE_NOTIFIER(PTimer, RTPFuzzingChannel, TransmitRTP);
PDECLARE_NOTIFIER(PTimer, RTPFuzzingChannel, TransmitRTCP);
protected:
PUDPSocket m_rtpSocket;
PUDPSocket m_rtcpSocket;
RTP_DataFrame m_rtpPacket;
PTimer m_rtpTransmitTimer;
PTimer m_rtcpTransmitTimer;
unsigned m_frameTime;
unsigned m_frameTimeUnits;
RTP_DataFrame::PayloadTypes m_payloadType;
DWORD m_syncSource;
DWORD m_timestamp;
unsigned m_percentBadRTPHeader;
unsigned m_percentBadRTPMedia;
unsigned m_percentBadRTCP;
};
///////////////////////////////////////////////////////////////////////////////
struct CallDetail
{
CallDetail()
: openedTransmitMedia(0),
openedReceiveMedia(0),
receivedMedia(0),
receivedAudio(false),
receivedVideo(false)
{ }
PTime openedTransmitMedia;
PTime openedReceiveMedia;
PTime receivedMedia;
bool receivedAudio;
bool receivedVideo;
H323TransportAddress mediaGateway;
void Drop(H323Connection & connection);
void OnRTPStatistics(const RTP_Session & session, const PString & token);
};
///////////////////////////////////////////////////////////////////////////////
class MyH323EndPoint;
class MyH323Connection : public H323Connection
{
PCLASSINFO(MyH323Connection, H323Connection);
public:
MyH323Connection(MyH323EndPoint & ep, unsigned callRef);
virtual ~MyH323Connection();
virtual PBoolean OnSendSignalSetup(H323SignalPDU & setupPDU);
virtual PBoolean OpenAudioChannel(
PBoolean isEncoding, /// Direction of data flow
unsigned bufferSize, /// Size of each audio buffer
H323AudioCodec & codec /// codec that is doing the opening
);
#ifdef H323_VIDEO
virtual PBoolean OpenVideoChannel(PBoolean isEncoding, H323VideoCodec & codec);
#ifdef H323_H239
void StartH239Transmission();
void StopH239Transmission();
PDECLARE_NOTIFIER(PTimer, MyH323Connection, StartH239TransmissionTrigger);
PDECLARE_NOTIFIER(PTimer, MyH323Connection, StopH239TransmissionTrigger);
virtual void OnEstablished();
virtual PBoolean OnInitialFlowRestriction(H323Channel & channel);
virtual PBoolean OpenExtendedVideoChannel(PBoolean isEncoding, H323VideoCodec & codec);
#endif
#endif
virtual H323Channel * CreateRealTimeLogicalChannel(const H323Capability & capability, H323Channel::Directions dir,
unsigned sessionID, const H245_H2250LogicalChannelParameters * param, RTP_QOS * rtpqos = NULL);
virtual void OnRTPStatistics(const RTP_Session & session) const;
CallDetail details;
protected:
MyH323EndPoint & endpoint;
PVideoChannel * videoChannelIn;
PVideoChannel * videoChannelOut;
map<unsigned, WORD> m_sessionPorts;
bool m_isH239ready;
bool m_haveStartedH239;
PTimer m_h239StartTimer;
PTimer m_h239StopTimer;
};
///////////////////////////////////////////////////////////////////////////////
class MyH323EndPoint : public H323EndPoint
{
PCLASSINFO(MyH323EndPoint, H323EndPoint);
public:
MyH323EndPoint();
// override from H323EndPoint
virtual H323Connection * CreateConnection(unsigned callReference);
virtual void OnConnectionEstablished(
H323Connection & connection, /// Connection that was established
const PString & token /// Token for identifying connection
);
virtual void OnConnectionCleared(
H323Connection & connection, /// Connection that was established
const PString & token /// Token for identifying connection
);
virtual PBoolean OnStartLogicalChannel(H323Connection & connection, H323Channel & PTRACE_channel);
virtual PBoolean SetVideoFrameSize(H323Capability::CapabilityFrameSize frameSize, int frameUnits = 1);
virtual H323Capability::CapabilityFrameSize GetMaxFrameSize() const { return m_maxFrameSize; }
// TODO: include in codec negotiations, only sets bearer capabilities right now
void SetPerCallBandwidth(unsigned bw) { m_rateMultiplier = ceil((float)bw / 64); }
BYTE GetRateMultiplier() const { return m_rateMultiplier; }
void SetVideoPattern(const PString & pattern, bool isH239 = false) { if (isH239) m_h239videoPattern = pattern; else m_videoPattern = pattern; }
PString GetVideoPattern(bool isH239) const { return isH239 ? m_h239videoPattern : m_videoPattern; }
void SetFrameRate(unsigned fps) { m_frameRate = fps; }
unsigned GetFrameRate() const { return m_frameRate; }
void SetFuzzing(bool val) { m_fuzzing = val; }
bool IsFuzzing() const { return m_fuzzing; }
void SetPercentBadRTPHeader(unsigned val) { m_percentBadRTPHeader = val; }
unsigned GetPercentBadRTPHeader() const { return m_percentBadRTPHeader; }
void SetPercentBadRTPMedia(unsigned val) { m_percentBadRTPMedia = val; }
unsigned GetPercentBadRTPMedia() const { return m_percentBadRTPMedia; }
void SetPercentBadRTCP(unsigned val) { m_percentBadRTCP = val; }
unsigned GetPercentBadRTCP() const { return m_percentBadRTCP; }
void SetStartH239(bool start) { m_startH239 = start; }
bool IsStartH239() const { return m_startH239; }
void SetH239Delay(int delay) { m_h239delay = delay; }
int GetH239Delay() { return m_h239delay; }
void SetH239Duration(int duration) { m_h239duration = duration; }
int GetH239Duration() { return m_h239duration; }
protected:
BYTE m_rateMultiplier;
PString m_videoPattern;
PString m_h239videoPattern;
unsigned m_frameRate;
H323Capability::CapabilityFrameSize m_maxFrameSize;
bool m_fuzzing;
unsigned m_percentBadRTPHeader;
unsigned m_percentBadRTPMedia;
unsigned m_percentBadRTCP;
bool m_startH239;
int m_h239delay;
int m_h239duration;
};
///////////////////////////////////////////////////////////////////////////////
class CallGen;
struct CallParams
{
CallParams(CallGen & app)
: callgen(app), repeat(0) { }
CallGen & callgen;
unsigned repeat;
PTimeInterval tmax_est;
PTimeInterval tmin_call;
PTimeInterval tmax_call;
PTimeInterval tmin_wait;
PTimeInterval tmax_wait;
};
///////////////////////////////////////////////////////////////////////////////
class CallThread : public PThread
{
PCLASSINFO(CallThread, PThread);
public:
CallThread(
unsigned index,
const PStringArray & destinations,
const CallParams & params
);
void Main();
void Stop();
protected:
PStringArray destinations;
unsigned index;
CallParams params;
PSyncPoint exit;
};
PLIST(CallThreadList, CallThread);
///////////////////////////////////////////////////////////////////////////////
class CallGen : public PProcess
{
PCLASSINFO(CallGen, PProcess)
public:
CallGen();
void Main();
static CallGen & Current() { return (CallGen&)PProcess::Current(); }
PString outgoingMessageFile;
PString incomingAudioDirectory;
PTextFile cdrFile;
PSyncPoint threadEnded;
unsigned totalAttempts;
unsigned totalEstablished;
PMutex coutMutex;
MyH323EndPoint * h323;
PBoolean Start(const PString & destination, PString & token) {
return h323->MakeCall(destination, token) != NULL;
}
PBoolean Exists(const PString & token) {
return h323->HasConnection(token);
}
PBoolean IsEstablished(const PString & token) {
return h323->IsConnectionEstablished(token);
}
PBoolean Clear(PString & token) {
return h323->ClearCallSynchronous(token);
}
void ClearAll() {
h323->ClearAllCalls();
}
protected:
PDECLARE_NOTIFIER(PThread, CallGen, Cancel);
PConsoleChannel console;
CallThreadList threadList;
};
///////////////////////////////////////////////////////////////////////////////