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

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

Issue 2627463004: Make the new jitter buffer the default jitter buffer. (Closed)
Patch Set: Offline feedback. Created 3 years, 11 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
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 193
194 if (config_.rtp.rtcp_xr.receiver_reference_time_report) 194 if (config_.rtp.rtcp_xr.receiver_reference_time_report)
195 rtp_rtcp_->SetRtcpXrRrtrStatus(true); 195 rtp_rtcp_->SetRtcpXrRrtrStatus(true);
196 196
197 // Stats callback for CNAME changes. 197 // Stats callback for CNAME changes.
198 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); 198 rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
199 199
200 process_thread_->RegisterModule(rtp_rtcp_.get()); 200 process_thread_->RegisterModule(rtp_rtcp_.get());
201 201
202 jitter_buffer_experiment_ = 202 nack_module_.reset(
203 field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") == "Enabled"; 203 new NackModule(clock_, nack_sender, keyframe_request_sender));
stefan-webrtc 2017/01/12 14:16:16 Move to initializer list if possible.
philipel 2017/01/12 16:41:35 I think it's better to do clean up in followup CLs
204 process_thread_->RegisterModule(nack_module_.get());
204 205
205 if (jitter_buffer_experiment_) { 206 packet_buffer_ = video_coding::PacketBuffer::Create(
stefan-webrtc 2017/01/12 14:16:16 Same here.
206 nack_module_.reset( 207 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this);
207 new NackModule(clock_, nack_sender, keyframe_request_sender)); 208 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this));
stefan-webrtc 2017/01/12 14:16:16 and here.
208 process_thread_->RegisterModule(nack_module_.get());
209
210 packet_buffer_ = video_coding::PacketBuffer::Create(
211 clock_, kPacketBufferStartSize, kPacketBufferMaxSixe, this);
212 reference_finder_.reset(new video_coding::RtpFrameReferenceFinder(this));
213 }
214 } 209 }
215 210
216 RtpStreamReceiver::~RtpStreamReceiver() { 211 RtpStreamReceiver::~RtpStreamReceiver() {
217 process_thread_->DeRegisterModule(rtp_rtcp_.get()); 212 process_thread_->DeRegisterModule(rtp_rtcp_.get());
218 213
219 if (jitter_buffer_experiment_) 214 process_thread_->DeRegisterModule(nack_module_.get());
220 process_thread_->DeRegisterModule(nack_module_.get());
221 215
222 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); 216 packet_router_->RemoveRtpModule(rtp_rtcp_.get());
223 rtp_rtcp_->SetREMBStatus(false); 217 rtp_rtcp_->SetREMBStatus(false);
224 remb_->RemoveReceiveChannel(rtp_rtcp_.get()); 218 remb_->RemoveReceiveChannel(rtp_rtcp_.get());
225 UpdateHistograms(); 219 UpdateHistograms();
226 } 220 }
227 221
228 bool RtpStreamReceiver::AddReceiveCodec( 222 bool RtpStreamReceiver::AddReceiveCodec(
229 const VideoCodec& video_codec, 223 const VideoCodec& video_codec,
230 const std::map<std::string, std::string>& codec_params) { 224 const std::map<std::string, std::string>& codec_params) {
(...skipping 23 matching lines...) Expand all
254 } 248 }
255 249
256 int32_t RtpStreamReceiver::OnReceivedPayloadData( 250 int32_t RtpStreamReceiver::OnReceivedPayloadData(
257 const uint8_t* payload_data, 251 const uint8_t* payload_data,
258 size_t payload_size, 252 size_t payload_size,
259 const WebRtcRTPHeader* rtp_header) { 253 const WebRtcRTPHeader* rtp_header) {
260 RTC_DCHECK(video_receiver_); 254 RTC_DCHECK(video_receiver_);
261 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header; 255 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
262 rtp_header_with_ntp.ntp_time_ms = 256 rtp_header_with_ntp.ntp_time_ms =
263 ntp_estimator_.Estimate(rtp_header->header.timestamp); 257 ntp_estimator_.Estimate(rtp_header->header.timestamp);
264 if (jitter_buffer_experiment_) { 258 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp);
265 VCMPacket packet(payload_data, payload_size, rtp_header_with_ntp); 259 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds());
266 timing_->IncomingTimestamp(packet.timestamp, clock_->TimeInMilliseconds()); 260 packet.timesNacked = nack_module_->OnReceivedPacket(packet);
267 packet.timesNacked = nack_module_->OnReceivedPacket(packet);
268 261
269 if (packet.codec == kVideoCodecH264) { 262 if (packet.codec == kVideoCodecH264) {
270 // Only when we start to receive packets will we know what payload type 263 // Only when we start to receive packets will we know what payload type
271 // that will be used. When we know the payload type insert the correct 264 // that will be used. When we know the payload type insert the correct
272 // sps/pps into the tracker. 265 // sps/pps into the tracker.
273 if (packet.payloadType != last_payload_type_) { 266 if (packet.payloadType != last_payload_type_) {
274 last_payload_type_ = packet.payloadType; 267 last_payload_type_ = packet.payloadType;
275 InsertSpsPpsIntoTracker(packet.payloadType); 268 InsertSpsPpsIntoTracker(packet.payloadType);
276 }
277
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 } 269 }
292 270
293 packet_buffer_->InsertPacket(&packet); 271 switch (tracker_.CopyAndFixBitstream(&packet)) {
272 case video_coding::H264SpsPpsTracker::kRequestKeyframe:
273 keyframe_request_sender_->RequestKeyFrame();
274 FALLTHROUGH();
275 case video_coding::H264SpsPpsTracker::kDrop:
276 return 0;
277 case video_coding::H264SpsPpsTracker::kInsert:
278 break;
279 }
294 } else { 280 } else {
295 if (video_receiver_->IncomingPacket(payload_data, payload_size, 281 uint8_t* data = new uint8_t[packet.sizeBytes];
296 rtp_header_with_ntp) != 0) { 282 memcpy(data, packet.dataPtr, packet.sizeBytes);
297 // Check this... 283 packet.dataPtr = data;
298 return -1;
299 }
300 } 284 }
285
286 packet_buffer_->InsertPacket(&packet);
301 return 0; 287 return 0;
302 } 288 }
303 289
304 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet, 290 bool RtpStreamReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
305 size_t rtp_packet_length) { 291 size_t rtp_packet_length) {
306 RTPHeader header; 292 RTPHeader header;
307 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { 293 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
308 return false; 294 return false;
309 } 295 }
310 header.payload_type_frequency = kVideoPayloadTypeFrequency; 296 header.payload_type_frequency = kVideoPayloadTypeFrequency;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 { 413 {
428 rtc::CritScope lock(&last_seq_num_cs_); 414 rtc::CritScope lock(&last_seq_num_cs_);
429 video_coding::RtpFrameObject* rtp_frame = 415 video_coding::RtpFrameObject* rtp_frame =
430 static_cast<video_coding::RtpFrameObject*>(frame.get()); 416 static_cast<video_coding::RtpFrameObject*>(frame.get());
431 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num(); 417 last_seq_num_for_pic_id_[rtp_frame->picture_id] = rtp_frame->last_seq_num();
432 } 418 }
433 complete_frame_callback_->OnCompleteFrame(std::move(frame)); 419 complete_frame_callback_->OnCompleteFrame(std::move(frame));
434 } 420 }
435 421
436 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 422 void RtpStreamReceiver::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
437 if (jitter_buffer_experiment_) 423 nack_module_->UpdateRtt(max_rtt_ms);
438 nack_module_->UpdateRtt(max_rtt_ms);
439 } 424 }
440 425
441 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet, 426 bool RtpStreamReceiver::ReceivePacket(const uint8_t* packet,
442 size_t packet_length, 427 size_t packet_length,
443 const RTPHeader& header, 428 const RTPHeader& header,
444 bool in_order) { 429 bool in_order) {
445 if (rtp_payload_registry_.IsEncapsulated(header)) { 430 if (rtp_payload_registry_.IsEncapsulated(header)) {
446 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header); 431 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
447 } 432 }
448 const uint8_t* payload = packet + header.headerLength; 433 const uint8_t* payload = packet + header.headerLength;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 &rtp_timestamp) != 0) { 541 &rtp_timestamp) != 0) {
557 // Waiting for RTCP. 542 // Waiting for RTCP.
558 return true; 543 return true;
559 } 544 }
560 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); 545 ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
561 546
562 return true; 547 return true;
563 } 548 }
564 549
565 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) { 550 void RtpStreamReceiver::FrameContinuous(uint16_t picture_id) {
566 if (jitter_buffer_experiment_) { 551 int seq_num = -1;
567 int seq_num = -1; 552 {
568 { 553 rtc::CritScope lock(&last_seq_num_cs_);
569 rtc::CritScope lock(&last_seq_num_cs_); 554 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
570 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); 555 if (seq_num_it != last_seq_num_for_pic_id_.end())
571 if (seq_num_it != last_seq_num_for_pic_id_.end()) 556 seq_num = seq_num_it->second;
572 seq_num = seq_num_it->second;
573 }
574 if (seq_num != -1)
575 nack_module_->ClearUpTo(seq_num);
576 } 557 }
558 if (seq_num != -1)
559 nack_module_->ClearUpTo(seq_num);
577 } 560 }
578 561
579 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) { 562 void RtpStreamReceiver::FrameDecoded(uint16_t picture_id) {
580 if (jitter_buffer_experiment_) { 563 int seq_num = -1;
581 int seq_num = -1; 564 {
582 { 565 rtc::CritScope lock(&last_seq_num_cs_);
583 rtc::CritScope lock(&last_seq_num_cs_); 566 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id);
584 auto seq_num_it = last_seq_num_for_pic_id_.find(picture_id); 567 if (seq_num_it != last_seq_num_for_pic_id_.end()) {
585 if (seq_num_it != last_seq_num_for_pic_id_.end()) { 568 seq_num = seq_num_it->second;
586 seq_num = seq_num_it->second; 569 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(),
587 last_seq_num_for_pic_id_.erase(last_seq_num_for_pic_id_.begin(), 570 ++seq_num_it);
588 ++seq_num_it);
589 }
590 } 571 }
591 if (seq_num != -1) { 572 }
592 packet_buffer_->ClearTo(seq_num); 573 if (seq_num != -1) {
593 reference_finder_->ClearTo(seq_num); 574 packet_buffer_->ClearTo(seq_num);
594 } 575 reference_finder_->ClearTo(seq_num);
595 } 576 }
596 } 577 }
597 578
598 void RtpStreamReceiver::SignalNetworkState(NetworkState state) { 579 void RtpStreamReceiver::SignalNetworkState(NetworkState state) {
599 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode 580 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode
600 : RtcpMode::kOff); 581 : RtcpMode::kOff);
601 } 582 }
602 583
603 void RtpStreamReceiver::StartReceive() { 584 void RtpStreamReceiver::StartReceive() {
604 rtc::CritScope lock(&receive_cs_); 585 rtc::CritScope lock(&receive_cs_);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 if (sprop_base64_it == codec_params_it->second.end()) 662 if (sprop_base64_it == codec_params_it->second.end())
682 return; 663 return;
683 664
684 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second)) 665 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second))
685 return; 666 return;
686 667
687 tracker_.InsertSpsPps(sprop_decoder.sps_nalu(), sprop_decoder.pps_nalu()); 668 tracker_.InsertSpsPps(sprop_decoder.sps_nalu(), sprop_decoder.pps_nalu());
688 } 669 }
689 670
690 } // namespace webrtc 671 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698