Index: webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.cc b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..95b57cc57a00e8f49b1207b9d927aff89df6e0c5 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.cc |
@@ -0,0 +1,55 @@ |
+/* |
+ * 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. |
+ */ |
+ |
+#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions_manager.h" |
+ |
+#include "webrtc/base/checks.h" |
+#include "webrtc/base/logging.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
+ |
+namespace webrtc { |
+ |
+RtpHeaderExtensionsManager::RtpHeaderExtensionsManager() { |
+ for (ExtensionType& extension : id_to_type_) { |
+ extension = kInvalidType; |
+ } |
+} |
+ |
+bool RtpHeaderExtensionsManager::RegisterByName(const std::string& name, |
+ MediaType type, |
+ uint8_t id) { |
+ return TryRegister<AbsoluteSendTime>(name, type, id) || |
+ TryRegister<AudioLevel>(name, type, id) || |
+ TryRegister<TransmissionOffset>(name, type, id) || |
+ TryRegister<TransportSequenceNumber>(name, type, id) || |
+ TryRegister<VideoOrientation>(name, type, id); |
+} |
+ |
+bool RtpHeaderExtensionsManager::Register(ExtensionType type, uint8_t id) { |
+ RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
+ RTC_CHECK(kMinId <= id && id <= kMaxId); |
+ if (id_to_type_[id - 1] != kInvalidType) { |
+ LOG(LS_ERROR) << "Extension with id " << static_cast<int>(id) |
+ << " already registered"; |
+ return false; |
+ } |
+ id_to_type_[id - 1] = type; |
+ return true; |
+} |
+ |
+uint8_t RtpHeaderExtensionsManager::GetId(ExtensionType type) const { |
+ for (uint8_t i = kMinId; i <= kMaxId; ++i) { |
+ if (id_to_type_[i - 1] == type) { |
+ return i; |
+ } |
+ } |
+ return kInvalidId; |
+} |
+} // namespace webrtc |