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

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

Issue 2987933003: Eliminate RtpVideoStreamReceiver::receive_cs_ in favor of using a SequencedTaskChecker (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « webrtc/video/rtp_video_stream_receiver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 restored_packet_in_use_(false), 105 restored_packet_in_use_(false),
106 last_packet_log_ms_(-1), 106 last_packet_log_ms_(-1),
107 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), 107 rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(),
108 transport, 108 transport,
109 rtt_stats, 109 rtt_stats,
110 receive_stats_proxy, 110 receive_stats_proxy,
111 packet_router)), 111 packet_router)),
112 complete_frame_callback_(complete_frame_callback), 112 complete_frame_callback_(complete_frame_callback),
113 keyframe_request_sender_(keyframe_request_sender), 113 keyframe_request_sender_(keyframe_request_sender),
114 timing_(timing), 114 timing_(timing),
115 has_received_frame_(false) { 115 has_received_frame_(false) {
danilchap 2017/07/27 10:24:59 does constructor always run on the worker thread t
eladalon 2017/07/27 10:41:46 It always runs on it for non-tests, AFAIK.
116 packet_router_->AddReceiveRtpModule(rtp_rtcp_.get()); 116 packet_router_->AddReceiveRtpModule(rtp_rtcp_.get());
117 rtp_receive_statistics_->RegisterRtpStatisticsCallback(receive_stats_proxy); 117 rtp_receive_statistics_->RegisterRtpStatisticsCallback(receive_stats_proxy);
118 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(receive_stats_proxy); 118 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
119 119
120 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff) 120 RTC_DCHECK(config_.rtp.rtcp_mode != RtcpMode::kOff)
121 << "A stream should not be configured with RTCP disabled. This value is " 121 << "A stream should not be configured with RTCP disabled. This value is "
122 "reserved for internal usage."; 122 "reserved for internal usage.";
123 RTC_DCHECK(config_.rtp.remote_ssrc != 0); 123 RTC_DCHECK(config_.rtp.remote_ssrc != 0);
124 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams? 124 // TODO(pbos): What's an appropriate local_ssrc for receive-only streams?
125 RTC_DCHECK(config_.rtp.local_ssrc != 0); 125 RTC_DCHECK(config_.rtp.local_ssrc != 0);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 const int frequency, 301 const int frequency,
302 const size_t channels, 302 const size_t channels,
303 const uint32_t rate) { 303 const uint32_t rate) {
304 RTC_NOTREACHED(); 304 RTC_NOTREACHED();
305 return 0; 305 return 0;
306 } 306 }
307 307
308 // This method handles both regular RTP packets and packets recovered 308 // This method handles both regular RTP packets and packets recovered
309 // via FlexFEC. 309 // via FlexFEC.
310 void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) { 310 void RtpVideoStreamReceiver::OnRtpPacket(const RtpPacketReceived& packet) {
311 { 311 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
312 rtc::CritScope lock(&receive_cs_);
313 if (!receiving_) {
314 return;
315 }
316 312
317 if (!packet.recovered()) { 313 if (!receiving_) {
318 int64_t now_ms = clock_->TimeInMilliseconds(); 314 return;
315 }
319 316
320 // Periodically log the RTP header of incoming packets. 317 if (!packet.recovered()) {
321 if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) { 318 int64_t now_ms = clock_->TimeInMilliseconds();
322 std::stringstream ss; 319
323 ss << "Packet received on SSRC: " << packet.Ssrc() 320 // Periodically log the RTP header of incoming packets.
324 << " with payload type: " << static_cast<int>(packet.PayloadType()) 321 if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) {
325 << ", timestamp: " << packet.Timestamp() 322 std::stringstream ss;
326 << ", sequence number: " << packet.SequenceNumber() 323 ss << "Packet received on SSRC: " << packet.Ssrc()
327 << ", arrival time: " << packet.arrival_time_ms(); 324 << " with payload type: " << static_cast<int>(packet.PayloadType())
328 int32_t time_offset; 325 << ", timestamp: " << packet.Timestamp()
329 if (packet.GetExtension<TransmissionOffset>(&time_offset)) { 326 << ", sequence number: " << packet.SequenceNumber()
330 ss << ", toffset: " << time_offset; 327 << ", arrival time: " << packet.arrival_time_ms();
331 } 328 int32_t time_offset;
332 uint32_t send_time; 329 if (packet.GetExtension<TransmissionOffset>(&time_offset)) {
333 if (packet.GetExtension<AbsoluteSendTime>(&send_time)) { 330 ss << ", toffset: " << time_offset;
334 ss << ", abs send time: " << send_time;
335 }
336 LOG(LS_INFO) << ss.str();
337 last_packet_log_ms_ = now_ms;
338 } 331 }
332 uint32_t send_time;
333 if (packet.GetExtension<AbsoluteSendTime>(&send_time)) {
334 ss << ", abs send time: " << send_time;
335 }
336 LOG(LS_INFO) << ss.str();
337 last_packet_log_ms_ = now_ms;
339 } 338 }
340 } 339 }
341 340
342 // TODO(nisse): Delete use of GetHeader, but needs refactoring of 341 // TODO(nisse): Delete use of GetHeader, but needs refactoring of
343 // ReceivePacket and IncomingPacket methods below. 342 // ReceivePacket and IncomingPacket methods below.
344 RTPHeader header; 343 RTPHeader header;
345 packet.GetHeader(&header); 344 packet.GetHeader(&header);
346 345
347 header.payload_type_frequency = kVideoPayloadTypeFrequency; 346 header.payload_type_frequency = kVideoPayloadTypeFrequency;
348 347
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType, 442 if (!rtp_payload_registry_.GetPayloadSpecifics(header.payloadType,
444 &payload_specific)) { 443 &payload_specific)) {
445 return; 444 return;
446 } 445 }
447 rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, 446 rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
448 payload_specific, in_order); 447 payload_specific, in_order);
449 } 448 }
450 449
451 void RtpVideoStreamReceiver::ParseAndHandleEncapsulatingHeader( 450 void RtpVideoStreamReceiver::ParseAndHandleEncapsulatingHeader(
452 const uint8_t* packet, size_t packet_length, const RTPHeader& header) { 451 const uint8_t* packet, size_t packet_length, const RTPHeader& header) {
452 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
453
453 if (rtp_payload_registry_.IsRed(header)) { 454 if (rtp_payload_registry_.IsRed(header)) {
454 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type(); 455 int8_t ulpfec_pt = rtp_payload_registry_.ulpfec_payload_type();
455 if (packet[header.headerLength] == ulpfec_pt) { 456 if (packet[header.headerLength] == ulpfec_pt) {
456 rtp_receive_statistics_->FecPacketReceived(header, packet_length); 457 rtp_receive_statistics_->FecPacketReceived(header, packet_length);
457 // Notify video_receiver about received FEC packets to avoid NACKing these 458 // Notify video_receiver about received FEC packets to avoid NACKing these
458 // packets. 459 // packets.
459 NotifyReceiverOfFecPacket(header); 460 NotifyReceiverOfFecPacket(header);
460 } 461 }
461 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length, 462 if (ulpfec_receiver_->AddReceivedRedPacket(header, packet, packet_length,
462 ulpfec_pt) != 0) { 463 ulpfec_pt) != 0) {
463 return; 464 return;
464 } 465 }
465 ulpfec_receiver_->ProcessReceivedFec(); 466 ulpfec_receiver_->ProcessReceivedFec();
466 } else if (rtp_payload_registry_.IsRtx(header)) { 467 } else if (rtp_payload_registry_.IsRtx(header)) {
467 if (header.headerLength + header.paddingLength == packet_length) { 468 if (header.headerLength + header.paddingLength == packet_length) {
468 // This is an empty packet and should be silently dropped before trying to 469 // This is an empty packet and should be silently dropped before trying to
469 // parse the RTX header. 470 // parse the RTX header.
470 return; 471 return;
471 } 472 }
472 // Remove the RTX header and parse the original RTP header. 473 // Remove the RTX header and parse the original RTP header.
473 if (packet_length < header.headerLength) 474 if (packet_length < header.headerLength)
474 return; 475 return;
475 if (packet_length > sizeof(restored_packet_)) 476 if (packet_length > sizeof(restored_packet_))
476 return; 477 return;
477 rtc::CritScope lock(&receive_cs_);
478 if (restored_packet_in_use_) { 478 if (restored_packet_in_use_) {
479 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet."; 479 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet.";
480 return; 480 return;
481 } 481 }
482 if (!rtp_payload_registry_.RestoreOriginalPacket( 482 if (!rtp_payload_registry_.RestoreOriginalPacket(
483 restored_packet_, packet, &packet_length, config_.rtp.remote_ssrc, 483 restored_packet_, packet, &packet_length, config_.rtp.remote_ssrc,
484 header)) { 484 header)) {
485 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header ssrc: " 485 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header ssrc: "
486 << header.ssrc << " payload type: " 486 << header.ssrc << " payload type: "
487 << static_cast<int>(header.payloadType); 487 << static_cast<int>(header.payloadType);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 rtp_header.type.Video.video_timing = header.extension.video_timing; 526 rtp_header.type.Video.video_timing = header.extension.video_timing;
527 rtp_header.type.Video.video_timing.is_timing_frame = true; 527 rtp_header.type.Video.video_timing.is_timing_frame = true;
528 } 528 }
529 rtp_header.type.Video.playout_delay = header.extension.playout_delay; 529 rtp_header.type.Video.playout_delay = header.extension.playout_delay;
530 530
531 OnReceivedPayloadData(nullptr, 0, &rtp_header); 531 OnReceivedPayloadData(nullptr, 0, &rtp_header);
532 } 532 }
533 533
534 bool RtpVideoStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet, 534 bool RtpVideoStreamReceiver::DeliverRtcp(const uint8_t* rtcp_packet,
535 size_t rtcp_packet_length) { 535 size_t rtcp_packet_length) {
536 { 536 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
537 rtc::CritScope lock(&receive_cs_); 537
538 if (!receiving_) { 538 if (!receiving_) {
539 return false; 539 return false;
540 }
541 } 540 }
542 541
543 rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length); 542 rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
544 543
545 int64_t rtt = 0; 544 int64_t rtt = 0;
546 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, nullptr, nullptr, nullptr); 545 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, nullptr, nullptr, nullptr);
547 if (rtt == 0) { 546 if (rtt == 0) {
548 // Waiting for valid rtt. 547 // Waiting for valid rtt.
549 return true; 548 return true;
550 } 549 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 reference_finder_->ClearTo(seq_num); 591 reference_finder_->ClearTo(seq_num);
593 } 592 }
594 } 593 }
595 594
596 void RtpVideoStreamReceiver::SignalNetworkState(NetworkState state) { 595 void RtpVideoStreamReceiver::SignalNetworkState(NetworkState state) {
597 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode 596 rtp_rtcp_->SetRTCPStatus(state == kNetworkUp ? config_.rtp.rtcp_mode
598 : RtcpMode::kOff); 597 : RtcpMode::kOff);
599 } 598 }
600 599
601 void RtpVideoStreamReceiver::StartReceive() { 600 void RtpVideoStreamReceiver::StartReceive() {
602 rtc::CritScope lock(&receive_cs_); 601 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
603 receiving_ = true; 602 receiving_ = true;
604 } 603 }
605 604
606 void RtpVideoStreamReceiver::StopReceive() { 605 void RtpVideoStreamReceiver::StopReceive() {
607 rtc::CritScope lock(&receive_cs_); 606 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
608 receiving_ = false; 607 receiving_ = false;
609 } 608 }
610 609
611 bool RtpVideoStreamReceiver::IsPacketInOrder(const RTPHeader& header) const { 610 bool RtpVideoStreamReceiver::IsPacketInOrder(const RTPHeader& header) const {
612 StreamStatistician* statistician = 611 StreamStatistician* statistician =
613 rtp_receive_statistics_->GetStatistician(header.ssrc); 612 rtp_receive_statistics_->GetStatistician(header.ssrc);
614 if (!statistician) 613 if (!statistician)
615 return false; 614 return false;
616 return statistician->IsPacketInOrder(header.sequenceNumber); 615 return statistician->IsPacketInOrder(header.sequenceNumber);
617 } 616 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 return; 679 return;
681 680
682 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str())) 681 if (!sprop_decoder.DecodeSprop(sprop_base64_it->second.c_str()))
683 return; 682 return;
684 683
685 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(), 684 tracker_.InsertSpsPpsNalus(sprop_decoder.sps_nalu(),
686 sprop_decoder.pps_nalu()); 685 sprop_decoder.pps_nalu());
687 } 686 }
688 687
689 } // namespace webrtc 688 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/rtp_video_stream_receiver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698