blob: cd01c1aaeb90a13aa1a9de0c4255f3a467172fdb [file] [log] [blame]
danilchap1edb7ab2016-04-20 05:25:10 -07001/*
2 * Copyright (c) 2016 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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_
11#define MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_
danilchap1edb7ab2016-04-20 05:25:10 -070012
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stddef.h>
pbosc7c26a02017-01-02 08:42:32 -080014#include <stdint.h>
danilchapef8d7732017-04-19 02:59:48 -070015#include <string>
pbosc7c26a02017-01-02 08:42:32 -080016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/array_view.h"
Yves Gerey988cc082018-10-23 12:03:01 +020018#include "api/rtp_headers.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/video/video_content_type.h"
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "api/video/video_frame_marking.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/video/video_rotation.h"
22#include "api/video/video_timing.h"
Yves Gerey988cc082018-10-23 12:03:01 +020023#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchap1edb7ab2016-04-20 05:25:10 -070025
26namespace webrtc {
27
28class AbsoluteSendTime {
29 public:
30 static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime;
31 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070032 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080033 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
danilchape2a01772016-10-28 07:08:58 -070034
danilchap978504e2017-04-06 01:03:53 -070035 static bool Parse(rtc::ArrayView<const uint8_t> data, uint32_t* time_24bits);
Danil Chapovalovf3ba6482017-06-12 15:43:55 +020036 static size_t ValueSize(uint32_t time_24bits) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020037 static bool Write(rtc::ArrayView<uint8_t> data, uint32_t time_24bits);
danilchapa897f262016-08-26 05:42:41 -070038
39 static constexpr uint32_t MsTo24Bits(int64_t time_ms) {
40 return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF;
41 }
danilchap1edb7ab2016-04-20 05:25:10 -070042};
43
44class AudioLevel {
45 public:
46 static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel;
47 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070048 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080049 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
danilchape2a01772016-10-28 07:08:58 -070050
danilchap978504e2017-04-06 01:03:53 -070051 static bool Parse(rtc::ArrayView<const uint8_t> data,
danilchap1edb7ab2016-04-20 05:25:10 -070052 bool* voice_activity,
53 uint8_t* audio_level);
erikvargae6b16192017-05-11 02:36:32 -070054 static size_t ValueSize(bool voice_activity, uint8_t audio_level) {
55 return kValueSizeBytes;
56 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020057 static bool Write(rtc::ArrayView<uint8_t> data,
58 bool voice_activity,
59 uint8_t audio_level);
danilchap1edb7ab2016-04-20 05:25:10 -070060};
61
62class TransmissionOffset {
63 public:
64 static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
65 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070066 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset";
danilchape2a01772016-10-28 07:08:58 -070067
danilchap978504e2017-04-06 01:03:53 -070068 static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time);
erikvargae6b16192017-05-11 02:36:32 -070069 static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020070 static bool Write(rtc::ArrayView<uint8_t> data, int32_t rtp_time);
danilchap1edb7ab2016-04-20 05:25:10 -070071};
72
73class TransportSequenceNumber {
74 public:
75 static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
76 static constexpr uint8_t kValueSizeBytes = 2;
Steve Antond14d9f72017-07-21 10:59:39 -070077 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080078 "http://www.ietf.org/id/"
79 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
danilchap978504e2017-04-06 01:03:53 -070080 static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value);
erikvargae6b16192017-05-11 02:36:32 -070081 static size_t ValueSize(uint16_t value) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020082 static bool Write(rtc::ArrayView<uint8_t> data, uint16_t value);
danilchap1edb7ab2016-04-20 05:25:10 -070083};
84
85class VideoOrientation {
86 public:
87 static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
88 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070089 static constexpr const char kUri[] = "urn:3gpp:video-orientation";
danilchape2a01772016-10-28 07:08:58 -070090
danilchap978504e2017-04-06 01:03:53 -070091 static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value);
erikvargae6b16192017-05-11 02:36:32 -070092 static size_t ValueSize(VideoRotation) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020093 static bool Write(rtc::ArrayView<uint8_t> data, VideoRotation value);
danilchap978504e2017-04-06 01:03:53 -070094 static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value);
erikvargae6b16192017-05-11 02:36:32 -070095 static size_t ValueSize(uint8_t value) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020096 static bool Write(rtc::ArrayView<uint8_t> data, uint8_t value);
danilchap1edb7ab2016-04-20 05:25:10 -070097};
98
Danil Chapovalov08b03512016-09-07 15:08:13 +020099class PlayoutDelayLimits {
100 public:
101 static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
102 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -0700103 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -0800104 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
danilchape2a01772016-10-28 07:08:58 -0700105
Danil Chapovalov08b03512016-09-07 15:08:13 +0200106 // Playout delay in milliseconds. A playout delay limit (min or max)
107 // has 12 bits allocated. This allows a range of 0-4095 values which
108 // translates to a range of 0-40950 in milliseconds.
109 static constexpr int kGranularityMs = 10;
110 // Maximum playout delay value in milliseconds.
111 static constexpr int kMaxMs = 0xfff * kGranularityMs; // 40950.
112
danilchap978504e2017-04-06 01:03:53 -0700113 static bool Parse(rtc::ArrayView<const uint8_t> data,
114 PlayoutDelay* playout_delay);
erikvargae6b16192017-05-11 02:36:32 -0700115 static size_t ValueSize(const PlayoutDelay&) {
116 return kValueSizeBytes;
117 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200118 static bool Write(rtc::ArrayView<uint8_t> data,
119 const PlayoutDelay& playout_delay);
Danil Chapovalov08b03512016-09-07 15:08:13 +0200120};
121
ilnik00d802b2017-04-11 10:34:31 -0700122class VideoContentTypeExtension {
123 public:
124 static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType;
125 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -0700126 static constexpr const char kUri[] =
ilnik00d802b2017-04-11 10:34:31 -0700127 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
128
129 static bool Parse(rtc::ArrayView<const uint8_t> data,
130 VideoContentType* content_type);
erikvargae6b16192017-05-11 02:36:32 -0700131 static size_t ValueSize(VideoContentType) {
132 return kValueSizeBytes;
133 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200134 static bool Write(rtc::ArrayView<uint8_t> data,
135 VideoContentType content_type);
ilnik00d802b2017-04-11 10:34:31 -0700136};
137
ilnik04f4d122017-06-19 07:18:55 -0700138class VideoTimingExtension {
139 public:
140 static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming;
sprangba050a62017-08-18 02:51:12 -0700141 static constexpr uint8_t kValueSizeBytes = 13;
Steve Antond14d9f72017-07-21 10:59:39 -0700142 static constexpr const char kUri[] =
ilnik04f4d122017-06-19 07:18:55 -0700143 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
144
ilnik2edc6842017-07-06 03:06:50 -0700145 static bool Parse(rtc::ArrayView<const uint8_t> data,
146 VideoSendTiming* timing);
147 static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200148 static bool Write(rtc::ArrayView<uint8_t> data,
149 const VideoSendTiming& timing);
ilnik04f4d122017-06-19 07:18:55 -0700150
151 static size_t ValueSize(uint16_t time_delta_ms, uint8_t idx) {
152 return kValueSizeBytes;
153 }
154 // Writes only single time delta to position idx.
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200155 static bool Write(rtc::ArrayView<uint8_t> data,
156 uint16_t time_delta_ms,
157 uint8_t idx);
ilnik04f4d122017-06-19 07:18:55 -0700158};
159
Johnny Leee0c8b232018-09-11 16:50:49 -0400160class FrameMarkingExtension {
161 public:
162 static constexpr RTPExtensionType kId = kRtpExtensionFrameMarking;
163 static constexpr const char kUri[] =
164 "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07";
165
166 static bool Parse(rtc::ArrayView<const uint8_t> data,
167 FrameMarking* frame_marking);
168 static size_t ValueSize(const FrameMarking& frame_marking);
169 static bool Write(rtc::ArrayView<uint8_t> data,
170 const FrameMarking& frame_marking);
171
172 private:
173 static bool IsScalable(uint8_t temporal_id, uint8_t layer_id);
174};
175
Steve Antona3251dd2017-07-21 09:58:31 -0700176// Base extension class for RTP header extensions which are strings.
177// Subclasses must defined kId and kUri static constexpr members.
178class BaseRtpStringExtension {
179 public:
Steve Antonf0482ea2018-04-09 13:33:52 -0700180 // String RTP header extensions are limited to 16 bytes because it is the
181 // maximum length that can be encoded with one-byte header extensions.
182 static constexpr uint8_t kMaxValueSizeBytes = 16;
183
Steve Antona3251dd2017-07-21 09:58:31 -0700184 static bool Parse(rtc::ArrayView<const uint8_t> data,
185 StringRtpHeaderExtension* str);
186 static size_t ValueSize(const StringRtpHeaderExtension& str) {
187 return str.size();
188 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200189 static bool Write(rtc::ArrayView<uint8_t> data,
190 const StringRtpHeaderExtension& str);
Steve Antona3251dd2017-07-21 09:58:31 -0700191
192 static bool Parse(rtc::ArrayView<const uint8_t> data, std::string* str);
193 static size_t ValueSize(const std::string& str) { return str.size(); }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200194 static bool Write(rtc::ArrayView<uint8_t> data, const std::string& str);
Steve Antona3251dd2017-07-21 09:58:31 -0700195};
196
197class RtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700198 public:
199 static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700200 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700201 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
danilchapef8d7732017-04-19 02:59:48 -0700202};
203
Steve Antona3251dd2017-07-21 09:58:31 -0700204class RepairedRtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700205 public:
206 static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700207 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700208 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Steve Antona3251dd2017-07-21 09:58:31 -0700209};
danilchapef8d7732017-04-19 02:59:48 -0700210
Steve Antona3251dd2017-07-21 09:58:31 -0700211class RtpMid : public BaseRtpStringExtension {
212 public:
213 static constexpr RTPExtensionType kId = kRtpExtensionMid;
Steve Antond14d9f72017-07-21 10:59:39 -0700214 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
danilchapef8d7732017-04-19 02:59:48 -0700215};
216
danilchap1edb7ab2016-04-20 05:25:10 -0700217} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200218#endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_