Signal detailed packet info for each packet sent.

Per-packet info is now signaled in SentPacket to provide useful stats
for bandwidth consumption and overhead analysis in the network stack.

Bug: webrtc:9103
Change-Id: I2b8f6491567d0fa54cc559fc5a96d7aac7d9565e
Reviewed-on: https://webrtc-review.googlesource.com/66281
Commit-Queue: Qingsi Wang <qingsi@google.com>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Bjorn Mellem <mellem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22834}
This commit is contained in:
Qingsi Wang
2018-04-11 20:14:17 -07:00
committed by Commit Bot
parent bc49b10a69
commit 6e641e64b2
17 changed files with 188 additions and 34 deletions

View File

@ -805,6 +805,7 @@ rtc_static_library("rtc_base_generic") {
"sigslot.cc",
"sigslot.h",
"sigslotrepeater.h",
"socket.cc",
"socket.h",
"socketadapters.cc",
"socketadapters.h",

View File

@ -12,18 +12,28 @@
namespace rtc {
PacketTimeUpdateParams::PacketTimeUpdateParams()
: rtp_sendtime_extension_id(-1),
srtp_auth_tag_len(-1),
srtp_packet_index(-1) {
}
PacketTimeUpdateParams::PacketTimeUpdateParams() = default;
PacketTimeUpdateParams::PacketTimeUpdateParams(
const PacketTimeUpdateParams& other) = default;
PacketTimeUpdateParams::~PacketTimeUpdateParams() = default;
AsyncPacketSocket::AsyncPacketSocket() {
}
PacketOptions::PacketOptions() = default;
PacketOptions::PacketOptions(DiffServCodePoint dscp) : dscp(dscp) {}
PacketOptions::PacketOptions(const PacketOptions& other) = default;
PacketOptions::~PacketOptions() = default;
AsyncPacketSocket::~AsyncPacketSocket() {
AsyncPacketSocket::AsyncPacketSocket() = default;
AsyncPacketSocket::~AsyncPacketSocket() = default;
void CopySocketInformationToPacketInfo(size_t packet_size_bytes,
const AsyncPacketSocket& socket_from,
rtc::PacketInfo* info) {
info->packet_size_bytes = packet_size_bytes;
info->local_socket_address = socket_from.GetLocalAddress();
info->remote_socket_address = socket_from.GetRemoteAddress();
}
}; // namespace rtc

View File

@ -24,23 +24,28 @@ namespace rtc {
// after changing the value.
struct PacketTimeUpdateParams {
PacketTimeUpdateParams();
PacketTimeUpdateParams(const PacketTimeUpdateParams& other);
~PacketTimeUpdateParams();
int rtp_sendtime_extension_id; // extension header id present in packet.
int rtp_sendtime_extension_id = -1; // extension header id present in packet.
std::vector<char> srtp_auth_key; // Authentication key.
int srtp_auth_tag_len; // Authentication tag length.
int64_t srtp_packet_index; // Required for Rtp Packet authentication.
int srtp_auth_tag_len = -1; // Authentication tag length.
int64_t srtp_packet_index = -1; // Required for Rtp Packet authentication.
};
// This structure holds meta information for the packet which is about to send
// over network.
struct PacketOptions {
PacketOptions() : dscp(DSCP_NO_CHANGE), packet_id(-1) {}
explicit PacketOptions(DiffServCodePoint dscp) : dscp(dscp), packet_id(-1) {}
PacketOptions();
explicit PacketOptions(DiffServCodePoint dscp);
PacketOptions(const PacketOptions& other);
~PacketOptions();
DiffServCodePoint dscp;
int packet_id; // 16 bits, -1 represents "not set".
DiffServCodePoint dscp = DSCP_NO_CHANGE;
int packet_id = -1; // 16 bits, -1 represents "not set".
PacketTimeUpdateParams packet_time_params;
// PacketInfo is passed to SentPacket when signaling this packet is sent.
PacketInfo info_signaled_after_sent;
};
// This structure will have the information about when packet is actually
@ -138,6 +143,10 @@ class AsyncPacketSocket : public sigslot::has_slots<> {
RTC_DISALLOW_COPY_AND_ASSIGN(AsyncPacketSocket);
};
void CopySocketInformationToPacketInfo(size_t packet_size_bytes,
const AsyncPacketSocket& socket_from,
rtc::PacketInfo* info);
} // namespace rtc
#endif // RTC_BASE_ASYNCPACKETSOCKET_H_

View File

@ -297,7 +297,9 @@ int AsyncTCPSocket::Send(const void *pv, size_t cb,
return res;
}
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis());
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis(),
options.info_signaled_after_sent);
CopySocketInformationToPacketInfo(cb, *this, &sent_packet.info);
SignalSentPacket(this, sent_packet);
// We claim to have sent the whole thing, even if we only sent partial

View File

@ -60,7 +60,9 @@ SocketAddress AsyncUDPSocket::GetRemoteAddress() const {
int AsyncUDPSocket::Send(const void *pv, size_t cb,
const rtc::PacketOptions& options) {
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis());
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis(),
options.info_signaled_after_sent);
CopySocketInformationToPacketInfo(cb, *this, &sent_packet.info);
int ret = socket_->Send(pv, cb);
SignalSentPacket(this, sent_packet);
return ret;
@ -69,7 +71,10 @@ int AsyncUDPSocket::Send(const void *pv, size_t cb,
int AsyncUDPSocket::SendTo(const void *pv, size_t cb,
const SocketAddress& addr,
const rtc::PacketOptions& options) {
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis());
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis(),
options.info_signaled_after_sent);
CopySocketInformationToPacketInfo(cb, *this, &sent_packet.info);
sent_packet.info.remote_socket_address = addr;
int ret = socket_->SendTo(pv, cb, addr);
SignalSentPacket(this, sent_packet);
return ret;

27
rtc_base/socket.cc Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/socket.h"
namespace rtc {
PacketInfo::PacketInfo() = default;
PacketInfo::PacketInfo(const PacketInfo& info) = default;
PacketInfo::~PacketInfo() = default;
SentPacket::SentPacket() = default;
SentPacket::SentPacket(int packet_id, int64_t send_time_ms)
: packet_id(packet_id), send_time_ms(send_time_ms) {}
SentPacket::SentPacket(int packet_id,
int64_t send_time_ms,
const rtc::PacketInfo& info)
: packet_id(packet_id), send_time_ms(send_time_ms), info(info) {}
} // namespace rtc

View File

@ -25,6 +25,7 @@
#include "rtc_base/win32.h"
#endif
#include "api/optional.h"
#include "rtc_base/basictypes.h"
#include "rtc_base/constructormagic.h"
#include "rtc_base/socketaddress.h"
@ -123,13 +124,46 @@ inline bool IsBlockingError(int e) {
return (e == EWOULDBLOCK) || (e == EAGAIN) || (e == EINPROGRESS);
}
struct SentPacket {
SentPacket() : packet_id(-1), send_time_ms(-1) {}
SentPacket(int packet_id, int64_t send_time_ms)
: packet_id(packet_id), send_time_ms(send_time_ms) {}
enum class PacketType {
kUnknown,
kData,
kIceConnectivityCheck,
kIceConnectivityCheckResponse,
kStunMessage,
kTurnMessage,
};
int packet_id;
int64_t send_time_ms;
enum class PacketInfoProtocolType {
kUnknown,
kUdp,
kTcp,
kSsltcp,
kTls,
};
struct PacketInfo {
PacketInfo();
PacketInfo(const PacketInfo& info);
~PacketInfo();
PacketType packet_type = PacketType::kUnknown;
PacketInfoProtocolType protocol = PacketInfoProtocolType::kUnknown;
// A unique id assigned by the network manager, and rtc::nullopt if not set.
rtc::Optional<uint16_t> network_id;
size_t packet_size_bytes = 0;
size_t turn_overhead_bytes = 0;
SocketAddress local_socket_address;
SocketAddress remote_socket_address;
};
struct SentPacket {
SentPacket();
SentPacket(int packet_id, int64_t send_time_ms);
SentPacket(int packet_id, int64_t send_time_ms, const rtc::PacketInfo& info);
int packet_id = -1;
int64_t send_time_ms = -1;
rtc::PacketInfo info;
};
// General interface for the socket implementations of various networks. The