forked from rgaufman/live555
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifications.patch
426 lines (390 loc) · 19.1 KB
/
modifications.patch
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
Binary files live/.DS_Store and live-new/.DS_Store differ
diff --color -ruN live/config.linux live-new/config.linux
--- live/config.linux 2023-06-14 08:05:16
+++ live-new/config.linux 2023-06-15 11:27:30
@@ -1,4 +1,4 @@
-COMPILE_OPTS = $(INCLUDES) -I/usr/local/include -I. -O2 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
+COMPILE_OPTS = $(INCLUDES) -I/usr/local/include -I. -O2 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DALLOW_RTSP_SERVER_PORT_REUSE=1
C = c
C_COMPILER = cc
C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS)
Binary files live/liveMedia/.DS_Store and live-new/liveMedia/.DS_Store differ
diff --color -ruN live/liveMedia/MediaSink.cpp live-new/liveMedia/MediaSink.cpp
--- live/liveMedia/MediaSink.cpp 2023-06-14 08:04:21
+++ live-new/liveMedia/MediaSink.cpp 2023-06-15 11:54:20
@@ -110,7 +110,7 @@
////////// OutPacketBuffer //////////
-unsigned OutPacketBuffer::maxSize = 60000; // by default
+unsigned OutPacketBuffer::maxSize = 2000000; // by default
OutPacketBuffer
::OutPacketBuffer(unsigned preferredPacketSize, unsigned maxPacketSize, unsigned maxBufferSize)
diff --color -ruN live/liveMedia/ProxyServerMediaSession.cpp live-new/liveMedia/ProxyServerMediaSession.cpp
--- live/liveMedia/ProxyServerMediaSession.cpp 2023-06-14 08:04:21
+++ live-new/liveMedia/ProxyServerMediaSession.cpp 2023-06-15 11:20:32
@@ -75,9 +75,9 @@
char const* rtspURL,
char const* username, char const* password,
portNumBits tunnelOverHTTPPortNum, int verbosityLevel,
- int socketNumToServer) {
+ int socketNumToServer, unsigned interPacketGapMaxTime) {
return new ProxyRTSPClient(ourServerMediaSession, rtspURL, username, password,
- tunnelOverHTTPPortNum, verbosityLevel, socketNumToServer);
+ tunnelOverHTTPPortNum, verbosityLevel, socketNumToServer, interPacketGapMaxTime);
}
ProxyServerMediaSession* ProxyServerMediaSession
@@ -85,10 +85,10 @@
char const* inputStreamURL, char const* streamName,
char const* username, char const* password,
portNumBits tunnelOverHTTPPortNum, int verbosityLevel, int socketNumToServer,
- MediaTranscodingTable* transcodingTable) {
+ MediaTranscodingTable* transcodingTable, unsigned interPacketGapMaxTime) {
return new ProxyServerMediaSession(env, ourMediaServer, inputStreamURL, streamName, username, password,
tunnelOverHTTPPortNum, verbosityLevel, socketNumToServer,
- transcodingTable);
+ transcodingTable, interPacketGapMaxTime);
}
@@ -99,6 +99,7 @@
portNumBits tunnelOverHTTPPortNum, int verbosityLevel,
int socketNumToServer,
MediaTranscodingTable* transcodingTable,
+ unsigned interPacketGapMaxTime,
createNewProxyRTSPClientFunc* ourCreateNewProxyRTSPClientFunc,
portNumBits initialPortNum, Boolean multiplexRTCPWithRTP)
: ServerMediaSession(env, streamName, NULL, NULL, False, NULL),
@@ -114,7 +115,7 @@
= (*fCreateNewProxyRTSPClientFunc)(*this, inputStreamURL, username, password,
tunnelOverHTTPPortNum,
verbosityLevel > 0 ? verbosityLevel-1 : verbosityLevel,
- socketNumToServer);
+ socketNumToServer, interPacketGapMaxTime);
fProxyRTSPClient->sendDESCRIBE();
}
@@ -244,13 +245,16 @@
ProxyRTSPClient::ProxyRTSPClient(ProxyServerMediaSession& ourServerMediaSession, char const* rtspURL,
char const* username, char const* password,
- portNumBits tunnelOverHTTPPortNum, int verbosityLevel, int socketNumToServer)
+ portNumBits tunnelOverHTTPPortNum, int verbosityLevel, int socketNumToServer,
+ unsigned interPacketGapMaxTime)
: RTSPClient(ourServerMediaSession.envir(), rtspURL, verbosityLevel, "ProxyRTSPClient",
tunnelOverHTTPPortNum == (portNumBits)(~0) ? 0 : tunnelOverHTTPPortNum, socketNumToServer),
fOurServerMediaSession(ourServerMediaSession), fOurURL(strDup(rtspURL)), fStreamRTPOverTCP(tunnelOverHTTPPortNum != 0),
fSetupQueueHead(NULL), fSetupQueueTail(NULL), fNumSetupsDone(0), fNextDESCRIBEDelay(1),
+ fTotNumPacketsReceived(~0), fInterPacketGapMaxTime(interPacketGapMaxTime),
fServerSupportsGetParameter(False), fLastCommandWasPLAY(False), fDoneDESCRIBE(False),
- fLivenessCommandTask(NULL), fDESCRIBECommandTask(NULL), fSubsessionTimerTask(NULL), fResetTask(NULL) {
+ fLivenessCommandTask(NULL), fDESCRIBECommandTask(NULL), fSubsessionTimerTask(NULL), fResetTask(NULL),
+ fInterPacketGapsTask(NULL) {
if (username != NULL && password != NULL) {
fOurAuthenticator = new Authenticator(username, password);
} else {
@@ -263,11 +267,13 @@
envir().taskScheduler().unscheduleDelayedTask(fDESCRIBECommandTask);
envir().taskScheduler().unscheduleDelayedTask(fSubsessionTimerTask);
envir().taskScheduler().unscheduleDelayedTask(fResetTask);
+ envir().taskScheduler().unscheduleDelayedTask(fInterPacketGapsTask); fInterPacketGapsTask = NULL;
fSetupQueueHead = fSetupQueueTail = NULL;
fNumSetupsDone = 0;
fNextDESCRIBEDelay = 1;
fLastCommandWasPLAY = False;
+ fTotNumPacketsReceived = ~0;
fDoneDESCRIBE = False;
RTSPClient::reset();
@@ -397,6 +403,7 @@
scheduleReset();
return;
}
+ if (fInterPacketGapsTask == NULL) checkInterPacketGaps_(True);
}
void ProxyRTSPClient::scheduleLivenessCommand() {
@@ -438,6 +445,45 @@
#endif
}
+void ProxyRTSPClient::checkInterPacketGaps_(Boolean delayReset) {
+ if (fInterPacketGapMaxTime == 0) return; // we're not checking
+
+ // Check each subsession, counting up how many packets have been received:
+ unsigned newTotNumPacketsReceived = 0;
+
+ MediaSubsessionIterator iter(*fOurServerMediaSession.fClientMediaSession);
+ MediaSubsession* subsession;
+ while ((subsession = iter.next()) != NULL) {
+ RTPSource* src = subsession->rtpSource();
+ if (src == NULL) continue;
+ newTotNumPacketsReceived += src->receptionStatsDB().totNumPacketsReceived();
+ }
+
+ //envir() << *this << "::doLivenessCheck fTotNumPacketsReceived: " << fTotNumPacketsReceived
+ // << ", newTotNumPacketsReceived: " << newTotNumPacketsReceived << "\n";
+
+ if (newTotNumPacketsReceived == fTotNumPacketsReceived) {
+ // No additional packets have been received since the last time we
+ // checked, so end this stream:
+ // *env << "Closing session, because we stopped receiving packets.\n";
+ if (fVerbosityLevel > 0) {
+ envir() << *this << "::doLivenessCheck last packet received: >" << fInterPacketGapMaxTime
+ << " seconds ago. Resetting session\n";
+ }
+ if (delayReset) scheduleReset();
+ else doReset();
+ } else {
+ fTotNumPacketsReceived = newTotNumPacketsReceived;
+ // Check again, after the specified delay:
+ fInterPacketGapsTask = envir().taskScheduler().scheduleDelayedTask(fInterPacketGapMaxTime*MILLION, checkInterPacketGaps, this);
+ }
+}
+
+void ProxyRTSPClient::checkInterPacketGaps(void* clientData) {
+ ProxyRTSPClient* rtspClient = (ProxyRTSPClient*)clientData;
+ rtspClient->checkInterPacketGaps_(False);
+}
+
void ProxyRTSPClient::scheduleReset() {
if (fVerbosityLevel > 0) {
envir() << "ProxyRTSPClient::scheduleReset\n";
@@ -663,6 +709,7 @@
// Send a "PAUSE" for the whole stream.
proxyRTSPClient->sendPauseCommand(fClientMediaSubsession.parentSession(), NULL, proxyRTSPClient->auth());
proxyRTSPClient->fLastCommandWasPLAY = False;
+ envir().taskScheduler().unscheduleDelayedTask(proxyRTSPClient->fInterPacketGapsTask); proxyRTSPClient->fInterPacketGapsTask = NULL;
}
}
}
diff --color -ruN live/liveMedia/include/ProxyServerMediaSession.hh live-new/liveMedia/include/ProxyServerMediaSession.hh
--- live/liveMedia/include/ProxyServerMediaSession.hh 2023-06-14 08:04:21
+++ live-new/liveMedia/include/ProxyServerMediaSession.hh 2023-06-15 11:18:54
@@ -43,7 +43,8 @@
public:
ProxyRTSPClient(class ProxyServerMediaSession& ourServerMediaSession, char const* rtspURL,
char const* username, char const* password,
- portNumBits tunnelOverHTTPPortNum, int verbosityLevel, int socketNumToServer);
+ portNumBits tunnelOverHTTPPortNum, int verbosityLevel, int socketNumToServer,
+ unsigned interPacketGapMaxTime = 0);
virtual ~ProxyRTSPClient();
void continueAfterDESCRIBE(char const* sdpDescription);
@@ -60,6 +61,8 @@
void scheduleLivenessCommand();
static void sendLivenessCommand(void* clientData);
+ void checkInterPacketGaps_(Boolean delayReset);
+ static void checkInterPacketGaps(void* clientData);
void doReset();
static void doReset(void* clientData);
@@ -80,8 +83,10 @@
class ProxyServerMediaSubsession *fSetupQueueHead, *fSetupQueueTail;
unsigned fNumSetupsDone;
unsigned fNextDESCRIBEDelay; // in seconds
+ unsigned fTotNumPacketsReceived;
+ unsigned fInterPacketGapMaxTime; // in seconds
Boolean fServerSupportsGetParameter, fLastCommandWasPLAY, fDoneDESCRIBE;
- TaskToken fLivenessCommandTask, fDESCRIBECommandTask, fSubsessionTimerTask, fResetTask;
+ TaskToken fLivenessCommandTask, fDESCRIBECommandTask, fSubsessionTimerTask, fResetTask, fInterPacketGapsTask;
};
@@ -90,13 +95,13 @@
char const* rtspURL,
char const* username, char const* password,
portNumBits tunnelOverHTTPPortNum, int verbosityLevel,
- int socketNumToServer);
+ int socketNumToServer, unsigned interPacketGapMaxTime);
ProxyRTSPClient*
defaultCreateNewProxyRTSPClientFunc(ProxyServerMediaSession& ourServerMediaSession,
char const* rtspURL,
char const* username, char const* password,
portNumBits tunnelOverHTTPPortNum, int verbosityLevel,
- int socketNumToServer);
+ int socketNumToServer, unsigned interPacketGapMaxTime);
class ProxyServerMediaSession: public ServerMediaSession {
public:
@@ -109,7 +114,8 @@
// for streaming the *proxied* (i.e., back-end) stream
int verbosityLevel = 0,
int socketNumToServer = -1,
- MediaTranscodingTable* transcodingTable = NULL);
+ MediaTranscodingTable* transcodingTable = NULL,
+ unsigned interPacketGapMaxTime = 0);
// Hack: "tunnelOverHTTPPortNum" == 0xFFFF (i.e., all-ones) means: Stream RTP/RTCP-over-TCP, but *not* using HTTP
// "verbosityLevel" == 1 means display basic proxy setup info; "verbosityLevel" == 2 means display RTSP client protocol also.
// If "socketNumToServer" is >= 0, then it is the socket number of an already-existing TCP connection to the server.
@@ -132,6 +138,7 @@
portNumBits tunnelOverHTTPPortNum, int verbosityLevel,
int socketNumToServer,
MediaTranscodingTable* transcodingTable,
+ unsigned interPacketGapMaxTime = 0,
createNewProxyRTSPClientFunc* ourCreateNewProxyRTSPClientFunc
= defaultCreateNewProxyRTSPClientFunc,
portNumBits initialPortNum = 6970,
diff --color -ruN live/mediaServer/DynamicRTSPServer.cpp live-new/mediaServer/DynamicRTSPServer.cpp
--- live/mediaServer/DynamicRTSPServer.cpp 2023-06-14 08:04:21
+++ live-new/mediaServer/DynamicRTSPServer.cpp 2023-06-15 11:54:19
@@ -68,15 +68,15 @@
sms = NULL;
} else {
- if (smsExists && isFirstLookupInSession) {
+ if (smsExists && isFirstLookupInSession) {
// Remove the existing "ServerMediaSession" and create a new one, in case the underlying
// file has changed in some way:
- removeServerMediaSession(sms);
+ removeServerMediaSession(sms);
sms = NULL;
- }
+ }
if (sms == NULL) {
- sms = createNewSMS(envir(), streamName, fid);
+ sms = createNewSMS(envir(), streamName, fid);
addServerMediaSession(sms);
}
@@ -145,12 +145,12 @@
} else if (strcmp(extension, ".264") == 0) {
// Assumed to be a H.264 Video Elementary Stream file:
NEW_SMS("H.264 Video");
- OutPacketBuffer::maxSize = 100000; // allow for some possibly large H.264 frames
+ OutPacketBuffer::maxSize = 2000000; // allow for some possibly large H.264 frames
sms->addSubsession(H264VideoFileServerMediaSubsession::createNew(env, fileName, reuseSource));
} else if (strcmp(extension, ".265") == 0) {
// Assumed to be a H.265 Video Elementary Stream file:
NEW_SMS("H.265 Video");
- OutPacketBuffer::maxSize = 100000; // allow for some possibly large H.265 frames
+ OutPacketBuffer::maxSize = 2000000; // allow for some possibly large H.265 frames
sms->addSubsession(H265VideoFileServerMediaSubsession::createNew(env, fileName, reuseSource));
} else if (strcmp(extension, ".mp3") == 0) {
// Assumed to be a MPEG-1 or 2 Audio file:
@@ -206,13 +206,13 @@
} else if (strcmp(extension, ".dv") == 0) {
// Assumed to be a DV Video file
// First, make sure that the RTPSinks' buffers will be large enough to handle the huge size of DV frames (as big as 288000).
- OutPacketBuffer::maxSize = 300000;
+ OutPacketBuffer::maxSize = 2000000;
NEW_SMS("DV Video");
sms->addSubsession(DVVideoFileServerMediaSubsession::createNew(env, fileName, reuseSource));
} else if (strcmp(extension, ".mkv") == 0 || strcmp(extension, ".webm") == 0) {
// Assumed to be a Matroska file (note that WebM ('.webm') files are also Matroska files)
- OutPacketBuffer::maxSize = 300000; // allow for some possibly large VP8 or VP9 frames
+ OutPacketBuffer::maxSize = 2000000; // allow for some possibly large VP8 or VP9 frames
NEW_SMS("Matroska video+audio+(optional)subtitles");
// Create a Matroska file server demultiplexor for the specified file.
diff --color -ruN live/proxyServer/live555ProxyServer.cpp live-new/proxyServer/live555ProxyServer.cpp
--- live/proxyServer/live555ProxyServer.cpp 2023-06-14 08:04:21
+++ live-new/proxyServer/live555ProxyServer.cpp 2023-06-15 11:54:18
@@ -35,6 +35,7 @@
Boolean proxyREGISTERRequests = False;
char* usernameForREGISTER = NULL;
char* passwordForREGISTER = NULL;
+unsigned interPacketGapMaxTime = 0;
static RTSPServer* createRTSPServer(Port port) {
if (proxyREGISTERRequests) {
@@ -51,6 +52,7 @@
<< " [-p <rtspServer-port>]"
<< " [-u <username> <password>]"
<< " [-R] [-U <username-for-REGISTER> <password-for-REGISTER>]"
+ << " [-D <max-inter-packet-gap-time>]"
<< " <rtsp-url-1> ... <rtsp-url-n>\n";
exit(1);
}
@@ -58,7 +60,7 @@
int main(int argc, char** argv) {
// Increase the maximum size of video frames that we can 'proxy' without truncation.
// (Such frames are unreasonably large; the back-end servers should really not be sending frames this large!)
- OutPacketBuffer::maxSize = 100000; // bytes
+ OutPacketBuffer::maxSize = 2000000; // bytes
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
@@ -98,7 +100,7 @@
case 'T': {
// stream RTP and RTCP over a HTTP connection
if (argc > 2 && argv[2][0] != '-') {
- // The next argument is the HTTP server port number:
+ // The next argument is the HTTP server port number:
if (sscanf(argv[2], "%hu", &tunnelOverHTTPPortNum) == 1
&& tunnelOverHTTPPortNum > 0) {
++argv; --argc;
@@ -112,7 +114,7 @@
}
case 'p': {
- // specify a rtsp server port number
+ // specify a rtsp server port number
if (argc > 2 && argv[2][0] != '-') {
// The next argument is the rtsp server port number:
if (sscanf(argv[2], "%hu", &rtspServerPortNum) == 1
@@ -126,7 +128,7 @@
usage();
break;
}
-
+
case 'u': { // specify a username and password (to be used if the 'back end' (i.e., proxied) stream requires authentication)
if (argc < 4) usage(); // there's no argv[3] (for the "password")
username = argv[2];
@@ -151,6 +153,19 @@
break;
}
+ case 'D': { // specify maximum number of seconds to wait for packets:
+ if (argc > 2 && argv[2][0] != '-') {
+ if (sscanf(argv[2], "%u", &interPacketGapMaxTime) == 1) {
+ ++argv; --argc;
+ break;
+ }
+ }
+
+ // If we get here, the option was specified incorrectly:
+ usage();
+ break;
+ }
+
default: {
usage();
break;
@@ -159,7 +174,7 @@
++argv; --argc;
}
- if (argc < 2 && !proxyREGISTERRequests) usage(); // there must be at least one URL at the end
+ if (argc < 2 && !proxyREGISTERRequests) usage(); // there must be at least one URL at the end
// Make sure that the remaining arguments appear to be "rtsp://" (or "rtsps://") URLs:
int i;
for (i = 1; i < argc; ++i) {
@@ -221,7 +236,7 @@
ServerMediaSession* sms
= ProxyServerMediaSession::createNew(*env, rtspServer,
proxiedStreamURL, streamName,
- username, password, tunnelOverHTTPPortNum, verbosityLevel);
+ username, password, tunnelOverHTTPPortNum, verbosityLevel, -1, NULL, interPacketGapMaxTime);
rtspServer->addServerMediaSession(sms);
char* proxyStreamURL = rtspServer->rtspURL(sms);
diff --color -ruN live/testProgs/testDVVideoStreamer.cpp live-new/testProgs/testDVVideoStreamer.cpp
--- live/testProgs/testDVVideoStreamer.cpp 2023-06-14 08:04:21
+++ live-new/testProgs/testDVVideoStreamer.cpp 2023-06-15 11:54:18
@@ -58,7 +58,7 @@
// Create a 'DV Video RTP' sink from the RTP 'groupsock':
// (But first, make sure that its buffers will be large enough to handle the huge size of DV frames (as big as 288000).)
- OutPacketBuffer::maxSize = 300000;
+ OutPacketBuffer::maxSize = 2000000;
videoSink = DVVideoRTPSink::createNew(*env, &rtpGroupsock, 96);
// Create (and start) a 'RTCP instance' for this RTP sink:
diff --color -ruN live/testProgs/testH264VideoStreamer.cpp live-new/testProgs/testH264VideoStreamer.cpp
--- live/testProgs/testH264VideoStreamer.cpp 2023-06-14 08:04:21
+++ live-new/testProgs/testH264VideoStreamer.cpp 2023-06-15 11:54:17
@@ -63,7 +63,7 @@
rtcpGroupsock.multicastSendOnly(); // we're a SSM source
// Create a 'H264 Video RTP' sink from the RTP 'groupsock':
- OutPacketBuffer::maxSize = 100000;
+ OutPacketBuffer::maxSize = 2000000;
videoSink = H264VideoRTPSink::createNew(*env, &rtpGroupsock, 96);
// Create (and start) a 'RTCP instance' for this RTP sink:
diff --color -ruN live/testProgs/testH265VideoStreamer.cpp live-new/testProgs/testH265VideoStreamer.cpp
--- live/testProgs/testH265VideoStreamer.cpp 2023-06-14 08:04:21
+++ live-new/testProgs/testH265VideoStreamer.cpp 2023-06-15 11:54:17
@@ -64,7 +64,7 @@
rtcpGroupsock.multicastSendOnly(); // we're a SSM source
// Create a 'H265 Video RTP' sink from the RTP 'groupsock':
- OutPacketBuffer::maxSize = 100000;
+ OutPacketBuffer::maxSize = 2000000;
videoSink = H265VideoRTPSink::createNew(*env, &rtpGroupsock, 96);
// Create (and start) a 'RTCP instance' for this RTP sink:
diff --color -ruN live/testProgs/testOnDemandRTSPServer.cpp live-new/testProgs/testOnDemandRTSPServer.cpp
--- live/testProgs/testOnDemandRTSPServer.cpp 2023-06-14 08:04:21
+++ live-new/testProgs/testOnDemandRTSPServer.cpp 2023-06-15 11:54:17
@@ -280,7 +280,7 @@
// A DV video stream:
{
// First, make sure that the RTPSinks' buffers will be large enough to handle the huge size of DV frames (as big as 288000).
- OutPacketBuffer::maxSize = 300000;
+ OutPacketBuffer::maxSize = 2000000;
char const* streamName = "dvVideoTest";
char const* inputFileName = "test.dv";