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

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

Issue 2484863007: Revert of Simplify and extend RtpHeaderExtensionMap (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> 14 #include <map>
15 #include <string>
16 15
17 #include "webrtc/base/basictypes.h"
18 #include "webrtc/base/checks.h"
19 #include "webrtc/config.h"
20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/typedefs.h"
21 18
22 namespace webrtc { 19 namespace webrtc {
23 20
24 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; 21 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
25 22
26 const size_t kRtpOneByteHeaderLength = 4; 23 const size_t kRtpOneByteHeaderLength = 4;
27 const size_t kTransmissionTimeOffsetLength = 4; 24 const size_t kTransmissionTimeOffsetLength = 4;
28 const size_t kAudioLevelLength = 2; 25 const size_t kAudioLevelLength = 2;
29 const size_t kAbsoluteSendTimeLength = 4; 26 const size_t kAbsoluteSendTimeLength = 4;
30 const size_t kVideoRotationLength = 2; 27 const size_t kVideoRotationLength = 2;
31 const size_t kTransportSequenceNumberLength = 3; 28 const size_t kTransportSequenceNumberLength = 3;
32 const size_t kPlayoutDelayLength = 4; 29 const size_t kPlayoutDelayLength = 4;
33 30
34 // Playout delay in milliseconds. A playout delay limit (min or max) 31 // Playout delay in milliseconds. A playout delay limit (min or max)
35 // has 12 bits allocated. This allows a range of 0-4095 values which translates 32 // has 12 bits allocated. This allows a range of 0-4095 values which translates
36 // to a range of 0-40950 in milliseconds. 33 // to a range of 0-40950 in milliseconds.
37 const int kPlayoutDelayGranularityMs = 10; 34 const int kPlayoutDelayGranularityMs = 10;
38 // Maximum playout delay value in milliseconds. 35 // Maximum playout delay value in milliseconds.
39 const int kPlayoutDelayMaxMs = 40950; 36 const int kPlayoutDelayMaxMs = 40950;
40 37
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
41 class RtpHeaderExtensionMap { 76 class RtpHeaderExtensionMap {
42 public: 77 public:
43 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; 78 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
44 static constexpr uint8_t kInvalidId = 0; 79 static constexpr uint8_t kInvalidId = 0;
80 RtpHeaderExtensionMap();
81 ~RtpHeaderExtensionMap();
45 82
46 RtpHeaderExtensionMap(); 83 void Erase();
47 RtpHeaderExtensionMap(std::initializer_list<RtpExtension>);
48 84
49 template <typename Extension> 85 int32_t Register(RTPExtensionType type, uint8_t id);
50 bool Register(uint8_t id) {
51 return Register(id, Extension::kId, Extension::kValueSizeBytes,
52 Extension::kUri);
53 }
54 bool RegisterByType(uint8_t id, RTPExtensionType type);
55 bool RegisterByUri(uint8_t id, const std::string& uri);
56 86
57 bool IsRegistered(RTPExtensionType type) const { 87 int32_t Deregister(RTPExtensionType type);
58 return GetId(type) != kInvalidId; 88
59 } 89 bool IsRegistered(RTPExtensionType type) const;
90
91 int32_t GetType(uint8_t id, RTPExtensionType* type) const;
60 // Return kInvalidType if not found. 92 // Return kInvalidType if not found.
61 RTPExtensionType GetType(uint8_t id) const { 93 RTPExtensionType GetType(uint8_t id) const;
62 RTC_DCHECK_GE(id, kMinId); 94
63 RTC_DCHECK_LE(id, kMaxId); 95 int32_t GetId(const RTPExtensionType type, uint8_t* id) const;
64 return types_[id];
65 }
66 // Return kInvalidId if not found. 96 // Return kInvalidId if not found.
67 uint8_t GetId(RTPExtensionType type) const { 97 uint8_t GetId(RTPExtensionType type) const;
68 RTC_DCHECK_GT(type, kRtpExtensionNone);
69 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
70 return ids_[type];
71 }
72
73 size_t GetTotalLengthInBytes() const; 98 size_t GetTotalLengthInBytes() const;
74 99
75 // TODO(danilchap): Remove use of the functions below. 100 void GetCopy(RtpHeaderExtensionMap* map) const;
76 void Erase() { *this = RtpHeaderExtensionMap(); } 101
77 int32_t Register(RTPExtensionType type, uint8_t id) { 102 int32_t Size() const;
78 return RegisterByType(id, type) ? 0 : -1;
79 }
80 int32_t Deregister(RTPExtensionType type);
81 int32_t GetType(uint8_t id, RTPExtensionType* type) const {
82 *type = GetType(id);
83 return *type == kInvalidType ? -1 : 0;
84 }
85 void GetCopy(RtpHeaderExtensionMap* copy) const { *copy = *this; }
86 103
87 private: 104 private:
88 static constexpr uint8_t kMinId = 1; 105 std::map<uint8_t, HeaderExtension*> extensionMap_;
89 static constexpr uint8_t kMaxId = 14;
90 bool Register(uint8_t id,
91 RTPExtensionType type,
92 size_t value_size,
93 const char* uri);
94
95 size_t total_values_size_bytes_ = 0;
96 RTPExtensionType types_[kMaxId + 1];
97 uint8_t ids_[kRtpExtensionNumberOfExtensions];
98 }; 106 };
99 } // namespace webrtc 107 } // namespace webrtc
100 108
101 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_ 109 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
102 110
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