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

Side by Side Diff: webrtc/video/rtp_stream_receiver.cc

Issue 1929313002: Removed all RTP dependencies from ViEChannel and renamed class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed pbos' comments in ps#1 Created 4 years, 7 months 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) 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"
26 #include "webrtc/system_wrappers/include/metrics.h" 27 #include "webrtc/system_wrappers/include/metrics.h"
27 #include "webrtc/system_wrappers/include/tick_util.h" 28 #include "webrtc/system_wrappers/include/tick_util.h"
28 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" 29 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h"
29 #include "webrtc/system_wrappers/include/trace.h" 30 #include "webrtc/system_wrappers/include/trace.h"
31 #include "webrtc/video/receive_statistics_proxy.h"
30 32
31 namespace webrtc { 33 namespace webrtc {
32 34
33 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule( 35 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule(
34 ReceiveStatistics* receive_statistics, 36 ReceiveStatistics* receive_statistics,
35 Transport* outgoing_transport, 37 Transport* outgoing_transport,
36 RtcpRttStats* rtt_stats, 38 RtcpRttStats* rtt_stats,
37 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, 39 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer,
38 RemoteBitrateEstimator* remote_bitrate_estimator, 40 RemoteBitrateEstimator* remote_bitrate_estimator,
39 RtpPacketSender* paced_sender, 41 RtpPacketSender* paced_sender,
(...skipping 17 matching lines...) Expand all
57 configuration.transport_feedback_callback = nullptr; 59 configuration.transport_feedback_callback = nullptr;
58 60
59 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration)); 61 std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration));
60 rtp_rtcp->SetSendingStatus(false); 62 rtp_rtcp->SetSendingStatus(false);
61 rtp_rtcp->SetSendingMediaStatus(false); 63 rtp_rtcp->SetSendingMediaStatus(false);
62 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); 64 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound);
63 65
64 return rtp_rtcp; 66 return rtp_rtcp;
65 } 67 }
66 68
67
68 static const int kPacketLogIntervalMs = 10000; 69 static const int kPacketLogIntervalMs = 10000;
69 70
70 RtpStreamReceiver::RtpStreamReceiver( 71 RtpStreamReceiver::RtpStreamReceiver(
71 vcm::VideoReceiver* video_receiver, 72 vcm::VideoReceiver* video_receiver,
72 RemoteBitrateEstimator* remote_bitrate_estimator, 73 RemoteBitrateEstimator* remote_bitrate_estimator,
73 Transport* transport, 74 Transport* transport,
74 RtcpRttStats* rtt_stats, 75 RtcpRttStats* rtt_stats,
75 PacedSender* paced_sender, 76 PacedSender* paced_sender,
76 PacketRouter* packet_router) 77 PacketRouter* packet_router,
78 const VideoReceiveStream::Config& config,
79 ReceiveStatisticsProxy* receive_stats_proxy)
77 : clock_(Clock::GetRealTimeClock()), 80 : clock_(Clock::GetRealTimeClock()),
78 video_receiver_(video_receiver), 81 video_receiver_(video_receiver),
79 remote_bitrate_estimator_(remote_bitrate_estimator), 82 remote_bitrate_estimator_(remote_bitrate_estimator),
80 packet_router_(packet_router), 83 packet_router_(packet_router),
81 ntp_estimator_(clock_), 84 ntp_estimator_(clock_),
82 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), 85 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)),
83 rtp_header_parser_(RtpHeaderParser::Create()), 86 rtp_header_parser_(RtpHeaderParser::Create()),
84 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, 87 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_,
85 this, 88 this,
86 this, 89 this,
87 &rtp_payload_registry_)), 90 &rtp_payload_registry_)),
88 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), 91 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)),
89 fec_receiver_(FecReceiver::Create(this)), 92 fec_receiver_(FecReceiver::Create(this)),
90 receiving_(false), 93 receiving_(false),
91 restored_packet_in_use_(false), 94 restored_packet_in_use_(false),
92 last_packet_log_ms_(-1), 95 last_packet_log_ms_(-1),
93 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), 96 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(),
94 transport, 97 transport,
95 rtt_stats, 98 rtt_stats,
96 &rtcp_packet_type_counter_observer_, 99 receive_stats_proxy,
97 remote_bitrate_estimator_, 100 remote_bitrate_estimator_,
98 paced_sender, 101 paced_sender,
99 packet_router)) { 102 packet_router)) {
100 packet_router_->AddRtpModule(rtp_rtcp_.get()); 103 packet_router_->AddRtpModule(rtp_rtcp_.get());
104 rtp_receive_statistics_->RegisterRtpStatisticsCallback(receive_stats_proxy);
105 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
106
107 RTC_DCHECK(config.rtp.rtcp_mode != RtcpMode::kOff)
108 << "A stream should not be configured with RTCP disabled. This value is "
109 "reserved for internal usage.";
110 rtp_rtcp_->SetRTCPStatus(config.rtp.rtcp_mode);
101 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); 111 rtp_rtcp_->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp);
112
113 static const int kMaxPacketAgeToNack = 450;
114 NACKMethod nack_method =
115 config.rtp.nack.rtp_history_ms > 0 ? kNackRtcp : kNackOff;
116 const int max_reordering_threshold = (nack_method == kNackRtcp)
117 ? kMaxPacketAgeToNack : kDefaultMaxReorderingThreshold;
118 rtp_receiver_->SetNACKStatus(nack_method);
119 rtp_receive_statistics_->SetMaxReorderingThreshold(max_reordering_threshold);
120 rtp_rtcp_->SetGenericFECStatus(false, 0, 0);
stefan-webrtc 2016/05/03 07:48:08 This is disabled because this is a receiver, right
mflodman 2016/05/03 07:56:52 Yes, this is copied from ViEChannel and how it was
102 } 121 }
103 122
104 RtpStreamReceiver::~RtpStreamReceiver() { 123 RtpStreamReceiver::~RtpStreamReceiver() {
105 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); 124 packet_router_->RemoveRtpModule(rtp_rtcp_.get());
106 UpdateHistograms(); 125 UpdateHistograms();
107 } 126 }
108 127
109 void RtpStreamReceiver::UpdateHistograms() { 128 void RtpStreamReceiver::UpdateHistograms() {
110 FecPacketCounter counter = fec_receiver_->GetPacketCounter(); 129 FecPacketCounter counter = fec_receiver_->GetPacketCounter();
111 if (counter.num_packets > 0) { 130 if (counter.num_packets > 0) {
(...skipping 15 matching lines...) Expand all
127 video_codec.plName, kVideoPayloadTypeFrequency, 0, 146 video_codec.plName, kVideoPayloadTypeFrequency, 0,
128 video_codec.maxBitrate, &old_pltype) != -1) { 147 video_codec.maxBitrate, &old_pltype) != -1) {
129 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype); 148 rtp_payload_registry_.DeRegisterReceivePayload(old_pltype);
130 } 149 }
131 150
132 return rtp_receiver_->RegisterReceivePayload( 151 return rtp_receiver_->RegisterReceivePayload(
133 video_codec.plName, video_codec.plType, kVideoPayloadTypeFrequency, 152 video_codec.plName, video_codec.plType, kVideoPayloadTypeFrequency,
134 0, 0) == 0; 153 0, 0) == 0;
135 } 154 }
136 155
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, 156 void RtpStreamReceiver::SetRtxPayloadType(int payload_type,
150 int associated_payload_type) { 157 int associated_payload_type) {
151 rtp_payload_registry_.SetRtxPayloadType(payload_type, 158 rtp_payload_registry_.SetRtxPayloadType(payload_type,
152 associated_payload_type); 159 associated_payload_type);
153 } 160 }
154 161
155 void RtpStreamReceiver::SetUseRtxPayloadMappingOnRestore(bool val) { 162 void RtpStreamReceiver::SetUseRtxPayloadMappingOnRestore(bool val) {
156 rtp_payload_registry_.set_use_rtx_payload_mapping_on_restore(val); 163 rtp_payload_registry_.set_use_rtx_payload_mapping_on_restore(val);
157 } 164 }
158 165
(...skipping 21 matching lines...) Expand all
180 return rtp_receiver_.get(); 187 return rtp_receiver_.get();
181 } 188 }
182 189
183 void RtpStreamReceiver::EnableReceiveRtpHeaderExtension( 190 void RtpStreamReceiver::EnableReceiveRtpHeaderExtension(
184 const std::string& extension, int id) { 191 const std::string& extension, int id) {
185 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); 192 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension));
186 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( 193 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
187 StringToRtpExtensionType(extension), id)); 194 StringToRtpExtensionType(extension), id));
188 } 195 }
189 196
190 void RtpStreamReceiver::RegisterRtcpPacketTypeCounterObserver(
191 RtcpPacketTypeCounterObserver* observer) {
192 rtcp_packet_type_counter_observer_.Set(observer);
193 }
194
195
196 int32_t RtpStreamReceiver::OnReceivedPayloadData( 197 int32_t RtpStreamReceiver::OnReceivedPayloadData(
197 const uint8_t* payload_data, 198 const uint8_t* payload_data,
198 const size_t payload_size, 199 const size_t payload_size,
199 const WebRtcRTPHeader* rtp_header) { 200 const WebRtcRTPHeader* rtp_header) {
200 RTC_DCHECK(video_receiver_); 201 RTC_DCHECK(video_receiver_);
201 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; 202 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
202 rtp_header_with_ntp.ntp_time_ms = 203 rtp_header_with_ntp.ntp_time_ms =
203 ntp_estimator_.Estimate(rtp_header->header.timestamp); 204 ntp_estimator_.Estimate(rtp_header->header.timestamp);
204 if (video_receiver_->IncomingPacket(payload_data, payload_size, 205 if (video_receiver_->IncomingPacket(payload_data, payload_size,
205 rtp_header_with_ntp) != 0) { 206 rtp_header_with_ntp) != 0) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 rtp_payload_registry_.SetIncomingPayloadType(header); 287 rtp_payload_registry_.SetIncomingPayloadType(header);
287 bool ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order); 288 bool ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order);
288 // Update receive statistics after ReceivePacket. 289 // Update receive statistics after ReceivePacket.
289 // Receive statistics will be reset if the payload type changes (make sure 290 // Receive statistics will be reset if the payload type changes (make sure
290 // that the first packet is included in the stats). 291 // that the first packet is included in the stats).
291 rtp_receive_statistics_->IncomingPacket( 292 rtp_receive_statistics_->IncomingPacket(
292 header, rtp_packet_length, IsPacketRetransmitted(header, in_order)); 293 header, rtp_packet_length, IsPacketRetransmitted(header, in_order));
293 return ret; 294 return ret;
294 } 295 }
295 296
297 int32_t RtpStreamReceiver::RequestKeyFrame() {
298 return rtp_rtcp_->RequestKeyFrame();
299 }
300
301 int32_t RtpStreamReceiver::SliceLossIndicationRequest(
302 const uint64_t picture_id) {
303 return rtp_rtcp_->SendRTCPSliceLossIndication(
304 static_cast<uint8_t>(picture_id));
305 }
306
307 int32_t RtpStreamReceiver::ResendPackets(const uint16_t* sequence_numbers,
308 uint16_t length) {
309 return rtp_rtcp_->SendNACK(sequence_numbers, length);
310 }
311
296 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, 312 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet,
297 size_t packet_length, 313 size_t packet_length,
298 const RTPHeader& header, 314 const RTPHeader& header,
299 bool in_order) { 315 bool in_order) {
300 if (rtp_payload_registry_.IsEncapsulated(header)) { 316 if (rtp_payload_registry_.IsEncapsulated(header)) {
301 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); 317 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
302 } 318 }
303 const uint8_t* payload = packet + header.headerLength; 319 const uint8_t* payload = packet + header.headerLength;
304 assert(packet_length >= header.headerLength); 320 assert(packet_length >= header.headerLength);
305 size_t payload_length = packet_length - header.headerLength; 321 size_t payload_length = packet_length - header.headerLength;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 rtp_receive_statistics_->GetStatistician(header.ssrc); 463 rtp_receive_statistics_->GetStatistician(header.ssrc);
448 if (!statistician) 464 if (!statistician)
449 return false; 465 return false;
450 // Check if this is a retransmission. 466 // Check if this is a retransmission.
451 int64_t min_rtt = 0; 467 int64_t min_rtt = 0;
452 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr); 468 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), nullptr, nullptr, &min_rtt, nullptr);
453 return !in_order && 469 return !in_order &&
454 statistician->IsRetransmitOfOldPacket(header, min_rtt); 470 statistician->IsRetransmitOfOldPacket(header, min_rtt);
455 } 471 }
456 } // namespace webrtc 472 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698