blob: 1da8ade7743ae19e2a33c00ae0c3f7168e1d3feb [file] [log] [blame]
Karl Wiberg884e49f2017-10-02 09:54:48 +02001/*
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 Gerey988cc082018-10-23 12:03:01 +020013#include <ctype.h>
14#include <string.h>
15#include <algorithm>
16#include <type_traits>
17
18#include "api/array_view.h"
19
Karl Wiberg884e49f2017-10-02 09:54:48 +020020namespace webrtc {
21
Patrik Höglund3e113432017-12-15 14:40:10 +010022StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
23
24constexpr size_t StreamId::kMaxSize;
25
Joachim Bauchd3b7ec22018-08-01 10:12:00 +020026// Check if passed character is a "token-char" from RFC 4566.
27static 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
33bool 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
38bool StreamId::IsLegalRsidName(rtc::ArrayView<const char> name) {
Patrik Höglund3e113432017-12-15 14:40:10 +010039 return (name.size() <= kMaxSize && name.size() > 0 &&
40 std::all_of(name.data(), name.data() + name.size(), isalnum));
41}
42
43void 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.
53static_assert(std::is_trivially_destructible<StreamId>::value, "");
54
Danil Chapovalovfb8e7ef2018-06-26 10:44:13 +020055PayloadUnion::PayloadUnion(const AudioPayload& payload) : payload_(payload) {}
56PayloadUnion::PayloadUnion(const VideoPayload& payload) : payload_(payload) {}
Karl Wiberg884e49f2017-10-02 09:54:48 +020057PayloadUnion::PayloadUnion(const PayloadUnion&) = default;
58PayloadUnion::PayloadUnion(PayloadUnion&&) = default;
59PayloadUnion::~PayloadUnion() = default;
60
61PayloadUnion& PayloadUnion::operator=(const PayloadUnion&) = default;
62PayloadUnion& PayloadUnion::operator=(PayloadUnion&&) = default;
63
Sebastian Jansson789f4592018-10-09 18:30:28 +020064PacketFeedback::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
75PacketFeedback::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
89PacketFeedback::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
104PacketFeedback::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
122PacketFeedback::PacketFeedback(const PacketFeedback&) = default;
123PacketFeedback& PacketFeedback::operator=(const PacketFeedback&) = default;
124PacketFeedback::~PacketFeedback() = default;
125
126bool 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 Wiberg884e49f2017-10-02 09:54:48 +0200133} // namespace webrtc