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

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

Issue 2480293002: New jitter buffer experiment. (Closed)
Patch Set: Nit fix. 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) 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 #include <utility>
14 15
15 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
17 #include "webrtc/common_types.h" 18 #include "webrtc/common_types.h"
18 #include "webrtc/config.h" 19 #include "webrtc/config.h"
19 #include "webrtc/modules/pacing/packet_router.h" 20 #include "webrtc/modules/pacing/packet_router.h"
20 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" 21 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h"
21 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" 22 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
22 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" 23 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
23 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" 24 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
24 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" 25 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
26 #include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h" 27 #include "webrtc/modules/rtp_rtcp/include/ulpfec_receiver.h"
28 #include "webrtc/modules/video_coding/frame_object.h"
29 #include "webrtc/modules/video_coding/h264_sps_pps_tracker.h"
30 #include "webrtc/modules/video_coding/packet_buffer.h"
27 #include "webrtc/modules/video_coding/video_coding_impl.h" 31 #include "webrtc/modules/video_coding/video_coding_impl.h"
32 #include "webrtc/system_wrappers/include/field_trial.h"
28 #include "webrtc/system_wrappers/include/metrics.h" 33 #include "webrtc/system_wrappers/include/metrics.h"
29 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" 34 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h"
30 #include "webrtc/system_wrappers/include/trace.h" 35 #include "webrtc/system_wrappers/include/trace.h"
31 #include "webrtc/video/receive_statistics_proxy.h" 36 #include "webrtc/video/receive_statistics_proxy.h"
32 #include "webrtc/video/vie_remb.h" 37 #include "webrtc/video/vie_remb.h"
33 38
34 namespace webrtc { 39 namespace webrtc {
35 40
41 namespace {
42 constexpr int kPacketBufferStartSize = 32;
43 constexpr int kPacketBufferMaxSixe = 2048;
44 }
45
36 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule( 46 std::unique_ptr<RtpRtcp> CreateRtpRtcpModule(
37 ReceiveStatistics* receive_statistics, 47 ReceiveStatistics* receive_statistics,
38 Transport* outgoing_transport, 48 Transport* outgoing_transport,
39 RtcpRttStats* rtt_stats, 49 RtcpRttStats* rtt_stats,
40 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, 50 RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer,
41 RemoteBitrateEstimator* remote_bitrate_estimator, 51 RemoteBitrateEstimator* remote_bitrate_estimator,
42 RtpPacketSender* paced_sender, 52 RtpPacketSender* paced_sender,
43 TransportSequenceNumberAllocator* transport_sequence_number_allocator, 53 TransportSequenceNumberAllocator* transport_sequence_number_allocator,
44 RateLimiter* retransmission_rate_limiter) { 54 RateLimiter* retransmission_rate_limiter) {
45 RtpRtcp::Configuration configuration; 55 RtpRtcp::Configuration configuration;
(...skipping 30 matching lines...) Expand all
76 vcm::VideoReceiver* video_receiver, 86 vcm::VideoReceiver* video_receiver,
77 RemoteBitrateEstimator* remote_bitrate_estimator, 87 RemoteBitrateEstimator* remote_bitrate_estimator,
78 Transport* transport, 88 Transport* transport,
79 RtcpRttStats* rtt_stats, 89 RtcpRttStats* rtt_stats,
80 PacedSender* paced_sender, 90 PacedSender* paced_sender,
81 PacketRouter* packet_router, 91 PacketRouter* packet_router,
82 VieRemb* remb, 92 VieRemb* remb,
83 const VideoReceiveStream::Config* config, 93 const VideoReceiveStream::Config* config,
84 ReceiveStatisticsProxy* receive_stats_proxy, 94 ReceiveStatisticsProxy* receive_stats_proxy,
85 ProcessThread* process_thread, 95 ProcessThread* process_thread,
86 RateLimiter* retransmission_rate_limiter) 96 RateLimiter* retransmission_rate_limiter,
97 NackSender* nack_sender,
98 KeyFrameRequestSender* keyframe_request_sender,
99 video_coding::OnCompleteFrameCallback* complete_frame_callback,
100 VCMTiming* timing)
87 : clock_(Clock::GetRealTimeClock()), 101 : clock_(Clock::GetRealTimeClock()),
88 config_(*config), 102 config_(*config),
89 video_receiver_(video_receiver), 103 video_receiver_(video_receiver),
90 remote_bitrate_estimator_(remote_bitrate_estimator), 104 remote_bitrate_estimator_(remote_bitrate_estimator),
91 packet_router_(packet_router), 105 packet_router_(packet_router),
92 remb_(remb), 106 remb_(remb),
93 process_thread_(process_thread), 107 process_thread_(process_thread),
94 ntp_estimator_(clock_), 108 ntp_estimator_(clock_),
95 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)), 109 rtp_payload_registry_(RTPPayloadStrategy::CreateStrategy(false)),
96 rtp_header_parser_(RtpHeaderParser::Create()), 110 rtp_header_parser_(RtpHeaderParser::Create()),
97 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_, 111 rtp_receiver_(RtpReceiver::CreateVideoReceiver(clock_,
98 this, 112 this,
99 this, 113 this,
100 &rtp_payload_registry_)), 114 &rtp_payload_registry_)),
101 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)), 115 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)),
102 ulpfec_receiver_(UlpfecReceiver::Create(this)), 116 ulpfec_receiver_(UlpfecReceiver::Create(this)),
103 receiving_(false), 117 receiving_(false),
104 restored_packet_in_use_(false), 118 restored_packet_in_use_(false),
105 last_packet_log_ms_(-1), 119 last_packet_log_ms_(-1),
106 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), 120 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(),
107 transport, 121 transport,
108 rtt_stats, 122 rtt_stats,
109 receive_stats_proxy, 123 receive_stats_proxy,
110 remote_bitrate_estimator_, 124 remote_bitrate_estimator_,
111 paced_sender, 125 paced_sender,
112 packet_router, 126 packet_router,
113 retransmission_rate_limiter)) { 127 retransmission_rate_limiter)),
128 complete_frame_callback_(complete_frame_callback),
129 keyframe_request_sender_(keyframe_request_sender),
130 timing_(timing) {
114 packet_router_->AddRtpModule(rtp_rtcp_.get()); 131 packet_router_->AddRtpModule(rtp_rtcp_.get());
115 rtp_receive_statistics_->RegisterRtpStatisticsCallback(receive_stats_proxy); 132 rtp_receive_statistics_->RegisterRtpStatisticsCallback(receive_stats_proxy);
116 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(receive_stats_proxy); 133 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
117 134
118 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) 135 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff)
119 << "A stream should not be configured with RTCP disabled. This value is " 136 << "A stream should not be configured with RTCP disabled. This value is "
120 "reserved for internal usage."; 137 "reserved for internal usage.";
121 RTC_DCHECK(config_.rtp.remote_ssrc != 0); 138 RTC_DCHECK(config_.rtp.remote_ssrc != 0);
122 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams? 139 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams?
123 RTC_DCHECK(config_.rtp.local_ssrc != 0); 140 RTC_DCHECK(config_.rtp.local_ssrc != 0);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 config_.rtp.ulpfec.ulpfec_payload_type); 202 config_.rtp.ulpfec.ulpfec_payload_type);
186 } 203 }
187 204
188 if (config_.rtp.rtcp_xr.receiver_reference_time_report) 205 if (config_.rtp.rtcp_xr.receiver_reference_time_report)
189 rtp_rtcp_->SetRtcpXrRrtrStatus(true); 206 rtp_rtcp_->SetRtcpXrRrtrStatus(true);
190 207
191 // Stats callback for CNAME changes. 208 // Stats callback for CNAME changes.
192 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); 209 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
193 210
194 process_thread_->RegisterModule(rtp_rtcp_.get()); 211 process_thread_->RegisterModule(rtp_rtcp_.get());
212
213 jitter_buffer_experiment_ =
214 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == "Enabled";
215
216 if (jitter_buffer_experiment_) {
217 nack_module_.reset(
218 new NackModule(clock_, nack_sender, keyframe_request_sender));
219 process_thread_->RegisterModule(nack_module_.get());
220
221 packet_buffer_ = video_coding::PacketBuffer::Create(
222 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this);
223 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this));
224 }
195 } 225 }
196 226
197 RtpStreamReceiver::~RtpStreamReceiver() { 227 RtpStreamReceiver::~RtpStreamReceiver() {
198 process_thread_->DeRegisterModule(rtp_rtcp_.get()); 228 process_thread_->DeRegisterModule(rtp_rtcp_.get());
199 229
230 if (jitter_buffer_experiment_)
231 process_thread_->DeRegisterModule(nack_module_.get());
232
200 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); 233 packet_router_->RemoveRtpModule(rtp_rtcp_.get());
201 rtp_rtcp_->SetREMBStatus(false); 234 rtp_rtcp_->SetREMBStatus(false);
202 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); 235 remb_->RemoveReceiveChannel(rtp_rtcp_.get());
203 UpdateHistograms(); 236 UpdateHistograms();
204 } 237 }
205 238
206 bool RtpStreamReceiver::SetReceiveCodec(const VideoCodec& video_codec) { 239 bool RtpStreamReceiver::SetReceiveCodec(const VideoCodec& video_codec) {
207 int8_t old_pltype = -1; 240 int8_t old_pltype = -1;
208 if (rtp_payload_registry_.ReceivePayloadType( 241 if (rtp_payload_registry_.ReceivePayloadType(
209 video_codec.plName, kVideoPayloadTypeFrequency, 0, 242 video_codec.plName, kVideoPayloadTypeFrequency, 0,
(...skipping 19 matching lines...) Expand all
229 } 262 }
230 263
231 int32_t RtpStreamReceiver::OnReceivedPayloadData( 264 int32_t RtpStreamReceiver::OnReceivedPayloadData(
232 const uint8_t* payload_data, 265 const uint8_t* payload_data,
233 size_t payload_size, 266 size_t payload_size,
234 const WebRtcRTPHeader* rtp_header) { 267 const WebRtcRTPHeader* rtp_header) {
235 RTC_DCHECK(video_receiver_); 268 RTC_DCHECK(video_receiver_);
236 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; 269 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
237 rtp_header_with_ntp.ntp_time_ms = 270 rtp_header_with_ntp.ntp_time_ms =
238 ntp_estimator_.Estimate(rtp_header->header.timestamp); 271 ntp_estimator_.Estimate(rtp_header->header.timestamp);
239 if (video_receiver_->IncomingPacket(payload_data, payload_size, 272 if (jitter_buffer_experiment_) {
240 rtp_header_with_ntp) != 0) { 273 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp);
241 // Check this... 274 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds());
242 return -1; 275 packet.timesNacked = nack_module_->OnReceivedPacket(packet);
276
277 if (packet.codec == kVideoCodecH264) {
278 switch (tracker_.CopyAndFixBitstream(&packet)) {
279 case video_coding::H264SpsPpsTracker::kRequestKeyframe:
280 keyframe_request_sender_->RequestKeyFrame();
281 FALLTHROUGH();
282 case video_coding::H264SpsPpsTracker::kDrop:
283 return 0;
284 case video_coding::H264SpsPpsTracker::kInsert:
285 break;
286 }
287 } else {
288 uint8_t* data = new uint8_t[packet.sizeBytes];
289 memcpy(data, packet.dataPtr, packet.sizeBytes);
290 packet.dataPtr = data;
291 }
292
293 packet_buffer_->InsertPacket(packet);
294 } else {
295 if (video_receiver_->IncomingPacket(payload_data, payload_size,
296 rtp_header_with_ntp) != 0) {
297 // Check this...
298 return -1;
299 }
243 } 300 }
244 return 0; 301 return 0;
245 } 302 }
246 303
247 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, 304 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
248 size_t rtp_packet_length) { 305 size_t rtp_packet_length) {
249 RTPHeader header; 306 RTPHeader header;
250 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { 307 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
251 return false; 308 return false;
252 } 309 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 void RtpStreamReceiver::RequestPacketRetransmit( 407 void RtpStreamReceiver::RequestPacketRetransmit(
351 const std::vector<uint16_t>& sequence_numbers) { 408 const std::vector<uint16_t>& sequence_numbers) {
352 rtp_rtcp_->SendNack(sequence_numbers); 409 rtp_rtcp_->SendNack(sequence_numbers);
353 } 410 }
354 411
355 int32_t RtpStreamReceiver::ResendPackets(const uint16_t* sequence_numbers, 412 int32_t RtpStreamReceiver::ResendPackets(const uint16_t* sequence_numbers,
356 uint16_t length) { 413 uint16_t length) {
357 return rtp_rtcp_->SendNACK(sequence_numbers, length); 414 return rtp_rtcp_->SendNACK(sequence_numbers, length);
358 } 415 }
359 416
417 void RtpStreamReceiver::OnReceivedFrame(
418 std::unique_ptr<video_coding::RtpFrameObject> frame) {
419 reference_finder_->ManageFrame(std::move(frame));
420 }
421
422 void RtpStreamReceiver::OnCompleteFrame(
423 std::unique_ptr<video_coding::FrameObject> frame) {
424 {
425 rtc::CritScope lock(&last_seq_num_cs_);
426 video_coding::RtpFrameObject* rtp_frame =
427 static_cast<video_coding::RtpFrameObject*>(frame.get());
428 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num();
429 }
430 complete_frame_callback_->OnCompleteFrame(std::move(frame));
431 }
432
433 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
434 if (jitter_buffer_experiment_)
435 nack_module_->UpdateRtt(max_rtt_ms);
436 }
437
360 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, 438 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet,
361 size_t packet_length, 439 size_t packet_length,
362 const RTPHeader& header, 440 const RTPHeader& header,
363 bool in_order) { 441 bool in_order) {
364 if (rtp_payload_registry_.IsEncapsulated(header)) { 442 if (rtp_payload_registry_.IsEncapsulated(header)) {
365 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); 443 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
366 } 444 }
367 const uint8_t* payload = packet + header.headerLength; 445 const uint8_t* payload = packet + header.headerLength;
368 assert(packet_length >= header.headerLength); 446 assert(packet_length >= header.headerLength);
369 size_t payload_length = packet_length - header.headerLength; 447 size_t payload_length = packet_length - header.headerLength;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr, 552 if (rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr,
475 &rtp_timestamp) != 0) { 553 &rtp_timestamp) != 0) {
476 // Waiting for RTCP. 554 // Waiting for RTCP.
477 return true; 555 return true;
478 } 556 }
479 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); 557 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
480 558
481 return true; 559 return true;
482 } 560 }
483 561
562 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) {
563 if (jitter_buffer_experiment_) {
564 int seq_num = -1;
565 {
566 rtc::CritScope lock(&last_seq_num_cs_);
567 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
568 if (seq_num_it != last_seq_num_for_pic_id_.end())
569 seq_num = seq_num_it->second;
570 }
571 if (seq_num != -1)
572 nack_module_->ClearUpTo(seq_num);
573 }
574 }
575
576 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) {
577 if (jitter_buffer_experiment_) {
578 int seq_num = -1;
579 {
580 rtc::CritScope lock(&last_seq_num_cs_);
581 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
582 if (seq_num_it != last_seq_num_for_pic_id_.end()) {
583 seq_num = seq_num_it->second;
584 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(),
585 ++seq_num_it);
586 }
587 }
588 if (seq_num != -1) {
589 packet_buffer_->ClearTo(seq_num);
590 reference_finder_->ClearTo(seq_num);
591 }
592 }
593 }
594
484 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { 595 void RtpStreamReceiver::SignalNetworkState(NetworkState state) {
485 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode 596 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode
486 : RtcpMode::kOff); 597 : RtcpMode::kOff);
487 } 598 }
488 599
489 void RtpStreamReceiver::StartReceive() { 600 void RtpStreamReceiver::StartReceive() {
490 rtc::CritScope lock(&receive_cs_); 601 rtc::CritScope lock(&receive_cs_);
491 receiving_ = true; 602 receiving_ = true;
492 } 603 }
493 604
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 const std::string& extension, int id) { 649 const std::string& extension, int id) {
539 // One-byte-extension local identifiers are in the range 1-14 inclusive. 650 // One-byte-extension local identifiers are in the range 1-14 inclusive.
540 RTC_DCHECK_GE(id, 1); 651 RTC_DCHECK_GE(id, 1);
541 RTC_DCHECK_LE(id, 14); 652 RTC_DCHECK_LE(id, 14);
542 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); 653 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension));
543 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( 654 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
544 StringToRtpExtensionType(extension), id)); 655 StringToRtpExtensionType(extension), id));
545 } 656 }
546 657
547 } // namespace webrtc 658 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698