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: |
| 30 | static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime; |
| 31 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 32 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 33 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 34 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 35 | 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] | 36 | static size_t ValueSize(uint32_t time_24bits) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 37 | static bool Write(rtc::ArrayView<uint8_t> data, uint32_t time_24bits); |
danilchap | a897f26 | 2016-08-26 05:42:41 -0700 | [diff] [blame] | 38 | |
| 39 | static constexpr uint32_t MsTo24Bits(int64_t time_ms) { |
| 40 | return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF; |
| 41 | } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | class AudioLevel { |
| 45 | public: |
| 46 | static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel; |
| 47 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 48 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 49 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 50 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 51 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 52 | bool* voice_activity, |
| 53 | uint8_t* audio_level); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 54 | static size_t ValueSize(bool voice_activity, uint8_t audio_level) { |
| 55 | return kValueSizeBytes; |
| 56 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 57 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 58 | bool voice_activity, |
| 59 | uint8_t audio_level); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | class TransmissionOffset { |
| 63 | public: |
| 64 | static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset; |
| 65 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 66 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 67 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 68 | static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 69 | static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 70 | static bool Write(rtc::ArrayView<uint8_t> data, int32_t rtp_time); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | class TransportSequenceNumber { |
| 74 | public: |
| 75 | static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber; |
| 76 | static constexpr uint8_t kValueSizeBytes = 2; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 77 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 78 | "http://www.ietf.org/id/" |
| 79 | "draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 80 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 81 | static size_t ValueSize(uint16_t value) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 82 | static bool Write(rtc::ArrayView<uint8_t> data, uint16_t value); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | class VideoOrientation { |
| 86 | public: |
| 87 | static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation; |
| 88 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 89 | static constexpr const char kUri[] = "urn:3gpp:video-orientation"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 90 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 91 | static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 92 | static size_t ValueSize(VideoRotation) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 93 | static bool Write(rtc::ArrayView<uint8_t> data, VideoRotation value); |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 94 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 95 | static size_t ValueSize(uint8_t value) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 96 | static bool Write(rtc::ArrayView<uint8_t> data, uint8_t value); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 99 | class PlayoutDelayLimits { |
| 100 | public: |
| 101 | static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay; |
| 102 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 103 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 104 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 105 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 106 | // 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 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 113 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 114 | PlayoutDelay* playout_delay); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 115 | static size_t ValueSize(const PlayoutDelay&) { |
| 116 | return kValueSizeBytes; |
| 117 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 118 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 119 | const PlayoutDelay& playout_delay); |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 122 | class VideoContentTypeExtension { |
| 123 | public: |
| 124 | static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType; |
| 125 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 126 | static constexpr const char kUri[] = |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 127 | "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); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 131 | static size_t ValueSize(VideoContentType) { |
| 132 | return kValueSizeBytes; |
| 133 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 134 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 135 | VideoContentType content_type); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 138 | class VideoTimingExtension { |
| 139 | public: |
| 140 | static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 141 | static constexpr uint8_t kValueSizeBytes = 13; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 142 | static constexpr const char kUri[] = |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 143 | "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; |
| 144 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 145 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 146 | VideoSendTiming* timing); |
| 147 | static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 148 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 149 | const VideoSendTiming& timing); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 150 | |
| 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 155 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 156 | uint16_t time_delta_ms, |
| 157 | uint8_t idx); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
Johnny Lee | e0c8b23 | 2018-09-11 16:50:49 -0400 | [diff] [blame] | 160 | class 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 Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 176 | // Base extension class for RTP header extensions which are strings. |
| 177 | // Subclasses must defined kId and kUri static constexpr members. |
| 178 | class BaseRtpStringExtension { |
| 179 | public: |
Steve Anton | f0482ea | 2018-04-09 13:33:52 -0700 | [diff] [blame] | 180 | // 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 Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 184 | 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 189 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 190 | const StringRtpHeaderExtension& str); |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 191 | |
| 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 194 | static bool Write(rtc::ArrayView<uint8_t> data, const std::string& str); |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | class RtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 198 | public: |
| 199 | static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 200 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 201 | "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 202 | }; |
| 203 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 204 | class RepairedRtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 205 | public: |
| 206 | static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 207 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 208 | "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"; |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 209 | }; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 210 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 211 | class RtpMid : public BaseRtpStringExtension { |
| 212 | public: |
| 213 | static constexpr RTPExtensionType kId = kRtpExtensionMid; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 214 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 217 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 218 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_ |