Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_header_extension.h

Issue 2501893004: Simplify creating RtpHeaderExtensionMap in EventLogAnalyzer (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_header_extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <initializer_list>
15 #include <string> 14 #include <string>
16 15
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 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; 24 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
25 25
26 const size_t kRtpOneByteHeaderLength = 4; 26 const size_t kRtpOneByteHeaderLength = 4;
(...skipping 10 matching lines...) Expand all
37 const int kPlayoutDelayGranularityMs = 10; 37 const int kPlayoutDelayGranularityMs = 10;
38 // Maximum playout delay value in milliseconds. 38 // Maximum playout delay value in milliseconds.
39 const int kPlayoutDelayMaxMs = 40950; 39 const int kPlayoutDelayMaxMs = 40950;
40 40
41 class RtpHeaderExtensionMap { 41 class RtpHeaderExtensionMap {
42 public: 42 public:
43 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; 43 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
44 static constexpr uint8_t kInvalidId = 0; 44 static constexpr uint8_t kInvalidId = 0;
45 45
46 RtpHeaderExtensionMap(); 46 RtpHeaderExtensionMap();
47 RtpHeaderExtensionMap(std::initializer_list<RtpExtension>); 47 explicit RtpHeaderExtensionMap(rtc::ArrayView<const RtpExtension> extensions);
48 48
49 template <typename Extension> 49 template <typename Extension>
50 bool Register(uint8_t id) { 50 bool Register(uint8_t id) {
51 return Register(id, Extension::kId, Extension::kValueSizeBytes, 51 return Register(id, Extension::kId, Extension::kValueSizeBytes,
52 Extension::kUri); 52 Extension::kUri);
53 } 53 }
54 bool RegisterByType(uint8_t id, RTPExtensionType type); 54 bool RegisterByType(uint8_t id, RTPExtensionType type);
55 bool RegisterByUri(uint8_t id, const std::string& uri); 55 bool RegisterByUri(uint8_t id, const std::string& uri);
56 56
57 bool IsRegistered(RTPExtensionType type) const { 57 bool IsRegistered(RTPExtensionType type) const {
58 return GetId(type) != kInvalidId; 58 return GetId(type) != kInvalidId;
59 } 59 }
60 // Return kInvalidType if not found. 60 // Return kInvalidType if not found.
61 RTPExtensionType GetType(uint8_t id) const { 61 RTPExtensionType GetType(uint8_t id) const {
62 RTC_DCHECK_GE(id, kMinId); 62 RTC_DCHECK_GE(id, kMinId);
63 RTC_DCHECK_LE(id, kMaxId); 63 RTC_DCHECK_LE(id, kMaxId);
64 return types_[id]; 64 return types_[id];
65 } 65 }
66 // Return kInvalidId if not found. 66 // Return kInvalidId if not found.
67 uint8_t GetId(RTPExtensionType type) const { 67 uint8_t GetId(RTPExtensionType type) const {
68 RTC_DCHECK_GT(type, kRtpExtensionNone); 68 RTC_DCHECK_GT(type, kRtpExtensionNone);
69 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); 69 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
70 return ids_[type]; 70 return ids_[type];
71 } 71 }
72 72
73 size_t GetTotalLengthInBytes() const; 73 size_t GetTotalLengthInBytes() const;
74 74
75 // TODO(danilchap): Remove use of the functions below. 75 // TODO(danilchap): Remove use of the functions below.
76 void Erase() { *this = RtpHeaderExtensionMap(); }
77 int32_t Register(RTPExtensionType type, uint8_t id) { 76 int32_t Register(RTPExtensionType type, uint8_t id) {
78 return RegisterByType(id, type) ? 0 : -1; 77 return RegisterByType(id, type) ? 0 : -1;
79 } 78 }
80 int32_t Deregister(RTPExtensionType type); 79 int32_t Deregister(RTPExtensionType type);
81 int32_t GetType(uint8_t id, RTPExtensionType* type) const { 80 int32_t GetType(uint8_t id, RTPExtensionType* type) const {
82 *type = GetType(id); 81 *type = GetType(id);
83 return *type == kInvalidType ? -1 : 0; 82 return *type == kInvalidType ? -1 : 0;
84 } 83 }
85 void GetCopy(RtpHeaderExtensionMap* copy) const { *copy = *this; } 84 void GetCopy(RtpHeaderExtensionMap* copy) const { *copy = *this; }
86 85
87 private: 86 private:
88 static constexpr uint8_t kMinId = 1; 87 static constexpr uint8_t kMinId = 1;
89 static constexpr uint8_t kMaxId = 14; 88 static constexpr uint8_t kMaxId = 14;
90 bool Register(uint8_t id, 89 bool Register(uint8_t id,
91 RTPExtensionType type, 90 RTPExtensionType type,
92 size_t value_size, 91 size_t value_size,
93 const char* uri); 92 const char* uri);
94 93
95 size_t total_values_size_bytes_ = 0; 94 size_t total_values_size_bytes_ = 0;
96 RTPExtensionType types_[kMaxId + 1]; 95 RTPExtensionType types_[kMaxId + 1];
97 uint8_t ids_[kRtpExtensionNumberOfExtensions]; 96 uint8_t ids_[kRtpExtensionNumberOfExtensions];
98 }; 97 };
98
99 } // namespace webrtc 99 } // namespace webrtc
100 100
101 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ 101 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
102 102
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_header_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698