OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ |
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ |
13 | 13 |
14 #include <map> | 14 #include <initializer_list> |
| 15 #include <string> |
15 | 16 |
| 17 #include "webrtc/base/basictypes.h" |
| 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/config.h" |
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
17 #include "webrtc/typedefs.h" | |
18 | 21 |
19 namespace webrtc { | 22 namespace webrtc { |
20 | 23 |
21 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; | 24 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; |
22 | 25 |
23 const size_t kRtpOneByteHeaderLength = 4; | 26 const size_t kRtpOneByteHeaderLength = 4; |
24 const size_t kTransmissionTimeOffsetLength = 4; | 27 const size_t kTransmissionTimeOffsetLength = 4; |
25 const size_t kAudioLevelLength = 2; | 28 const size_t kAudioLevelLength = 2; |
26 const size_t kAbsoluteSendTimeLength = 4; | 29 const size_t kAbsoluteSendTimeLength = 4; |
27 const size_t kVideoRotationLength = 2; | 30 const size_t kVideoRotationLength = 2; |
28 const size_t kTransportSequenceNumberLength = 3; | 31 const size_t kTransportSequenceNumberLength = 3; |
29 const size_t kPlayoutDelayLength = 4; | 32 const size_t kPlayoutDelayLength = 4; |
30 | 33 |
31 // Playout delay in milliseconds. A playout delay limit (min or max) | 34 // Playout delay in milliseconds. A playout delay limit (min or max) |
32 // has 12 bits allocated. This allows a range of 0-4095 values which translates | 35 // has 12 bits allocated. This allows a range of 0-4095 values which translates |
33 // to a range of 0-40950 in milliseconds. | 36 // to a range of 0-40950 in milliseconds. |
34 const int kPlayoutDelayGranularityMs = 10; | 37 const int kPlayoutDelayGranularityMs = 10; |
35 // Maximum playout delay value in milliseconds. | 38 // Maximum playout delay value in milliseconds. |
36 const int kPlayoutDelayMaxMs = 40950; | 39 const int kPlayoutDelayMaxMs = 40950; |
37 | 40 |
38 struct HeaderExtension { | |
39 explicit HeaderExtension(RTPExtensionType extension_type) | |
40 : type(extension_type), length(0) { | |
41 Init(); | |
42 } | |
43 | |
44 void Init() { | |
45 // TODO(solenberg): Create handler classes for header extensions so we can | |
46 // get rid of switches like these as well as handling code spread out all | |
47 // over. | |
48 switch (type) { | |
49 case kRtpExtensionTransmissionTimeOffset: | |
50 length = kTransmissionTimeOffsetLength; | |
51 break; | |
52 case kRtpExtensionAudioLevel: | |
53 length = kAudioLevelLength; | |
54 break; | |
55 case kRtpExtensionAbsoluteSendTime: | |
56 length = kAbsoluteSendTimeLength; | |
57 break; | |
58 case kRtpExtensionVideoRotation: | |
59 length = kVideoRotationLength; | |
60 break; | |
61 case kRtpExtensionTransportSequenceNumber: | |
62 length = kTransportSequenceNumberLength; | |
63 break; | |
64 case kRtpExtensionPlayoutDelay: | |
65 length = kPlayoutDelayLength; | |
66 break; | |
67 default: | |
68 assert(false); | |
69 } | |
70 } | |
71 | |
72 const RTPExtensionType type; | |
73 uint8_t length; | |
74 }; | |
75 | |
76 class RtpHeaderExtensionMap { | 41 class RtpHeaderExtensionMap { |
77 public: | 42 public: |
78 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; | 43 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; |
79 static constexpr uint8_t kInvalidId = 0; | 44 static constexpr uint8_t kInvalidId = 0; |
| 45 |
80 RtpHeaderExtensionMap(); | 46 RtpHeaderExtensionMap(); |
81 ~RtpHeaderExtensionMap(); | 47 RtpHeaderExtensionMap(std::initializer_list<RtpExtension>); |
82 | 48 |
83 void Erase(); | 49 template <typename Extension> |
| 50 bool Register(uint8_t id) { |
| 51 return Register(id, Extension::kId, Extension::kValueSizeBytes, |
| 52 Extension::kUri); |
| 53 } |
| 54 bool RegisterByType(uint8_t id, RTPExtensionType type); |
| 55 bool RegisterByUri(uint8_t id, const std::string& uri); |
84 | 56 |
85 int32_t Register(RTPExtensionType type, uint8_t id); | 57 bool IsRegistered(RTPExtensionType type) const { |
| 58 return GetId(type) != kInvalidId; |
| 59 } |
| 60 // Return kInvalidType if not found. |
| 61 RTPExtensionType GetType(uint8_t id) const { |
| 62 RTC_DCHECK_GE(id, kMinId); |
| 63 RTC_DCHECK_LE(id, kMaxId); |
| 64 return types_[id]; |
| 65 } |
| 66 // Return kInvalidId if not found. |
| 67 uint8_t GetId(RTPExtensionType type) const { |
| 68 RTC_DCHECK_GT(type, kRtpExtensionNone); |
| 69 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); |
| 70 return ids_[type]; |
| 71 } |
86 | 72 |
87 int32_t Deregister(RTPExtensionType type); | |
88 | |
89 bool IsRegistered(RTPExtensionType type) const; | |
90 | |
91 int32_t GetType(uint8_t id, RTPExtensionType* type) const; | |
92 // Return kInvalidType if not found. | |
93 RTPExtensionType GetType(uint8_t id) const; | |
94 | |
95 int32_t GetId(const RTPExtensionType type, uint8_t* id) const; | |
96 // Return kInvalidId if not found. | |
97 uint8_t GetId(RTPExtensionType type) const; | |
98 size_t GetTotalLengthInBytes() const; | 73 size_t GetTotalLengthInBytes() const; |
99 | 74 |
100 void GetCopy(RtpHeaderExtensionMap* map) const; | 75 // TODO(danilchap): Remove use of the functions below. |
101 | 76 void Erase() { *this = RtpHeaderExtensionMap(); } |
102 int32_t Size() const; | 77 int32_t Register(RTPExtensionType type, uint8_t id) { |
| 78 return RegisterByType(id, type) ? 0 : -1; |
| 79 } |
| 80 int32_t Deregister(RTPExtensionType type); |
| 81 int32_t GetType(uint8_t id, RTPExtensionType* type) const { |
| 82 *type = GetType(id); |
| 83 return *type == kInvalidType ? -1 : 0; |
| 84 } |
| 85 void GetCopy(RtpHeaderExtensionMap* copy) const { *copy = *this; } |
103 | 86 |
104 private: | 87 private: |
105 std::map<uint8_t, HeaderExtension*> extensionMap_; | 88 static constexpr uint8_t kMinId = 1; |
| 89 static constexpr uint8_t kMaxId = 14; |
| 90 bool Register(uint8_t id, |
| 91 RTPExtensionType type, |
| 92 size_t value_size, |
| 93 const char* uri); |
| 94 |
| 95 size_t total_values_size_bytes_ = 0; |
| 96 RTPExtensionType types_[kMaxId + 1]; |
| 97 uint8_t ids_[kRtpExtensionNumberOfExtensions]; |
106 }; | 98 }; |
107 } // namespace webrtc | 99 } // namespace webrtc |
108 | 100 |
109 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ | 101 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ |
110 | 102 |
OLD | NEW |