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 |
11 #include "webrtc/video/rtp_stream_receiver.h" | 11 #include "webrtc/video/rtp_stream_receiver.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
| 16 #include "webrtc/common_types.h" |
16 #include "webrtc/config.h" | 17 #include "webrtc/config.h" |
17 #include "webrtc/modules/pacing/packet_router.h" | 18 #include "webrtc/modules/pacing/packet_router.h" |
18 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
19 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h" | 20 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h" |
20 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" | 21 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
21 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 22 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
23 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
25 #include "webrtc/modules/video_coding/video_coding_impl.h" | 26 #include "webrtc/modules/video_coding/video_coding_impl.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 configuration.transport_feedback_callback = nullptr; | 58 configuration.transport_feedback_callback = nullptr; |
58 | 59 |
59 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); | 60 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); |
60 rtp_rtcp->SetSendingStatus(false); | 61 rtp_rtcp->SetSendingStatus(false); |
61 rtp_rtcp->SetSendingMediaStatus(false); | 62 rtp_rtcp->SetSendingMediaStatus(false); |
62 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); | 63 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); |
63 | 64 |
64 return rtp_rtcp; | 65 return rtp_rtcp; |
65 } | 66 } |
66 | 67 |
67 | |
68 static const int kPacketLogIntervalMs = 10000; | 68 static const int kPacketLogIntervalMs = 10000; |
69 | 69 |
70 RtpStreamReceiver::RtpStreamReceiver( | 70 RtpStreamReceiver::RtpStreamReceiver( |
71 vcm::VideoReceiver* video_receiver, | 71 vcm::VideoReceiver* video_receiver, |
72 RemoteBitrateEstimator* remote_bitrate_estimator, | 72 RemoteBitrateEstimator* remote_bitrate_estimator, |
73 Transport* transport, | 73 Transport* transport, |
74 RtcpRttStats* rtt_stats, | 74 RtcpRttStats* rtt_stats, |
75 PacedSender* paced_sender, | 75 PacedSender* paced_sender, |
76 PacketRouter* packet_router) | 76 PacketRouter* packet_router, |
| 77 const VideoReceiveStream::Config& config, |
| 78 StreamDataCountersCallback* stream_data_counters_callback, |
| 79 RtcpStatisticsCallback* rtcp_statistics_callback, |
| 80 RtcpPacketTypeCounterObserver* rtcp_counter_observer) |
77 : clock_(Clock::GetRealTimeClock()), | 81 : clock_(Clock::GetRealTimeClock()), |
78 video_receiver_(video_receiver), | 82 video_receiver_(video_receiver), |
79 remote_bitrate_estimator_(remote_bitrate_estimator), | 83 remote_bitrate_estimator_(remote_bitrate_estimator), |
80 packet_router_(packet_router), | 84 packet_router_(packet_router), |
81 ntp_estimator_(clock_), | 85 ntp_estimator_(clock_), |
82 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), | 86 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), |
83 rtp_header_parser_(RtpHeaderParser::Create()), | 87 rtp_header_parser_(RtpHeaderParser::Create()), |
84 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, | 88 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, |
85 this, | 89 this, |
86 this, | 90 this, |
87 &rtp_payload_registry_)), | 91 &rtp_payload_registry_)), |
88 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), | 92 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), |
89 fec_receiver_(FecReceiver::Create(this)), | 93 fec_receiver_(FecReceiver::Create(this)), |
90 receiving_(false), | 94 receiving_(false), |
91 restored_packet_in_use_(false), | 95 restored_packet_in_use_(false), |
92 last_packet_log_ms_(-1), | 96 last_packet_log_ms_(-1), |
93 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), | 97 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), |
94 transport, | 98 transport, |
95 rtt_stats, | 99 rtt_stats, |
96 &rtcp_packet_type_counter_observer_, | 100 rtcp_counter_observer, |
97 remote_bitrate_estimator_, | 101 remote_bitrate_estimator_, |
98 paced_sender, | 102 paced_sender, |
99 packet_router)) { | 103 packet_router)) { |
100 packet_router_->AddRtpModule(rtp_rtcp_.get()); | 104 packet_router_->AddRtpModule(rtp_rtcp_.get()); |
| 105 rtp_receive_statistics_->RegisterRtpStatisticsCallback( |
| 106 stream_data_counters_callback); |
| 107 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( |
| 108 rtcp_statistics_callback); |
| 109 |
| 110 RTC_DCHECK(config.rtp.rtcp_mode != RtcpMode::kOff) |
| 111 << "A stream should not be configured with RTCP disabled. This value is " |
| 112 "reserved for internal usage."; |
| 113 rtp_rtcp_->SetRTCPStatus(config.rtp.rtcp_mode); |
101 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); | 114 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); |
| 115 |
| 116 static const int kMaxPacketAgeToNack = 450; |
| 117 NACKMethod nack_method = |
| 118 config.rtp.nack.rtp_history_ms > 0 ? kNackRtcp : kNackOff; |
| 119 const int max_reordering_threshold = (nack_method == kNackRtcp) |
| 120 ? kMaxPacketAgeToNack : kDefaultMaxReorderingThreshold; |
| 121 rtp_receiver_->SetNACKStatus(nack_method); |
| 122 rtp_receive_statistics_->SetMaxReorderingThreshold(max_reordering_threshold); |
| 123 rtp_rtcp_->SetGenericFECStatus(false, 0, 0); |
102 } | 124 } |
103 | 125 |
104 RtpStreamReceiver::~RtpStreamReceiver() { | 126 RtpStreamReceiver::~RtpStreamReceiver() { |
105 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); | 127 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); |
106 UpdateHistograms(); | 128 UpdateHistograms(); |
107 } | 129 } |
108 | 130 |
109 void RtpStreamReceiver::UpdateHistograms() { | 131 void RtpStreamReceiver::UpdateHistograms() { |
110 FecPacketCounter counter = fec_receiver_->GetPacketCounter(); | 132 FecPacketCounter counter = fec_receiver_->GetPacketCounter(); |
111 if (counter.num_packets > 0) { | 133 if (counter.num_packets > 0) { |
(...skipping 15 matching lines...) Expand all Loading... |
127 video_codec.plName, kVideoPayloadTypeFrequency, 0, | 149 video_codec.plName, kVideoPayloadTypeFrequency, 0, |
128 video_codec.maxBitrate, &old_pltype) != -1) { | 150 video_codec.maxBitrate, &old_pltype) != -1) { |
129 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype); | 151 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype); |
130 } | 152 } |
131 | 153 |
132 return rtp_receiver_->RegisterReceivePayload( | 154 return rtp_receiver_->RegisterReceivePayload( |
133 video_codec.plName, video_codec.plType, kVideoPayloadTypeFrequency, | 155 video_codec.plName, video_codec.plType, kVideoPayloadTypeFrequency, |
134 0, 0) == 0; | 156 0, 0) == 0; |
135 } | 157 } |
136 | 158 |
137 void RtpStreamReceiver::SetNackStatus(bool enable, | |
138 int max_nack_reordering_threshold) { | |
139 if (!enable) { | |
140 // Reset the threshold back to the lower default threshold when NACK is | |
141 // disabled since we no longer will be receiving retransmissions. | |
142 max_nack_reordering_threshold = kDefaultMaxReorderingThreshold; | |
143 } | |
144 rtp_receive_statistics_->SetMaxReorderingThreshold( | |
145 max_nack_reordering_threshold); | |
146 rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff); | |
147 } | |
148 | |
149 void RtpStreamReceiver::SetRtxPayloadType(int payload_type, | 159 void RtpStreamReceiver::SetRtxPayloadType(int payload_type, |
150 int associated_payload_type) { | 160 int associated_payload_type) { |
151 rtp_payload_registry_.SetRtxPayloadType(payload_type, | 161 rtp_payload_registry_.SetRtxPayloadType(payload_type, |
152 associated_payload_type); | 162 associated_payload_type); |
153 } | 163 } |
154 | 164 |
155 void RtpStreamReceiver::SetUseRtxPayloadMappingOnRestore(bool val) { | 165 void RtpStreamReceiver::SetUseRtxPayloadMappingOnRestore(bool val) { |
156 rtp_payload_registry_.set_use_rtx_payload_mapping_on_restore(val); | 166 rtp_payload_registry_.set_use_rtx_payload_mapping_on_restore(val); |
157 } | 167 } |
158 | 168 |
(...skipping 21 matching lines...) Expand all Loading... |
180 return rtp_receiver_.get(); | 190 return rtp_receiver_.get(); |
181 } | 191 } |
182 | 192 |
183 void RtpStreamReceiver::EnableReceiveRtpHeaderExtension( | 193 void RtpStreamReceiver::EnableReceiveRtpHeaderExtension( |
184 const std::string& extension, int id) { | 194 const std::string& extension, int id) { |
185 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); | 195 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); |
186 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 196 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
187 StringToRtpExtensionType(extension), id)); | 197 StringToRtpExtensionType(extension), id)); |
188 } | 198 } |
189 | 199 |
190 void RtpStreamReceiver::RegisterRtcpPacketTypeCounterObserver( | |
191 RtcpPacketTypeCounterObserver* observer) { | |
192 rtcp_packet_type_counter_observer_.Set(observer); | |
193 } | |
194 | |
195 | |
196 int32_t RtpStreamReceiver::OnReceivedPayloadData( | 200 int32_t RtpStreamReceiver::OnReceivedPayloadData( |
197 const uint8_t* payload_data, | 201 const uint8_t* payload_data, |
198 const size_t payload_size, | 202 const size_t payload_size, |
199 const WebRtcRTPHeader* rtp_header) { | 203 const WebRtcRTPHeader* rtp_header) { |
200 RTC_DCHECK(video_receiver_); | 204 RTC_DCHECK(video_receiver_); |
201 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; | 205 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; |
202 rtp_header_with_ntp.ntp_time_ms = | 206 rtp_header_with_ntp.ntp_time_ms = |
203 ntp_estimator_.Estimate(rtp_header->header.timestamp); | 207 ntp_estimator_.Estimate(rtp_header->header.timestamp); |
204 if (video_receiver_->IncomingPacket(payload_data, payload_size, | 208 if (video_receiver_->IncomingPacket(payload_data, payload_size, |
205 rtp_header_with_ntp) != 0) { | 209 rtp_header_with_ntp) != 0) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 rtp_payload_registry_.SetIncomingPayloadType(header); | 290 rtp_payload_registry_.SetIncomingPayloadType(header); |
287 bool ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); | 291 bool ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); |
288 // Update receive statistics after ReceivePacket. | 292 // Update receive statistics after ReceivePacket. |
289 // Receive statistics will be reset if the payload type changes (make sure | 293 // Receive statistics will be reset if the payload type changes (make sure |
290 // that the first packet is included in the stats). | 294 // that the first packet is included in the stats). |
291 rtp_receive_statistics_->IncomingPacket( | 295 rtp_receive_statistics_->IncomingPacket( |
292 header, rtp_packet_length, IsPacketRetransmitted(header, in_order)); | 296 header, rtp_packet_length, IsPacketRetransmitted(header, in_order)); |
293 return ret; | 297 return ret; |
294 } | 298 } |
295 | 299 |
| 300 int32_t RtpStreamReceiver::RequestKeyFrame() { |
| 301 return rtp_rtcp_->RequestKeyFrame(); |
| 302 } |
| 303 |
| 304 int32_t RtpStreamReceiver::SliceLossIndicationRequest( |
| 305 const uint64_t picture_id) { |
| 306 return rtp_rtcp_->SendRTCPSliceLossIndication( |
| 307 static_cast<uint8_t>(picture_id)); |
| 308 } |
| 309 |
| 310 int32_t RtpStreamReceiver::ResendPackets(const uint16_t* sequence_numbers, |
| 311 uint16_t length) { |
| 312 return rtp_rtcp_->SendNACK(sequence_numbers, length); |
| 313 } |
| 314 |
296 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, | 315 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, |
297 size_t packet_length, | 316 size_t packet_length, |
298 const RTPHeader& header, | 317 const RTPHeader& header, |
299 bool in_order) { | 318 bool in_order) { |
300 if (rtp_payload_registry_.IsEncapsulated(header)) { | 319 if (rtp_payload_registry_.IsEncapsulated(header)) { |
301 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); | 320 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); |
302 } | 321 } |
303 const uint8_t* payload = packet + header.headerLength; | 322 const uint8_t* payload = packet + header.headerLength; |
304 assert(packet_length >= header.headerLength); | 323 assert(packet_length >= header.headerLength); |
305 size_t payload_length = packet_length - header.headerLength; | 324 size_t payload_length = packet_length - header.headerLength; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 rtp_receive_statistics_->GetStatistician(header.ssrc); | 466 rtp_receive_statistics_->GetStatistician(header.ssrc); |
448 if (!statistician) | 467 if (!statistician) |
449 return false; | 468 return false; |
450 // Check if this is a retransmission. | 469 // Check if this is a retransmission. |
451 int64_t min_rtt = 0; | 470 int64_t min_rtt = 0; |
452 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr); | 471 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr); |
453 return !in_order && | 472 return !in_order && |
454 statistician->IsRetransmitOfOldPacket(header, min_rtt); | 473 statistician->IsRetransmitOfOldPacket(header, min_rtt); |
455 } | 474 } |
456 } // namespace webrtc | 475 } // namespace webrtc |
OLD | NEW |