summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/rtc_base/async_udp_socket.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/libwebrtc/rtc_base/async_udp_socket.cc40
1 files changed, 25 insertions, 15 deletions
diff --git a/third_party/libwebrtc/rtc_base/async_udp_socket.cc b/third_party/libwebrtc/rtc_base/async_udp_socket.cc
index 358420a5de..3d258bcb26 100644
--- a/third_party/libwebrtc/rtc_base/async_udp_socket.cc
+++ b/third_party/libwebrtc/rtc_base/async_udp_socket.cc
@@ -10,9 +10,11 @@
#include "rtc_base/async_udp_socket.h"
-
+#include "absl/types/optional.h"
+#include "api/units/time_delta.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
+#include "rtc_base/network/received_packet.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/field_trial.h"
@@ -109,10 +111,8 @@ void AsyncUDPSocket::OnReadEvent(Socket* socket) {
RTC_DCHECK(socket_.get() == socket);
RTC_DCHECK_RUN_ON(&sequence_checker_);
- SocketAddress remote_addr;
- int64_t timestamp = -1;
- int len = socket_->RecvFrom(buf_, BUF_SIZE, &remote_addr, &timestamp);
-
+ Socket::ReceiveBuffer receive_buffer(buffer_);
+ int len = socket_->RecvFrom(receive_buffer);
if (len < 0) {
// An error here typically means we got an ICMP error in response to our
// send datagram, indicating the remote address was unreachable.
@@ -123,21 +123,31 @@ void AsyncUDPSocket::OnReadEvent(Socket* socket) {
<< "] receive failed with error " << socket_->GetError();
return;
}
- if (timestamp == -1) {
+ if (len == 0) {
+ // Spurios wakeup.
+ return;
+ }
+
+ if (!receive_buffer.arrival_time) {
// Timestamp from socket is not available.
- timestamp = TimeMicros();
+ receive_buffer.arrival_time = webrtc::Timestamp::Micros(rtc::TimeMicros());
} else {
if (!socket_time_offset_) {
- socket_time_offset_ =
- !IsScmTimeStampExperimentDisabled() ? TimeMicros() - timestamp : 0;
+ // Estimate timestamp offset from first packet arrival time unless
+ // disabled
+ bool estimate_time_offset = !IsScmTimeStampExperimentDisabled();
+ if (estimate_time_offset) {
+ socket_time_offset_ = webrtc::Timestamp::Micros(rtc::TimeMicros()) -
+ *receive_buffer.arrival_time;
+ } else {
+ socket_time_offset_ = webrtc::TimeDelta::Micros(0);
+ }
}
- timestamp += *socket_time_offset_;
+ *receive_buffer.arrival_time += *socket_time_offset_;
}
-
- // TODO: Make sure that we got all of the packet.
- // If we did not, then we should resize our buffer to be large enough.
- NotifyPacketReceived(
- rtc::ReceivedPacket::CreateFromLegacy(buf_, len, timestamp, remote_addr));
+ NotifyPacketReceived(ReceivedPacket(receive_buffer.payload,
+ receive_buffer.source_address,
+ receive_buffer.arrival_time));
}
void AsyncUDPSocket::OnWriteEvent(Socket* socket) {