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 <string> | 14 #include <string> |
15 | 15 |
16 #include "webrtc/base/array_view.h" | 16 #include "webrtc/base/array_view.h" |
17 #include "webrtc/base/basictypes.h" | 17 #include "webrtc/base/basictypes.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/config.h" | 19 #include "webrtc/config.h" |
20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
| 24 struct RtpExtensionSize { |
| 25 RTPExtensionType type; |
| 26 uint8_t value_size; |
| 27 }; |
| 28 |
24 class RtpHeaderExtensionMap { | 29 class RtpHeaderExtensionMap { |
25 public: | 30 public: |
26 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; | 31 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; |
27 static constexpr uint8_t kInvalidId = 0; | 32 static constexpr uint8_t kInvalidId = 0; |
28 | 33 |
29 RtpHeaderExtensionMap(); | 34 RtpHeaderExtensionMap(); |
30 explicit RtpHeaderExtensionMap(rtc::ArrayView<const RtpExtension> extensions); | 35 explicit RtpHeaderExtensionMap(rtc::ArrayView<const RtpExtension> extensions); |
31 | 36 |
32 template <typename Extension> | 37 template <typename Extension> |
33 bool Register(uint8_t id) { | 38 bool Register(uint8_t id) { |
34 return Register(id, Extension::kId, Extension::kValueSizeBytes, | 39 return Register(id, Extension::kId, Extension::kUri); |
35 Extension::kUri); | |
36 } | 40 } |
37 bool RegisterByType(uint8_t id, RTPExtensionType type); | 41 bool RegisterByType(uint8_t id, RTPExtensionType type); |
38 bool RegisterByUri(uint8_t id, const std::string& uri); | 42 bool RegisterByUri(uint8_t id, const std::string& uri); |
39 | 43 |
40 bool IsRegistered(RTPExtensionType type) const { | 44 bool IsRegistered(RTPExtensionType type) const { |
41 return GetId(type) != kInvalidId; | 45 return GetId(type) != kInvalidId; |
42 } | 46 } |
43 // Return kInvalidType if not found. | 47 // Return kInvalidType if not found. |
44 RTPExtensionType GetType(uint8_t id) const { | 48 RTPExtensionType GetType(uint8_t id) const { |
45 RTC_DCHECK_GE(id, kMinId); | 49 RTC_DCHECK_GE(id, kMinId); |
46 RTC_DCHECK_LE(id, kMaxId); | 50 RTC_DCHECK_LE(id, kMaxId); |
47 return types_[id]; | 51 return types_[id]; |
48 } | 52 } |
49 // Return kInvalidId if not found. | 53 // Return kInvalidId if not found. |
50 uint8_t GetId(RTPExtensionType type) const { | 54 uint8_t GetId(RTPExtensionType type) const { |
51 RTC_DCHECK_GT(type, kRtpExtensionNone); | 55 RTC_DCHECK_GT(type, kRtpExtensionNone); |
52 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); | 56 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); |
53 return ids_[type]; | 57 return ids_[type]; |
54 } | 58 } |
55 | 59 |
56 size_t GetTotalLengthInBytes() const; | 60 size_t GetTotalLengthInBytes( |
| 61 rtc::ArrayView<const RtpExtensionSize> extensions) const; |
57 | 62 |
58 // TODO(danilchap): Remove use of the functions below. | 63 // TODO(danilchap): Remove use of the functions below. |
59 int32_t Register(RTPExtensionType type, uint8_t id) { | 64 int32_t Register(RTPExtensionType type, uint8_t id) { |
60 return RegisterByType(id, type) ? 0 : -1; | 65 return RegisterByType(id, type) ? 0 : -1; |
61 } | 66 } |
62 int32_t Deregister(RTPExtensionType type); | 67 int32_t Deregister(RTPExtensionType type); |
63 | 68 |
64 private: | 69 private: |
65 static constexpr uint8_t kMinId = 1; | 70 static constexpr uint8_t kMinId = 1; |
66 static constexpr uint8_t kMaxId = 14; | 71 static constexpr uint8_t kMaxId = 14; |
67 bool Register(uint8_t id, | 72 bool Register(uint8_t id, RTPExtensionType type, const char* uri); |
68 RTPExtensionType type, | |
69 size_t value_size, | |
70 const char* uri); | |
71 | 73 |
72 size_t total_values_size_bytes_ = 0; | |
73 RTPExtensionType types_[kMaxId + 1]; | 74 RTPExtensionType types_[kMaxId + 1]; |
74 uint8_t ids_[kRtpExtensionNumberOfExtensions]; | 75 uint8_t ids_[kRtpExtensionNumberOfExtensions]; |
75 }; | 76 }; |
76 | 77 |
77 } // namespace webrtc | 78 } // namespace webrtc |
78 | 79 |
79 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ | 80 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ |
80 | |
OLD | NEW |