blob: c766899b9fd88f4a2c2ee9090f7f8cb69e9462bd [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
85struct RTPHeaderExtension {
86 RTPHeaderExtension();
87 RTPHeaderExtension(const RTPHeaderExtension& other);
88 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
89
90 bool hasTransmissionTimeOffset;
91 int32_t transmissionTimeOffset;
92 bool hasAbsoluteSendTime;
93 uint32_t absoluteSendTime;
94 bool hasTransportSequenceNumber;
95 uint16_t transportSequenceNumber;
96
97 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
98 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
99 bool hasAudioLevel;
100 bool voiceActivity;
101 uint8_t audioLevel;
102
103 // For Coordination of Video Orientation. See
104 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
105 // ts_126114v120700p.pdf
106 bool hasVideoRotation;
107 VideoRotation videoRotation;
108
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200109 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 14:40:10 +0100110 // a corresponding bool flag.
111 bool hasVideoContentType;
112 VideoContentType videoContentType;
113
114 bool has_video_timing;
115 VideoSendTiming video_timing;
116
Johnny Leee0c8b232018-09-11 16:50:49 -0400117 bool has_frame_marking;
118 FrameMarking frame_marking;
119
Patrik Höglund3e113432017-12-15 14:40:10 +0100120 PlayoutDelay playout_delay = {-1, -1};
121
122 // For identification of a stream when ssrc is not signaled. See
123 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
124 // TODO(danilchap): Update url from draft to release version.
125 StreamId stream_id;
126 StreamId repaired_stream_id;
127
128 // For identifying the media section used to interpret this RTP packet. See
129 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
130 Mid mid;
Johannes Kronad1d9f02018-11-09 11:12:36 +0100131
Johannes Kron09d65882018-11-27 14:36:41 +0100132 absl::optional<ColorSpace> color_space;
Patrik Höglund3e113432017-12-15 14:40:10 +0100133};
134
135struct RTPHeader {
136 RTPHeader();
137 RTPHeader(const RTPHeader& other);
138 RTPHeader& operator=(const RTPHeader& other);
139
140 bool markerBit;
141 uint8_t payloadType;
142 uint16_t sequenceNumber;
143 uint32_t timestamp;
144 uint32_t ssrc;
145 uint8_t numCSRCs;
146 uint32_t arrOfCSRCs[kRtpCsrcSize];
147 size_t paddingLength;
148 size_t headerLength;
149 int payload_type_frequency;
150 RTPHeaderExtension extension;
151};
152
153// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
154// RTCP mode is described by RFC 5506.
155enum class RtcpMode { kOff, kCompound, kReducedSize };
156
157enum NetworkState {
158 kNetworkUp,
159 kNetworkDown,
160};
161
162struct RtpKeepAliveConfig final {
163 // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
164 // packet. The keep-alive packet is an empty (no payload) RTP packet with a
165 // payload type of 20 as long as the other end has not negotiated the use of
166 // this value. If this value has already been negotiated, then some other
167 // unused static payload type from table 5 of RFC 3551 shall be used and set
168 // in |payload_type|.
169 int64_t timeout_interval_ms = -1;
170 uint8_t payload_type = 20;
171
172 bool operator==(const RtpKeepAliveConfig& o) const {
173 return timeout_interval_ms == o.timeout_interval_ms &&
174 payload_type == o.payload_type;
175 }
176 bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
177};
178
Patrik Höglund3e113432017-12-15 14:40:10 +0100179} // namespace webrtc
180
181#endif // API_RTP_HEADERS_H_