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 | |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 13 | #include <stdint.h> |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 14 | #include <string> |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #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" |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class AbsoluteSendTime { |
| 25 | public: |
| 26 | static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime; |
| 27 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 28 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 29 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 30 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 31 | 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] | 32 | static size_t ValueSize(uint32_t time_24bits) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 33 | static bool Write(rtc::ArrayView<uint8_t> data, uint32_t time_24bits); |
danilchap | a897f26 | 2016-08-26 05:42:41 -0700 | [diff] [blame] | 34 | |
| 35 | static constexpr uint32_t MsTo24Bits(int64_t time_ms) { |
| 36 | return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF; |
| 37 | } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | class AudioLevel { |
| 41 | public: |
| 42 | static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel; |
| 43 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 44 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 45 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 46 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 47 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 48 | bool* voice_activity, |
| 49 | uint8_t* audio_level); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 50 | static size_t ValueSize(bool voice_activity, uint8_t audio_level) { |
| 51 | return kValueSizeBytes; |
| 52 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 53 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 54 | bool voice_activity, |
| 55 | uint8_t audio_level); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | class TransmissionOffset { |
| 59 | public: |
| 60 | static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset; |
| 61 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 62 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 63 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 64 | static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 65 | static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 66 | static bool Write(rtc::ArrayView<uint8_t> data, int32_t rtp_time); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | class TransportSequenceNumber { |
| 70 | public: |
| 71 | static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber; |
| 72 | static constexpr uint8_t kValueSizeBytes = 2; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 73 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 74 | "http://www.ietf.org/id/" |
| 75 | "draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 76 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 77 | static size_t ValueSize(uint16_t value) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 78 | static bool Write(rtc::ArrayView<uint8_t> data, uint16_t value); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | class VideoOrientation { |
| 82 | public: |
| 83 | static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation; |
| 84 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 85 | static constexpr const char kUri[] = "urn:3gpp:video-orientation"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 86 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 87 | static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 88 | static size_t ValueSize(VideoRotation) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 89 | static bool Write(rtc::ArrayView<uint8_t> data, VideoRotation value); |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 90 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 91 | static size_t ValueSize(uint8_t value) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 92 | static bool Write(rtc::ArrayView<uint8_t> data, uint8_t value); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 95 | class PlayoutDelayLimits { |
| 96 | public: |
| 97 | static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay; |
| 98 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 99 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 100 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 101 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 102 | // 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 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 109 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 110 | PlayoutDelay* playout_delay); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 111 | static size_t ValueSize(const PlayoutDelay&) { |
| 112 | return kValueSizeBytes; |
| 113 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 114 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 115 | const PlayoutDelay& playout_delay); |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 118 | class VideoContentTypeExtension { |
| 119 | public: |
| 120 | static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType; |
| 121 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 122 | static constexpr const char kUri[] = |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 123 | "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); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 127 | static size_t ValueSize(VideoContentType) { |
| 128 | return kValueSizeBytes; |
| 129 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 130 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 131 | VideoContentType content_type); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 134 | class VideoTimingExtension { |
| 135 | public: |
| 136 | static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 137 | static constexpr uint8_t kValueSizeBytes = 13; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 138 | static constexpr const char kUri[] = |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 139 | "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; |
| 140 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 141 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 142 | VideoSendTiming* timing); |
| 143 | static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 144 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 145 | const VideoSendTiming& timing); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 146 | |
| 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 Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 151 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 152 | uint16_t time_delta_ms, |
| 153 | uint8_t idx); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Johnny Lee | e0c8b23 | 2018-09-11 16:50:49 -0400 | [diff] [blame^] | 156 | class FrameMarkingExtension { |
| 157 | public: |
| 158 | static constexpr RTPExtensionType kId = kRtpExtensionFrameMarking; |
| 159 | static constexpr const char kUri[] = |
| 160 | "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07"; |
| 161 | |
| 162 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 163 | FrameMarking* frame_marking); |
| 164 | static size_t ValueSize(const FrameMarking& frame_marking); |
| 165 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 166 | const FrameMarking& frame_marking); |
| 167 | |
| 168 | private: |
| 169 | static bool IsScalable(uint8_t temporal_id, uint8_t layer_id); |
| 170 | }; |
| 171 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 172 | // Base extension class for RTP header extensions which are strings. |
| 173 | // Subclasses must defined kId and kUri static constexpr members. |
| 174 | class BaseRtpStringExtension { |
| 175 | public: |
Steve Anton | f0482ea | 2018-04-09 13:33:52 -0700 | [diff] [blame] | 176 | // String RTP header extensions are limited to 16 bytes because it is the |
| 177 | // maximum length that can be encoded with one-byte header extensions. |
| 178 | static constexpr uint8_t kMaxValueSizeBytes = 16; |
| 179 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 180 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 181 | StringRtpHeaderExtension* str); |
| 182 | static size_t ValueSize(const StringRtpHeaderExtension& str) { |
| 183 | return str.size(); |
| 184 | } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 185 | static bool Write(rtc::ArrayView<uint8_t> data, |
| 186 | const StringRtpHeaderExtension& str); |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 187 | |
| 188 | static bool Parse(rtc::ArrayView<const uint8_t> data, std::string* str); |
| 189 | static size_t ValueSize(const std::string& str) { return str.size(); } |
Danil Chapovalov | 9bf3158 | 2018-06-18 13:48:20 +0200 | [diff] [blame] | 190 | static bool Write(rtc::ArrayView<uint8_t> data, const std::string& str); |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | class RtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 194 | public: |
| 195 | static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 196 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 197 | "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 200 | class RepairedRtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 201 | public: |
| 202 | static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 203 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 204 | "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"; |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 205 | }; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 206 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 207 | class RtpMid : public BaseRtpStringExtension { |
| 208 | public: |
| 209 | static constexpr RTPExtensionType kId = kRtpExtensionMid; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 210 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 213 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 214 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_ |