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