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

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

Issue 2452293004: Simplify and extend RtpHeaderExtensionMap (Closed)
Patch Set: make kExtensions constexpr 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
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 <map> 14 #include <initializer_list>
15 15 #include <string>
16 #include "webrtc/base/basictypes.h"
17 #include "webrtc/config.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/typedefs.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
21 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; 22 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
22 23
23 const size_t kRtpOneByteHeaderLength = 4; 24 const size_t kRtpOneByteHeaderLength = 4;
24 const size_t kTransmissionTimeOffsetLength = 4; 25 const size_t kTransmissionTimeOffsetLength = 4;
25 const size_t kAudioLevelLength = 2; 26 const size_t kAudioLevelLength = 2;
26 const size_t kAbsoluteSendTimeLength = 4; 27 const size_t kAbsoluteSendTimeLength = 4;
27 const size_t kVideoRotationLength = 2; 28 const size_t kVideoRotationLength = 2;
28 const size_t kTransportSequenceNumberLength = 3; 29 const size_t kTransportSequenceNumberLength = 3;
29 const size_t kPlayoutDelayLength = 4; 30 const size_t kPlayoutDelayLength = 4;
30 31
31 // Playout delay in milliseconds. A playout delay limit (min or max) 32 // Playout delay in milliseconds. A playout delay limit (min or max)
32 // has 12 bits allocated. This allows a range of 0-4095 values which translates 33 // has 12 bits allocated. This allows a range of 0-4095 values which translates
33 // to a range of 0-40950 in milliseconds. 34 // to a range of 0-40950 in milliseconds.
34 const int kPlayoutDelayGranularityMs = 10; 35 const int kPlayoutDelayGranularityMs = 10;
35 // Maximum playout delay value in milliseconds. 36 // Maximum playout delay value in milliseconds.
36 const int kPlayoutDelayMaxMs = 40950; 37 const int kPlayoutDelayMaxMs = 40950;
37 38
38 struct HeaderExtension {
39 explicit HeaderExtension(RTPExtensionType extension_type)
40 : type(extension_type), length(0) {
41 Init();
42 }
43
44 void Init() {
45 // TODO(solenberg): Create handler classes for header extensions so we can
46 // get rid of switches like these as well as handling code spread out all
47 // over.
48 switch (type) {
49 case kRtpExtensionTransmissionTimeOffset:
50 length = kTransmissionTimeOffsetLength;
51 break;
52 case kRtpExtensionAudioLevel:
53 length = kAudioLevelLength;
54 break;
55 case kRtpExtensionAbsoluteSendTime:
56 length = kAbsoluteSendTimeLength;
57 break;
58 case kRtpExtensionVideoRotation:
59 length = kVideoRotationLength;
60 break;
61 case kRtpExtensionTransportSequenceNumber:
62 length = kTransportSequenceNumberLength;
63 break;
64 case kRtpExtensionPlayoutDelay:
65 length = kPlayoutDelayLength;
66 break;
67 default:
68 assert(false);
69 }
70 }
71
72 const RTPExtensionType type;
73 uint8_t length;
74 };
75
76 class RtpHeaderExtensionMap { 39 class RtpHeaderExtensionMap {
77 public: 40 public:
78 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; 41 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
79 static constexpr uint8_t kInvalidId = 0; 42 static constexpr uint8_t kInvalidId = 0;
43
80 RtpHeaderExtensionMap(); 44 RtpHeaderExtensionMap();
81 ~RtpHeaderExtensionMap(); 45 RtpHeaderExtensionMap(std::initializer_list<RtpExtension>);
82 46
83 void Erase(); 47 template <typename Extension>
84 48 bool Register(uint8_t id) {
85 int32_t Register(RTPExtensionType type, uint8_t id); 49 return Register(id, Extension::kId, Extension::kValueSizeBytes,
86 50 Extension::kUri);
87 int32_t Deregister(RTPExtensionType type); 51 }
52 bool RegisterByType(uint8_t id, RTPExtensionType type);
53 bool RegisterByUri(uint8_t id, const std::string& uri);
88 54
89 bool IsRegistered(RTPExtensionType type) const; 55 bool IsRegistered(RTPExtensionType type) const;
56 // Return kInvalidType if not found.
57 RTPExtensionType GetType(uint8_t id) const { return types_[id]; }
sprang_webrtc 2016/11/08 16:13:37 Maybe we should dcheck id. Also, could we return a
danilchap 2016/11/08 17:13:41 Done.
sprang_webrtc 2016/11/08 19:19:57 Fair enough. Thanks!
58 // Return kInvalidId if not found.
59 uint8_t GetId(RTPExtensionType type) const { return ids_[type]; }
sprang_webrtc 2016/11/08 16:13:37 dito
90 60
91 int32_t GetType(uint8_t id, RTPExtensionType* type) const;
92 // Return kInvalidType if not found.
93 RTPExtensionType GetType(uint8_t id) const;
94
95 int32_t GetId(const RTPExtensionType type, uint8_t* id) const;
96 // Return kInvalidId if not found.
97 uint8_t GetId(RTPExtensionType type) const;
98 size_t GetTotalLengthInBytes() const; 61 size_t GetTotalLengthInBytes() const;
99 62
100 void GetCopy(RtpHeaderExtensionMap* map) const; 63 // TODO(danilchap): Remove use of the functions below.
101 64 void Erase() { *this = RtpHeaderExtensionMap(); }
102 int32_t Size() const; 65 int32_t Register(RTPExtensionType type, uint8_t id) {
66 return RegisterByType(id, type) ? 0 : -1;
67 }
68 int32_t Deregister(RTPExtensionType type);
69 int32_t GetType(uint8_t id, RTPExtensionType* type) const {
70 *type = GetType(id);
71 return *type == kInvalidType ? -1 : 0;
72 }
73 void GetCopy(RtpHeaderExtensionMap* copy) const { *copy = *this; }
103 74
104 private: 75 private:
105 std::map<uint8_t, HeaderExtension*> extensionMap_; 76 static constexpr uint8_t kMinId = 1;
77 static constexpr uint8_t kMaxId = 14;
78 bool Register(uint8_t id,
79 RTPExtensionType type,
80 size_t value_size,
81 const char* uri);
82
83 size_t total_values_size_bytes_ = 0;
84 RTPExtensionType types_[kMaxId + 1];
85 uint8_t ids_[kRtpExtensionNumberOfExtensions];
106 }; 86 };
107 } // namespace webrtc 87 } // namespace webrtc
108 88
109 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ 89 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
110 90
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698