mediasoup 3.11.21 → 3.11.23

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 (47) hide show
  1. package/node/lib/ActiveSpeakerObserver.d.ts +1 -1
  2. package/node/lib/ActiveSpeakerObserver.d.ts.map +1 -1
  3. package/node/lib/AudioLevelObserver.d.ts +1 -1
  4. package/node/lib/AudioLevelObserver.d.ts.map +1 -1
  5. package/node/lib/DirectTransport.d.ts +1 -1
  6. package/node/lib/DirectTransport.d.ts.map +1 -1
  7. package/node/lib/PipeTransport.d.ts +1 -1
  8. package/node/lib/PipeTransport.d.ts.map +1 -1
  9. package/node/lib/PlainTransport.d.ts +1 -1
  10. package/node/lib/PlainTransport.d.ts.map +1 -1
  11. package/node/lib/RtpObserver.d.ts +1 -1
  12. package/node/lib/RtpObserver.d.ts.map +1 -1
  13. package/node/lib/Transport.d.ts +1 -1
  14. package/node/lib/Transport.d.ts.map +1 -1
  15. package/node/lib/WebRtcTransport.d.ts +1 -1
  16. package/node/lib/WebRtcTransport.d.ts.map +1 -1
  17. package/node/lib/Worker.js +1 -1
  18. package/node/lib/index.d.ts +1 -1
  19. package/node/lib/index.js +1 -1
  20. package/package.json +5 -5
  21. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc +20 -1
  22. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.h +3 -0
  23. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/delay_based_bwe.cc +2 -2
  24. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.cc +1 -1
  25. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/trendline_estimator.cc +113 -106
  26. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/trendline_estimator.h +47 -26
  27. package/worker/deps/libwebrtc/libwebrtc/rtc_base/experiments/alr_experiment.cc +8 -5
  28. package/worker/deps/libwebrtc/libwebrtc/rtc_base/experiments/alr_experiment.h +1 -0
  29. package/worker/include/RTC/RtcLogger.hpp +58 -0
  30. package/worker/include/RTC/RtpPacket.hpp +4 -0
  31. package/worker/include/RTC/RtpStreamRecv.hpp +3 -1
  32. package/worker/include/RTC/SeqManager.hpp +0 -1
  33. package/worker/meson.build +7 -0
  34. package/worker/meson_options.txt +1 -0
  35. package/worker/src/RTC/PipeConsumer.cpp +15 -0
  36. package/worker/src/RTC/Producer.cpp +14 -1
  37. package/worker/src/RTC/Router.cpp +2 -0
  38. package/worker/src/RTC/RtcLogger.cpp +101 -0
  39. package/worker/src/RTC/RtpPacket.cpp +9 -0
  40. package/worker/src/RTC/RtpStreamRecv.cpp +14 -11
  41. package/worker/src/RTC/SeqManager.cpp +48 -65
  42. package/worker/src/RTC/SimpleConsumer.cpp +17 -0
  43. package/worker/src/RTC/SimulcastConsumer.cpp +34 -0
  44. package/worker/src/RTC/SvcConsumer.cpp +19 -0
  45. package/worker/src/RTC/Transport.cpp +7 -0
  46. package/worker/test/src/RTC/TestRtpStreamRecv.cpp +4 -3
  47. package/worker/test/src/RTC/TestSeqManager.cpp +80 -83
@@ -672,6 +672,8 @@ namespace RTC
672
672
  {
673
673
  MS_TRACE();
674
674
 
675
+ packet->logger.producerId = this->id;
676
+
675
677
  // Reset current packet.
676
678
  this->currentRtpPacket = nullptr;
677
679
 
@@ -684,6 +686,8 @@ namespace RTC
684
686
  {
685
687
  MS_WARN_TAG(rtp, "no stream found for received packet [ssrc:%" PRIu32 "]", packet->GetSsrc());
686
688
 
689
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::RECV_RTP_STREAM_NOT_FOUND);
690
+
687
691
  return ReceiveRtpPacketResult::DISCARDED;
688
692
  }
689
693
 
@@ -705,6 +709,8 @@ namespace RTC
705
709
  if (this->mapSsrcRtpStream.size() > numRtpStreamsBefore)
706
710
  NotifyNewRtpStream(rtpStream);
707
711
 
712
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::RECV_RTP_STREAM_DISCARDED);
713
+
708
714
  return result;
709
715
  }
710
716
  }
@@ -716,7 +722,11 @@ namespace RTC
716
722
 
717
723
  // Process the packet.
718
724
  if (!rtpStream->ReceiveRtxPacket(packet))
725
+ {
726
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::RECV_RTP_STREAM_NOT_FOUND);
727
+
719
728
  return result;
729
+ }
720
730
  }
721
731
  // Should not happen.
722
732
  else
@@ -1213,8 +1223,11 @@ namespace RTC
1213
1223
  }
1214
1224
  }
1215
1225
 
1226
+ // Only perform RTP inactivity check on simulcast.
1227
+ auto useRtpInactivityCheck = this->type == RtpParameters::Type::SIMULCAST;
1228
+
1216
1229
  // Create a RtpStreamRecv for receiving a media stream.
1217
- auto* rtpStream = new RTC::RtpStreamRecv(this, params, SendNackDelay);
1230
+ auto* rtpStream = new RTC::RtpStreamRecv(this, params, SendNackDelay, useRtpInactivityCheck);
1218
1231
 
1219
1232
  // Insert into the maps.
1220
1233
  this->mapSsrcRtpStream[ssrc] = rtpStream;
@@ -706,6 +706,8 @@ namespace RTC
706
706
  {
707
707
  MS_TRACE();
708
708
 
709
+ packet->logger.routerId = this->id;
710
+
709
711
  auto& consumers = this->mapProducerConsumers.at(producer);
710
712
 
711
713
  if (!consumers.empty())
@@ -0,0 +1,101 @@
1
+ #define MS_CLASS "RTC::RtcLogger"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "RTC/RtcLogger.hpp"
5
+ #include "Logger.hpp"
6
+
7
+ namespace RTC
8
+ {
9
+ namespace RtcLogger
10
+ {
11
+ // clang-format off
12
+ absl::flat_hash_map<RtpPacket::DropReason, std::string> RtpPacket::dropReason2String = {
13
+ { RtpPacket::DropReason::NONE, "None" },
14
+ { RtpPacket::DropReason::PRODUCER_NOT_FOUND, "ProducerNotFound" },
15
+ { RtpPacket::DropReason::RECV_RTP_STREAM_NOT_FOUND, "RecvRtpStreamNotFound" },
16
+ { RtpPacket::DropReason::RECV_RTP_STREAM_DISCARDED, "RecvRtpStreamDiscarded" },
17
+ { RtpPacket::DropReason::CONSUMER_INACTIVE, "ConsumerInactive" },
18
+ { RtpPacket::DropReason::INVALID_TARGET_LAYER, "InvalidTargetLayer" },
19
+ { RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE, "UnsupportedPayloadType" },
20
+ { RtpPacket::DropReason::NOT_A_KEYFRAME, "NotAKeyframe" },
21
+ { RtpPacket::DropReason::SPATIAL_LAYER_MISMATCH, "SpatialLayerMismatch" },
22
+ { RtpPacket::DropReason::TOO_HIGH_TIMESTAMP_EXTRA_NEEDED, "TooHighTimestampExtraNeeded" },
23
+ { RtpPacket::DropReason::PACKET_PREVIOUS_TO_SPATIAL_LAYER_SWITCH, "PacketPreviousToSpatialLayerSwitch" },
24
+ { RtpPacket::DropReason::DROPPED_BY_CODEC, "DroppedByCodec" },
25
+ { RtpPacket::DropReason::SEND_RTP_STREAM_DISCARDED, "SendRtpStreamDiscarded" },
26
+ };
27
+ // clang-format on
28
+
29
+ void RtpPacket::Sent()
30
+ {
31
+ MS_TRACE();
32
+
33
+ this->dropped = false;
34
+
35
+ Log();
36
+ Clear();
37
+ }
38
+
39
+ void RtpPacket::Dropped(DropReason dropReason)
40
+ {
41
+ MS_TRACE();
42
+
43
+ this->dropped = true;
44
+ this->dropReason = dropReason;
45
+
46
+ Log();
47
+ Clear();
48
+ }
49
+
50
+ void RtpPacket::Log() const
51
+ {
52
+ #ifdef MS_RTC_LOGGER_RTP
53
+ MS_TRACE();
54
+
55
+ std::cout << "{";
56
+ std::cout << "\"timestamp\": " << this->timestamp;
57
+
58
+ if (!this->recvTransportId.empty())
59
+ {
60
+ std::cout << ", \"recvTransportId\": \"" << this->recvTransportId << "\"";
61
+ }
62
+ if (!this->sendTransportId.empty())
63
+ {
64
+ std::cout << ", \"sendTransportId\": \"" << this->sendTransportId << "\"";
65
+ }
66
+ if (!this->routerId.empty())
67
+ {
68
+ std::cout << ", \"routerId\": \"" << this->routerId << "\"";
69
+ }
70
+ if (!this->producerId.empty())
71
+ {
72
+ std::cout << ", \"producerId\": \"" << this->producerId << "\"";
73
+ }
74
+ if (!this->consumerId.empty())
75
+ {
76
+ std::cout << ", \"consumerId\": \"" << this->consumerId << "\"";
77
+ }
78
+
79
+ std::cout << ", \"recvRtpTimestamp\": " << this->recvRtpTimestamp;
80
+ std::cout << ", \"sendRtpTimestamp\": " << this->sendRtpTimestamp;
81
+ std::cout << ", \"recvSeqNumber\": " << this->recvSeqNumber;
82
+ std::cout << ", \"sendSeqNumber\": " << this->sendSeqNumber;
83
+ std::cout << ", \"dropped\": " << (this->dropped ? "true" : "false");
84
+ std::cout << ", \"dropReason\": '" << dropReason2String[this->dropReason] << "'";
85
+ std::cout << "}" << std::endl;
86
+ #endif
87
+ }
88
+
89
+ void RtpPacket::Clear()
90
+ {
91
+ MS_TRACE();
92
+
93
+ this->sendTransportId = {};
94
+ this->routerId = {};
95
+ this->producerId = {};
96
+ this->sendSeqNumber = { 0 };
97
+ this->dropped = { false };
98
+ this->dropReason = { DropReason::NONE };
99
+ }
100
+ } // namespace RtcLogger
101
+ } // namespace RTC
@@ -2,6 +2,7 @@
2
2
  // #define MS_LOG_DEV_LEVEL 3
3
3
 
4
4
  #include "RTC/RtpPacket.hpp"
5
+ #include "DepLibUV.hpp"
5
6
  #include "Logger.hpp"
6
7
  #include <cstring> // std::memcpy(), std::memmove(), std::memset()
7
8
  #include <iterator> // std::ostream_iterator
@@ -139,6 +140,14 @@ namespace RTC
139
140
 
140
141
  // Parse RFC 5285 header extension.
141
142
  ParseExtensions();
143
+
144
+ // Avoid retrieving the time if RTC logger is disabled.
145
+ #ifdef MS_RTC_LOGGER_RTP
146
+ // Initialize logger.
147
+ this->logger.timestamp = DepLibUV::GetTimeMs();
148
+ this->logger.recvRtpTimestamp = this->GetTimestamp();
149
+ this->logger.recvSeqNumber = this->GetSequenceNumber();
150
+ #endif
142
151
  }
143
152
 
144
153
  RtpPacket::~RtpPacket()
@@ -189,8 +189,12 @@ namespace RTC
189
189
  /* Instance methods. */
190
190
 
191
191
  RtpStreamRecv::RtpStreamRecv(
192
- RTC::RtpStreamRecv::Listener* listener, RTC::RtpStream::Params& params, unsigned int sendNackDelayMs)
192
+ RTC::RtpStreamRecv::Listener* listener,
193
+ RTC::RtpStream::Params& params,
194
+ unsigned int sendNackDelayMs,
195
+ bool useRtpInactivityCheck)
193
196
  : RTC::RtpStream::RtpStream(listener, params, 10), sendNackDelayMs(sendNackDelayMs),
197
+ useRtpInactivityCheck(useRtpInactivityCheck),
194
198
  transmissionCounter(
195
199
  params.spatialLayers, params.temporalLayers, this->params.useDtx ? 6000 : 2500)
196
200
  {
@@ -201,18 +205,16 @@ namespace RTC
201
205
  this->nackGenerator.reset(new RTC::NackGenerator(this, this->sendNackDelayMs));
202
206
  }
203
207
 
204
- // Run the RTP inactivity periodic timer (use a different timeout if DTX is
205
- // enabled).
206
- this->inactivityCheckPeriodicTimer = new Timer(this);
207
- this->inactive = false;
208
+ this->inactive = false;
208
209
 
209
- if (!this->params.useDtx)
210
+ if (this->useRtpInactivityCheck)
210
211
  {
211
- this->inactivityCheckPeriodicTimer->Start(InactivityCheckInterval);
212
- }
213
- else
214
- {
215
- this->inactivityCheckPeriodicTimer->Start(InactivityCheckIntervalWithDtx);
212
+ // Run the RTP inactivity periodic timer (use a different timeout if DTX is
213
+ // enabled).
214
+ this->inactivityCheckPeriodicTimer = new Timer(this);
215
+
216
+ this->inactivityCheckPeriodicTimer->Start(
217
+ this->params.useDtx ? InactivityCheckIntervalWithDtx : InactivityCheckInterval);
216
218
  }
217
219
  }
218
220
 
@@ -222,6 +224,7 @@ namespace RTC
222
224
 
223
225
  // Close the RTP inactivity check periodic timer.
224
226
  delete this->inactivityCheckPeriodicTimer;
227
+ this->inactivityCheckPeriodicTimer = nullptr;
225
228
  }
226
229
 
227
230
  void RtpStreamRecv::FillJsonStats(json& jsonObject)
@@ -58,14 +58,11 @@ namespace RTC
58
58
  // Mark as dropped if 'input' is higher than anyone already processed.
59
59
  if (SeqManager<T, N>::IsSeqHigherThan(input, this->maxInput))
60
60
  {
61
+ this->maxInput = input;
61
62
  this->dropped.insert(input);
62
- }
63
- }
64
63
 
65
- template<typename T, uint8_t N>
66
- void SeqManager<T, N>::Offset(T offset)
67
- {
68
- this->base = (this->base + offset) & MaxValue;
64
+ ClearDropped();
65
+ }
69
66
  }
70
67
 
71
68
  template<typename T, uint8_t N>
@@ -73,44 +70,52 @@ namespace RTC
73
70
  {
74
71
  auto base = this->base;
75
72
 
76
- // There are dropped inputs. Synchronize.
77
- if (!this->dropped.empty())
73
+ // No dropped inputs to consider.
74
+ if (this->dropped.empty())
75
+ {
76
+ goto done;
77
+ }
78
+ // Dropped inputs present, cleanup and update base.
79
+ else
78
80
  {
79
- // Check whether this input was dropped.
80
- if (this->dropped.find(input) != this->dropped.end())
81
+ // Set 'maxInput' here if needed before calling ClearDropped().
82
+ if (this->started && IsSeqHigherThan(input, this->maxInput))
81
83
  {
82
- MS_DEBUG_DEV("trying to send a dropped input");
83
-
84
- return false;
84
+ this->maxInput = input;
85
85
  }
86
86
 
87
- // Dropped entries count that must be considered for the output.
88
- size_t count{ 0 };
87
+ ClearDropped();
88
+
89
+ base = this->base;
90
+ }
89
91
 
90
- /*
91
- * Consider values lower than input and those higher that input
92
- * which belong to a previous cycle.
93
- */
94
- for (const auto& value : this->dropped)
92
+ // No dropped inputs to consider after cleanup.
93
+ if (this->dropped.empty())
94
+ {
95
+ goto done;
96
+ }
97
+ // This input was dropped.
98
+ else if (this->dropped.find(input) != this->dropped.end())
99
+ {
100
+ MS_DEBUG_DEV("trying to send a dropped input");
101
+
102
+ return false;
103
+ }
104
+ // There are dropped inputs, calculate 'base' for this input.
105
+ else
106
+ {
107
+ // Get the first dropped input which is higher than or equal 'input'.
108
+ auto it = this->dropped.lower_bound(input);
109
+
110
+ // There are dropped inputs lower than 'input'.
111
+ if (it != this->dropped.begin())
95
112
  {
96
- // clang-format off
97
- if
98
- (
99
- IsSeqLowerThan(value, input) ||
100
- (
101
- (value > input && (value - input > MaxValue / 3)) ||
102
- (value < input && (input - value > MaxValue / 3))
103
- )
104
- )
105
- // clang-format on
106
- {
107
- count++;
108
- }
113
+ auto count = std::distance(this->dropped.begin(), it);
114
+ base = (this->base - count) & MaxValue;
109
115
  }
110
-
111
- base = (this->base - count) & MaxValue;
112
116
  }
113
117
 
118
+ done:
114
119
  output = (input + base) & MaxValue;
115
120
 
116
121
  if (!this->started)
@@ -122,23 +127,19 @@ namespace RTC
122
127
  }
123
128
  else
124
129
  {
125
- // New input is higher than the maximum seen. But less than acceptable units higher.
126
- // Keep it as the maximum seen. See Drop().
130
+ // New input is higher than the maximum seen.
127
131
  if (IsSeqHigherThan(input, this->maxInput))
128
132
  {
129
133
  this->maxInput = input;
130
134
  }
131
135
 
132
- // New output is higher than the maximum seen. But less than acceptable units higher.
133
- // Keep it as the maximum seen. See Sync().
136
+ // New output is higher than the maximum seen.
134
137
  if (IsSeqHigherThan(output, this->maxOutput))
135
138
  {
136
139
  this->maxOutput = output;
137
140
  }
138
141
  }
139
142
 
140
- ClearDropped();
141
-
142
143
  return true;
143
144
  }
144
145
 
@@ -155,7 +156,7 @@ namespace RTC
155
156
  }
156
157
 
157
158
  /*
158
- * Delete droped inputs greater than maxInput that belong to a previous
159
+ * Delete droped inputs greater than maxInput, which belong to a previous
159
160
  * cycle.
160
161
  */
161
162
  template<typename T, uint8_t N>
@@ -167,37 +168,19 @@ namespace RTC
167
168
  return;
168
169
  }
169
170
 
170
- const size_t threshold = (this->maxInput + MaxValue / 3) & MaxValue;
171
171
  const size_t previousDroppedSize = this->dropped.size();
172
- const auto it1 = this->dropped.upper_bound(this->maxInput);
173
- const auto it2 = this->dropped.lower_bound(threshold);
174
172
 
175
- // There is no dropped value greater than this->maxInput.
176
- if (it1 == this->dropped.end())
177
- {
178
- return;
179
- }
180
-
181
- // There is a single value in the range.
182
- if (it1 == it2)
183
- {
184
- this->dropped.erase(it1);
185
- }
186
- // There are many values in the range.
187
- else
173
+ for (auto it = this->dropped.begin(); it != this->dropped.end();)
188
174
  {
189
- // Measure the distance of it1 and it2 to the beggining of dropped.
190
- auto distanceIt1 = std::distance(this->dropped.begin(), it1);
191
- auto distanceIt2 = std::distance(this->dropped.begin(), it2);
175
+ auto value = *it;
192
176
 
193
- // it2 goes out of range, only it1 is within the range.
194
- if (distanceIt2 < distanceIt1)
177
+ if (isSeqHigherThan(value, this->maxInput))
195
178
  {
196
- this->dropped.erase(it1);
179
+ it = this->dropped.erase(it);
197
180
  }
198
181
  else
199
182
  {
200
- this->dropped.erase(it1, it2);
183
+ break;
201
184
  }
202
185
  }
203
186
 
@@ -265,8 +265,14 @@ namespace RTC
265
265
  {
266
266
  MS_TRACE();
267
267
 
268
+ packet->logger.consumerId = this->id;
269
+
268
270
  if (!IsActive())
271
+ {
272
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
273
+
269
274
  return;
275
+ }
270
276
 
271
277
  auto payloadType = packet->GetPayloadType();
272
278
 
@@ -276,6 +282,8 @@ namespace RTC
276
282
  {
277
283
  MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
278
284
 
285
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE);
286
+
279
287
  return;
280
288
  }
281
289
 
@@ -292,13 +300,19 @@ namespace RTC
292
300
 
293
301
  this->rtpSeqManager.Drop(packet->GetSequenceNumber());
294
302
 
303
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::DROPPED_BY_CODEC);
304
+
295
305
  return;
296
306
  }
297
307
 
298
308
  // If we need to sync, support key frames and this is not a key frame, ignore
299
309
  // the packet.
300
310
  if (this->syncRequired && this->keyFrameSupported && !packet->IsKeyFrame())
311
+ {
312
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
313
+
301
314
  return;
315
+ }
302
316
 
303
317
  // Whether this is the first packet after re-sync.
304
318
  const bool isSyncPacket = this->syncRequired;
@@ -327,6 +341,9 @@ namespace RTC
327
341
  packet->SetSsrc(this->rtpParameters.encodings[0].ssrc);
328
342
  packet->SetSequenceNumber(seq);
329
343
 
344
+ packet->logger.sendRtpTimestamp = packet->GetTimestamp();
345
+ packet->logger.sendSeqNumber = seq;
346
+
330
347
  if (isSyncPacket)
331
348
  {
332
349
  MS_DEBUG_TAG(
@@ -664,11 +664,21 @@ namespace RTC
664
664
  {
665
665
  MS_TRACE();
666
666
 
667
+ packet->logger.consumerId = this->id;
668
+
667
669
  if (!IsActive())
670
+ {
671
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
672
+
668
673
  return;
674
+ }
669
675
 
670
676
  if (this->targetTemporalLayer == -1)
677
+ {
678
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::INVALID_TARGET_LAYER);
679
+
671
680
  return;
681
+ }
672
682
 
673
683
  auto payloadType = packet->GetPayloadType();
674
684
 
@@ -678,6 +688,8 @@ namespace RTC
678
688
  {
679
689
  MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
680
690
 
691
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE);
692
+
681
693
  return;
682
694
  }
683
695
 
@@ -690,7 +702,11 @@ namespace RTC
690
702
  {
691
703
  // Ignore if not a key frame.
692
704
  if (!packet->IsKeyFrame())
705
+ {
706
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
707
+
693
708
  return;
709
+ }
694
710
 
695
711
  shouldSwitchCurrentSpatialLayer = true;
696
712
 
@@ -702,12 +718,18 @@ namespace RTC
702
718
  // drop it.
703
719
  else if (spatialLayer != this->currentSpatialLayer)
704
720
  {
721
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::SPATIAL_LAYER_MISMATCH);
722
+
705
723
  return;
706
724
  }
707
725
 
708
726
  // If we need to sync and this is not a key frame, ignore the packet.
709
727
  if (this->syncRequired && !packet->IsKeyFrame())
728
+ {
729
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
730
+
710
731
  return;
732
+ }
711
733
 
712
734
  // Whether this is the first packet after re-sync.
713
735
  const bool isSyncPacket = this->syncRequired;
@@ -814,6 +836,8 @@ namespace RTC
814
836
  this->syncRequired = false;
815
837
  this->spatialLayerToSync = -1;
816
838
 
839
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::TOO_HIGH_TIMESTAMP_EXTRA_NEEDED);
840
+
817
841
  return;
818
842
  }
819
843
 
@@ -854,6 +878,9 @@ namespace RTC
854
878
  if (SeqManager<uint16_t>::IsSeqLowerThan(
855
879
  packet->GetSequenceNumber(), this->snReferenceSpatialLayer))
856
880
  {
881
+ packet->logger.Dropped(
882
+ RtcLogger::RtpPacket::DropReason::PACKET_PREVIOUS_TO_SPATIAL_LAYER_SWITCH);
883
+
857
884
  return;
858
885
  }
859
886
  else if (SeqManager<uint16_t>::IsSeqHigherThan(
@@ -898,6 +925,8 @@ namespace RTC
898
925
  {
899
926
  this->rtpSeqManager.Drop(packet->GetSequenceNumber());
900
927
 
928
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::DROPPED_BY_CODEC);
929
+
901
930
  return;
902
931
  }
903
932
 
@@ -921,6 +950,9 @@ namespace RTC
921
950
  packet->SetSequenceNumber(seq);
922
951
  packet->SetTimestamp(timestamp);
923
952
 
953
+ packet->logger.sendRtpTimestamp = timestamp;
954
+ packet->logger.sendSeqNumber = seq;
955
+
924
956
  if (isSyncPacket)
925
957
  {
926
958
  MS_DEBUG_TAG(
@@ -959,6 +991,8 @@ namespace RTC
959
991
  origSsrc,
960
992
  origSeq,
961
993
  origTimestamp);
994
+
995
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::SEND_RTP_STREAM_DISCARDED);
962
996
  }
963
997
 
964
998
  // Restore packet fields.
@@ -593,8 +593,14 @@ namespace RTC
593
593
  {
594
594
  MS_TRACE();
595
595
 
596
+ packet->logger.consumerId = this->id;
597
+
596
598
  if (!IsActive())
599
+ {
600
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
601
+
597
602
  return;
603
+ }
598
604
 
599
605
  // clang-format off
600
606
  if (
@@ -603,6 +609,8 @@ namespace RTC
603
609
  )
604
610
  // clang-format on
605
611
  {
612
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::INVALID_TARGET_LAYER);
613
+
606
614
  return;
607
615
  }
608
616
 
@@ -614,12 +622,18 @@ namespace RTC
614
622
  {
615
623
  MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
616
624
 
625
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE);
626
+
617
627
  return;
618
628
  }
619
629
 
620
630
  // If we need to sync and this is not a key frame, ignore the packet.
621
631
  if (this->syncRequired && !packet->IsKeyFrame())
632
+ {
633
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
634
+
622
635
  return;
636
+ }
623
637
 
624
638
  // Whether this is the first packet after re-sync.
625
639
  const bool isSyncPacket = this->syncRequired;
@@ -646,6 +660,8 @@ namespace RTC
646
660
  {
647
661
  this->rtpSeqManager.Drop(packet->GetSequenceNumber());
648
662
 
663
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::DROPPED_BY_CODEC);
664
+
649
665
  return;
650
666
  }
651
667
 
@@ -673,6 +689,9 @@ namespace RTC
673
689
  packet->SetSsrc(this->rtpParameters.encodings[0].ssrc);
674
690
  packet->SetSequenceNumber(seq);
675
691
 
692
+ packet->logger.sendRtpTimestamp = packet->GetTimestamp();
693
+ packet->logger.sendSeqNumber = seq;
694
+
676
695
  if (marker)
677
696
  {
678
697
  packet->SetMarker(true);
@@ -1692,6 +1692,8 @@ namespace RTC
1692
1692
  {
1693
1693
  MS_TRACE();
1694
1694
 
1695
+ packet->logger.recvTransportId = this->id;
1696
+
1695
1697
  // Apply the Transport RTP header extension ids so the RTP listener can use them.
1696
1698
  packet->SetMidExtensionId(this->recvRtpHeaderExtensionIds.mid);
1697
1699
  packet->SetRidExtensionId(this->recvRtpHeaderExtensionIds.rid);
@@ -1712,6 +1714,8 @@ namespace RTC
1712
1714
 
1713
1715
  if (!producer)
1714
1716
  {
1717
+ packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::PRODUCER_NOT_FOUND);
1718
+
1715
1719
  MS_WARN_TAG(
1716
1720
  rtp,
1717
1721
  "no suitable Producer for received RTP packet [ssrc:%" PRIu32 ", payloadType:%" PRIu8 "]",
@@ -2663,6 +2667,9 @@ namespace RTC
2663
2667
  {
2664
2668
  MS_TRACE();
2665
2669
 
2670
+ packet->logger.sendTransportId = this->id;
2671
+ packet->logger.Sent();
2672
+
2666
2673
  // Update abs-send-time if present.
2667
2674
  packet->UpdateAbsSendTime(DepLibUV::GetTimeMs());
2668
2675
 
@@ -11,6 +11,7 @@ using namespace RTC;
11
11
  // 17: 16 bit mask + the initial sequence number.
12
12
  static constexpr size_t MaxRequestedPackets{ 17 };
13
13
  static constexpr unsigned int SendNackDelay{ 0u }; // In ms.
14
+ static const bool UseRtpInactivityCheck{ false };
14
15
 
15
16
  SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]")
16
17
  {
@@ -141,7 +142,7 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]")
141
142
  SECTION("NACK one packet")
142
143
  {
143
144
  RtpStreamRecvListener listener;
144
- RtpStreamRecv rtpStream(&listener, params, SendNackDelay);
145
+ RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
145
146
 
146
147
  packet->SetSequenceNumber(1);
147
148
  rtpStream.ReceivePacket(packet);
@@ -170,7 +171,7 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]")
170
171
  SECTION("wrapping sequence numbers")
171
172
  {
172
173
  RtpStreamRecvListener listener;
173
- RtpStreamRecv rtpStream(&listener, params, SendNackDelay);
174
+ RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
174
175
 
175
176
  packet->SetSequenceNumber(0xfffe);
176
177
  rtpStream.ReceivePacket(packet);
@@ -190,7 +191,7 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]")
190
191
  SECTION("require key frame")
191
192
  {
192
193
  RtpStreamRecvListener listener;
193
- RtpStreamRecv rtpStream(&listener, params, SendNackDelay);
194
+ RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
194
195
 
195
196
  packet->SetSequenceNumber(1);
196
197
  rtpStream.ReceivePacket(packet);