This metric was always supposed to be the spec's answer to googBucketDelay, and is defined as "The total number of seconds that packets have spent buffered locally before being transmitted onto the network." But our implementation measured the time between capture and send, including encode time. This is incorrect and yields a much larger value than expected. This CL updated the metric to do what the spec says. Implementation-wise we measure the time between pushing and popping each packet from the queue (in modules/pacing/prioritized_packet_queue.cc). The spec says to increment the delay counter at the same time as we increment the packet counter in order for the app to be able to do "delta totalPacketSendDelay / delta packetSent". For this reason, `total_packet_delay` is added to RtpPacketCounter. (Previously, the two counters were incremented on different threads and observers.) Running Google Meet on a good network, I could observe a 2-3 ms average send delay per packet with this implementation compared to 20-30 ms with the old implementation. See b/137014977#comment170 for comparison with googBucketDelay which is a little bit different by design - totalPacketSendDelay is clearly better than googBucketDelay. Since none of this depend on the media kind, we can wire up this metric for audio as well in a follow-up: https://webrtc-review.googlesource.com/c/src/+/280523 Bug: webrtc:14593 Change-Id: If8fcd82fee74030d0923ee5df2c2aea2264600d4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280443 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38480}
76 lines
2.5 KiB
C++
76 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) 2017 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 "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <type_traits>
|
|
|
|
#include "absl/algorithm/container.h"
|
|
#include "api/array_view.h"
|
|
#include "modules/rtp_rtcp/source/rtp_packet.h"
|
|
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
|
|
|
namespace webrtc {
|
|
|
|
namespace {
|
|
constexpr size_t kMidRsidMaxSize = 16;
|
|
|
|
// Check if passed character is a "token-char" from RFC 4566.
|
|
// https://datatracker.ietf.org/doc/html/rfc4566#section-9
|
|
// token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39
|
|
// / %x41-5A / %x5E-7E
|
|
bool IsTokenChar(char ch) {
|
|
return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b ||
|
|
ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) ||
|
|
(ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e);
|
|
}
|
|
} // namespace
|
|
|
|
bool IsLegalMidName(absl::string_view name) {
|
|
return (name.size() <= kMidRsidMaxSize && !name.empty() &&
|
|
absl::c_all_of(name, IsTokenChar));
|
|
}
|
|
|
|
bool IsLegalRsidName(absl::string_view name) {
|
|
return (name.size() <= kMidRsidMaxSize && !name.empty() &&
|
|
absl::c_all_of(name, isalnum));
|
|
}
|
|
|
|
StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
|
|
|
|
RtpPacketCounter::RtpPacketCounter(const RtpPacket& packet)
|
|
: header_bytes(packet.headers_size()),
|
|
payload_bytes(packet.payload_size()),
|
|
padding_bytes(packet.padding_size()),
|
|
packets(1) {}
|
|
|
|
RtpPacketCounter::RtpPacketCounter(const RtpPacketToSend& packet_to_send)
|
|
: RtpPacketCounter(static_cast<const RtpPacket&>(packet_to_send)) {
|
|
total_packet_delay =
|
|
packet_to_send.time_in_send_queue().value_or(TimeDelta::Zero());
|
|
}
|
|
|
|
void RtpPacketCounter::AddPacket(const RtpPacket& packet) {
|
|
++packets;
|
|
header_bytes += packet.headers_size();
|
|
padding_bytes += packet.padding_size();
|
|
payload_bytes += packet.payload_size();
|
|
}
|
|
|
|
void RtpPacketCounter::AddPacket(const RtpPacketToSend& packet_to_send) {
|
|
AddPacket(static_cast<const RtpPacket&>(packet_to_send));
|
|
total_packet_delay +=
|
|
packet_to_send.time_in_send_queue().value_or(TimeDelta::Zero());
|
|
}
|
|
|
|
} // namespace webrtc
|