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