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; } |
| 33 | static bool Write(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 | } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 53 | static bool Write(uint8_t* data, bool voice_activity, uint8_t audio_level); |
| 54 | }; |
| 55 | |
| 56 | class TransmissionOffset { |
| 57 | public: |
| 58 | static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset; |
| 59 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 60 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 61 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 62 | static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 63 | static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; } |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 64 | static bool Write(uint8_t* data, int32_t rtp_time); |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | class TransportSequenceNumber { |
| 68 | public: |
| 69 | static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber; |
| 70 | static constexpr uint8_t kValueSizeBytes = 2; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 71 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 72 | "http://www.ietf.org/id/" |
| 73 | "draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 74 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 75 | static size_t ValueSize(uint16_t value) { return kValueSizeBytes; } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 76 | static bool Write(uint8_t* data, uint16_t value); |
| 77 | }; |
| 78 | |
| 79 | class VideoOrientation { |
| 80 | public: |
| 81 | static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation; |
| 82 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 83 | static constexpr const char kUri[] = "urn:3gpp:video-orientation"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 84 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 85 | static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 86 | static size_t ValueSize(VideoRotation) { return kValueSizeBytes; } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 87 | static bool Write(uint8_t* data, VideoRotation value); |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 88 | static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 89 | static size_t ValueSize(uint8_t value) { return kValueSizeBytes; } |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 90 | static bool Write(uint8_t* data, uint8_t value); |
| 91 | }; |
| 92 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 93 | class PlayoutDelayLimits { |
| 94 | public: |
| 95 | static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay; |
| 96 | static constexpr uint8_t kValueSizeBytes = 3; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 97 | static constexpr const char kUri[] = |
danilchap | 6ba58d6 | 2016-11-09 05:46:39 -0800 | [diff] [blame] | 98 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
danilchap | e2a0177 | 2016-10-28 07:08:58 -0700 | [diff] [blame] | 99 | |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 100 | // Playout delay in milliseconds. A playout delay limit (min or max) |
| 101 | // has 12 bits allocated. This allows a range of 0-4095 values which |
| 102 | // translates to a range of 0-40950 in milliseconds. |
| 103 | static constexpr int kGranularityMs = 10; |
| 104 | // Maximum playout delay value in milliseconds. |
| 105 | static constexpr int kMaxMs = 0xfff * kGranularityMs; // 40950. |
| 106 | |
danilchap | 978504e | 2017-04-06 01:03:53 -0700 | [diff] [blame] | 107 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 108 | PlayoutDelay* playout_delay); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 109 | static size_t ValueSize(const PlayoutDelay&) { |
| 110 | return kValueSizeBytes; |
| 111 | } |
Danil Chapovalov | 08b0351 | 2016-09-07 15:08:13 +0200 | [diff] [blame] | 112 | static bool Write(uint8_t* data, const PlayoutDelay& playout_delay); |
| 113 | }; |
| 114 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 115 | class VideoContentTypeExtension { |
| 116 | public: |
| 117 | static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType; |
| 118 | static constexpr uint8_t kValueSizeBytes = 1; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 119 | static constexpr const char kUri[] = |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 120 | "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"; |
| 121 | |
| 122 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 123 | VideoContentType* content_type); |
erikvarga | e6b1619 | 2017-05-11 02:36:32 -0700 | [diff] [blame] | 124 | static size_t ValueSize(VideoContentType) { |
| 125 | return kValueSizeBytes; |
| 126 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 127 | static bool Write(uint8_t* data, VideoContentType content_type); |
| 128 | }; |
| 129 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 130 | class VideoTimingExtension { |
| 131 | public: |
| 132 | static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 133 | static constexpr uint8_t kValueSizeBytes = 13; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 134 | static constexpr const char kUri[] = |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 135 | "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; |
| 136 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 137 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 138 | VideoSendTiming* timing); |
| 139 | static size_t ValueSize(const VideoSendTiming&) { return kValueSizeBytes; } |
| 140 | static bool Write(uint8_t* data, const VideoSendTiming& timing); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 141 | |
| 142 | static size_t ValueSize(uint16_t time_delta_ms, uint8_t idx) { |
| 143 | return kValueSizeBytes; |
| 144 | } |
| 145 | // Writes only single time delta to position idx. |
| 146 | static bool Write(uint8_t* data, uint16_t time_delta_ms, uint8_t idx); |
| 147 | }; |
| 148 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 149 | // Base extension class for RTP header extensions which are strings. |
| 150 | // Subclasses must defined kId and kUri static constexpr members. |
| 151 | class BaseRtpStringExtension { |
| 152 | public: |
Steve Anton | f0482ea | 2018-04-09 13:33:52 -0700 | [diff] [blame^] | 153 | // String RTP header extensions are limited to 16 bytes because it is the |
| 154 | // maximum length that can be encoded with one-byte header extensions. |
| 155 | static constexpr uint8_t kMaxValueSizeBytes = 16; |
| 156 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 157 | static bool Parse(rtc::ArrayView<const uint8_t> data, |
| 158 | StringRtpHeaderExtension* str); |
| 159 | static size_t ValueSize(const StringRtpHeaderExtension& str) { |
| 160 | return str.size(); |
| 161 | } |
| 162 | static bool Write(uint8_t* data, const StringRtpHeaderExtension& str); |
| 163 | |
| 164 | static bool Parse(rtc::ArrayView<const uint8_t> data, std::string* str); |
| 165 | static size_t ValueSize(const std::string& str) { return str.size(); } |
| 166 | static bool Write(uint8_t* data, const std::string& str); |
| 167 | }; |
| 168 | |
| 169 | class RtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 170 | public: |
| 171 | static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 172 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 173 | "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 176 | class RepairedRtpStreamId : public BaseRtpStringExtension { |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 177 | public: |
| 178 | static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 179 | static constexpr const char kUri[] = |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 180 | "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"; |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 181 | }; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 182 | |
Steve Anton | a3251dd | 2017-07-21 09:58:31 -0700 | [diff] [blame] | 183 | class RtpMid : public BaseRtpStringExtension { |
| 184 | public: |
| 185 | static constexpr RTPExtensionType kId = kRtpExtensionMid; |
Steve Anton | d14d9f7 | 2017-07-21 10:59:39 -0700 | [diff] [blame] | 186 | static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid"; |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
danilchap | 1edb7ab | 2016-04-20 05:25:10 -0700 | [diff] [blame] | 189 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 190 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_ |