OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2013 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_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | |
12 #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | |
13 | |
14 #pragma message("WARNING: rtp_rtcp/interface is DEPRECATED; use include dir.") | |
15 | |
16 #include "webrtc/base/scoped_ptr.h" | |
17 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" | |
18 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | |
19 | |
20 namespace webrtc { | |
21 | |
22 // This strategy deals with the audio/video-specific aspects | |
23 // of payload handling. | |
24 class RTPPayloadStrategy { | |
25 public: | |
26 virtual ~RTPPayloadStrategy() {} | |
27 | |
28 virtual bool CodecsMustBeUnique() const = 0; | |
29 | |
30 virtual bool PayloadIsCompatible(const RtpUtility::Payload& payload, | |
31 const uint32_t frequency, | |
32 const uint8_t channels, | |
33 const uint32_t rate) const = 0; | |
34 | |
35 virtual void UpdatePayloadRate(RtpUtility::Payload* payload, | |
36 const uint32_t rate) const = 0; | |
37 | |
38 virtual RtpUtility::Payload* CreatePayloadType( | |
39 const char payloadName[RTP_PAYLOAD_NAME_SIZE], | |
40 const int8_t payloadType, | |
41 const uint32_t frequency, | |
42 const uint8_t channels, | |
43 const uint32_t rate) const = 0; | |
44 | |
45 virtual int GetPayloadTypeFrequency( | |
46 const RtpUtility::Payload& payload) const = 0; | |
47 | |
48 static RTPPayloadStrategy* CreateStrategy(const bool handling_audio); | |
49 | |
50 protected: | |
51 RTPPayloadStrategy() {} | |
52 }; | |
53 | |
54 class RTPPayloadRegistry { | |
55 public: | |
56 // The registry takes ownership of the strategy. | |
57 RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy); | |
58 ~RTPPayloadRegistry(); | |
59 | |
60 int32_t RegisterReceivePayload( | |
61 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | |
62 const int8_t payload_type, | |
63 const uint32_t frequency, | |
64 const uint8_t channels, | |
65 const uint32_t rate, | |
66 bool* created_new_payload_type); | |
67 | |
68 int32_t DeRegisterReceivePayload( | |
69 const int8_t payload_type); | |
70 | |
71 int32_t ReceivePayloadType( | |
72 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | |
73 const uint32_t frequency, | |
74 const uint8_t channels, | |
75 const uint32_t rate, | |
76 int8_t* payload_type) const; | |
77 | |
78 bool RtxEnabled() const; | |
79 | |
80 void SetRtxSsrc(uint32_t ssrc); | |
81 | |
82 bool GetRtxSsrc(uint32_t* ssrc) const; | |
83 | |
84 void SetRtxPayloadType(int payload_type, int associated_payload_type); | |
85 | |
86 bool IsRtx(const RTPHeader& header) const; | |
87 | |
88 // DEPRECATED. Use RestoreOriginalPacket below that takes a uint8_t* | |
89 // restored_packet, instead of a uint8_t**. | |
90 // TODO(noahric): Remove this when all callers have been updated. | |
91 bool RestoreOriginalPacket(uint8_t** restored_packet, | |
92 const uint8_t* packet, | |
93 size_t* packet_length, | |
94 uint32_t original_ssrc, | |
95 const RTPHeader& header) const; | |
96 | |
97 bool RestoreOriginalPacket(uint8_t* restored_packet, | |
98 const uint8_t* packet, | |
99 size_t* packet_length, | |
100 uint32_t original_ssrc, | |
101 const RTPHeader& header) const; | |
102 | |
103 bool IsRed(const RTPHeader& header) const; | |
104 | |
105 // Returns true if the media of this RTP packet is encapsulated within an | |
106 // extra header, such as RTX or RED. | |
107 bool IsEncapsulated(const RTPHeader& header) const; | |
108 | |
109 bool GetPayloadSpecifics(uint8_t payload_type, PayloadUnion* payload) const; | |
110 | |
111 int GetPayloadTypeFrequency(uint8_t payload_type) const; | |
112 | |
113 bool PayloadTypeToPayload(const uint8_t payload_type, | |
114 RtpUtility::Payload*& payload) const; | |
115 | |
116 void ResetLastReceivedPayloadTypes() { | |
117 CriticalSectionScoped cs(crit_sect_.get()); | |
118 last_received_payload_type_ = -1; | |
119 last_received_media_payload_type_ = -1; | |
120 } | |
121 | |
122 // This sets the payload type of the packets being received from the network | |
123 // on the media SSRC. For instance if packets are encapsulated with RED, this | |
124 // payload type will be the RED payload type. | |
125 void SetIncomingPayloadType(const RTPHeader& header); | |
126 | |
127 // Returns true if the new media payload type has not changed. | |
128 bool ReportMediaPayloadType(uint8_t media_payload_type); | |
129 | |
130 int8_t red_payload_type() const { | |
131 CriticalSectionScoped cs(crit_sect_.get()); | |
132 return red_payload_type_; | |
133 } | |
134 int8_t ulpfec_payload_type() const { | |
135 CriticalSectionScoped cs(crit_sect_.get()); | |
136 return ulpfec_payload_type_; | |
137 } | |
138 int8_t last_received_payload_type() const { | |
139 CriticalSectionScoped cs(crit_sect_.get()); | |
140 return last_received_payload_type_; | |
141 } | |
142 void set_last_received_payload_type(int8_t last_received_payload_type) { | |
143 CriticalSectionScoped cs(crit_sect_.get()); | |
144 last_received_payload_type_ = last_received_payload_type; | |
145 } | |
146 | |
147 int8_t last_received_media_payload_type() const { | |
148 CriticalSectionScoped cs(crit_sect_.get()); | |
149 return last_received_media_payload_type_; | |
150 }; | |
151 | |
152 bool use_rtx_payload_mapping_on_restore() const { | |
153 CriticalSectionScoped cs(crit_sect_.get()); | |
154 return use_rtx_payload_mapping_on_restore_; | |
155 } | |
156 | |
157 void set_use_rtx_payload_mapping_on_restore(bool val) { | |
158 CriticalSectionScoped cs(crit_sect_.get()); | |
159 use_rtx_payload_mapping_on_restore_ = val; | |
160 } | |
161 | |
162 private: | |
163 // Prunes the payload type map of the specific payload type, if it exists. | |
164 void DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType( | |
165 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | |
166 const size_t payload_name_length, | |
167 const uint32_t frequency, | |
168 const uint8_t channels, | |
169 const uint32_t rate); | |
170 | |
171 bool IsRtxInternal(const RTPHeader& header) const; | |
172 | |
173 rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; | |
174 RtpUtility::PayloadTypeMap payload_type_map_; | |
175 rtc::scoped_ptr<RTPPayloadStrategy> rtp_payload_strategy_; | |
176 int8_t red_payload_type_; | |
177 int8_t ulpfec_payload_type_; | |
178 int8_t incoming_payload_type_; | |
179 int8_t last_received_payload_type_; | |
180 int8_t last_received_media_payload_type_; | |
181 bool rtx_; | |
182 // TODO(changbin): Remove rtx_payload_type_ once interop with old clients that | |
183 // only understand one RTX PT is no longer needed. | |
184 int rtx_payload_type_; | |
185 // Mapping rtx_payload_type_map_[rtx] = associated. | |
186 std::map<int, int> rtx_payload_type_map_; | |
187 // When true, use rtx_payload_type_map_ when restoring RTX packets to get the | |
188 // correct payload type. | |
189 bool use_rtx_payload_mapping_on_restore_; | |
190 uint32_t ssrc_rtx_; | |
191 }; | |
192 | |
193 } // namespace webrtc | |
194 | |
195 #endif // WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_PAYLOAD_REGISTRY_H_ | |
OLD | NEW |