blob: 2621db9bd7b6fee879798276b363b0b3b7e3f68a [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>
Yves Gerey988cc082018-10-23 12:03:01 +020015#include <stdint.h>
Patrik Höglund3e113432017-12-15 14:40:10 +010016#include <string.h>
Patrik Höglund3e113432017-12-15 14:40:10 +010017
Johannes Kronad1d9f02018-11-09 11:12:36 +010018#include "absl/types/optional.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010019#include "api/array_view.h"
Johannes Kron09d65882018-11-27 14:36:41 +010020#include "api/video/color_space.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010021#include "api/video/video_content_type.h"
Johnny Leee0c8b232018-09-11 16:50:49 -040022#include "api/video/video_frame_marking.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010023#include "api/video/video_rotation.h"
24#include "api/video/video_timing.h"
Yves Gerey665174f2018-06-19 15:03:05 +020025#include "common_types.h" // NOLINT(build/include)
Patrik Höglund3e113432017-12-15 14:40:10 +010026
27namespace webrtc {
28
29// Class to represent the value of RTP header extensions that are
30// variable-length strings (e.g., RtpStreamId and RtpMid).
31// Unlike std::string, it can be copied with memcpy and cleared with memset.
32//
33// Empty value represents unset header extension (use empty() to query).
34class StringRtpHeaderExtension {
35 public:
36 // String RTP header extensions are limited to 16 bytes because it is the
37 // maximum length that can be encoded with one-byte header extensions.
38 static constexpr size_t kMaxSize = 16;
39
Joachim Bauchd3b7ec22018-08-01 10:12:00 +020040 static bool IsLegalMidName(rtc::ArrayView<const char> name);
41 static bool IsLegalRsidName(rtc::ArrayView<const char> name);
42
43 // TODO(bugs.webrtc.org/9537): Deprecate and remove when third parties have
44 // migrated to "IsLegalRsidName".
45 static bool IsLegalName(rtc::ArrayView<const char> name) {
46 return IsLegalRsidName(name);
47 }
Patrik Höglund3e113432017-12-15 14:40:10 +010048
49 StringRtpHeaderExtension() { value_[0] = 0; }
50 explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
51 Set(value.data(), value.size());
52 }
53 StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
54 StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
55 default;
56
57 bool empty() const { return value_[0] == 0; }
58 const char* data() const { return value_; }
59 size_t size() const { return strnlen(value_, kMaxSize); }
60
61 void Set(rtc::ArrayView<const uint8_t> value) {
62 Set(reinterpret_cast<const char*>(value.data()), value.size());
63 }
64 void Set(const char* data, size_t size);
65
66 friend bool operator==(const StringRtpHeaderExtension& lhs,
67 const StringRtpHeaderExtension& rhs) {
68 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
69 }
70 friend bool operator!=(const StringRtpHeaderExtension& lhs,
71 const StringRtpHeaderExtension& rhs) {
72 return !(lhs == rhs);
73 }
74
75 private:
76 char value_[kMaxSize];
77};
78
79// StreamId represents RtpStreamId which is a string.
80typedef StringRtpHeaderExtension StreamId;
81
82// Mid represents RtpMid which is a string.
83typedef StringRtpHeaderExtension Mid;
84
Johannes Kron075f6872019-02-14 14:41:05 +010085struct FeedbackRequest {
86 // Determines whether the recv delta as specified in
87 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
88 // should be included.
89 bool include_timestamps;
90 // Include feedback of received packets in the range [sequence_number -
91 // sequence_count, sequence_number].
92 int sequence_count;
93};
94
Patrik Höglund3e113432017-12-15 14:40:10 +010095struct RTPHeaderExtension {
96 RTPHeaderExtension();
97 RTPHeaderExtension(const RTPHeaderExtension& other);
98 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
99
100 bool hasTransmissionTimeOffset;
101 int32_t transmissionTimeOffset;
102 bool hasAbsoluteSendTime;
103 uint32_t absoluteSendTime;
104 bool hasTransportSequenceNumber;
105 uint16_t transportSequenceNumber;
Johannes Kron075f6872019-02-14 14:41:05 +0100106 absl::optional<FeedbackRequest> feedback_request;
Patrik Höglund3e113432017-12-15 14:40:10 +0100107
108 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
109 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
110 bool hasAudioLevel;
111 bool voiceActivity;
112 uint8_t audioLevel;
113
114 // For Coordination of Video Orientation. See
115 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
116 // ts_126114v120700p.pdf
117 bool hasVideoRotation;
118 VideoRotation videoRotation;
119
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200120 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 14:40:10 +0100121 // a corresponding bool flag.
122 bool hasVideoContentType;
123 VideoContentType videoContentType;
124
125 bool has_video_timing;
126 VideoSendTiming video_timing;
127
Johnny Leee0c8b232018-09-11 16:50:49 -0400128 bool has_frame_marking;
129 FrameMarking frame_marking;
130
Patrik Höglund3e113432017-12-15 14:40:10 +0100131 PlayoutDelay playout_delay = {-1, -1};
132
133 // For identification of a stream when ssrc is not signaled. See
134 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
135 // TODO(danilchap): Update url from draft to release version.
136 StreamId stream_id;
137 StreamId repaired_stream_id;
138
139 // For identifying the media section used to interpret this RTP packet. See
140 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
141 Mid mid;
Johannes Kronad1d9f02018-11-09 11:12:36 +0100142
Johannes Kron09d65882018-11-27 14:36:41 +0100143 absl::optional<ColorSpace> color_space;
Patrik Höglund3e113432017-12-15 14:40:10 +0100144};
145
146struct RTPHeader {
147 RTPHeader();
148 RTPHeader(const RTPHeader& other);
149 RTPHeader& operator=(const RTPHeader& other);
150
151 bool markerBit;
152 uint8_t payloadType;
153 uint16_t sequenceNumber;
154 uint32_t timestamp;
155 uint32_t ssrc;
156 uint8_t numCSRCs;
157 uint32_t arrOfCSRCs[kRtpCsrcSize];
158 size_t paddingLength;
159 size_t headerLength;
160 int payload_type_frequency;
161 RTPHeaderExtension extension;
162};
163
164// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
165// RTCP mode is described by RFC 5506.
166enum class RtcpMode { kOff, kCompound, kReducedSize };
167
168enum NetworkState {
169 kNetworkUp,
170 kNetworkDown,
171};
172
173struct RtpKeepAliveConfig final {
174 // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
175 // packet. The keep-alive packet is an empty (no payload) RTP packet with a
176 // payload type of 20 as long as the other end has not negotiated the use of
177 // this value. If this value has already been negotiated, then some other
178 // unused static payload type from table 5 of RFC 3551 shall be used and set
179 // in |payload_type|.
180 int64_t timeout_interval_ms = -1;
181 uint8_t payload_type = 20;
182
183 bool operator==(const RtpKeepAliveConfig& o) const {
184 return timeout_interval_ms == o.timeout_interval_ms &&
185 payload_type == o.payload_type;
186 }
187 bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
188};
189
Patrik Höglund3e113432017-12-15 14:40:10 +0100190} // namespace webrtc
191
192#endif // API_RTP_HEADERS_H_