blob: 0d30848f965cd09776e13163eb44e11c85db817e [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 */
10#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_
11#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_
12
pbosc7c26a02017-01-02 08:42:32 -080013#include <stdint.h>
14
ilnik00d802b2017-04-11 10:34:31 -070015#include "webrtc/api/video/video_content_type.h"
nisseaf916892017-01-10 07:44:26 -080016#include "webrtc/api/video/video_rotation.h"
danilchap978504e2017-04-06 01:03:53 -070017#include "webrtc/base/array_view.h"
danilchap1edb7ab2016-04-20 05:25:10 -070018#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19
20namespace webrtc {
21
22class AbsoluteSendTime {
23 public:
24 static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime;
25 static constexpr uint8_t kValueSizeBytes = 3;
danilchap6ba58d62016-11-09 05:46:39 -080026 static constexpr const char* kUri =
27 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
danilchape2a01772016-10-28 07:08:58 -070028
danilchap978504e2017-04-06 01:03:53 -070029 static bool Parse(rtc::ArrayView<const uint8_t> data, uint32_t* time_24bits);
danilchap1edb7ab2016-04-20 05:25:10 -070030 static bool Write(uint8_t* data, int64_t time_ms);
danilchapa897f262016-08-26 05:42:41 -070031
32 static constexpr uint32_t MsTo24Bits(int64_t time_ms) {
33 return static_cast<uint32_t>(((time_ms << 18) + 500) / 1000) & 0x00FFFFFF;
34 }
danilchap1edb7ab2016-04-20 05:25:10 -070035};
36
37class AudioLevel {
38 public:
39 static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel;
40 static constexpr uint8_t kValueSizeBytes = 1;
danilchap6ba58d62016-11-09 05:46:39 -080041 static constexpr const char* kUri =
42 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
danilchape2a01772016-10-28 07:08:58 -070043
danilchap978504e2017-04-06 01:03:53 -070044 static bool Parse(rtc::ArrayView<const uint8_t> data,
danilchap1edb7ab2016-04-20 05:25:10 -070045 bool* voice_activity,
46 uint8_t* audio_level);
47 static bool Write(uint8_t* data, bool voice_activity, uint8_t audio_level);
48};
49
50class TransmissionOffset {
51 public:
52 static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
53 static constexpr uint8_t kValueSizeBytes = 3;
danilchap6ba58d62016-11-09 05:46:39 -080054 static constexpr const char* kUri = "urn:ietf:params:rtp-hdrext:toffset";
danilchape2a01772016-10-28 07:08:58 -070055
danilchap978504e2017-04-06 01:03:53 -070056 static bool Parse(rtc::ArrayView<const uint8_t> data, int32_t* rtp_time);
Danil Chapovalov31e4e802016-08-03 18:27:40 +020057 static bool Write(uint8_t* data, int32_t rtp_time);
danilchap1edb7ab2016-04-20 05:25:10 -070058};
59
60class TransportSequenceNumber {
61 public:
62 static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
63 static constexpr uint8_t kValueSizeBytes = 2;
danilchap6ba58d62016-11-09 05:46:39 -080064 static constexpr const char* kUri =
65 "http://www.ietf.org/id/"
66 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
danilchap978504e2017-04-06 01:03:53 -070067 static bool Parse(rtc::ArrayView<const uint8_t> data, uint16_t* value);
danilchap1edb7ab2016-04-20 05:25:10 -070068 static bool Write(uint8_t* data, uint16_t value);
69};
70
71class VideoOrientation {
72 public:
73 static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
74 static constexpr uint8_t kValueSizeBytes = 1;
danilchap6ba58d62016-11-09 05:46:39 -080075 static constexpr const char* kUri = "urn:3gpp:video-orientation";
danilchape2a01772016-10-28 07:08:58 -070076
danilchap978504e2017-04-06 01:03:53 -070077 static bool Parse(rtc::ArrayView<const uint8_t> data, VideoRotation* value);
danilchap1edb7ab2016-04-20 05:25:10 -070078 static bool Write(uint8_t* data, VideoRotation value);
danilchap978504e2017-04-06 01:03:53 -070079 static bool Parse(rtc::ArrayView<const uint8_t> data, uint8_t* value);
danilchap1edb7ab2016-04-20 05:25:10 -070080 static bool Write(uint8_t* data, uint8_t value);
81};
82
Danil Chapovalov08b03512016-09-07 15:08:13 +020083class PlayoutDelayLimits {
84 public:
85 static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
86 static constexpr uint8_t kValueSizeBytes = 3;
danilchap6ba58d62016-11-09 05:46:39 -080087 static constexpr const char* kUri =
88 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
danilchape2a01772016-10-28 07:08:58 -070089
Danil Chapovalov08b03512016-09-07 15:08:13 +020090 // Playout delay in milliseconds. A playout delay limit (min or max)
91 // has 12 bits allocated. This allows a range of 0-4095 values which
92 // translates to a range of 0-40950 in milliseconds.
93 static constexpr int kGranularityMs = 10;
94 // Maximum playout delay value in milliseconds.
95 static constexpr int kMaxMs = 0xfff * kGranularityMs; // 40950.
96
danilchap978504e2017-04-06 01:03:53 -070097 static bool Parse(rtc::ArrayView<const uint8_t> data,
98 PlayoutDelay* playout_delay);
Danil Chapovalov08b03512016-09-07 15:08:13 +020099 static bool Write(uint8_t* data, const PlayoutDelay& playout_delay);
100};
101
ilnik00d802b2017-04-11 10:34:31 -0700102class VideoContentTypeExtension {
103 public:
104 static constexpr RTPExtensionType kId = kRtpExtensionVideoContentType;
105 static constexpr uint8_t kValueSizeBytes = 1;
106 static constexpr const char* kUri =
107 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
108
109 static bool Parse(rtc::ArrayView<const uint8_t> data,
110 VideoContentType* content_type);
111 static bool Write(uint8_t* data, VideoContentType content_type);
112};
113
danilchap1edb7ab2016-04-20 05:25:10 -0700114} // namespace webrtc
115#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_