• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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 
11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
13 
14 #include <map>
15 
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/typedefs.h"
18 
19 namespace webrtc {
20 
21 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
22 
23 const size_t kRtpOneByteHeaderLength = 4;
24 const size_t kTransmissionTimeOffsetLength = 4;
25 const size_t kAudioLevelLength = 2;
26 const size_t kAbsoluteSendTimeLength = 4;
27 const size_t kVideoRotationLength = 2;
28 const size_t kTransportSequenceNumberLength = 3;
29 
30 struct HeaderExtension {
HeaderExtensionHeaderExtension31   explicit HeaderExtension(RTPExtensionType extension_type)
32       : type(extension_type), length(0), active(true) {
33     Init();
34   }
35 
HeaderExtensionHeaderExtension36   HeaderExtension(RTPExtensionType extension_type, bool active)
37       : type(extension_type), length(0), active(active) {
38     Init();
39   }
40 
InitHeaderExtension41   void Init() {
42     // TODO(solenberg): Create handler classes for header extensions so we can
43     // get rid of switches like these as well as handling code spread out all
44     // over.
45     switch (type) {
46       case kRtpExtensionTransmissionTimeOffset:
47         length = kTransmissionTimeOffsetLength;
48         break;
49       case kRtpExtensionAudioLevel:
50         length = kAudioLevelLength;
51         break;
52       case kRtpExtensionAbsoluteSendTime:
53         length = kAbsoluteSendTimeLength;
54         break;
55       case kRtpExtensionVideoRotation:
56         length = kVideoRotationLength;
57         break;
58       case kRtpExtensionTransportSequenceNumber:
59         length = kTransportSequenceNumberLength;
60         break;
61       default:
62         assert(false);
63     }
64   }
65 
66   const RTPExtensionType type;
67   uint8_t length;
68   bool active;
69 };
70 
71 class RtpHeaderExtensionMap {
72  public:
73   RtpHeaderExtensionMap();
74   ~RtpHeaderExtensionMap();
75 
76   void Erase();
77 
78   int32_t Register(const RTPExtensionType type, const uint8_t id);
79 
80   // Active is a concept for a registered rtp header extension which doesn't
81   // take effect yet until being activated. Inactive RTP header extensions do
82   // not take effect and should not be included in size calculations until they
83   // are activated.
84   int32_t RegisterInactive(const RTPExtensionType type, const uint8_t id);
85   bool SetActive(const RTPExtensionType type, bool active);
86 
87   int32_t Deregister(const RTPExtensionType type);
88 
89   bool IsRegistered(RTPExtensionType type) const;
90 
91   int32_t GetType(const uint8_t id, RTPExtensionType* type) const;
92 
93   int32_t GetId(const RTPExtensionType type, uint8_t* id) const;
94 
95   //
96   // Methods below ignore any inactive rtp header extensions.
97   //
98 
99   size_t GetTotalLengthInBytes() const;
100 
101   int32_t GetLengthUntilBlockStartInBytes(const RTPExtensionType type) const;
102 
103   void GetCopy(RtpHeaderExtensionMap* map) const;
104 
105   int32_t Size() const;
106 
107   RTPExtensionType First() const;
108 
109   RTPExtensionType Next(RTPExtensionType type) const;
110 
111  private:
112   int32_t Register(const RTPExtensionType type, const uint8_t id, bool active);
113   std::map<uint8_t, HeaderExtension*> extensionMap_;
114 };
115 }  // namespace webrtc
116 
117 #endif  // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
118 
119