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 <ctype.h> 14 #include <string.h> 15 16 #include <type_traits> 17 18 #include "absl/algorithm/container.h" 19 #include "api/array_view.h" 20 #include "modules/rtp_rtcp/source/rtp_packet.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. IsTokenChar(char ch)28bool IsTokenChar(char ch) { 29 return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b || 30 ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) || 31 (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e); 32 } 33 } // namespace 34 IsLegalMidName(absl::string_view name)35bool IsLegalMidName(absl::string_view name) { 36 return (name.size() <= kMidRsidMaxSize && !name.empty() && 37 absl::c_all_of(name, IsTokenChar)); 38 } 39 IsLegalRsidName(absl::string_view name)40bool IsLegalRsidName(absl::string_view name) { 41 return (name.size() <= kMidRsidMaxSize && !name.empty() && 42 absl::c_all_of(name, isalnum)); 43 } 44 StreamDataCounters()45StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} 46 RtpPacketCounter(const RtpPacket & packet)47RtpPacketCounter::RtpPacketCounter(const RtpPacket& packet) 48 : header_bytes(packet.headers_size()), 49 payload_bytes(packet.payload_size()), 50 padding_bytes(packet.padding_size()), 51 packets(1) {} 52 AddPacket(const RtpPacket & packet)53void RtpPacketCounter::AddPacket(const RtpPacket& packet) { 54 ++packets; 55 header_bytes += packet.headers_size(); 56 padding_bytes += packet.padding_size(); 57 payload_bytes += packet.payload_size(); 58 } 59 60 } // namespace webrtc 61