diff --git a/call/video_receive_stream.h b/call/video_receive_stream.h index 3d54d31d1e..998710d044 100644 --- a/call/video_receive_stream.h +++ b/call/video_receive_stream.h @@ -294,6 +294,10 @@ class VideoReceiveStreamInterface : public MediaReceiveStreamInterface { // thread` but will be `network thread`. virtual void SetFlexFecProtection(RtpPacketSinkInterface* flexfec_sink) = 0; + // Turns on/off loss notifications. Must be called on the packet delivery + // thread. + virtual void SetLossNotificationEnabled(bool enabled) = 0; + protected: virtual ~VideoReceiveStreamInterface() {} }; diff --git a/media/engine/fake_webrtc_call.h b/media/engine/fake_webrtc_call.h index eef15bfd80..9276a78784 100644 --- a/media/engine/fake_webrtc_call.h +++ b/media/engine/fake_webrtc_call.h @@ -289,6 +289,10 @@ class FakeVideoReceiveStream final config_.rtp.protected_by_flexfec = (sink != nullptr); } + void SetLossNotificationEnabled(bool enabled) override { + config_.rtp.lntf.enabled = enabled; + } + void Start() override; void Stop() override; diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 529338ccd7..a7c6024ec2 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -2985,7 +2985,7 @@ bool WebRtcVideoChannel::WebRtcVideoReceiveStream::ReconfigureCodecs( const bool has_lntf = HasLntf(codec.codec); if (config_.rtp.lntf.enabled != has_lntf) { config_.rtp.lntf.enabled = has_lntf; - recreate_needed = true; + stream_->SetLossNotificationEnabled(has_lntf); } const int rtp_history_ms = HasNack(codec.codec) ? kNackHistoryMs : 0; @@ -3060,23 +3060,26 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetFeedbackParameters( } } + config_.rtp.lntf.enabled = lntf_enabled; + stream_->SetLossNotificationEnabled(lntf_enabled); + int nack_history_ms = nack_enabled ? rtx_time != -1 ? rtx_time : kNackHistoryMs : 0; - if (config_.rtp.lntf.enabled == lntf_enabled && - config_.rtp.nack.rtp_history_ms == nack_history_ms) { + if (config_.rtp.nack.rtp_history_ms == nack_history_ms) { RTC_LOG(LS_INFO) << "Ignoring call to SetFeedbackParameters because parameters are " - "unchanged; lntf=" - << lntf_enabled << ", nack=" << nack_enabled - << ", rtx_time=" << rtx_time; + "unchanged; nack=" + << nack_enabled << ", rtx_time=" << rtx_time; return; } - config_.rtp.lntf.enabled = lntf_enabled; + RTC_LOG_F(LS_INFO) << "(recv) because of SetFeedbackParameters; nack=" + << nack_enabled << ". rtp_history_ms " + << config_.rtp.nack.rtp_history_ms << "->" + << nack_history_ms; + config_.rtp.nack.rtp_history_ms = nack_history_ms; - RTC_LOG_F(LS_INFO) << "(recv) because of SetFeedbackParameters; nack=" - << nack_enabled; RecreateReceiveStream(); } diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc index 2ac51697e4..2fe72d14ec 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -202,6 +202,11 @@ void RtpVideoStreamReceiver2::RtcpFeedbackBuffer::SendBufferedRtcpFeedback() { } } +void RtpVideoStreamReceiver2::RtcpFeedbackBuffer::ClearLossNotificationState() { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); + lntf_state_.reset(); +} + RtpVideoStreamReceiver2::RtpVideoStreamReceiver2( TaskQueueBase* current_queue, Clock* clock, @@ -935,6 +940,18 @@ void RtpVideoStreamReceiver2::SetPacketSink( packet_sink_ = packet_sink; } +void RtpVideoStreamReceiver2::SetLossNotificationEnabled(bool enabled) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); + if (enabled && !loss_notification_controller_) { + loss_notification_controller_ = + std::make_unique(&rtcp_feedback_buffer_, + &rtcp_feedback_buffer_); + } else if (!enabled && loss_notification_controller_) { + loss_notification_controller_.reset(); + rtcp_feedback_buffer_.ClearLossNotificationState(); + } +} + absl::optional RtpVideoStreamReceiver2::LastReceivedPacketMs() const { RTC_DCHECK_RUN_ON(&packet_sequence_checker_); if (last_received_rtp_system_time_) { diff --git a/video/rtp_video_stream_receiver2.h b/video/rtp_video_stream_receiver2.h index d416afd700..dff3bfcf38 100644 --- a/video/rtp_video_stream_receiver2.h +++ b/video/rtp_video_stream_receiver2.h @@ -194,6 +194,10 @@ class RtpVideoStreamReceiver2 : public LossNotificationSender, // thread` but will be `network thread`. void SetPacketSink(RtpPacketSinkInterface* packet_sink); + // Turns on/off loss notifications. Must be called on the packet delivery + // thread. + void SetLossNotificationEnabled(bool enabled); + absl::optional LastReceivedPacketMs() const; absl::optional LastReceivedKeyframePacketMs() const; @@ -236,6 +240,8 @@ class RtpVideoStreamReceiver2 : public LossNotificationSender, // Send all RTCP feedback messages buffered thus far. void SendBufferedRtcpFeedback(); + void ClearLossNotificationState(); + private: // LNTF-related state. struct LossNotificationState { @@ -336,7 +342,8 @@ class RtpVideoStreamReceiver2 : public LossNotificationSender, RtcpFeedbackBuffer rtcp_feedback_buffer_; const std::unique_ptr nack_module_; - std::unique_ptr loss_notification_controller_; + std::unique_ptr loss_notification_controller_ + RTC_GUARDED_BY(packet_sequence_checker_); video_coding::PacketBuffer packet_buffer_ RTC_GUARDED_BY(packet_sequence_checker_); diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc index 969e6511dd..f84b981dcb 100644 --- a/video/video_receive_stream2.cc +++ b/video/video_receive_stream2.cc @@ -517,6 +517,13 @@ void VideoReceiveStream2::SetFlexFecProtection( (flexfec_sink != nullptr); } +void VideoReceiveStream2::SetLossNotificationEnabled(bool enabled) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); + // TODO(tommi): Stop using the config struct for the internal state. + const_cast(config_.rtp.lntf.enabled) = enabled; + rtp_video_stream_receiver_.SetLossNotificationEnabled(enabled); +} + void VideoReceiveStream2::CreateAndRegisterExternalDecoder( const Decoder& decoder) { TRACE_EVENT0("webrtc", diff --git a/video/video_receive_stream2.h b/video/video_receive_stream2.h index ca0db1e3ba..79bd6caf5a 100644 --- a/video/video_receive_stream2.h +++ b/video/video_receive_stream2.h @@ -147,6 +147,7 @@ class VideoReceiveStream2 void SetTransportCc(bool transport_cc) override; void SetRtcpMode(RtcpMode mode) override; void SetFlexFecProtection(RtpPacketSinkInterface* flexfec_sink) override; + void SetLossNotificationEnabled(bool enabled) override; webrtc::VideoReceiveStreamInterface::Stats GetStats() const override;