OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_MANAGER_H_ |
| 11 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_MANAGER_H_ |
| 12 |
| 13 #include <memory> |
| 14 #include <string> |
| 15 |
| 16 #include "webrtc/base/basictypes.h" |
| 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/thread_checker.h" |
| 20 #include "webrtc/call.h" |
| 21 |
| 22 namespace webrtc { |
| 23 |
| 24 class RtpHeaderExtensionsManager { |
| 25 public: |
| 26 using ExtensionType = const char*; |
| 27 |
| 28 static constexpr uint8_t kInvalidId = 0; |
| 29 static constexpr uint8_t kMinId = 1; |
| 30 static constexpr uint8_t kMaxId = 14; |
| 31 static constexpr ExtensionType kInvalidType = nullptr; |
| 32 |
| 33 RtpHeaderExtensionsManager(); |
| 34 |
| 35 // Rtp header extensions. |
| 36 template <typename Extension> |
| 37 bool Register(uint8_t id) { |
| 38 return Register(Extension::kId, id); |
| 39 } |
| 40 bool RegisterByName(const std::string& name, MediaType type, uint8_t id); |
| 41 |
| 42 // Return kInvalidId if type is not found. |
| 43 uint8_t GetId(ExtensionType type) const; |
| 44 template <typename Extension> |
| 45 bool IsRegistered() const { |
| 46 return IsRegistered(Extension::kId); |
| 47 } |
| 48 bool IsRegistered(ExtensionType type) const { |
| 49 return GetId(type) != kInvalidId; |
| 50 } |
| 51 // Return kInvalidExtension if no extension registered for given id. |
| 52 ExtensionType GetType(uint8_t id) const { |
| 53 RTC_DCHECK(kMinId <= id && id <= kMaxId); |
| 54 return id_to_type_[id - 1]; |
| 55 } |
| 56 |
| 57 private: |
| 58 template <typename Extesnsion> |
| 59 bool TryRegister(const std::string& name, MediaType type, uint8_t id); |
| 60 bool Register(ExtensionType type, uint8_t id); |
| 61 |
| 62 rtc::ThreadChecker configuration_thread_checker_; |
| 63 ExtensionType id_to_type_[kMaxId - kMinId + 1]; |
| 64 RTC_DISALLOW_COPY_AND_ASSIGN(RtpHeaderExtensionsManager); |
| 65 }; |
| 66 |
| 67 template <typename Extension> |
| 68 bool RtpHeaderExtensionsManager::TryRegister(const std::string& name, |
| 69 MediaType type, |
| 70 uint8_t id) { |
| 71 return Extension::IsSupportedFor(type) && name == Extension::kId && |
| 72 Register<Extension>(id); |
| 73 } |
| 74 |
| 75 } // namespace webrtc |
| 76 |
| 77 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_MANAGER_H_ |
OLD | NEW |