blob: 2624a33e5f5ddb966815851c16deba22fabee22a [file] [log] [blame]
Patrik Höglund3e113432017-12-15 14:40:10 +01001/*
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#ifndef API_RTP_HEADERS_H_
12#define API_RTP_HEADERS_H_
13
14#include <stddef.h>
15#include <string.h>
16#include <ostream>
17#include <string>
18#include <vector>
19
20#include "api/array_view.h"
21#include "api/optional.h"
22#include "api/video/video_content_type.h"
23#include "api/video/video_rotation.h"
24#include "api/video/video_timing.h"
25
26#include "rtc_base/checks.h"
27#include "rtc_base/deprecation.h"
28#include "common_types.h" // NOLINT(build/include)
29#include "typedefs.h" // NOLINT(build/include)
30
31namespace webrtc {
32
33// Class to represent the value of RTP header extensions that are
34// variable-length strings (e.g., RtpStreamId and RtpMid).
35// Unlike std::string, it can be copied with memcpy and cleared with memset.
36//
37// Empty value represents unset header extension (use empty() to query).
38class StringRtpHeaderExtension {
39 public:
40 // String RTP header extensions are limited to 16 bytes because it is the
41 // maximum length that can be encoded with one-byte header extensions.
42 static constexpr size_t kMaxSize = 16;
43
44 static bool IsLegalName(rtc::ArrayView<const char> name);
45
46 StringRtpHeaderExtension() { value_[0] = 0; }
47 explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
48 Set(value.data(), value.size());
49 }
50 StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
51 StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
52 default;
53
54 bool empty() const { return value_[0] == 0; }
55 const char* data() const { return value_; }
56 size_t size() const { return strnlen(value_, kMaxSize); }
57
58 void Set(rtc::ArrayView<const uint8_t> value) {
59 Set(reinterpret_cast<const char*>(value.data()), value.size());
60 }
61 void Set(const char* data, size_t size);
62
63 friend bool operator==(const StringRtpHeaderExtension& lhs,
64 const StringRtpHeaderExtension& rhs) {
65 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
66 }
67 friend bool operator!=(const StringRtpHeaderExtension& lhs,
68 const StringRtpHeaderExtension& rhs) {
69 return !(lhs == rhs);
70 }
71
72 private:
73 char value_[kMaxSize];
74};
75
76// StreamId represents RtpStreamId which is a string.
77typedef StringRtpHeaderExtension StreamId;
78
79// Mid represents RtpMid which is a string.
80typedef StringRtpHeaderExtension Mid;
81
82struct RTPHeaderExtension {
83 RTPHeaderExtension();
84 RTPHeaderExtension(const RTPHeaderExtension& other);
85 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
86
87 bool hasTransmissionTimeOffset;
88 int32_t transmissionTimeOffset;
89 bool hasAbsoluteSendTime;
90 uint32_t absoluteSendTime;
91 bool hasTransportSequenceNumber;
92 uint16_t transportSequenceNumber;
93
94 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
95 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
96 bool hasAudioLevel;
97 bool voiceActivity;
98 uint8_t audioLevel;
99
100 // For Coordination of Video Orientation. See
101 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
102 // ts_126114v120700p.pdf
103 bool hasVideoRotation;
104 VideoRotation videoRotation;
105
106 // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove
107 // a corresponding bool flag.
108 bool hasVideoContentType;
109 VideoContentType videoContentType;
110
111 bool has_video_timing;
112 VideoSendTiming video_timing;
113
114 PlayoutDelay playout_delay = {-1, -1};
115
116 // For identification of a stream when ssrc is not signaled. See
117 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
118 // TODO(danilchap): Update url from draft to release version.
119 StreamId stream_id;
120 StreamId repaired_stream_id;
121
122 // For identifying the media section used to interpret this RTP packet. See
123 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
124 Mid mid;
125};
126
127struct RTPHeader {
128 RTPHeader();
129 RTPHeader(const RTPHeader& other);
130 RTPHeader& operator=(const RTPHeader& other);
131
132 bool markerBit;
133 uint8_t payloadType;
134 uint16_t sequenceNumber;
135 uint32_t timestamp;
136 uint32_t ssrc;
137 uint8_t numCSRCs;
138 uint32_t arrOfCSRCs[kRtpCsrcSize];
139 size_t paddingLength;
140 size_t headerLength;
141 int payload_type_frequency;
142 RTPHeaderExtension extension;
143};
144
145// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
146// RTCP mode is described by RFC 5506.
147enum class RtcpMode { kOff, kCompound, kReducedSize };
148
149enum NetworkState {
150 kNetworkUp,
151 kNetworkDown,
152};
153
154struct RtpKeepAliveConfig final {
155 // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
156 // packet. The keep-alive packet is an empty (no payload) RTP packet with a
157 // payload type of 20 as long as the other end has not negotiated the use of
158 // this value. If this value has already been negotiated, then some other
159 // unused static payload type from table 5 of RFC 3551 shall be used and set
160 // in |payload_type|.
161 int64_t timeout_interval_ms = -1;
162 uint8_t payload_type = 20;
163
164 bool operator==(const RtpKeepAliveConfig& o) const {
165 return timeout_interval_ms == o.timeout_interval_ms &&
166 payload_type == o.payload_type;
167 }
168 bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
169};
170
171// Currently only VP8/VP9 specific.
172struct RtpPayloadState {
173 int16_t picture_id = -1;
174};
175
176} // namespace webrtc
177
178#endif // API_RTP_HEADERS_H_