danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_ |
| 11 | #define MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_ |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stddef.h> |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 14 | #include <stdint.h> |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 15 | #include <string> |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/array_view.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 18 | #include "api/rtp_headers.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/video/video_content_type.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 20 | #include "api/video/video_frame_marking.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/video/video_rotation.h" |
| 22 | #include "api/video/video_timing.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 23 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | class AbsoluteSendTime { |
| 29 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 30 | using value_type = uint32_t; |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 31 | static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime; |
| 32 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 33 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 34 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 35 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 36 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint32_t* time_24bits); |
Danil Chapovalov | f3ba648 | 2017-06-12 15:43:55 +0200 | [diff] [blame] | 37 | static size_t ValueSize(uint32_t time_24bits) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 38 | static bool Write(rtc::ArrayView<uint8_t> data, uint32_t time_24bits); |
danilchap | a897f26 | 2016-08-26 05:42:41 -0700 | [diff] [blame] | 39 | |
| 40 | static constexpr uint32_t MsTo24Bits(int64_t time_ms) { |
| 41 | return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF; |
| 42 | } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | class AudioLevel { |
| 46 | public: |
| 47 | static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel; |
| 48 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 49 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 50 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 51 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 52 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 53 | bool* voice_activity, |
| 54 | uint8_t* audio_level); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 55 | static size_t ValueSize(bool voice_activity, uint8_t audio_level) { |
| 56 | return kValueSizeBytes; |
| 57 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 58 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 59 | bool voice_activity, |
| 60 | uint8_t audio_level); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | class TransmissionOffset { |
| 64 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 65 | using value_type = int32_t; |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 66 | static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset; |
| 67 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 68 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 69 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 70 | static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 71 | static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 72 | static bool Write(rtc::ArrayView<uint8_t> data, int32_t rtp_time); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | class TransportSequenceNumber { |
| 76 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 77 | using value_type = uint16_t; |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 78 | static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber; |
| 79 | static constexpr uint8_t kValueSizeBytes = 2; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 80 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 81 | "http://www.ietf.org/id/" |
| 82 | "draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 83 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 84 | static size_t ValueSize(uint16_t value) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 85 | static bool Write(rtc::ArrayView<uint8_t> data, uint16_t value); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | class VideoOrientation { |
| 89 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 90 | using value_type = VideoRotation; |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 91 | static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation; |
| 92 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 93 | static constexpr const char kUri[] = "urn:3gpp:video-orientation"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 94 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 95 | static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 96 | static size_t ValueSize(VideoRotation) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 97 | static bool Write(rtc::ArrayView<uint8_t> data, VideoRotation value); |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 98 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 99 | static size_t ValueSize(uint8_t value) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 100 | static bool Write(rtc::ArrayView<uint8_t> data, uint8_t value); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 103 | class PlayoutDelayLimits { |
| 104 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 105 | using value_type = PlayoutDelay; |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 106 | static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay; |
| 107 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 108 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 109 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 110 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 111 | // 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 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 118 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 119 | PlayoutDelay* playout_delay); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 120 | static size_t ValueSize(const PlayoutDelay&) { |
| 121 | return kValueSizeBytes; |
| 122 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 123 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 124 | const PlayoutDelay& playout_delay); |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 125 | }; |
| 126 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 127 | class VideoContentTypeExtension { |
| 128 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 129 | using value_type = VideoContentType; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 130 | static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType; |
| 131 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 132 | static constexpr const char kUri[] = |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 133 | "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); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 137 | static size_t ValueSize(VideoContentType) { |
| 138 | return kValueSizeBytes; |
| 139 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 140 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 141 | VideoContentType content_type); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 144 | class VideoTimingExtension { |
| 145 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 146 | using value_type = VideoSendTiming; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 147 | static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 148 | static constexpr uint8_t kValueSizeBytes = 13; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 149 | static constexpr const char kUri[] = |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 150 | "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; |
| 151 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 152 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 153 | VideoSendTiming* timing); |
| 154 | static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 155 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 156 | const VideoSendTiming& timing); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 157 | |
| 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 162 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 163 | uint16_t time_delta_ms, |
| 164 | uint8_t idx); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
Johnny Lee | e0c8b23 | 2018-09-11 16:50:49 -0400 | [diff] [blame] | 167 | class FrameMarkingExtension { |
| 168 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 169 | using value_type = FrameMarking; |
Johnny Lee | e0c8b23 | 2018-09-11 16:50:49 -0400 | [diff] [blame] | 170 | 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 Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 184 | // Base extension class for RTP header extensions which are strings. |
| 185 | // Subclasses must defined kId and kUri static constexpr members. |
| 186 | class BaseRtpStringExtension { |
| 187 | public: |
Danil Chapovalov | c5dd300 | 2018-11-08 15:12:45 +0100 | [diff] [blame^] | 188 | using value_type = std::string; |
Steve Anton | f0482ea | 2018-04-09 13:33:52 -0700 | [diff] [blame] | 189 | // 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 Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 193 | 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 198 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 199 | const StringRtpHeaderExtension& str); |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 200 | |
| 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 203 | static bool Write(rtc::ArrayView<uint8_t> data, const std::string& str); |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | class RtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 207 | public: |
| 208 | static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 209 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 210 | "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 213 | class RepairedRtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 214 | public: |
| 215 | static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 216 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 217 | "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"; |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 218 | }; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 219 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 220 | class RtpMid : public BaseRtpStringExtension { |
| 221 | public: |
| 222 | static constexpr RTPExtensionType kId = kRtpExtensionMid; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 223 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 226 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 227 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_ |