Karl Wiberg | 884e49f | 2017-10-02 09:54:48 +0200 | [diff] [blame] | 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 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 13 | #include <ctype.h> |
| 14 | #include <string.h> |
| 15 | #include <algorithm> |
| 16 | #include <type_traits> |
| 17 | |
| 18 | #include "api/array_view.h" |
| 19 | |
Karl Wiberg | 884e49f | 2017-10-02 09:54:48 +0200 | [diff] [blame] | 20 | namespace webrtc { |
| 21 | |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 22 | StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} |
| 23 | |
| 24 | constexpr size_t StreamId::kMaxSize; |
| 25 | |
Joachim Bauch | d3b7ec2 | 2018-08-01 10:12:00 +0200 | [diff] [blame] | 26 | // Check if passed character is a "token-char" from RFC 4566. |
| 27 | static bool IsTokenChar(char ch) { |
| 28 | return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b || |
| 29 | ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) || |
| 30 | (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e); |
| 31 | } |
| 32 | |
| 33 | bool StreamId::IsLegalMidName(rtc::ArrayView<const char> name) { |
| 34 | return (name.size() <= kMaxSize && name.size() > 0 && |
| 35 | std::all_of(name.data(), name.data() + name.size(), IsTokenChar)); |
| 36 | } |
| 37 | |
| 38 | bool StreamId::IsLegalRsidName(rtc::ArrayView<const char> name) { |
Patrik Höglund | 3e11343 | 2017-12-15 14:40:10 +0100 | [diff] [blame] | 39 | return (name.size() <= kMaxSize && name.size() > 0 && |
| 40 | std::all_of(name.data(), name.data() + name.size(), isalnum)); |
| 41 | } |
| 42 | |
| 43 | void StreamId::Set(const char* data, size_t size) { |
| 44 | // If |data| contains \0, the stream id size might become less than |size|. |
| 45 | RTC_CHECK_LE(size, kMaxSize); |
| 46 | memcpy(value_, data, size); |
| 47 | if (size < kMaxSize) |
| 48 | value_[size] = 0; |
| 49 | } |
| 50 | |
| 51 | // StreamId is used as member of RTPHeader that is sometimes copied with memcpy |
| 52 | // and thus assume trivial destructibility. |
| 53 | static_assert(std::is_trivially_destructible<StreamId>::value, ""); |
| 54 | |
Danil Chapovalov | fb8e7ef | 2018-06-26 10:44:13 +0200 | [diff] [blame] | 55 | PayloadUnion::PayloadUnion(const AudioPayload& payload) : payload_(payload) {} |
| 56 | PayloadUnion::PayloadUnion(const VideoPayload& payload) : payload_(payload) {} |
Karl Wiberg | 884e49f | 2017-10-02 09:54:48 +0200 | [diff] [blame] | 57 | PayloadUnion::PayloadUnion(const PayloadUnion&) = default; |
| 58 | PayloadUnion::PayloadUnion(PayloadUnion&&) = default; |
| 59 | PayloadUnion::~PayloadUnion() = default; |
| 60 | |
| 61 | PayloadUnion& PayloadUnion::operator=(const PayloadUnion&) = default; |
| 62 | PayloadUnion& PayloadUnion::operator=(PayloadUnion&&) = default; |
| 63 | |
Sebastian Jansson | 789f459 | 2018-10-09 18:30:28 +0200 | [diff] [blame] | 64 | PacketFeedback::PacketFeedback(int64_t arrival_time_ms, |
| 65 | uint16_t sequence_number) |
| 66 | : PacketFeedback(-1, |
| 67 | arrival_time_ms, |
| 68 | kNoSendTime, |
| 69 | sequence_number, |
| 70 | 0, |
| 71 | 0, |
| 72 | 0, |
| 73 | PacedPacketInfo()) {} |
| 74 | |
| 75 | PacketFeedback::PacketFeedback(int64_t arrival_time_ms, |
| 76 | int64_t send_time_ms, |
| 77 | uint16_t sequence_number, |
| 78 | size_t payload_size, |
| 79 | const PacedPacketInfo& pacing_info) |
| 80 | : PacketFeedback(-1, |
| 81 | arrival_time_ms, |
| 82 | send_time_ms, |
| 83 | sequence_number, |
| 84 | payload_size, |
| 85 | 0, |
| 86 | 0, |
| 87 | pacing_info) {} |
| 88 | |
| 89 | PacketFeedback::PacketFeedback(int64_t creation_time_ms, |
| 90 | uint16_t sequence_number, |
| 91 | size_t payload_size, |
| 92 | uint16_t local_net_id, |
| 93 | uint16_t remote_net_id, |
| 94 | const PacedPacketInfo& pacing_info) |
| 95 | : PacketFeedback(creation_time_ms, |
| 96 | kNotReceived, |
| 97 | kNoSendTime, |
| 98 | sequence_number, |
| 99 | payload_size, |
| 100 | local_net_id, |
| 101 | remote_net_id, |
| 102 | pacing_info) {} |
| 103 | |
| 104 | PacketFeedback::PacketFeedback(int64_t creation_time_ms, |
| 105 | int64_t arrival_time_ms, |
| 106 | int64_t send_time_ms, |
| 107 | uint16_t sequence_number, |
| 108 | size_t payload_size, |
| 109 | uint16_t local_net_id, |
| 110 | uint16_t remote_net_id, |
| 111 | const PacedPacketInfo& pacing_info) |
| 112 | : creation_time_ms(creation_time_ms), |
| 113 | arrival_time_ms(arrival_time_ms), |
| 114 | send_time_ms(send_time_ms), |
| 115 | sequence_number(sequence_number), |
| 116 | payload_size(payload_size), |
| 117 | unacknowledged_data(0), |
| 118 | local_net_id(local_net_id), |
| 119 | remote_net_id(remote_net_id), |
| 120 | pacing_info(pacing_info) {} |
| 121 | |
| 122 | PacketFeedback::PacketFeedback(const PacketFeedback&) = default; |
| 123 | PacketFeedback& PacketFeedback::operator=(const PacketFeedback&) = default; |
| 124 | PacketFeedback::~PacketFeedback() = default; |
| 125 | |
| 126 | bool PacketFeedback::operator==(const PacketFeedback& rhs) const { |
| 127 | return arrival_time_ms == rhs.arrival_time_ms && |
| 128 | send_time_ms == rhs.send_time_ms && |
| 129 | sequence_number == rhs.sequence_number && |
| 130 | payload_size == rhs.payload_size && pacing_info == rhs.pacing_info; |
| 131 | } |
| 132 | |
Karl Wiberg | 884e49f | 2017-10-02 09:54:48 +0200 | [diff] [blame] | 133 | } // namespace webrtc |