blob: 808356a5b8366805cdb3a3e77301fb55d5cbae0c [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:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +010030 using value_type = uint32_t;
danilchap1edb7ab2016-04-20 05:25:10 -070031 static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime;
32 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070033 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080034 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
danilchape2a01772016-10-28 07:08:58 -070035
danilchap978504e2017-04-06 01:03:53 -070036 static bool Parse(rtc::ArrayView<const uint8_t> data, uint32_t* time_24bits);
Danil Chapovalovf3ba6482017-06-12 15:43:55 +020037 static size_t ValueSize(uint32_t time_24bits) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020038 static bool Write(rtc::ArrayView<uint8_t> data, uint32_t time_24bits);
danilchapa897f262016-08-26 05:42:41 -070039
40 static constexpr uint32_t MsTo24Bits(int64_t time_ms) {
41 return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF;
42 }
danilchap1edb7ab2016-04-20 05:25:10 -070043};
44
45class AudioLevel {
46 public:
47 static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel;
48 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070049 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080050 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
danilchape2a01772016-10-28 07:08:58 -070051
danilchap978504e2017-04-06 01:03:53 -070052 static bool Parse(rtc::ArrayView<const uint8_t> data,
danilchap1edb7ab2016-04-20 05:25:10 -070053 bool* voice_activity,
54 uint8_t* audio_level);
erikvargae6b16192017-05-11 02:36:32 -070055 static size_t ValueSize(bool voice_activity, uint8_t audio_level) {
56 return kValueSizeBytes;
57 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020058 static bool Write(rtc::ArrayView<uint8_t> data,
59 bool voice_activity,
60 uint8_t audio_level);
danilchap1edb7ab2016-04-20 05:25:10 -070061};
62
63class TransmissionOffset {
64 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +010065 using value_type = int32_t;
danilchap1edb7ab2016-04-20 05:25:10 -070066 static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
67 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070068 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset";
danilchape2a01772016-10-28 07:08:58 -070069
danilchap978504e2017-04-06 01:03:53 -070070 static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time);
erikvargae6b16192017-05-11 02:36:32 -070071 static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020072 static bool Write(rtc::ArrayView<uint8_t> data, int32_t rtp_time);
danilchap1edb7ab2016-04-20 05:25:10 -070073};
74
75class TransportSequenceNumber {
76 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +010077 using value_type = uint16_t;
danilchap1edb7ab2016-04-20 05:25:10 -070078 static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
79 static constexpr uint8_t kValueSizeBytes = 2;
Steve Antond14d9f72017-07-21 10:59:39 -070080 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080081 "http://www.ietf.org/id/"
82 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
danilchap978504e2017-04-06 01:03:53 -070083 static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value);
erikvargae6b16192017-05-11 02:36:32 -070084 static size_t ValueSize(uint16_t value) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020085 static bool Write(rtc::ArrayView<uint8_t> data, uint16_t value);
danilchap1edb7ab2016-04-20 05:25:10 -070086};
87
88class VideoOrientation {
89 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +010090 using value_type = VideoRotation;
danilchap1edb7ab2016-04-20 05:25:10 -070091 static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
92 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070093 static constexpr const char kUri[] = "urn:3gpp:video-orientation";
danilchape2a01772016-10-28 07:08:58 -070094
danilchap978504e2017-04-06 01:03:53 -070095 static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value);
erikvargae6b16192017-05-11 02:36:32 -070096 static size_t ValueSize(VideoRotation) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020097 static bool Write(rtc::ArrayView<uint8_t> data, VideoRotation value);
danilchap978504e2017-04-06 01:03:53 -070098 static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value);
erikvargae6b16192017-05-11 02:36:32 -070099 static size_t ValueSize(uint8_t value) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200100 static bool Write(rtc::ArrayView<uint8_t> data, uint8_t value);
danilchap1edb7ab2016-04-20 05:25:10 -0700101};
102
Danil Chapovalov08b03512016-09-07 15:08:13 +0200103class PlayoutDelayLimits {
104 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +0100105 using value_type = PlayoutDelay;
Danil Chapovalov08b03512016-09-07 15:08:13 +0200106 static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
107 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -0700108 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -0800109 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
danilchape2a01772016-10-28 07:08:58 -0700110
Danil Chapovalov08b03512016-09-07 15:08:13 +0200111 // Playout delay in milliseconds. A playout delay limit (min or max)
112 // has 12 bits allocated. This allows a range of 0-4095 values which
113 // translates to a range of 0-40950 in milliseconds.
114 static constexpr int kGranularityMs = 10;
115 // Maximum playout delay value in milliseconds.
116 static constexpr int kMaxMs = 0xfff * kGranularityMs; // 40950.
117
danilchap978504e2017-04-06 01:03:53 -0700118 static bool Parse(rtc::ArrayView<const uint8_t> data,
119 PlayoutDelay* playout_delay);
erikvargae6b16192017-05-11 02:36:32 -0700120 static size_t ValueSize(const PlayoutDelay&) {
121 return kValueSizeBytes;
122 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200123 static bool Write(rtc::ArrayView<uint8_t> data,
124 const PlayoutDelay& playout_delay);
Danil Chapovalov08b03512016-09-07 15:08:13 +0200125};
126
ilnik00d802b2017-04-11 10:34:31 -0700127class VideoContentTypeExtension {
128 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +0100129 using value_type = VideoContentType;
ilnik00d802b2017-04-11 10:34:31 -0700130 static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType;
131 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -0700132 static constexpr const char kUri[] =
ilnik00d802b2017-04-11 10:34:31 -0700133 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
134
135 static bool Parse(rtc::ArrayView<const uint8_t> data,
136 VideoContentType* content_type);
erikvargae6b16192017-05-11 02:36:32 -0700137 static size_t ValueSize(VideoContentType) {
138 return kValueSizeBytes;
139 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200140 static bool Write(rtc::ArrayView<uint8_t> data,
141 VideoContentType content_type);
ilnik00d802b2017-04-11 10:34:31 -0700142};
143
ilnik04f4d122017-06-19 07:18:55 -0700144class VideoTimingExtension {
145 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +0100146 using value_type = VideoSendTiming;
ilnik04f4d122017-06-19 07:18:55 -0700147 static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming;
sprangba050a62017-08-18 02:51:12 -0700148 static constexpr uint8_t kValueSizeBytes = 13;
Steve Antond14d9f72017-07-21 10:59:39 -0700149 static constexpr const char kUri[] =
ilnik04f4d122017-06-19 07:18:55 -0700150 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
151
ilnik2edc6842017-07-06 03:06:50 -0700152 static bool Parse(rtc::ArrayView<const uint8_t> data,
153 VideoSendTiming* timing);
154 static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200155 static bool Write(rtc::ArrayView<uint8_t> data,
156 const VideoSendTiming& timing);
ilnik04f4d122017-06-19 07:18:55 -0700157
158 static size_t ValueSize(uint16_t time_delta_ms, uint8_t idx) {
159 return kValueSizeBytes;
160 }
161 // Writes only single time delta to position idx.
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200162 static bool Write(rtc::ArrayView<uint8_t> data,
163 uint16_t time_delta_ms,
164 uint8_t idx);
ilnik04f4d122017-06-19 07:18:55 -0700165};
166
Johnny Leee0c8b232018-09-11 16:50:49 -0400167class FrameMarkingExtension {
168 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +0100169 using value_type = FrameMarking;
Johnny Leee0c8b232018-09-11 16:50:49 -0400170 static constexpr RTPExtensionType kId = kRtpExtensionFrameMarking;
171 static constexpr const char kUri[] =
172 "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07";
173
174 static bool Parse(rtc::ArrayView<const uint8_t> data,
175 FrameMarking* frame_marking);
176 static size_t ValueSize(const FrameMarking& frame_marking);
177 static bool Write(rtc::ArrayView<uint8_t> data,
178 const FrameMarking& frame_marking);
179
180 private:
181 static bool IsScalable(uint8_t temporal_id, uint8_t layer_id);
182};
183
Steve Antona3251dd2017-07-21 09:58:31 -0700184// Base extension class for RTP header extensions which are strings.
185// Subclasses must defined kId and kUri static constexpr members.
186class BaseRtpStringExtension {
187 public:
Danil Chapovalovc5dd3002018-11-08 15:12:45 +0100188 using value_type = std::string;
Steve Antonf0482ea2018-04-09 13:33:52 -0700189 // String RTP header extensions are limited to 16 bytes because it is the
190 // maximum length that can be encoded with one-byte header extensions.
191 static constexpr uint8_t kMaxValueSizeBytes = 16;
192
Steve Antona3251dd2017-07-21 09:58:31 -0700193 static bool Parse(rtc::ArrayView<const uint8_t> data,
194 StringRtpHeaderExtension* str);
195 static size_t ValueSize(const StringRtpHeaderExtension& str) {
196 return str.size();
197 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200198 static bool Write(rtc::ArrayView<uint8_t> data,
199 const StringRtpHeaderExtension& str);
Steve Antona3251dd2017-07-21 09:58:31 -0700200
201 static bool Parse(rtc::ArrayView<const uint8_t> data, std::string* str);
202 static size_t ValueSize(const std::string& str) { return str.size(); }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200203 static bool Write(rtc::ArrayView<uint8_t> data, const std::string& str);
Steve Antona3251dd2017-07-21 09:58:31 -0700204};
205
206class RtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700207 public:
208 static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700209 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700210 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
danilchapef8d7732017-04-19 02:59:48 -0700211};
212
Steve Antona3251dd2017-07-21 09:58:31 -0700213class RepairedRtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700214 public:
215 static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700216 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700217 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Steve Antona3251dd2017-07-21 09:58:31 -0700218};
danilchapef8d7732017-04-19 02:59:48 -0700219
Steve Antona3251dd2017-07-21 09:58:31 -0700220class RtpMid : public BaseRtpStringExtension {
221 public:
222 static constexpr RTPExtensionType kId = kRtpExtensionMid;
Steve Antond14d9f72017-07-21 10:59:39 -0700223 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
danilchapef8d7732017-04-19 02:59:48 -0700224};
225
danilchap1edb7ab2016-04-20 05:25:10 -0700226} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200227#endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_