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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc

Issue 2469093003: Remove RED/RTX workaround from sender/receiver and VideoEngine2. (Closed)
Patch Set: Fix warning message. 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
OLDNEW
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
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 if (apt_mapping == rtx_payload_type_map_.end()) {
262 // No associated payload type found. Warn, unless we have already done so.
263 if (payload_types_with_suppressed_warnings_.find(header.payloadType) ==
264 payload_types_with_suppressed_warnings_.end()) {
265 LOG(LS_WARNING)
266 << "No RTX associated payload type mapping was available; "
267 "not able to restore original packet from RTX packet "
268 "with payload type: "
269 << static_cast<int>(header.payloadType) << ". "
270 << "Suppressing further warnings for this payload type.";
271 payload_types_with_suppressed_warnings_.insert(header.payloadType);
272 }
264 return false; 273 return false;
265 associated_payload_type = apt_mapping->second;
266 if (red_payload_type_ != -1) {
267 // Assume red will be used if it's configured.
268 // This is a workaround for a Chrome sdp bug where rtx is associated
269 // with the media codec even though media is sent over red.
270 // TODO(holmer): Remove once the Chrome versions exposing this bug are
271 // old enough, which should be once Chrome Stable reaches M53 as this
272 // work-around went into M50.
273 associated_payload_type = red_payload_type_;
274 } 274 }
275 restored_packet[1] = static_cast<uint8_t>(associated_payload_type); 275 restored_packet[1] = static_cast<uint8_t>(apt_mapping->second);
276 if (header.markerBit) { 276 if (header.markerBit) {
277 restored_packet[1] |= kRtpMarkerBitMask; // Marker bit is set. 277 restored_packet[1] |= kRtpMarkerBitMask; // Marker bit is set.
278 } 278 }
279 return true; 279 return true;
280 } 280 }
281 281
282 void RTPPayloadRegistry::SetRtxSsrc(uint32_t ssrc) { 282 void RTPPayloadRegistry::SetRtxSsrc(uint32_t ssrc) {
283 rtc::CritScope cs(&crit_sect_); 283 rtc::CritScope cs(&crit_sect_);
284 ssrc_rtx_ = ssrc; 284 ssrc_rtx_ = ssrc;
285 rtx_ = true; 285 rtx_ = true;
286 } 286 }
287 287
288 bool RTPPayloadRegistry::GetRtxSsrc(uint32_t* ssrc) const { 288 bool RTPPayloadRegistry::GetRtxSsrc(uint32_t* ssrc) const {
289 rtc::CritScope cs(&crit_sect_); 289 rtc::CritScope cs(&crit_sect_);
290 *ssrc = ssrc_rtx_; 290 *ssrc = ssrc_rtx_;
291 return rtx_; 291 return rtx_;
292 } 292 }
293 293
294 void RTPPayloadRegistry::SetRtxPayloadType(int payload_type, 294 void RTPPayloadRegistry::SetRtxPayloadType(int payload_type,
295 int associated_payload_type) { 295 int associated_payload_type) {
296 rtc::CritScope cs(&crit_sect_); 296 rtc::CritScope cs(&crit_sect_);
297 if (payload_type < 0) { 297 if (payload_type < 0) {
298 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; 298 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type;
299 return; 299 return;
300 } 300 }
301 301
302 rtx_payload_type_map_[payload_type] = associated_payload_type; 302 rtx_payload_type_map_[payload_type] = associated_payload_type;
303 rtx_ = true; 303 rtx_ = true;
304 rtx_payload_type_ = payload_type;
305 } 304 }
306 305
307 bool RTPPayloadRegistry::IsRed(const RTPHeader& header) const { 306 bool RTPPayloadRegistry::IsRed(const RTPHeader& header) const {
308 rtc::CritScope cs(&crit_sect_); 307 rtc::CritScope cs(&crit_sect_);
309 return red_payload_type_ == header.payloadType; 308 return red_payload_type_ == header.payloadType;
310 } 309 }
311 310
312 bool RTPPayloadRegistry::IsEncapsulated(const RTPHeader& header) const { 311 bool RTPPayloadRegistry::IsEncapsulated(const RTPHeader& header) const {
313 return IsRed(header) || IsRtx(header); 312 return IsRed(header) || IsRtx(header);
314 } 313 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 RTPPayloadStrategy* RTPPayloadStrategy::CreateStrategy( 465 RTPPayloadStrategy* RTPPayloadStrategy::CreateStrategy(
467 const bool handling_audio) { 466 const bool handling_audio) {
468 if (handling_audio) { 467 if (handling_audio) {
469 return new RTPPayloadAudioStrategy(); 468 return new RTPPayloadAudioStrategy();
470 } else { 469 } else {
471 return new RTPPayloadVideoStrategy(); 470 return new RTPPayloadVideoStrategy();
472 } 471 }
473 } 472 }
474 473
475 } // namespace webrtc 474 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698