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