• 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_RTP_HEADER_EXTENSION_H_
12 #define WEBRTC_MODULES_RTP_RTCP_RTP_HEADER_EXTENSION_H_
13 
14 #include <map>
15 
16 #include "webrtc/modules/rtp_rtcp/interface/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 = 4;
26 const size_t kAbsoluteSendTimeLength = 4;
27 
28 struct HeaderExtension {
HeaderExtensionHeaderExtension29   HeaderExtension(RTPExtensionType extension_type)
30     : type(extension_type),
31       length(0) {
32     // TODO(solenberg): Create handler classes for header extensions so we can
33     // get rid of switches like these as well as handling code spread out all
34     // over.
35     switch (type) {
36       case kRtpExtensionTransmissionTimeOffset:
37         length = kTransmissionTimeOffsetLength;
38         break;
39       case kRtpExtensionAudioLevel:
40         length = kAudioLevelLength;
41         break;
42       case kRtpExtensionAbsoluteSendTime:
43         length = kAbsoluteSendTimeLength;
44         break;
45       default:
46         assert(false);
47     }
48   }
49 
50    const RTPExtensionType type;
51    uint8_t length;
52 };
53 
54 class RtpHeaderExtensionMap {
55  public:
56   RtpHeaderExtensionMap();
57   ~RtpHeaderExtensionMap();
58 
59   void Erase();
60 
61   int32_t Register(const RTPExtensionType type, const uint8_t id);
62 
63   int32_t Deregister(const RTPExtensionType type);
64 
65   bool IsRegistered(RTPExtensionType type) const;
66 
67   int32_t GetType(const uint8_t id, RTPExtensionType* type) const;
68 
69   int32_t GetId(const RTPExtensionType type, uint8_t* id) const;
70 
71   uint16_t GetTotalLengthInBytes() const;
72 
73   int32_t GetLengthUntilBlockStartInBytes(const RTPExtensionType type) const;
74 
75   void GetCopy(RtpHeaderExtensionMap* map) const;
76 
77   int32_t Size() const;
78 
79   RTPExtensionType First() const;
80 
81   RTPExtensionType Next(RTPExtensionType type) const;
82 
83  private:
84   std::map<uint8_t, HeaderExtension*> extensionMap_;
85 };
86 }
87 
88 #endif // WEBRTC_MODULES_RTP_RTCP_RTP_HEADER_EXTENSION_H_
89