tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtp_rtcp_defines.cc (3485B)


      1 /*
      2 *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     12 
     13 #include <cctype>
     14 #include <cstring>
     15 
     16 #include "absl/algorithm/container.h"
     17 #include "absl/strings/string_view.h"
     18 #include "api/transport/ecn_marking.h"
     19 #include "api/units/time_delta.h"
     20 #include "modules/rtp_rtcp/source/rtp_packet.h"
     21 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
     22 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
     23 
     24 namespace webrtc {
     25 
     26 namespace {
     27 constexpr size_t kMidRsidMaxSize = 16;
     28 
     29 // Check if passed character is a "token-char" from RFC 4566.
     30 // https://datatracker.ietf.org/doc/html/rfc4566#section-9
     31 //    token-char =          %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39
     32 //                         / %x41-5A / %x5E-7E
     33 bool IsTokenChar(char ch) {
     34  return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b ||
     35         ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) ||
     36         (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e);
     37 }
     38 }  // namespace
     39 
     40 bool IsLegalMidName(absl::string_view name) {
     41  return (name.size() <= kMidRsidMaxSize && !name.empty() &&
     42          absl::c_all_of(name, IsTokenChar));
     43 }
     44 
     45 bool IsLegalRsidName(absl::string_view name) {
     46  return (name.size() <= kMidRsidMaxSize && !name.empty() &&
     47          absl::c_all_of(name, isalnum));
     48 }
     49 
     50 StreamDataCounters::StreamDataCounters() = default;
     51 
     52 RtpPacketCounter::RtpPacketCounter(const RtpPacket& packet)
     53    : header_bytes(packet.headers_size()),
     54      payload_bytes(packet.payload_size()),
     55      padding_bytes(packet.padding_size()),
     56      packets(1),
     57      packets_with_ect1(0),
     58      packets_with_ce(0) {}
     59 
     60 RtpPacketCounter::RtpPacketCounter(const RtpPacketToSend& packet_to_send)
     61    : RtpPacketCounter(static_cast<const RtpPacket&>(packet_to_send)) {
     62  total_packet_delay =
     63      packet_to_send.time_in_send_queue().value_or(TimeDelta::Zero());
     64  if (packet_to_send.send_as_ect1()) {
     65    ++packets_with_ect1;
     66  }
     67 }
     68 
     69 RtpPacketCounter::RtpPacketCounter(const RtpPacketReceived& packet_received)
     70    : RtpPacketCounter(static_cast<const RtpPacket&>(packet_received)) {
     71  EcnMarking ecn = packet_received.ecn();
     72  if (ecn == EcnMarking::kEct1) {
     73    ++packets_with_ect1;
     74  } else if (ecn == EcnMarking::kCe) {
     75    ++packets_with_ce;
     76  }
     77 }
     78 
     79 void RtpPacketCounter::AddPacket(const RtpPacket& packet) {
     80  ++packets;
     81  header_bytes += packet.headers_size();
     82  padding_bytes += packet.padding_size();
     83  payload_bytes += packet.payload_size();
     84 }
     85 
     86 void RtpPacketCounter::AddPacket(const RtpPacketToSend& packet_to_send) {
     87  AddPacket(static_cast<const RtpPacket&>(packet_to_send));
     88  total_packet_delay +=
     89      packet_to_send.time_in_send_queue().value_or(TimeDelta::Zero());
     90  if (packet_to_send.send_as_ect1()) {
     91    ++packets_with_ect1;
     92  }
     93 }
     94 
     95 void RtpPacketCounter::AddPacket(const RtpPacketReceived& packet_received) {
     96  AddPacket(static_cast<const RtpPacket&>(packet_received));
     97  EcnMarking ecn = packet_received.ecn();
     98  if (ecn == EcnMarking::kEct1) {
     99    ++packets_with_ect1;
    100  } else if (ecn == EcnMarking::kCe) {
    101    ++packets_with_ce;
    102  }
    103 }
    104 
    105 }  // namespace webrtc