OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 11 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
12 | 12 |
13 #include "webrtc/base/logging.h" | 13 #include "webrtc/base/logging.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 RTPPayloadRegistry::RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy) | 18 RTPPayloadRegistry::RTPPayloadRegistry(RTPPayloadStrategy* rtp_payload_strategy) |
19 : rtp_payload_strategy_(rtp_payload_strategy), | 19 : rtp_payload_strategy_(rtp_payload_strategy), |
20 red_payload_type_(-1), | 20 red_payload_type_(-1), |
21 ulpfec_payload_type_(-1), | 21 ulpfec_payload_type_(-1), |
22 incoming_payload_type_(-1), | 22 incoming_payload_type_(-1), |
23 last_received_payload_type_(-1), | 23 last_received_payload_type_(-1), |
24 last_received_media_payload_type_(-1), | 24 last_received_media_payload_type_(-1), |
25 rtx_(false), | 25 rtx_(false), |
26 rtx_payload_type_(-1), | |
27 ssrc_rtx_(0) {} | 26 ssrc_rtx_(0) {} |
28 | 27 |
29 RTPPayloadRegistry::~RTPPayloadRegistry() { | 28 RTPPayloadRegistry::~RTPPayloadRegistry() { |
30 while (!payload_type_map_.empty()) { | 29 while (!payload_type_map_.empty()) { |
31 RtpUtility::PayloadTypeMap::iterator it = payload_type_map_.begin(); | 30 RtpUtility::PayloadTypeMap::iterator it = payload_type_map_.begin(); |
32 delete it->second; | 31 delete it->second; |
33 payload_type_map_.erase(it); | 32 payload_type_map_.erase(it); |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 } | 226 } |
228 | 227 |
229 bool RTPPayloadRegistry::IsRtxInternal(const RTPHeader& header) const { | 228 bool RTPPayloadRegistry::IsRtxInternal(const RTPHeader& header) const { |
230 return rtx_ && ssrc_rtx_ == header.ssrc; | 229 return rtx_ && ssrc_rtx_ == header.ssrc; |
231 } | 230 } |
232 | 231 |
233 bool RTPPayloadRegistry::RestoreOriginalPacket(uint8_t* restored_packet, | 232 bool RTPPayloadRegistry::RestoreOriginalPacket(uint8_t* restored_packet, |
234 const uint8_t* packet, | 233 const uint8_t* packet, |
235 size_t* packet_length, | 234 size_t* packet_length, |
236 uint32_t original_ssrc, | 235 uint32_t original_ssrc, |
237 const RTPHeader& header) const { | 236 const RTPHeader& header) { |
238 if (kRtxHeaderSize + header.headerLength + header.paddingLength > | 237 if (kRtxHeaderSize + header.headerLength + header.paddingLength > |
239 *packet_length) { | 238 *packet_length) { |
240 return false; | 239 return false; |
241 } | 240 } |
242 const uint8_t* rtx_header = packet + header.headerLength; | 241 const uint8_t* rtx_header = packet + header.headerLength; |
243 uint16_t original_sequence_number = (rtx_header[0] << 8) + rtx_header[1]; | 242 uint16_t original_sequence_number = (rtx_header[0] << 8) + rtx_header[1]; |
244 | 243 |
245 // Copy the packet into the restored packet, except for the RTX header. | 244 // Copy the packet into the restored packet, except for the RTX header. |
246 memcpy(restored_packet, packet, header.headerLength); | 245 memcpy(restored_packet, packet, header.headerLength); |
247 memcpy(restored_packet + header.headerLength, | 246 memcpy(restored_packet + header.headerLength, |
248 packet + header.headerLength + kRtxHeaderSize, | 247 packet + header.headerLength + kRtxHeaderSize, |
249 *packet_length - header.headerLength - kRtxHeaderSize); | 248 *packet_length - header.headerLength - kRtxHeaderSize); |
250 *packet_length -= kRtxHeaderSize; | 249 *packet_length -= kRtxHeaderSize; |
251 | 250 |
252 // Replace the SSRC and the sequence number with the originals. | 251 // Replace the SSRC and the sequence number with the originals. |
253 ByteWriter<uint16_t>::WriteBigEndian(restored_packet + 2, | 252 ByteWriter<uint16_t>::WriteBigEndian(restored_packet + 2, |
254 original_sequence_number); | 253 original_sequence_number); |
255 ByteWriter<uint32_t>::WriteBigEndian(restored_packet + 8, original_ssrc); | 254 ByteWriter<uint32_t>::WriteBigEndian(restored_packet + 8, original_ssrc); |
256 | 255 |
257 rtc::CritScope cs(&crit_sect_); | 256 rtc::CritScope cs(&crit_sect_); |
258 if (!rtx_) | 257 if (!rtx_) |
259 return true; | 258 return true; |
260 | 259 |
261 int associated_payload_type; | |
262 auto apt_mapping = rtx_payload_type_map_.find(header.payloadType); | 260 auto apt_mapping = rtx_payload_type_map_.find(header.payloadType); |
263 if (apt_mapping == rtx_payload_type_map_.end()) | 261 int associated_payload_type = apt_mapping->second; |
danilchap
2016/11/03 12:10:36
do not think you can do this if apt_mapping == end
brandtr
2016/11/03 13:48:09
Wow. This was terrible, sorry for that. I guess th
| |
264 return false; | 262 if (apt_mapping == rtx_payload_type_map_.end()) { |
265 associated_payload_type = apt_mapping->second; | 263 // No associated payload type found. Warn, unless we have already done so. |
266 if (red_payload_type_ != -1) { | 264 if (payload_types_with_suppressed_warnings_.count( |
267 // Assume red will be used if it's configured. | 265 associated_payload_type) == 0) { |
danilchap
2016/11/03 12:10:36
guess you want to use header.payloadType instead o
stefan-webrtc
2016/11/03 12:17:15
I prefer find() over count() when you don't care a
brandtr
2016/11/03 13:48:09
Done.
| |
268 // This is a workaround for a Chrome sdp bug where rtx is associated | 266 LOG(LS_WARNING) |
269 // with the media codec even though media is sent over red. | 267 << "No RTX associated payload type mapping was available; " |
270 // TODO(holmer): Remove once the Chrome versions exposing this bug are | 268 "not able to restore original packet from RTX packet " |
271 // old enough, which should be once Chrome Stable reaches M53 as this | 269 "with payload type: " |
272 // work-around went into M50. | 270 << header.payloadType << ". " |
273 associated_payload_type = red_payload_type_; | 271 << "Suppressing further warnings for this payload type."; |
272 payload_types_with_suppressed_warnings_.insert(associated_payload_type); | |
273 return false; | |
274 } | |
274 } | 275 } |
stefan-webrtc
2016/11/03 12:17:15
Shouldn't we return false here too?
brandtr
2016/11/03 13:48:09
Yes!
| |
275 restored_packet[1] = static_cast<uint8_t>(associated_payload_type); | 276 restored_packet[1] = static_cast<uint8_t>(associated_payload_type); |
276 if (header.markerBit) { | 277 if (header.markerBit) { |
277 restored_packet[1] |= kRtpMarkerBitMask; // Marker bit is set. | 278 restored_packet[1] |= kRtpMarkerBitMask; // Marker bit is set. |
278 } | 279 } |
279 return true; | 280 return true; |
280 } | 281 } |
281 | 282 |
282 void RTPPayloadRegistry::SetRtxSsrc(uint32_t ssrc) { | 283 void RTPPayloadRegistry::SetRtxSsrc(uint32_t ssrc) { |
283 rtc::CritScope cs(&crit_sect_); | 284 rtc::CritScope cs(&crit_sect_); |
284 ssrc_rtx_ = ssrc; | 285 ssrc_rtx_ = ssrc; |
285 rtx_ = true; | 286 rtx_ = true; |
286 } | 287 } |
287 | 288 |
288 bool RTPPayloadRegistry::GetRtxSsrc(uint32_t* ssrc) const { | 289 bool RTPPayloadRegistry::GetRtxSsrc(uint32_t* ssrc) const { |
289 rtc::CritScope cs(&crit_sect_); | 290 rtc::CritScope cs(&crit_sect_); |
290 *ssrc = ssrc_rtx_; | 291 *ssrc = ssrc_rtx_; |
291 return rtx_; | 292 return rtx_; |
292 } | 293 } |
293 | 294 |
294 void RTPPayloadRegistry::SetRtxPayloadType(int payload_type, | 295 void RTPPayloadRegistry::SetRtxPayloadType(int payload_type, |
295 int associated_payload_type) { | 296 int associated_payload_type) { |
296 rtc::CritScope cs(&crit_sect_); | 297 rtc::CritScope cs(&crit_sect_); |
297 if (payload_type < 0) { | 298 if (payload_type < 0) { |
298 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; | 299 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; |
299 return; | 300 return; |
300 } | 301 } |
301 | 302 |
302 rtx_payload_type_map_[payload_type] = associated_payload_type; | 303 rtx_payload_type_map_[payload_type] = associated_payload_type; |
303 rtx_ = true; | 304 rtx_ = true; |
304 rtx_payload_type_ = payload_type; | |
305 } | 305 } |
306 | 306 |
307 bool RTPPayloadRegistry::IsRed(const RTPHeader& header) const { | 307 bool RTPPayloadRegistry::IsRed(const RTPHeader& header) const { |
308 rtc::CritScope cs(&crit_sect_); | 308 rtc::CritScope cs(&crit_sect_); |
309 return red_payload_type_ == header.payloadType; | 309 return red_payload_type_ == header.payloadType; |
310 } | 310 } |
311 | 311 |
312 bool RTPPayloadRegistry::IsEncapsulated(const RTPHeader& header) const { | 312 bool RTPPayloadRegistry::IsEncapsulated(const RTPHeader& header) const { |
313 return IsRed(header) || IsRtx(header); | 313 return IsRed(header) || IsRtx(header); |
314 } | 314 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 RTPPayloadStrategy* RTPPayloadStrategy::CreateStrategy( | 466 RTPPayloadStrategy* RTPPayloadStrategy::CreateStrategy( |
467 const bool handling_audio) { | 467 const bool handling_audio) { |
468 if (handling_audio) { | 468 if (handling_audio) { |
469 return new RTPPayloadAudioStrategy(); | 469 return new RTPPayloadAudioStrategy(); |
470 } else { | 470 } else { |
471 return new RTPPayloadVideoStrategy(); | 471 return new RTPPayloadVideoStrategy(); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 } // namespace webrtc | 475 } // namespace webrtc |
OLD | NEW |