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 <string.h> 14 15 #include <type_traits> 16 17 #include "absl/algorithm/container.h" 18 #include "api/array_view.h" 19 #include "modules/rtp_rtcp/source/rtp_packet.h" 20 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" 21 22 namespace webrtc { 23 24 namespace { 25 constexpr size_t kMidRsidMaxSize = 16; 26 27 // Check if passed character is a "token-char" from RFC 4566. 28 // https://datatracker.ietf.org/doc/html/rfc4566#section-9 29 // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 30 // / %x41-5A / %x5E-7E IsTokenChar(char ch)31bool IsTokenChar(char ch) { 32 return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b || 33 ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) || 34 (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e); 35 } 36 } // namespace 37 IsLegalMidName(absl::string_view name)38bool IsLegalMidName(absl::string_view name) { 39 return (name.size() <= kMidRsidMaxSize && !name.empty() && 40 absl::c_all_of(name, IsTokenChar)); 41 } 42 IsLegalRsidName(absl::string_view name)43bool IsLegalRsidName(absl::string_view name) { 44 return (name.size() <= kMidRsidMaxSize && !name.empty() && 45 absl::c_all_of(name, isalnum)); 46 } 47 StreamDataCounters()48StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} 49 RtpPacketCounter(const RtpPacket & packet)50RtpPacketCounter::RtpPacketCounter(const RtpPacket& packet) 51 : header_bytes(packet.headers_size()), 52 payload_bytes(packet.payload_size()), 53 padding_bytes(packet.padding_size()), 54 packets(1) {} 55 RtpPacketCounter(const RtpPacketToSend & packet_to_send)56RtpPacketCounter::RtpPacketCounter(const RtpPacketToSend& packet_to_send) 57 : RtpPacketCounter(static_cast<const RtpPacket&>(packet_to_send)) { 58 total_packet_delay = 59 packet_to_send.time_in_send_queue().value_or(TimeDelta::Zero()); 60 } 61 AddPacket(const RtpPacket & packet)62void RtpPacketCounter::AddPacket(const RtpPacket& packet) { 63 ++packets; 64 header_bytes += packet.headers_size(); 65 padding_bytes += packet.padding_size(); 66 payload_bytes += packet.payload_size(); 67 } 68 AddPacket(const RtpPacketToSend & packet_to_send)69void RtpPacketCounter::AddPacket(const RtpPacketToSend& packet_to_send) { 70 AddPacket(static_cast<const RtpPacket&>(packet_to_send)); 71 total_packet_delay += 72 packet_to_send.time_in_send_queue().value_or(TimeDelta::Zero()); 73 } 74 75 } // namespace webrtc 76