Skip to content

Commit

Permalink
- libwebrtc Apply patch by @sspanak and @Ivaka to avoid crash. Relate…
Browse files Browse the repository at this point in the history
…d issue: #357

- PortManager.cpp: Do not use `UV_UDP_RECVMMSG` in Windows due to a bug in libuv 1.37.0
  • Loading branch information
ibc committed Apr 24, 2020
1 parent fdd0090 commit 490ff5f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

### 3.5.9 (WIP)

* `libwebrtc`: Apply patch by @sspanak and @Ivaka to avoid crash. Related issue: #357.
* `PortManager.cpp`: Do not use `UV_UDP_RECVMMSG` in Windows due to a bug in libuv 1.37.0.
* Update Node deps.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
current_timestamp_group_.timestamp = timestamp;
current_timestamp_group_.first_timestamp = timestamp;
current_timestamp_group_.first_arrival_ms = arrival_time_ms;
} else if (!PacketInOrder(timestamp)) {
} else if (!PacketInOrder(timestamp, arrival_time_ms)) {
return false;
} else if (NewTimestampGroup(arrival_time_ms, timestamp)) {
// First packet of a later frame, the previous frame sample is ready.
Expand Down Expand Up @@ -110,16 +110,31 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
return calculated_deltas;
}

bool InterArrival::PacketInOrder(uint32_t timestamp) {
bool InterArrival::PacketInOrder(uint32_t timestamp, int64_t arrival_time_ms) {
if (current_timestamp_group_.IsFirstPacket()) {
return true;
} else if (arrival_time_ms < 0) {
// NOTE: Change related to https://github.com/versatica/mediasoup/issues/357
//
// Sometimes we do get negative arrival time, which causes BelongsToBurst()
// to fail, which may cause anything that uses InterArrival to crash.
//
// Credits to @sspanak and @Ivaka.
return false;
} else {
// Assume that a diff which is bigger than half the timestamp interval
// (32 bits) must be due to reordering. This code is almost identical to
// that in IsNewerTimestamp() in module_common_types.h.
uint32_t timestamp_diff =
timestamp - current_timestamp_group_.first_timestamp;
return timestamp_diff < 0x80000000;

const static uint32_t int_middle = 0x80000000;

if (timestamp_diff == int_middle) {
return timestamp > current_timestamp_group_.first_timestamp;
}

return timestamp_diff < int_middle;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ class InterArrival {
};

// Returns true if the packet with timestamp |timestamp| arrived in order.
bool PacketInOrder(uint32_t timestamp);
//
// NOTE: Change related to https://github.com/versatica/mediasoup/issues/357
//
// bool PacketInOrder(uint32_t timestamp);
bool PacketInOrder(uint32_t timestamp, int64_t arrival_time_ms);

// Returns true if the last packet was the end of the current batch and the
// packet with |timestamp| is the first of a new batch.
Expand Down
11 changes: 9 additions & 2 deletions worker/src/RTC/PortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ namespace RTC
{
case Transport::UDP:
uvHandle = reinterpret_cast<uv_handle_t*>(new uv_udp_t());
err = uv_udp_init_ex(
DepLibUV::GetLoop(), reinterpret_cast<uv_udp_t*>(uvHandle), UV_UDP_RECVMMSG);
#ifdef _WIN32
// TODO: Avoid libuv bug in Windows. Let's remove this condition once
// the issue is fixed.
// https://github.com/libuv/libuv/issues/2806
err = uv_udp_init(DepLibUV::GetLoop(), reinterpret_cast<uv_udp_t*>(uvHandle));
#else
err = uv_udp_init_ex(
DepLibUV::GetLoop(), reinterpret_cast<uv_udp_t*>(uvHandle), UV_UDP_RECVMMSG);
#endif
break;

case Transport::TCP:
Expand Down

0 comments on commit 490ff5f

Please sign in to comment.