blob: 4e1afc1d9792dc4685c4356f3c38594e0894ba3c [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
pbosc7c26a02017-01-02 08:42:32 -080013#include <stdint.h>
danilchapef8d7732017-04-19 02:59:48 -070014#include <string>
pbosc7c26a02017-01-02 08:42:32 -080015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/array_view.h"
17#include "api/video/video_content_type.h"
18#include "api/video/video_rotation.h"
19#include "api/video/video_timing.h"
20#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchap1edb7ab2016-04-20 05:25:10 -070021
22namespace webrtc {
23
24class AbsoluteSendTime {
25 public:
26 static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime;
27 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070028 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080029 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
danilchape2a01772016-10-28 07:08:58 -070030
danilchap978504e2017-04-06 01:03:53 -070031 static bool Parse(rtc::ArrayView<const uint8_t> data, uint32_t* time_24bits);
Danil Chapovalovf3ba6482017-06-12 15:43:55 +020032 static size_t ValueSize(uint32_t time_24bits) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020033 static bool Write(rtc::ArrayView<uint8_t> data, uint32_t time_24bits);
danilchapa897f262016-08-26 05:42:41 -070034
35 static constexpr uint32_t MsTo24Bits(int64_t time_ms) {
36 return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF;
37 }
danilchap1edb7ab2016-04-20 05:25:10 -070038};
39
40class AudioLevel {
41 public:
42 static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel;
43 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070044 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080045 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
danilchape2a01772016-10-28 07:08:58 -070046
danilchap978504e2017-04-06 01:03:53 -070047 static bool Parse(rtc::ArrayView<const uint8_t> data,
danilchap1edb7ab2016-04-20 05:25:10 -070048 bool* voice_activity,
49 uint8_t* audio_level);
erikvargae6b16192017-05-11 02:36:32 -070050 static size_t ValueSize(bool voice_activity, uint8_t audio_level) {
51 return kValueSizeBytes;
52 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020053 static bool Write(rtc::ArrayView<uint8_t> data,
54 bool voice_activity,
55 uint8_t audio_level);
danilchap1edb7ab2016-04-20 05:25:10 -070056};
57
58class TransmissionOffset {
59 public:
60 static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
61 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070062 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset";
danilchape2a01772016-10-28 07:08:58 -070063
danilchap978504e2017-04-06 01:03:53 -070064 static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time);
erikvargae6b16192017-05-11 02:36:32 -070065 static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020066 static bool Write(rtc::ArrayView<uint8_t> data, int32_t rtp_time);
danilchap1edb7ab2016-04-20 05:25:10 -070067};
68
69class TransportSequenceNumber {
70 public:
71 static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
72 static constexpr uint8_t kValueSizeBytes = 2;
Steve Antond14d9f72017-07-21 10:59:39 -070073 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080074 "http://www.ietf.org/id/"
75 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
danilchap978504e2017-04-06 01:03:53 -070076 static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value);
erikvargae6b16192017-05-11 02:36:32 -070077 static size_t ValueSize(uint16_t value) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020078 static bool Write(rtc::ArrayView<uint8_t> data, uint16_t value);
danilchap1edb7ab2016-04-20 05:25:10 -070079};
80
81class VideoOrientation {
82 public:
83 static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
84 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070085 static constexpr const char kUri[] = "urn:3gpp:video-orientation";
danilchape2a01772016-10-28 07:08:58 -070086
danilchap978504e2017-04-06 01:03:53 -070087 static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value);
erikvargae6b16192017-05-11 02:36:32 -070088 static size_t ValueSize(VideoRotation) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020089 static bool Write(rtc::ArrayView<uint8_t> data, VideoRotation value);
danilchap978504e2017-04-06 01:03:53 -070090 static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value);
erikvargae6b16192017-05-11 02:36:32 -070091 static size_t ValueSize(uint8_t value) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +020092 static bool Write(rtc::ArrayView<uint8_t> data, uint8_t value);
danilchap1edb7ab2016-04-20 05:25:10 -070093};
94
Danil Chapovalov08b03512016-09-07 15:08:13 +020095class PlayoutDelayLimits {
96 public:
97 static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
98 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070099 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -0800100 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
danilchape2a01772016-10-28 07:08:58 -0700101
Danil Chapovalov08b03512016-09-07 15:08:13 +0200102 // Playout delay in milliseconds. A playout delay limit (min or max)
103 // has 12 bits allocated. This allows a range of 0-4095 values which
104 // translates to a range of 0-40950 in milliseconds.
105 static constexpr int kGranularityMs = 10;
106 // Maximum playout delay value in milliseconds.
107 static constexpr int kMaxMs = 0xfff * kGranularityMs; // 40950.
108
danilchap978504e2017-04-06 01:03:53 -0700109 static bool Parse(rtc::ArrayView<const uint8_t> data,
110 PlayoutDelay* playout_delay);
erikvargae6b16192017-05-11 02:36:32 -0700111 static size_t ValueSize(const PlayoutDelay&) {
112 return kValueSizeBytes;
113 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200114 static bool Write(rtc::ArrayView<uint8_t> data,
115 const PlayoutDelay& playout_delay);
Danil Chapovalov08b03512016-09-07 15:08:13 +0200116};
117
ilnik00d802b2017-04-11 10:34:31 -0700118class VideoContentTypeExtension {
119 public:
120 static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType;
121 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -0700122 static constexpr const char kUri[] =
ilnik00d802b2017-04-11 10:34:31 -0700123 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
124
125 static bool Parse(rtc::ArrayView<const uint8_t> data,
126 VideoContentType* content_type);
erikvargae6b16192017-05-11 02:36:32 -0700127 static size_t ValueSize(VideoContentType) {
128 return kValueSizeBytes;
129 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200130 static bool Write(rtc::ArrayView<uint8_t> data,
131 VideoContentType content_type);
ilnik00d802b2017-04-11 10:34:31 -0700132};
133
ilnik04f4d122017-06-19 07:18:55 -0700134class VideoTimingExtension {
135 public:
136 static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming;
sprangba050a62017-08-18 02:51:12 -0700137 static constexpr uint8_t kValueSizeBytes = 13;
Steve Antond14d9f72017-07-21 10:59:39 -0700138 static constexpr const char kUri[] =
ilnik04f4d122017-06-19 07:18:55 -0700139 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
140
ilnik2edc6842017-07-06 03:06:50 -0700141 static bool Parse(rtc::ArrayView<const uint8_t> data,
142 VideoSendTiming* timing);
143 static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200144 static bool Write(rtc::ArrayView<uint8_t> data,
145 const VideoSendTiming& timing);
ilnik04f4d122017-06-19 07:18:55 -0700146
147 static size_t ValueSize(uint16_t time_delta_ms, uint8_t idx) {
148 return kValueSizeBytes;
149 }
150 // Writes only single time delta to position idx.
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200151 static bool Write(rtc::ArrayView<uint8_t> data,
152 uint16_t time_delta_ms,
153 uint8_t idx);
ilnik04f4d122017-06-19 07:18:55 -0700154};
155
Steve Antona3251dd2017-07-21 09:58:31 -0700156// Base extension class for RTP header extensions which are strings.
157// Subclasses must defined kId and kUri static constexpr members.
158class BaseRtpStringExtension {
159 public:
Steve Antonf0482ea2018-04-09 13:33:52 -0700160 // String RTP header extensions are limited to 16 bytes because it is the
161 // maximum length that can be encoded with one-byte header extensions.
162 static constexpr uint8_t kMaxValueSizeBytes = 16;
163
Steve Antona3251dd2017-07-21 09:58:31 -0700164 static bool Parse(rtc::ArrayView<const uint8_t> data,
165 StringRtpHeaderExtension* str);
166 static size_t ValueSize(const StringRtpHeaderExtension& str) {
167 return str.size();
168 }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200169 static bool Write(rtc::ArrayView<uint8_t> data,
170 const StringRtpHeaderExtension& str);
Steve Antona3251dd2017-07-21 09:58:31 -0700171
172 static bool Parse(rtc::ArrayView<const uint8_t> data, std::string* str);
173 static size_t ValueSize(const std::string& str) { return str.size(); }
Danil Chapovalov9bf31582018-06-18 13:48:20 +0200174 static bool Write(rtc::ArrayView<uint8_t> data, const std::string& str);
Steve Antona3251dd2017-07-21 09:58:31 -0700175};
176
177class RtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700178 public:
179 static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700180 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700181 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
danilchapef8d7732017-04-19 02:59:48 -0700182};
183
Steve Antona3251dd2017-07-21 09:58:31 -0700184class RepairedRtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700185 public:
186 static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700187 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700188 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Steve Antona3251dd2017-07-21 09:58:31 -0700189};
danilchapef8d7732017-04-19 02:59:48 -0700190
Steve Antona3251dd2017-07-21 09:58:31 -0700191class RtpMid : public BaseRtpStringExtension {
192 public:
193 static constexpr RTPExtensionType kId = kRtpExtensionMid;
Steve Antond14d9f72017-07-21 10:59:39 -0700194 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
danilchapef8d7732017-04-19 02:59:48 -0700195};
196
danilchap1edb7ab2016-04-20 05:25:10 -0700197} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200198#endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_