blob: 8526f13d6f8c57f9ae38de9a027267f972c9493d [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; }
33 static bool Write(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 }
danilchap1edb7ab2016-04-20 05:25:10 -070053 static bool Write(uint8_t* data, bool voice_activity, uint8_t audio_level);
54};
55
56class TransmissionOffset {
57 public:
58 static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
59 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070060 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:toffset";
danilchape2a01772016-10-28 07:08:58 -070061
danilchap978504e2017-04-06 01:03:53 -070062 static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time);
erikvargae6b16192017-05-11 02:36:32 -070063 static size_t ValueSize(int32_t rtp_time) { return kValueSizeBytes; }
Danil Chapovalov31e4e802016-08-03 18:27:40 +020064 static bool Write(uint8_t* data, int32_t rtp_time);
danilchap1edb7ab2016-04-20 05:25:10 -070065};
66
67class TransportSequenceNumber {
68 public:
69 static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
70 static constexpr uint8_t kValueSizeBytes = 2;
Steve Antond14d9f72017-07-21 10:59:39 -070071 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080072 "http://www.ietf.org/id/"
73 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
danilchap978504e2017-04-06 01:03:53 -070074 static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value);
erikvargae6b16192017-05-11 02:36:32 -070075 static size_t ValueSize(uint16_t value) { return kValueSizeBytes; }
danilchap1edb7ab2016-04-20 05:25:10 -070076 static bool Write(uint8_t* data, uint16_t value);
77};
78
79class VideoOrientation {
80 public:
81 static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
82 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -070083 static constexpr const char kUri[] = "urn:3gpp:video-orientation";
danilchape2a01772016-10-28 07:08:58 -070084
danilchap978504e2017-04-06 01:03:53 -070085 static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value);
erikvargae6b16192017-05-11 02:36:32 -070086 static size_t ValueSize(VideoRotation) { return kValueSizeBytes; }
danilchap1edb7ab2016-04-20 05:25:10 -070087 static bool Write(uint8_t* data, VideoRotation value);
danilchap978504e2017-04-06 01:03:53 -070088 static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value);
erikvargae6b16192017-05-11 02:36:32 -070089 static size_t ValueSize(uint8_t value) { return kValueSizeBytes; }
danilchap1edb7ab2016-04-20 05:25:10 -070090 static bool Write(uint8_t* data, uint8_t value);
91};
92
Danil Chapovalov08b03512016-09-07 15:08:13 +020093class PlayoutDelayLimits {
94 public:
95 static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
96 static constexpr uint8_t kValueSizeBytes = 3;
Steve Antond14d9f72017-07-21 10:59:39 -070097 static constexpr const char kUri[] =
danilchap6ba58d62016-11-09 05:46:39 -080098 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
danilchape2a01772016-10-28 07:08:58 -070099
Danil Chapovalov08b03512016-09-07 15:08:13 +0200100 // 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
danilchap978504e2017-04-06 01:03:53 -0700107 static bool Parse(rtc::ArrayView<const uint8_t> data,
108 PlayoutDelay* playout_delay);
erikvargae6b16192017-05-11 02:36:32 -0700109 static size_t ValueSize(const PlayoutDelay&) {
110 return kValueSizeBytes;
111 }
Danil Chapovalov08b03512016-09-07 15:08:13 +0200112 static bool Write(uint8_t* data, const PlayoutDelay& playout_delay);
113};
114
ilnik00d802b2017-04-11 10:34:31 -0700115class VideoContentTypeExtension {
116 public:
117 static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType;
118 static constexpr uint8_t kValueSizeBytes = 1;
Steve Antond14d9f72017-07-21 10:59:39 -0700119 static constexpr const char kUri[] =
ilnik00d802b2017-04-11 10:34:31 -0700120 "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);
erikvargae6b16192017-05-11 02:36:32 -0700124 static size_t ValueSize(VideoContentType) {
125 return kValueSizeBytes;
126 }
ilnik00d802b2017-04-11 10:34:31 -0700127 static bool Write(uint8_t* data, VideoContentType content_type);
128};
129
ilnik04f4d122017-06-19 07:18:55 -0700130class VideoTimingExtension {
131 public:
132 static constexpr RTPExtensionType kId = kRtpExtensionVideoTiming;
sprangba050a62017-08-18 02:51:12 -0700133 static constexpr uint8_t kValueSizeBytes = 13;
Steve Antond14d9f72017-07-21 10:59:39 -0700134 static constexpr const char kUri[] =
ilnik04f4d122017-06-19 07:18:55 -0700135 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
136
ilnik2edc6842017-07-06 03:06:50 -0700137 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);
ilnik04f4d122017-06-19 07:18:55 -0700141
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 Antona3251dd2017-07-21 09:58:31 -0700149// Base extension class for RTP header extensions which are strings.
150// Subclasses must defined kId and kUri static constexpr members.
151class BaseRtpStringExtension {
152 public:
Steve Antonf0482ea2018-04-09 13:33:52 -0700153 // 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 Antona3251dd2017-07-21 09:58:31 -0700157 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
169class RtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700170 public:
171 static constexpr RTPExtensionType kId = kRtpExtensionRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700172 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700173 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
danilchapef8d7732017-04-19 02:59:48 -0700174};
175
Steve Antona3251dd2017-07-21 09:58:31 -0700176class RepairedRtpStreamId : public BaseRtpStringExtension {
danilchapef8d7732017-04-19 02:59:48 -0700177 public:
178 static constexpr RTPExtensionType kId = kRtpExtensionRepairedRtpStreamId;
Steve Antond14d9f72017-07-21 10:59:39 -0700179 static constexpr const char kUri[] =
danilchapef8d7732017-04-19 02:59:48 -0700180 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Steve Antona3251dd2017-07-21 09:58:31 -0700181};
danilchapef8d7732017-04-19 02:59:48 -0700182
Steve Antona3251dd2017-07-21 09:58:31 -0700183class RtpMid : public BaseRtpStringExtension {
184 public:
185 static constexpr RTPExtensionType kId = kRtpExtensionMid;
Steve Antond14d9f72017-07-21 10:59:39 -0700186 static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
danilchapef8d7732017-04-19 02:59:48 -0700187};
188
danilchap1edb7ab2016-04-20 05:25:10 -0700189} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200190#endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_