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