mediasoup 3.20.5 → 3.20.7

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.
Files changed (113) hide show
  1. package/node/lib/Worker.d.ts +1 -1
  2. package/node/lib/Worker.d.ts.map +1 -1
  3. package/node/lib/Worker.js +1 -11
  4. package/node/lib/WorkerTypes.d.ts +0 -9
  5. package/node/lib/WorkerTypes.d.ts.map +1 -1
  6. package/node/lib/fbs/plain-transport/connect-response.d.ts.map +1 -1
  7. package/node/lib/fbs/plain-transport/connect-response.js +0 -1
  8. package/node/lib/fbs/worker/dump-response.d.ts +1 -5
  9. package/node/lib/fbs/worker/dump-response.d.ts.map +1 -1
  10. package/node/lib/fbs/worker/dump-response.js +3 -16
  11. package/node/lib/index.d.ts +1 -1
  12. package/node/lib/index.d.ts.map +1 -1
  13. package/node/lib/index.js +1 -2
  14. package/node/lib/test/test-PlainTransport.js +30 -0
  15. package/node/lib/test/test-Worker.js +0 -1
  16. package/npm-scripts.mjs +13 -8
  17. package/package.json +8 -8
  18. package/worker/fbs/meson.build +0 -1
  19. package/worker/fbs/plainTransport.fbs +1 -1
  20. package/worker/fbs/worker.fbs +0 -2
  21. package/worker/include/RTC/Consumer.hpp +80 -45
  22. package/worker/include/RTC/ICE/StunPacket.hpp +8 -9
  23. package/worker/include/RTC/PipeProducerStreamManager.hpp +78 -0
  24. package/worker/include/RTC/ProducerStreamManager.hpp +181 -0
  25. package/worker/include/RTC/RTP/Packet.hpp +1 -1
  26. package/worker/include/RTC/RTP/ProbationGenerator.hpp +1 -1
  27. package/worker/include/RTC/SCTP/association/Association.hpp +24 -0
  28. package/worker/include/RTC/SCTP/association/StateCookie.hpp +104 -11
  29. package/worker/include/RTC/SCTP/packet/Chunk.hpp +1 -1
  30. package/worker/include/RTC/SCTP/packet/ErrorCause.hpp +1 -1
  31. package/worker/include/RTC/SCTP/packet/Packet.hpp +1 -2
  32. package/worker/include/RTC/SCTP/packet/Parameter.hpp +1 -1
  33. package/worker/include/RTC/SCTP/packet/TLV.hpp +1 -1
  34. package/worker/include/RTC/SCTP/packet/chunks/DataChunk.hpp +1 -1
  35. package/worker/include/RTC/SCTP/packet/chunks/ForwardTsnChunk.hpp +1 -1
  36. package/worker/include/RTC/SCTP/packet/chunks/IDataChunk.hpp +1 -1
  37. package/worker/include/RTC/SCTP/packet/chunks/IForwardTsnChunk.hpp +1 -1
  38. package/worker/include/RTC/SCTP/packet/chunks/InitAckChunk.hpp +1 -1
  39. package/worker/include/RTC/SCTP/packet/chunks/InitChunk.hpp +1 -1
  40. package/worker/include/RTC/SCTP/packet/chunks/SackChunk.hpp +1 -1
  41. package/worker/include/RTC/SCTP/packet/chunks/ShutdownChunk.hpp +1 -1
  42. package/worker/include/RTC/SCTP/packet/errorCauses/InvalidStreamIdentifierErrorCause.hpp +1 -1
  43. package/worker/include/RTC/SCTP/packet/errorCauses/MissingMandatoryParameterErrorCause.hpp +1 -1
  44. package/worker/include/RTC/SCTP/packet/errorCauses/NoUserDataErrorCause.hpp +1 -1
  45. package/worker/include/RTC/SCTP/packet/errorCauses/StaleCookieErrorCause.hpp +1 -1
  46. package/worker/include/RTC/SCTP/packet/parameters/AddIncomingStreamsRequestParameter.hpp +1 -1
  47. package/worker/include/RTC/SCTP/packet/parameters/AddOutgoingStreamsRequestParameter.hpp +1 -1
  48. package/worker/include/RTC/SCTP/packet/parameters/CookiePreservativeParameter.hpp +1 -1
  49. package/worker/include/RTC/SCTP/packet/parameters/IPv4AddressParameter.hpp +1 -1
  50. package/worker/include/RTC/SCTP/packet/parameters/IPv6AddressParameter.hpp +1 -1
  51. package/worker/include/RTC/SCTP/packet/parameters/IncomingSsnResetRequestParameter.hpp +1 -1
  52. package/worker/include/RTC/SCTP/packet/parameters/OutgoingSsnResetRequestParameter.hpp +1 -1
  53. package/worker/include/RTC/SCTP/packet/parameters/ReconfigurationResponseParameter.hpp +2 -2
  54. package/worker/include/RTC/SCTP/packet/parameters/SsnTsnResetRequestParameter.hpp +1 -1
  55. package/worker/include/RTC/SCTP/packet/parameters/StateCookieParameter.hpp +4 -1
  56. package/worker/include/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.hpp +1 -1
  57. package/worker/include/RTC/SCTP/public/SctpOptions.hpp +13 -0
  58. package/worker/include/RTC/SimpleProducerStreamManager.hpp +72 -0
  59. package/worker/include/RTC/SimulcastProducerStreamManager.hpp +93 -0
  60. package/worker/include/RTC/SvcProducerStreamManager.hpp +72 -0
  61. package/worker/include/RTC/Transport.hpp +7 -1
  62. package/worker/include/Settings.hpp +0 -1
  63. package/worker/include/handles/TcpConnectionHandle.hpp +0 -4
  64. package/worker/include/handles/UdpSocketHandle.hpp +0 -4
  65. package/worker/meson.build +9 -39
  66. package/worker/meson_options.txt +0 -1
  67. package/worker/src/RTC/Consumer.cpp +1404 -30
  68. package/worker/src/RTC/DirectTransport.cpp +4 -1
  69. package/worker/src/RTC/PipeProducerStreamManager.cpp +266 -0
  70. package/worker/src/RTC/PipeTransport.cpp +9 -6
  71. package/worker/src/RTC/PlainTransport.cpp +9 -6
  72. package/worker/src/RTC/RTP/Packet.cpp +0 -2
  73. package/worker/src/RTC/RTP/RtpStreamSend.cpp +0 -20
  74. package/worker/src/RTC/Router.cpp +0 -37
  75. package/worker/src/RTC/SCTP/association/Association.cpp +150 -8
  76. package/worker/src/RTC/SCTP/association/StateCookie.cpp +96 -31
  77. package/worker/src/RTC/SCTP/packet/Packet.cpp +1 -1
  78. package/worker/src/RTC/SCTP/packet/parameters/StateCookieParameter.cpp +12 -3
  79. package/worker/src/RTC/SCTP/public/SctpOptions.cpp +4 -0
  80. package/worker/src/RTC/SimpleProducerStreamManager.cpp +343 -0
  81. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +1068 -0
  82. package/worker/src/RTC/SrtpSession.cpp +0 -24
  83. package/worker/src/RTC/SvcProducerStreamManager.cpp +664 -0
  84. package/worker/src/RTC/Transport.cpp +10 -66
  85. package/worker/src/RTC/WebRtcTransport.cpp +13 -7
  86. package/worker/src/Settings.cpp +0 -14
  87. package/worker/src/Utils/Crypto.cpp +3 -3
  88. package/worker/src/Utils/String.cpp +1 -1
  89. package/worker/src/Worker.cpp +5 -38
  90. package/worker/src/handles/TcpConnectionHandle.cpp +1 -42
  91. package/worker/src/handles/UdpSocketHandle.cpp +1 -42
  92. package/worker/src/lib.cpp +1 -10
  93. package/worker/test/include/RTC/SCTP/sctpCommon.hpp +1 -1
  94. package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +115 -0
  95. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +123 -0
  96. package/worker/test/src/RTC/SCTP/packet/TestPacket.cpp +4 -4
  97. package/worker/test/src/RTC/{TestSimpleConsumer.cpp → TestConsumer.cpp} +6 -7
  98. package/worker/test/src/RTC/TestPipeProducerStreamManager.cpp +471 -0
  99. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +531 -0
  100. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +1040 -0
  101. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +1278 -0
  102. package/worker/fbs/liburing.fbs +0 -7
  103. package/worker/include/DepLibUring.hpp +0 -143
  104. package/worker/include/RTC/PipeConsumer.hpp +0 -95
  105. package/worker/include/RTC/SimpleConsumer.hpp +0 -102
  106. package/worker/include/RTC/SimulcastConsumer.hpp +0 -141
  107. package/worker/include/RTC/SvcConsumer.hpp +0 -118
  108. package/worker/src/DepLibUring.cpp +0 -638
  109. package/worker/src/RTC/PipeConsumer.cpp +0 -874
  110. package/worker/src/RTC/SimpleConsumer.cpp +0 -882
  111. package/worker/src/RTC/SimulcastConsumer.cpp +0 -1887
  112. package/worker/src/RTC/SvcConsumer.cpp +0 -1384
  113. package/worker/subprojects/liburing.wrap +0 -14
@@ -0,0 +1,343 @@
1
+ #define MS_CLASS "RTC::SimpleProducerStreamManager"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "RTC/SimpleProducerStreamManager.hpp"
5
+ #include "Logger.hpp"
6
+
7
+ namespace RTC
8
+ {
9
+ /* Instance methods. */
10
+
11
+ SimpleProducerStreamManager::SimpleProducerStreamManager(
12
+ const std::vector<RTC::RtpEncodingParameters>& consumableRtpEncodings,
13
+ const RTC::ConsumerTypes::VideoLayers& preferredLayers,
14
+ std::unique_ptr<RTC::RTP::Codecs::EncodingContext> encodingContext,
15
+ RTC::Media::Kind kind,
16
+ bool keyFrameSupported,
17
+ Listener* listener,
18
+ SharedInterface* shared)
19
+ : ProducerStreamManager(
20
+ consumableRtpEncodings,
21
+ preferredLayers,
22
+ std::move(encodingContext),
23
+ kind,
24
+ keyFrameSupported,
25
+ listener,
26
+ shared)
27
+ {
28
+ MS_TRACE();
29
+ }
30
+
31
+ RTC::RTP::RtpStreamRecv* SimpleProducerStreamManager::GetProducerCurrentRtpStream() const
32
+ {
33
+ MS_TRACE();
34
+
35
+ return this->producerRtpStream;
36
+ }
37
+
38
+ RTC::RTP::RtpStreamRecv* SimpleProducerStreamManager::GetProducerTargetRtpStream() const
39
+ {
40
+ MS_TRACE();
41
+
42
+ return this->producerRtpStream;
43
+ }
44
+
45
+ bool SimpleProducerStreamManager::IsActive() const
46
+ {
47
+ MS_TRACE();
48
+
49
+ // clang-format off
50
+ return (
51
+ this->listener->IsActive() &&
52
+ this->producerRtpStream &&
53
+ // If there is no RTP inactivity check do not consider the stream
54
+ // inactive despite it has score 0.
55
+ (this->producerRtpStream->GetScore() > 0u || !this->producerRtpStream->HasRtpInactivityCheckEnabled())
56
+ );
57
+ // clang-format on
58
+ }
59
+
60
+ void SimpleProducerStreamManager::ProducerRtpStream(
61
+ RTC::RTP::RtpStreamRecv* rtpStream, uint32_t /*mappedSsrc*/)
62
+ {
63
+ MS_TRACE();
64
+
65
+ this->producerRtpStream = rtpStream;
66
+ }
67
+
68
+ void SimpleProducerStreamManager::ProducerNewRtpStream(
69
+ RTC::RTP::RtpStreamRecv* rtpStream, uint32_t /*mappedSsrc*/)
70
+ {
71
+ MS_TRACE();
72
+
73
+ this->producerRtpStream = rtpStream;
74
+
75
+ // Emit the score event.
76
+ this->listener->OnProducerStreamManagerScore();
77
+ }
78
+
79
+ void SimpleProducerStreamManager::ProducerRtpStreamScore(
80
+ RTC::RTP::RtpStreamRecv* /*rtpStream*/, uint8_t /*score*/, uint8_t /*previousScore*/)
81
+ {
82
+ MS_TRACE();
83
+ }
84
+
85
+ void SimpleProducerStreamManager::ProducerRtcpSenderReport(
86
+ RTC::RTP::RtpStreamRecv* /*rtpStream*/, bool /*first*/)
87
+ {
88
+ MS_TRACE();
89
+
90
+ // Do nothing.
91
+ }
92
+
93
+ uint32_t SimpleProducerStreamManager::IncreaseLayer(
94
+ uint32_t bitrate, bool /*considerLoss*/, float /*lossPercentage*/, uint64_t nowMs)
95
+ {
96
+ MS_TRACE();
97
+
98
+ MS_ASSERT(this->externallyManagedBitrate, "bitrate is not externally managed");
99
+ MS_ASSERT(this->kind == RTC::Media::Kind::VIDEO, "should be video");
100
+ MS_ASSERT(IsActive(), "should be active");
101
+
102
+ // If this is not the first time this method is called within the same
103
+ // iteration, return 0 since a video Simple consumer does not keep state
104
+ // about this.
105
+ if (this->managingBitrate)
106
+ {
107
+ return 0u;
108
+ }
109
+
110
+ this->managingBitrate = true;
111
+
112
+ if (!this->producerRtpStream)
113
+ {
114
+ return 0u;
115
+ }
116
+
117
+ // Video Simple consumer does not really play the BWE game. However, let's
118
+ // be honest and try to be nice.
119
+ auto desiredBitrate = this->producerRtpStream->GetBitrate(nowMs);
120
+
121
+ if (desiredBitrate < bitrate)
122
+ {
123
+ return desiredBitrate;
124
+ }
125
+ else
126
+ {
127
+ return bitrate;
128
+ }
129
+ }
130
+
131
+ void SimpleProducerStreamManager::ApplyLayers(uint64_t /*rtpStreamActiveMs*/)
132
+ {
133
+ MS_TRACE();
134
+
135
+ MS_ASSERT(this->externallyManagedBitrate, "bitrate is not externally managed");
136
+ MS_ASSERT(this->kind == RTC::Media::Kind::VIDEO, "should be video");
137
+ MS_ASSERT(IsActive(), "should be active");
138
+
139
+ this->managingBitrate = false;
140
+
141
+ // Simple does not play the BWE game (even if video kind).
142
+ }
143
+
144
+ uint32_t SimpleProducerStreamManager::GetDesiredBitrate(uint64_t nowMs) const
145
+ {
146
+ MS_TRACE();
147
+
148
+ MS_ASSERT(this->externallyManagedBitrate, "bitrate is not externally managed");
149
+
150
+ // Audio does not play the BWE game.
151
+ if (this->kind != RTC::Media::Kind::VIDEO)
152
+ {
153
+ return 0u;
154
+ }
155
+
156
+ if (!IsActive())
157
+ {
158
+ return 0u;
159
+ }
160
+
161
+ return this->producerRtpStream->GetBitrate(nowMs);
162
+ }
163
+
164
+ ProducerStreamManager::RtpPacketProcessResult SimpleProducerStreamManager::ProcessRtpPacket(
165
+ RTC::RTP::Packet* packet,
166
+ bool /*lastSentPacketHasMarker*/,
167
+ uint32_t /*clockRate*/,
168
+ uint32_t /*maxPacketTs*/)
169
+ {
170
+ MS_TRACE();
171
+
172
+ RtpPacketProcessResult result;
173
+
174
+ // If we need to sync, support key frames and this is not a key frame,
175
+ // ignore the packet.
176
+ if (this->syncRequired && this->keyFrameSupported && !packet->IsKeyFrame())
177
+ {
178
+ // NOTE: No need to drop the packet in the RTP sequence manager since here
179
+ // we are blocking all packets but the key frame that would trigger sync
180
+ // below.
181
+
182
+ // Store the packet for the scenario in which this packet is part of the
183
+ // key frame and it arrived before the first packet of the key frame.
184
+ result.type = RtpPacketProcessResult::Type::BUFFER;
185
+
186
+ #ifdef MS_RTC_LOGGER_RTP
187
+ packet->logger.Discarded(RTC::RtcLogger::RtpPacket::DiscardReason::NOT_A_KEYFRAME);
188
+ #endif
189
+
190
+ return result;
191
+ }
192
+
193
+ // Packets with only padding are not forwarded.
194
+ if (packet->GetPayloadLength() == 0)
195
+ {
196
+ result.type = RtpPacketProcessResult::Type::DROP;
197
+
198
+ #ifdef MS_RTC_LOGGER_RTP
199
+ packet->logger.Discarded(RTC::RtcLogger::RtpPacket::DiscardReason::EMPTY_PAYLOAD);
200
+ #endif
201
+
202
+ return result;
203
+ }
204
+
205
+ // Preserve the original marker bit. ProcessPayload may update it.
206
+ bool marker{ packet->HasMarker() };
207
+
208
+ // Process the payload if needed. Drop packet if necessary.
209
+ if (this->encodingContext && !packet->ProcessPayload(this->encodingContext.get(), marker))
210
+ {
211
+ MS_DEBUG_DEV(
212
+ "discarding packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "]",
213
+ packet->GetSsrc(),
214
+ packet->GetSequenceNumber(),
215
+ packet->GetTimestamp());
216
+
217
+ result.type = RtpPacketProcessResult::Type::DROP;
218
+
219
+ #ifdef MS_RTC_LOGGER_RTP
220
+ packet->logger.Discarded(RTC::RtcLogger::RtpPacket::DiscardReason::DROPPED_BY_CODEC);
221
+ #endif
222
+
223
+ return result;
224
+ }
225
+
226
+ // Whether this is the first packet after re-sync.
227
+ const bool isSyncPacket = this->syncRequired;
228
+
229
+ // Whether packets stored in the target layer retransmission buffer must be
230
+ // sent once this packet is sent.
231
+ bool sendBufferedPackets{ false };
232
+
233
+ // Sync sequence number and timestamp if required.
234
+ if (isSyncPacket)
235
+ {
236
+ if (packet->IsKeyFrame())
237
+ {
238
+ MS_DEBUG_TAG(
239
+ rtp,
240
+ "sync key frame received [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "]",
241
+ packet->GetSsrc(),
242
+ packet->GetSequenceNumber(),
243
+ packet->GetTimestamp());
244
+
245
+ sendBufferedPackets = true;
246
+ }
247
+
248
+ result.isSyncPacket = true;
249
+ result.syncSeqValue = packet->GetSequenceNumber() - 1;
250
+
251
+ this->syncRequired = false;
252
+ }
253
+
254
+ // Set forward action.
255
+ result.type = RtpPacketProcessResult::Type::FORWARD;
256
+ result.tsOffset = 0u;
257
+ result.marker = marker;
258
+ result.sendBufferedPackets = sendBufferedPackets;
259
+
260
+ return result;
261
+ }
262
+
263
+ void SimpleProducerStreamManager::RequestKeyFrame()
264
+ {
265
+ MS_TRACE();
266
+
267
+ if (this->kind != RTC::Media::Kind::VIDEO)
268
+ {
269
+ return;
270
+ }
271
+
272
+ auto mappedSsrc = this->consumableRtpEncodings[0].ssrc;
273
+
274
+ this->listener->OnProducerStreamManagerKeyFrameRequested(mappedSsrc);
275
+ }
276
+
277
+ void SimpleProducerStreamManager::RequestKeyFrameForTargetSpatialLayer()
278
+ {
279
+ MS_TRACE();
280
+
281
+ RequestKeyFrame();
282
+ }
283
+
284
+ void SimpleProducerStreamManager::RequestKeyFrameForCurrentSpatialLayer()
285
+ {
286
+ MS_TRACE();
287
+
288
+ RequestKeyFrame();
289
+ }
290
+
291
+ void SimpleProducerStreamManager::UpdateTargetLayers(int16_t /*spatial*/, int16_t /*temporal*/)
292
+ {
293
+ MS_TRACE();
294
+ }
295
+
296
+ bool SimpleProducerStreamManager::RecalculateTargetLayers(
297
+ RTC::ConsumerTypes::VideoLayers& /*newTargetLayers*/) const
298
+ {
299
+ MS_TRACE();
300
+
301
+ // No layer changes possible for Simple.
302
+ return false;
303
+ }
304
+
305
+ void SimpleProducerStreamManager::OnTransportConnected()
306
+ {
307
+ MS_TRACE();
308
+
309
+ this->syncRequired = true;
310
+
311
+ if (IsActive())
312
+ {
313
+ RequestKeyFrame();
314
+ }
315
+ }
316
+
317
+ void SimpleProducerStreamManager::OnTransportDisconnected()
318
+ {
319
+ MS_TRACE();
320
+
321
+ // Nothing specific for Simple.
322
+ }
323
+
324
+ void SimpleProducerStreamManager::OnPaused()
325
+ {
326
+ MS_TRACE();
327
+
328
+ // Nothing specific for Simple.
329
+ }
330
+
331
+ void SimpleProducerStreamManager::OnResumed()
332
+ {
333
+ MS_TRACE();
334
+
335
+ this->syncRequired = true;
336
+
337
+ if (IsActive())
338
+ {
339
+ RequestKeyFrame();
340
+ }
341
+ }
342
+
343
+ } // namespace RTC