| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return rtp_rtcp; | 79 return rtp_rtcp; |
| 80 } | 80 } |
| 81 | 81 |
| 82 static const int kPacketLogIntervalMs = 10000; | 82 static const int kPacketLogIntervalMs = 10000; |
| 83 | 83 |
| 84 RtpVideoStreamReceiver::RtpVideoStreamReceiver( | 84 RtpVideoStreamReceiver::RtpVideoStreamReceiver( |
| 85 Transport* transport, | 85 Transport* transport, |
| 86 RtcpRttStats* rtt_stats, | 86 RtcpRttStats* rtt_stats, |
| 87 PacketRouter* packet_router, | 87 PacketRouter* packet_router, |
| 88 const VideoReceiveStream::Config* config, | 88 const VideoReceiveStream::Config* config, |
| 89 ReceiveStatistics* rtp_receive_statistics, |
| 89 ReceiveStatisticsProxy* receive_stats_proxy, | 90 ReceiveStatisticsProxy* receive_stats_proxy, |
| 90 ProcessThread* process_thread, | 91 ProcessThread* process_thread, |
| 91 NackSender* nack_sender, | 92 NackSender* nack_sender, |
| 92 KeyFrameRequestSender* keyframe_request_sender, | 93 KeyFrameRequestSender* keyframe_request_sender, |
| 93 video_coding::OnCompleteFrameCallback* complete_frame_callback, | 94 video_coding::OnCompleteFrameCallback* complete_frame_callback, |
| 94 VCMTiming* timing) | 95 VCMTiming* timing) |
| 95 : clock_(Clock::GetRealTimeClock()), | 96 : clock_(Clock::GetRealTimeClock()), |
| 96 config_(*config), | 97 config_(*config), |
| 97 packet_router_(packet_router), | 98 packet_router_(packet_router), |
| 98 process_thread_(process_thread), | 99 process_thread_(process_thread), |
| 99 ntp_estimator_(clock_), | 100 ntp_estimator_(clock_), |
| 100 rtp_header_parser_(RtpHeaderParser::Create()), | 101 rtp_header_parser_(RtpHeaderParser::Create()), |
| 101 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, | 102 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, |
| 102 this, | 103 this, |
| 103 this, | 104 this, |
| 104 &rtp_payload_registry_)), | 105 &rtp_payload_registry_)), |
| 105 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), | 106 rtp_receive_statistics_(rtp_receive_statistics), |
| 106 ulpfec_receiver_(UlpfecReceiver::Create(config->rtp.remote_ssrc, this)), | 107 ulpfec_receiver_(UlpfecReceiver::Create(config->rtp.remote_ssrc, this)), |
| 107 receiving_(false), | 108 receiving_(false), |
| 108 restored_packet_in_use_(false), | |
| 109 last_packet_log_ms_(-1), | 109 last_packet_log_ms_(-1), |
| 110 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), | 110 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_, |
| 111 transport, | 111 transport, |
| 112 rtt_stats, | 112 rtt_stats, |
| 113 receive_stats_proxy, | 113 receive_stats_proxy, |
| 114 packet_router)), | 114 packet_router)), |
| 115 complete_frame_callback_(complete_frame_callback), | 115 complete_frame_callback_(complete_frame_callback), |
| 116 keyframe_request_sender_(keyframe_request_sender), | 116 keyframe_request_sender_(keyframe_request_sender), |
| 117 timing_(timing), | 117 timing_(timing), |
| 118 has_received_frame_(false) { | 118 has_received_frame_(false) { |
| 119 constexpr bool remb_candidate = true; | 119 constexpr bool remb_candidate = true; |
| 120 packet_router_->AddReceiveRtpModule(rtp_rtcp_.get(), remb_candidate); | 120 packet_router_->AddReceiveRtpModule(rtp_rtcp_.get(), remb_candidate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 config_.rtp.extensions[i].id); | 139 config_.rtp.extensions[i].id); |
| 140 } | 140 } |
| 141 | 141 |
| 142 static const int kMaxPacketAgeToNack = 450; | 142 static const int kMaxPacketAgeToNack = 450; |
| 143 const int max_reordering_threshold = (config_.rtp.nack.rtp_history_ms > 0) | 143 const int max_reordering_threshold = (config_.rtp.nack.rtp_history_ms > 0) |
| 144 ? kMaxPacketAgeToNack | 144 ? kMaxPacketAgeToNack |
| 145 : kDefaultMaxReorderingThreshold; | 145 : kDefaultMaxReorderingThreshold; |
| 146 rtp_receive_statistics_->SetMaxReorderingThreshold(max_reordering_threshold); | 146 rtp_receive_statistics_->SetMaxReorderingThreshold(max_reordering_threshold); |
| 147 | 147 |
| 148 if (config_.rtp.rtx_ssrc) { | 148 if (config_.rtp.rtx_ssrc) { |
| 149 // Needed for rtp_payload_registry_.RtxEnabled(). |
| 149 rtp_payload_registry_.SetRtxSsrc(config_.rtp.rtx_ssrc); | 150 rtp_payload_registry_.SetRtxSsrc(config_.rtp.rtx_ssrc); |
| 150 | |
| 151 for (const auto& kv : config_.rtp.rtx_associated_payload_types) { | |
| 152 RTC_DCHECK_NE(kv.first, 0); | |
| 153 rtp_payload_registry_.SetRtxPayloadType(kv.first, kv.second); | |
| 154 } | |
| 155 } | 151 } |
| 156 | 152 |
| 157 if (IsUlpfecEnabled()) { | 153 if (IsUlpfecEnabled()) { |
| 158 VideoCodec ulpfec_codec = {}; | 154 VideoCodec ulpfec_codec = {}; |
| 159 ulpfec_codec.codecType = kVideoCodecULPFEC; | 155 ulpfec_codec.codecType = kVideoCodecULPFEC; |
| 160 strncpy(ulpfec_codec.plName, "ulpfec", sizeof(ulpfec_codec.plName)); | 156 strncpy(ulpfec_codec.plName, "ulpfec", sizeof(ulpfec_codec.plName)); |
| 161 ulpfec_codec.plType = config_.rtp.ulpfec.ulpfec_payload_type; | 157 ulpfec_codec.plType = config_.rtp.ulpfec.ulpfec_payload_type; |
| 162 RTC_CHECK(AddReceiveCodec(ulpfec_codec)); | 158 RTC_CHECK(AddReceiveCodec(ulpfec_codec)); |
| 163 } | 159 } |
| 164 | 160 |
| 165 if (IsRedEnabled()) { | 161 if (IsRedEnabled()) { |
| 166 VideoCodec red_codec = {}; | 162 VideoCodec red_codec = {}; |
| 167 red_codec.codecType = kVideoCodecRED; | 163 red_codec.codecType = kVideoCodecRED; |
| 168 strncpy(red_codec.plName, "red", sizeof(red_codec.plName)); | 164 strncpy(red_codec.plName, "red", sizeof(red_codec.plName)); |
| 169 red_codec.plType = config_.rtp.ulpfec.red_payload_type; | 165 red_codec.plType = config_.rtp.ulpfec.red_payload_type; |
| 170 RTC_CHECK(AddReceiveCodec(red_codec)); | 166 RTC_CHECK(AddReceiveCodec(red_codec)); |
| 171 if (config_.rtp.ulpfec.red_rtx_payload_type != -1) { | |
| 172 rtp_payload_registry_.SetRtxPayloadType( | |
| 173 config_.rtp.ulpfec.red_rtx_payload_type, | |
| 174 config_.rtp.ulpfec.red_payload_type); | |
| 175 } | |
| 176 } | 167 } |
| 177 | 168 |
| 178 if (config_.rtp.rtcp_xr.receiver_reference_time_report) | 169 if (config_.rtp.rtcp_xr.receiver_reference_time_report) |
| 179 rtp_rtcp_->SetRtcpXrRrtrStatus(true); | 170 rtp_rtcp_->SetRtcpXrRrtrStatus(true); |
| 180 | 171 |
| 181 // Stats callback for CNAME changes. | 172 // Stats callback for CNAME changes. |
| 182 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); | 173 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); |
| 183 | 174 |
| 184 process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE); | 175 process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE); |
| 185 | 176 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // Notify video_receiver about received FEC packets to avoid NACKing these | 479 // Notify video_receiver about received FEC packets to avoid NACKing these |
| 489 // packets. | 480 // packets. |
| 490 NotifyReceiverOfFecPacket(header); | 481 NotifyReceiverOfFecPacket(header); |
| 491 } | 482 } |
| 492 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length, | 483 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length, |
| 493 ulpfec_pt) != 0) { | 484 ulpfec_pt) != 0) { |
| 494 return; | 485 return; |
| 495 } | 486 } |
| 496 ulpfec_receiver_->ProcessReceivedFec(); | 487 ulpfec_receiver_->ProcessReceivedFec(); |
| 497 } else if (rtp_payload_registry_.IsRtx(header)) { | 488 } else if (rtp_payload_registry_.IsRtx(header)) { |
| 498 if (header.headerLength + header.paddingLength == packet_length) { | 489 LOG(LS_WARNING) << "Unexpected RTX packet on media ssrc"; |
| 499 // This is an empty packet and should be silently dropped before trying to | |
| 500 // parse the RTX header. | |
| 501 return; | |
| 502 } | |
| 503 // Remove the RTX header and parse the original RTP header. | |
| 504 if (packet_length < header.headerLength) | |
| 505 return; | |
| 506 if (packet_length > sizeof(restored_packet_)) | |
| 507 return; | |
| 508 if (restored_packet_in_use_) { | |
| 509 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet."; | |
| 510 return; | |
| 511 } | |
| 512 if (!rtp_payload_registry_.RestoreOriginalPacket( | |
| 513 restored_packet_, packet, &packet_length, config_.rtp.remote_ssrc, | |
| 514 header)) { | |
| 515 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header ssrc: " | |
| 516 << header.ssrc << " payload type: " | |
| 517 << static_cast<int>(header.payloadType); | |
| 518 return; | |
| 519 } | |
| 520 restored_packet_in_use_ = true; | |
| 521 OnRecoveredPacket(restored_packet_, packet_length); | |
| 522 restored_packet_in_use_ = false; | |
| 523 } | 490 } |
| 524 } | 491 } |
| 525 | 492 |
| 526 void RtpVideoStreamReceiver::NotifyReceiverOfFecPacket( | 493 void RtpVideoStreamReceiver::NotifyReceiverOfFecPacket( |
| 527 const RTPHeader& header) { | 494 const RTPHeader& header) { |
| 528 int8_t last_media_payload_type = | 495 int8_t last_media_payload_type = |
| 529 rtp_payload_registry_.last_received_media_payload_type(); | 496 rtp_payload_registry_.last_received_media_payload_type(); |
| 530 if (last_media_payload_type < 0) { | 497 if (last_media_payload_type < 0) { |
| 531 LOG(LS_WARNING) << "Failed to get last media payload type."; | 498 LOG(LS_WARNING) << "Failed to get last media payload type."; |
| 532 return; | 499 return; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 return; | 675 return; |
| 709 | 676 |
| 710 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) | 677 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) |
| 711 return; | 678 return; |
| 712 | 679 |
| 713 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), | 680 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), |
| 714 sprop_decoder.pps_nalu()); | 681 sprop_decoder.pps_nalu()); |
| 715 } | 682 } |
| 716 | 683 |
| 717 } // namespace webrtc | 684 } // namespace webrtc |
| OLD | NEW |