Index: webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.h |
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.h b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..77d9be05f1e480c5f278c509740bdca92a4f0a00 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.h |
@@ -0,0 +1,77 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_MANAGER_H_ |
+#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_MANAGER_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "webrtc/base/basictypes.h" |
+#include "webrtc/base/checks.h" |
+#include "webrtc/base/constructormagic.h" |
+#include "webrtc/base/thread_checker.h" |
+#include "webrtc/call.h" |
+ |
+namespace webrtc { |
+ |
+class RtpHeaderExtensionsManager { |
+ public: |
+ using ExtensionType = const char*; |
+ |
+ static constexpr uint8_t kInvalidId = 0; |
+ static constexpr uint8_t kMinId = 1; |
+ static constexpr uint8_t kMaxId = 14; |
+ static constexpr ExtensionType kInvalidType = nullptr; |
+ |
+ RtpHeaderExtensionsManager(); |
+ |
+ // Rtp header extensions. |
+ template <typename Extension> |
+ bool Register(uint8_t id) { |
+ return Register(Extension::kId, id); |
+ } |
+ bool RegisterByName(const std::string& name, MediaType type, uint8_t id); |
+ |
+ // Return kInvalidId if type is not found. |
+ uint8_t GetId(ExtensionType type) const; |
+ template <typename Extension> |
+ bool IsRegistered() const { |
+ return IsRegistered(Extension::kId); |
+ } |
+ bool IsRegistered(ExtensionType type) const { |
+ return GetId(type) != kInvalidId; |
+ } |
+ // Return kInvalidExtension if no extension registered for given id. |
+ ExtensionType GetType(uint8_t id) const { |
+ RTC_DCHECK(kMinId <= id && id <= kMaxId); |
+ return id_to_type_[id - 1]; |
+ } |
+ |
+ private: |
+ template <typename Extesnsion> |
+ bool TryRegister(const std::string& name, MediaType type, uint8_t id); |
+ bool Register(ExtensionType type, uint8_t id); |
+ |
+ rtc::ThreadChecker configuration_thread_checker_; |
+ ExtensionType id_to_type_[kMaxId - kMinId + 1]; |
+ RTC_DISALLOW_COPY_AND_ASSIGN(RtpHeaderExtensionsManager); |
+}; |
+ |
+template <typename Extension> |
+bool RtpHeaderExtensionsManager::TryRegister(const std::string& name, |
+ MediaType type, |
+ uint8_t id) { |
+ return Extension::IsSupportedFor(type) && name == Extension::kId && |
+ Register<Extension>(id); |
+} |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_MANAGER_H_ |