mediasoup 3.20.1 → 3.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node/lib/DataConsumer.d.ts +2 -3
- package/node/lib/DataConsumer.d.ts.map +1 -1
- package/node/lib/DataConsumer.js +8 -6
- package/node/lib/DataConsumerTypes.d.ts +5 -4
- package/node/lib/DataConsumerTypes.d.ts.map +1 -1
- package/node/lib/fbs/data-consumer/send-response.d.ts +21 -0
- package/node/lib/fbs/data-consumer/send-response.d.ts.map +1 -0
- package/node/lib/fbs/data-consumer/send-response.js +91 -0
- package/node/lib/fbs/data-consumer.d.ts +1 -0
- package/node/lib/fbs/data-consumer.d.ts.map +1 -1
- package/node/lib/fbs/data-consumer.js +4 -1
- package/node/lib/fbs/response/body.d.ts +7 -5
- package/node/lib/fbs/response/body.d.ts.map +1 -1
- package/node/lib/fbs/response/body.js +7 -3
- package/node/lib/fbs/response/response.d.ts +3 -2
- package/node/lib/fbs/response/response.d.ts.map +1 -1
- package/node/lib/test/test-DataConsumer.js +6 -0
- package/node/lib/test/test-werift-sctp.js +7 -0
- package/package.json +4 -4
- package/worker/Makefile +5 -1
- package/worker/fbs/dataConsumer.fbs +4 -0
- package/worker/fbs/response.fbs +1 -0
- package/worker/include/RTC/PortManager.hpp +91 -11
- package/worker/include/RTC/TcpServer.hpp +3 -2
- package/worker/include/RTC/UdpSocket.hpp +3 -2
- package/worker/meson.build +1 -0
- package/worker/src/RTC/DataConsumer.cpp +12 -2
- package/worker/src/RTC/PipeTransport.cpp +5 -4
- package/worker/src/RTC/PlainTransport.cpp +9 -8
- package/worker/src/RTC/PortManager.cpp +174 -114
- package/worker/src/RTC/SCTP/association/Association.cpp +17 -14
- package/worker/src/RTC/TcpServer.cpp +4 -4
- package/worker/src/RTC/Transport.cpp +33 -10
- package/worker/src/RTC/UdpSocket.cpp +4 -4
- package/worker/src/RTC/WebRtcServer.cpp +8 -8
- package/worker/src/RTC/WebRtcTransport.cpp +9 -8
- package/worker/tasks.py +293 -196
- package/worker/test/src/RTC/TestNackGenerator.cpp +1 -1
- package/worker/test/src/RTC/TestPortManager.cpp +126 -0
- package/worker/test/src/RTC/TestTransportTuple.cpp +3 -2
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#include "common.hpp"
|
|
5
5
|
#include "RTC/Transport.hpp"
|
|
6
|
+
#include "Utils.hpp"
|
|
6
7
|
#include <uv.h>
|
|
7
8
|
#include <ankerl/unordered_dense.h>
|
|
9
|
+
#include <ostream>
|
|
8
10
|
#include <string>
|
|
9
11
|
#include <vector>
|
|
10
12
|
|
|
@@ -12,13 +14,75 @@ namespace RTC
|
|
|
12
14
|
{
|
|
13
15
|
class PortManager
|
|
14
16
|
{
|
|
15
|
-
|
|
17
|
+
public:
|
|
16
18
|
enum class Protocol : uint8_t
|
|
17
19
|
{
|
|
18
20
|
UDP = 1,
|
|
19
21
|
TCP
|
|
20
22
|
};
|
|
21
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Opaque-ish key identifying one (protocol, bind address, port range)
|
|
26
|
+
* tuple. Issued by Bind*() and consumed by Unbind(). Callers store it as
|
|
27
|
+
* an opaque token; equality and hashing are exact-tuple based, so distinct
|
|
28
|
+
* tuples never collide regardless of how close their numeric
|
|
29
|
+
* representations are.
|
|
30
|
+
*/
|
|
31
|
+
class PortRangeKey
|
|
32
|
+
{
|
|
33
|
+
private:
|
|
34
|
+
friend class PortManager;
|
|
35
|
+
friend struct PortRangeKeyHash;
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
PortRangeKey() = default;
|
|
39
|
+
PortRangeKey(
|
|
40
|
+
Protocol protocol, const sockaddr_storage& bindAddr, uint16_t minPort, uint16_t maxPort);
|
|
41
|
+
|
|
42
|
+
bool operator==(const PortRangeKey& other) const noexcept;
|
|
43
|
+
bool operator!=(const PortRangeKey& other) const noexcept
|
|
44
|
+
{
|
|
45
|
+
return !(*this == other);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
Protocol GetProtocol() const
|
|
50
|
+
{
|
|
51
|
+
return this->protocol;
|
|
52
|
+
}
|
|
53
|
+
const sockaddr_storage& GetSockaddrStorage() const
|
|
54
|
+
{
|
|
55
|
+
return this->bindAddr;
|
|
56
|
+
}
|
|
57
|
+
uint16_t GetMinPort() const
|
|
58
|
+
{
|
|
59
|
+
return this->minPort;
|
|
60
|
+
}
|
|
61
|
+
uint16_t GetMaxPort() const
|
|
62
|
+
{
|
|
63
|
+
return this->maxPort;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private:
|
|
67
|
+
Protocol protocol{ Protocol::UDP };
|
|
68
|
+
sockaddr_storage bindAddr{};
|
|
69
|
+
uint16_t minPort{ 0u };
|
|
70
|
+
uint16_t maxPort{ 0u };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
struct PortRangeKeyHash
|
|
74
|
+
{
|
|
75
|
+
/**
|
|
76
|
+
* Hash function. Uses ankerl::unordered_dense per-field hashes combined
|
|
77
|
+
* with the standard boost-style `hash_combine` seed mixer. We deliberately
|
|
78
|
+
* do NOT hash the raw `sockaddr_storage` bytes (padding is
|
|
79
|
+
* caller-controlled and would cause structurally-equal keys to hash
|
|
80
|
+
* differently); instead we hash the same fields that `operator==`
|
|
81
|
+
* inspects.
|
|
82
|
+
*/
|
|
83
|
+
size_t operator()(const PortRangeKey& key) const noexcept;
|
|
84
|
+
};
|
|
85
|
+
|
|
22
86
|
private:
|
|
23
87
|
struct PortRange
|
|
24
88
|
{
|
|
@@ -42,9 +106,9 @@ namespace RTC
|
|
|
42
106
|
uint16_t minPort,
|
|
43
107
|
uint16_t maxPort,
|
|
44
108
|
RTC::Transport::SocketFlags& flags,
|
|
45
|
-
|
|
109
|
+
PortRangeKey& key)
|
|
46
110
|
{
|
|
47
|
-
return reinterpret_cast<uv_udp_t*>(Bind(Protocol::UDP, ip, minPort, maxPort, flags,
|
|
111
|
+
return reinterpret_cast<uv_udp_t*>(Bind(Protocol::UDP, ip, minPort, maxPort, flags, key));
|
|
48
112
|
}
|
|
49
113
|
static uv_tcp_t* BindTcp(std::string& ip, uint16_t port, RTC::Transport::SocketFlags& flags)
|
|
50
114
|
{
|
|
@@ -55,11 +119,11 @@ namespace RTC
|
|
|
55
119
|
uint16_t minPort,
|
|
56
120
|
uint16_t maxPort,
|
|
57
121
|
RTC::Transport::SocketFlags& flags,
|
|
58
|
-
|
|
122
|
+
PortRangeKey& key)
|
|
59
123
|
{
|
|
60
|
-
return reinterpret_cast<uv_tcp_t*>(Bind(Protocol::TCP, ip, minPort, maxPort, flags,
|
|
124
|
+
return reinterpret_cast<uv_tcp_t*>(Bind(Protocol::TCP, ip, minPort, maxPort, flags, key));
|
|
61
125
|
}
|
|
62
|
-
static void Unbind(
|
|
126
|
+
static void Unbind(const PortRangeKey& key, uint16_t port);
|
|
63
127
|
void Dump(int indentation = 0) const;
|
|
64
128
|
|
|
65
129
|
private:
|
|
@@ -71,15 +135,31 @@ namespace RTC
|
|
|
71
135
|
uint16_t minPort,
|
|
72
136
|
uint16_t maxPort,
|
|
73
137
|
RTC::Transport::SocketFlags& flags,
|
|
74
|
-
|
|
75
|
-
static
|
|
76
|
-
Protocol protocol, sockaddr_storage* bindAddr, uint16_t minPort, uint16_t maxPort);
|
|
77
|
-
static PortRange& GetOrCreatePortRange(uint64_t hash, uint16_t minPort, uint16_t maxPort);
|
|
138
|
+
PortRangeKey& key);
|
|
139
|
+
static PortRange& GetOrCreatePortRange(const PortRangeKey& key, uint16_t minPort, uint16_t maxPort);
|
|
78
140
|
static uint8_t ConvertSocketFlags(RTC::Transport::SocketFlags& flags, Protocol protocol, int family);
|
|
79
141
|
|
|
80
142
|
private:
|
|
81
|
-
static thread_local ankerl::unordered_dense::map<
|
|
143
|
+
static thread_local ankerl::unordered_dense::map<PortRangeKey, PortRange, PortRangeKeyHash> mapPortRanges;
|
|
82
144
|
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* For Catch2 to print it nicely.
|
|
148
|
+
*/
|
|
149
|
+
inline std::ostream& operator<<(std::ostream& os, const PortManager::PortRangeKey& k)
|
|
150
|
+
{
|
|
151
|
+
const std::string protocolStr = (k.GetProtocol() == PortManager::Protocol::UDP) ? "udp" : "tcp";
|
|
152
|
+
|
|
153
|
+
int family;
|
|
154
|
+
uint16_t port;
|
|
155
|
+
std::string ip;
|
|
156
|
+
auto* storage = const_cast<sockaddr_storage*>(std::addressof(k.GetSockaddrStorage()));
|
|
157
|
+
|
|
158
|
+
Utils::IP::GetAddressInfo(reinterpret_cast<sockaddr*>(storage), family, ip, port);
|
|
159
|
+
|
|
160
|
+
return os << "{protocol:" << protocolStr << ", family:" << family << ", ip:" << ip
|
|
161
|
+
<< ", minPort:" << k.GetMinPort() << ", maxPort:" << k.GetMaxPort() << "}";
|
|
162
|
+
}
|
|
83
163
|
} // namespace RTC
|
|
84
164
|
|
|
85
165
|
#endif
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "common.hpp"
|
|
5
5
|
#include "handles/TcpConnectionHandle.hpp"
|
|
6
6
|
#include "handles/TcpServerHandle.hpp"
|
|
7
|
+
#include "RTC/PortManager.hpp"
|
|
7
8
|
#include "RTC/TcpConnection.hpp"
|
|
8
9
|
#include "RTC/Transport.hpp"
|
|
9
10
|
#include <string>
|
|
@@ -37,7 +38,7 @@ namespace RTC
|
|
|
37
38
|
uint16_t minPort,
|
|
38
39
|
uint16_t maxPort,
|
|
39
40
|
RTC::Transport::SocketFlags& flags,
|
|
40
|
-
|
|
41
|
+
RTC::PortManager::PortRangeKey& portRangeKey);
|
|
41
42
|
~TcpServer() override;
|
|
42
43
|
|
|
43
44
|
/* Pure virtual methods inherited from ::TcpServerHandle. */
|
|
@@ -50,7 +51,7 @@ namespace RTC
|
|
|
50
51
|
Listener* listener{ nullptr };
|
|
51
52
|
RTC::TcpConnection::Listener* connListener{ nullptr };
|
|
52
53
|
bool fixedPort{ false };
|
|
53
|
-
|
|
54
|
+
RTC::PortManager::PortRangeKey portRangeKey{};
|
|
54
55
|
};
|
|
55
56
|
} // namespace RTC
|
|
56
57
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include "common.hpp"
|
|
5
5
|
#include "handles/UdpSocketHandle.hpp"
|
|
6
|
+
#include "RTC/PortManager.hpp"
|
|
6
7
|
#include "RTC/Transport.hpp"
|
|
7
8
|
#include <string>
|
|
8
9
|
|
|
@@ -33,7 +34,7 @@ namespace RTC
|
|
|
33
34
|
uint16_t minPort,
|
|
34
35
|
uint16_t maxPort,
|
|
35
36
|
RTC::Transport::SocketFlags& flags,
|
|
36
|
-
|
|
37
|
+
RTC::PortManager::PortRangeKey& portRangeKey);
|
|
37
38
|
~UdpSocket() override;
|
|
38
39
|
|
|
39
40
|
/* Pure virtual methods inherited from ::UdpSocketHandle. */
|
|
@@ -45,7 +46,7 @@ namespace RTC
|
|
|
45
46
|
// Passed by argument.
|
|
46
47
|
Listener* listener{ nullptr };
|
|
47
48
|
bool fixedPort{ false };
|
|
48
|
-
|
|
49
|
+
RTC::PortManager::PortRangeKey portRangeKey{};
|
|
49
50
|
};
|
|
50
51
|
} // namespace RTC
|
|
51
52
|
|
package/worker/meson.build
CHANGED
|
@@ -451,6 +451,7 @@ test_sources = [
|
|
|
451
451
|
'test/src/testHelpers.cpp',
|
|
452
452
|
'test/src/RTC/TestKeyFrameRequestManager.cpp',
|
|
453
453
|
'test/src/RTC/TestNackGenerator.cpp',
|
|
454
|
+
'test/src/RTC/TestPortManager.cpp',
|
|
454
455
|
'test/src/RTC/TestRateCalculator.cpp',
|
|
455
456
|
'test/src/RTC/TestRtpEncodingParameters.cpp',
|
|
456
457
|
'test/src/RTC/TestSeqManager.cpp',
|
|
@@ -277,12 +277,22 @@ namespace RTC
|
|
|
277
277
|
len);
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
// NOTE: Capturing `this` and `request` (by reference) is safe here because the
|
|
281
|
+
// callback is always invoked synchronously within this same call stack (never
|
|
282
|
+
// deferred).
|
|
280
283
|
const auto* cb = new onQueuedCallback(
|
|
281
|
-
[&request](bool queued, bool sctpSendBufferFull)
|
|
284
|
+
[this, &request](bool queued, bool sctpSendBufferFull)
|
|
282
285
|
{
|
|
283
286
|
if (queued)
|
|
284
287
|
{
|
|
285
|
-
|
|
288
|
+
uint32_t bufferedAmount{ 0 };
|
|
289
|
+
|
|
290
|
+
this->listener->OnDataConsumerNeedBufferedAmount(this, bufferedAmount);
|
|
291
|
+
|
|
292
|
+
auto responseOffset = FBS::DataConsumer::CreateGetBufferedAmountResponse(
|
|
293
|
+
request->GetBufferBuilder(), bufferedAmount);
|
|
294
|
+
|
|
295
|
+
request->Accept(FBS::Response::Body::DataConsumer_SendResponse, responseOffset);
|
|
286
296
|
}
|
|
287
297
|
else
|
|
288
298
|
{
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "RTC/PipeTransport.hpp"
|
|
5
5
|
#include "Logger.hpp"
|
|
6
6
|
#include "MediaSoupErrors.hpp"
|
|
7
|
+
#include "RTC/PortManager.hpp"
|
|
7
8
|
#include "RTC/SCTP/packet/Packet.hpp"
|
|
8
9
|
#include "Settings.hpp"
|
|
9
10
|
#include "Utils.hpp"
|
|
@@ -72,7 +73,7 @@ namespace RTC
|
|
|
72
73
|
{
|
|
73
74
|
if (this->listenInfo.portRange.min != 0 && this->listenInfo.portRange.max != 0)
|
|
74
75
|
{
|
|
75
|
-
|
|
76
|
+
RTC::PortManager::PortRangeKey portRangeKey;
|
|
76
77
|
|
|
77
78
|
this->udpSocket = new RTC::UdpSocket(
|
|
78
79
|
this,
|
|
@@ -80,7 +81,7 @@ namespace RTC
|
|
|
80
81
|
this->listenInfo.portRange.min,
|
|
81
82
|
this->listenInfo.portRange.max,
|
|
82
83
|
this->listenInfo.flags,
|
|
83
|
-
|
|
84
|
+
portRangeKey);
|
|
84
85
|
}
|
|
85
86
|
else if (this->listenInfo.port != 0)
|
|
86
87
|
{
|
|
@@ -92,7 +93,7 @@ namespace RTC
|
|
|
92
93
|
// required.
|
|
93
94
|
else
|
|
94
95
|
{
|
|
95
|
-
|
|
96
|
+
RTC::PortManager::PortRangeKey portRangeKey;
|
|
96
97
|
|
|
97
98
|
this->udpSocket = new RTC::UdpSocket(
|
|
98
99
|
this,
|
|
@@ -100,7 +101,7 @@ namespace RTC
|
|
|
100
101
|
Settings::configuration.rtcMinPort,
|
|
101
102
|
Settings::configuration.rtcMaxPort,
|
|
102
103
|
this->listenInfo.flags,
|
|
103
|
-
|
|
104
|
+
portRangeKey);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
if (this->listenInfo.sendBufferSize != 0)
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#include "RTC/PlainTransport.hpp"
|
|
5
5
|
#include "Logger.hpp"
|
|
6
6
|
#include "MediaSoupErrors.hpp"
|
|
7
|
+
#include "RTC/PortManager.hpp"
|
|
7
8
|
#include "RTC/SCTP/packet/Packet.hpp"
|
|
8
9
|
#include "Settings.hpp"
|
|
9
10
|
#include "Utils.hpp"
|
|
@@ -151,7 +152,7 @@ namespace RTC
|
|
|
151
152
|
{
|
|
152
153
|
if (this->listenInfo.portRange.min != 0 && this->listenInfo.portRange.max != 0)
|
|
153
154
|
{
|
|
154
|
-
|
|
155
|
+
RTC::PortManager::PortRangeKey portRangeKey;
|
|
155
156
|
|
|
156
157
|
this->udpSocket = new RTC::UdpSocket(
|
|
157
158
|
this,
|
|
@@ -159,7 +160,7 @@ namespace RTC
|
|
|
159
160
|
this->listenInfo.portRange.min,
|
|
160
161
|
this->listenInfo.portRange.max,
|
|
161
162
|
this->listenInfo.flags,
|
|
162
|
-
|
|
163
|
+
portRangeKey);
|
|
163
164
|
}
|
|
164
165
|
else if (this->listenInfo.port != 0)
|
|
165
166
|
{
|
|
@@ -171,7 +172,7 @@ namespace RTC
|
|
|
171
172
|
// required.
|
|
172
173
|
else
|
|
173
174
|
{
|
|
174
|
-
|
|
175
|
+
RTC::PortManager::PortRangeKey portRangeKey;
|
|
175
176
|
|
|
176
177
|
this->udpSocket = new RTC::UdpSocket(
|
|
177
178
|
this,
|
|
@@ -179,7 +180,7 @@ namespace RTC
|
|
|
179
180
|
Settings::configuration.rtcMinPort,
|
|
180
181
|
Settings::configuration.rtcMaxPort,
|
|
181
182
|
this->listenInfo.flags,
|
|
182
|
-
|
|
183
|
+
portRangeKey);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
if (this->listenInfo.sendBufferSize != 0)
|
|
@@ -198,7 +199,7 @@ namespace RTC
|
|
|
198
199
|
{
|
|
199
200
|
if (this->rtcpListenInfo.portRange.min != 0 && this->rtcpListenInfo.portRange.max != 0)
|
|
200
201
|
{
|
|
201
|
-
|
|
202
|
+
RTC::PortManager::PortRangeKey portRangeKey;
|
|
202
203
|
|
|
203
204
|
this->rtcpUdpSocket = new RTC::UdpSocket(
|
|
204
205
|
this,
|
|
@@ -206,7 +207,7 @@ namespace RTC
|
|
|
206
207
|
this->rtcpListenInfo.portRange.min,
|
|
207
208
|
this->rtcpListenInfo.portRange.max,
|
|
208
209
|
this->rtcpListenInfo.flags,
|
|
209
|
-
|
|
210
|
+
portRangeKey);
|
|
210
211
|
}
|
|
211
212
|
else if (this->rtcpListenInfo.port != 0)
|
|
212
213
|
{
|
|
@@ -218,7 +219,7 @@ namespace RTC
|
|
|
218
219
|
// required.
|
|
219
220
|
else
|
|
220
221
|
{
|
|
221
|
-
|
|
222
|
+
RTC::PortManager::PortRangeKey portRangeKey;
|
|
222
223
|
|
|
223
224
|
this->rtcpUdpSocket = new RTC::UdpSocket(
|
|
224
225
|
this,
|
|
@@ -226,7 +227,7 @@ namespace RTC
|
|
|
226
227
|
Settings::configuration.rtcMinPort,
|
|
227
228
|
Settings::configuration.rtcMaxPort,
|
|
228
229
|
this->rtcpListenInfo.flags,
|
|
229
|
-
|
|
230
|
+
portRangeKey);
|
|
230
231
|
}
|
|
231
232
|
|
|
232
233
|
if (this->rtcpListenInfo.sendBufferSize != 0)
|