Line data Source code
1 : /*
2 : * Copyright (c) 2012 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 :
11 : #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
12 : #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
13 :
14 : #include <string>
15 :
16 : #include "webrtc/base/array_view.h"
17 : #include "webrtc/base/basictypes.h"
18 : #include "webrtc/base/checks.h"
19 : #include "webrtc/config.h"
20 : #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
21 :
22 : namespace webrtc {
23 :
24 : const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
25 :
26 : const size_t kRtpOneByteHeaderLength = 4;
27 : const size_t kTransmissionTimeOffsetLength = 4;
28 : const size_t kAudioLevelLength = 2;
29 : const size_t kAbsoluteSendTimeLength = 4;
30 : const size_t kVideoRotationLength = 2;
31 : const size_t kTransportSequenceNumberLength = 3;
32 : const size_t kPlayoutDelayLength = 4;
33 : // kRtpStreamIdLength is variable
34 : const size_t kRtpStreamIdLength = 4; // max 1-byte header extension length
35 :
36 : // Playout delay in milliseconds. A playout delay limit (min or max)
37 : // has 12 bits allocated. This allows a range of 0-4095 values which translates
38 : // to a range of 0-40950 in milliseconds.
39 : const int kPlayoutDelayGranularityMs = 10;
40 : // Maximum playout delay value in milliseconds.
41 : const int kPlayoutDelayMaxMs = 40950;
42 :
43 : class RtpHeaderExtensionMap {
44 : public:
45 : static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
46 : static constexpr uint8_t kInvalidId = 0;
47 :
48 : RtpHeaderExtensionMap();
49 : explicit RtpHeaderExtensionMap(rtc::ArrayView<const RtpExtension> extensions);
50 :
51 : template <typename Extension>
52 0 : bool Register(uint8_t id) {
53 : return Register(id, Extension::kId, Extension::kValueSizeBytes,
54 0 : Extension::kUri);
55 : }
56 : bool RegisterByType(uint8_t id, RTPExtensionType type);
57 : bool RegisterByUri(uint8_t id, const std::string& uri);
58 :
59 0 : bool IsRegistered(RTPExtensionType type) const {
60 0 : return GetId(type) != kInvalidId;
61 : }
62 : // Return kInvalidType if not found.
63 0 : RTPExtensionType GetType(uint8_t id) const {
64 0 : RTC_DCHECK_GE(id, kMinId);
65 0 : RTC_DCHECK_LE(id, kMaxId);
66 0 : return types_[id];
67 : }
68 : // Return kInvalidId if not found.
69 0 : uint8_t GetId(RTPExtensionType type) const {
70 0 : RTC_DCHECK_GT(type, kRtpExtensionNone);
71 0 : RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
72 0 : return ids_[type];
73 : }
74 :
75 : size_t GetTotalLengthInBytes() const;
76 :
77 : // TODO(danilchap): Remove use of the functions below.
78 0 : int32_t Register(RTPExtensionType type, uint8_t id) {
79 0 : return RegisterByType(id, type) ? 0 : -1;
80 : }
81 : int32_t Deregister(RTPExtensionType type);
82 :
83 : private:
84 : static constexpr uint8_t kMinId = 1;
85 : static constexpr uint8_t kMaxId = 14;
86 : bool Register(uint8_t id,
87 : RTPExtensionType type,
88 : size_t value_size,
89 : const char* uri);
90 :
91 : size_t total_values_size_bytes_ = 0;
92 : RTPExtensionType types_[kMaxId + 1];
93 : uint8_t ids_[kRtpExtensionNumberOfExtensions];
94 : };
95 :
96 : } // namespace webrtc
97 :
98 : #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
99 :
|