diff --git a/webrtc/modules/rtp_rtcp/include/rtp_rtcp.h b/webrtc/modules/rtp_rtcp/include/rtp_rtcp.h index 68429c6748..fe88b1b674 100644 --- a/webrtc/modules/rtp_rtcp/include/rtp_rtcp.h +++ b/webrtc/modules/rtp_rtcp/include/rtp_rtcp.h @@ -17,6 +17,7 @@ #include #include "webrtc/base/constructormagic.h" +#include "webrtc/base/deprecation.h" #include "webrtc/modules/include/module.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/modules/video_coding/include/video_coding_defines.h" @@ -446,8 +447,15 @@ class RtpRtcp : public Module { virtual void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type) = 0; - virtual int32_t SetFecParameters(const FecProtectionParams* delta_params, - const FecProtectionParams* key_params) = 0; + // Set FEC rates, max frames before FEC is sent, and type of FEC masks. + // Returns false on failure. + virtual bool SetFecParameters(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params) = 0; + + // Deprecated version of member function above. + RTC_DEPRECATED + int32_t SetFecParameters(const FecProtectionParams* delta_params, + const FecProtectionParams* key_params); // Set method for requestion a new key frame. // Returns -1 on failure else 0. diff --git a/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h b/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h index ff8d90f6db..d39fce8ec1 100644 --- a/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h +++ b/webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h @@ -189,8 +189,8 @@ class MockRtpRtcp : public RtpRtcp { MOCK_METHOD2(SetUlpfecConfig, void(int red_payload_type, int fec_payload_type)); MOCK_METHOD2(SetFecParameters, - int32_t(const FecProtectionParams* delta_params, - const FecProtectionParams* key_params)); + bool(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params)); MOCK_METHOD1(SetKeyFrameRequestMethod, int32_t(KeyFrameRequestMethod method)); MOCK_METHOD0(RequestKeyFrame, int32_t()); MOCK_METHOD0(TimeUntilNextProcess, int64_t()); diff --git a/webrtc/modules/rtp_rtcp/source/flexfec_sender.cc b/webrtc/modules/rtp_rtcp/source/flexfec_sender.cc index 9f04161e52..55e8e52669 100644 --- a/webrtc/modules/rtp_rtcp/source/flexfec_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/flexfec_sender.cc @@ -91,7 +91,7 @@ FlexfecSender::~FlexfecSender() = default; // AddRtpPacketAndGenerateFec, and FecAvailable. void FlexfecSender::SetFecParameters(const FecProtectionParams& params) { RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); - ulpfec_generator_.SetFecParameters(¶ms); + ulpfec_generator_.SetFecParameters(params); } bool FlexfecSender::AddRtpPacketAndGenerateFec( diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 2a2bf0df4b..664bf3acd1 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -61,6 +61,14 @@ RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) { } } +// Deprecated. +int32_t RtpRtcp::SetFecParameters(const FecProtectionParams* delta_params, + const FecProtectionParams* key_params) { + RTC_DCHECK(delta_params); + RTC_DCHECK(key_params); + return SetFecParameters(*delta_params, *key_params) ? 0 : -1; +} + ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration) : rtp_sender_(configuration.audio, configuration.clock, @@ -794,9 +802,9 @@ void ModuleRtpRtcpImpl::SetUlpfecConfig(int red_payload_type, rtp_sender_.SetUlpfecConfig(red_payload_type, ulpfec_payload_type); } -int32_t ModuleRtpRtcpImpl::SetFecParameters( - const FecProtectionParams* delta_params, - const FecProtectionParams* key_params) { +bool ModuleRtpRtcpImpl::SetFecParameters( + const FecProtectionParams& delta_params, + const FecProtectionParams& key_params) { return rtp_sender_.SetFecParameters(delta_params, key_params); } diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h index f055bbe001..8cd47ed280 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -279,8 +279,8 @@ class ModuleRtpRtcpImpl : public RtpRtcp, public RTCPReceiver::ModuleRtpRtcp { void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type) override; - int32_t SetFecParameters(const FecProtectionParams* delta_params, - const FecProtectionParams* key_params) override; + bool SetFecParameters(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params) override; bool LastReceivedNTP(uint32_t* NTPsecs, uint32_t* NTPfrac, diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc index a3593c604e..fafbf11bae 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.cc @@ -1136,14 +1136,13 @@ void RTPSender::SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type) { video_->SetUlpfecConfig(red_payload_type, ulpfec_payload_type); } -int32_t RTPSender::SetFecParameters( - const FecProtectionParams *delta_params, - const FecProtectionParams *key_params) { +bool RTPSender::SetFecParameters(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params) { if (audio_configured_) { - return -1; + return false; } video_->SetFecParameters(delta_params, key_params); - return 0; + return true; } std::unique_ptr RTPSender::BuildRtxPacket( diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender.h b/webrtc/modules/rtp_rtcp/source/rtp_sender.h index dafddc59f1..c589d0bbbe 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender.h @@ -186,8 +186,8 @@ class RTPSender { // ULPFEC. void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type); - int32_t SetFecParameters(const FecProtectionParams *delta_params, - const FecProtectionParams *key_params); + bool SetFecParameters(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params); RTC_DEPRECATED size_t SendPadData(size_t bytes, diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc index fa8db8a4c4..d02d25eb21 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc @@ -1129,7 +1129,7 @@ TEST_F(RtpSenderTestWithoutPacer, StreamDataCountersCallbacks) { fec_params.fec_mask_type = kFecMaskRandom; fec_params.fec_rate = 1; fec_params.max_fec_frames = 1; - rtp_sender_->SetFecParameters(&fec_params, &fec_params); + rtp_sender_->SetFecParameters(fec_params, fec_params); ASSERT_TRUE(rtp_sender_->SendOutgoingData( kVideoFrameDelta, payload_type, 1234, 4321, payload, sizeof(payload), nullptr, nullptr, nullptr)); diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc index 2450a43d48..916561ea87 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -227,14 +227,12 @@ size_t RTPSenderVideo::FecPacketOverhead() const { return overhead; } -void RTPSenderVideo::SetFecParameters(const FecProtectionParams* delta_params, - const FecProtectionParams* key_params) { +void RTPSenderVideo::SetFecParameters(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params) { rtc::CritScope cs(&crit_); - RTC_DCHECK(delta_params); - RTC_DCHECK(key_params); if (ulpfec_enabled()) { - delta_fec_params_ = *delta_params; - key_fec_params_ = *key_params; + delta_fec_params_ = delta_params; + key_fec_params_ = key_params; } } @@ -292,8 +290,8 @@ bool RTPSenderVideo::SendVideo(RtpVideoCodecTypes video_type, bool first_frame = first_frame_sent_(); { rtc::CritScope cs(&crit_); - FecProtectionParams* fec_params = - frame_type == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_; + const FecProtectionParams& fec_params = + frame_type == kVideoFrameKey ? key_fec_params_ : delta_fec_params_; ulpfec_generator_.SetFecParameters(fec_params); storage = packetizer->GetStorageType(retransmission_settings_); red_enabled = this->red_enabled(); diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h index 2cb40e3397..56167eb6eb 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_video.h @@ -63,8 +63,8 @@ class RTPSenderVideo { void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type); void GetUlpfecConfig(int* red_payload_type, int* ulpfec_payload_type) const; - void SetFecParameters(const FecProtectionParams* delta_params, - const FecProtectionParams* key_params); + void SetFecParameters(const FecProtectionParams& delta_params, + const FecProtectionParams& key_params); uint32_t VideoBitrateSent() const; uint32_t FecOverheadRate() const; diff --git a/webrtc/modules/rtp_rtcp/source/ulpfec_generator.cc b/webrtc/modules/rtp_rtcp/source/ulpfec_generator.cc index c9de401d71..4c50e22291 100644 --- a/webrtc/modules/rtp_rtcp/source/ulpfec_generator.cc +++ b/webrtc/modules/rtp_rtcp/source/ulpfec_generator.cc @@ -120,13 +120,13 @@ std::unique_ptr UlpfecGenerator::BuildRedPacket( return red_packet; } -void UlpfecGenerator::SetFecParameters(const FecProtectionParams* params) { - RTC_DCHECK_GE(params->fec_rate, 0); - RTC_DCHECK_LE(params->fec_rate, 255); +void UlpfecGenerator::SetFecParameters(const FecProtectionParams& params) { + RTC_DCHECK_GE(params.fec_rate, 0); + RTC_DCHECK_LE(params.fec_rate, 255); // Store the new params and apply them for the next set of FEC packets being // produced. - new_params_ = *params; - if (params->fec_rate > kHighProtectionThreshold) { + new_params_ = params; + if (params.fec_rate > kHighProtectionThreshold) { min_num_media_packets_ = kMinMediaPackets; } else { min_num_media_packets_ = 1; diff --git a/webrtc/modules/rtp_rtcp/source/ulpfec_generator.h b/webrtc/modules/rtp_rtcp/source/ulpfec_generator.h index e5b6064ccc..faff58fff5 100644 --- a/webrtc/modules/rtp_rtcp/source/ulpfec_generator.h +++ b/webrtc/modules/rtp_rtcp/source/ulpfec_generator.h @@ -53,7 +53,7 @@ class UlpfecGenerator { size_t rtp_header_length, int red_payload_type); - void SetFecParameters(const FecProtectionParams* params); + void SetFecParameters(const FecProtectionParams& params); // Adds a media packet to the internal buffer. When enough media packets // have been added, the FEC packets are generated and stored internally. diff --git a/webrtc/modules/rtp_rtcp/source/ulpfec_generator_unittest.cc b/webrtc/modules/rtp_rtcp/source/ulpfec_generator_unittest.cc index 9b47ff5c61..3712a373a5 100644 --- a/webrtc/modules/rtp_rtcp/source/ulpfec_generator_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/ulpfec_generator_unittest.cc @@ -81,7 +81,7 @@ TEST_F(UlpfecGeneratorTest, NoEmptyFecWithSeqNumGaps) { protected_packets.push_back({21, 0, 55, 0}); protected_packets.push_back({13, 3, 57, 1}); FecProtectionParams params = {117, 3, kFecMaskBursty}; - ulpfec_generator_.SetFecParameters(¶ms); + ulpfec_generator_.SetFecParameters(params); uint8_t packet[28] = {0}; for (Packet p : protected_packets) { if (p.marker_bit) { @@ -112,7 +112,7 @@ TEST_F(UlpfecGeneratorTest, OneFrameFec) { constexpr size_t kNumPackets = 4; FecProtectionParams params = {15, 3, kFecMaskRandom}; packet_generator_.NewFrame(kNumPackets); - ulpfec_generator_.SetFecParameters(¶ms); // Expecting one FEC packet. + ulpfec_generator_.SetFecParameters(params); // Expecting one FEC packet. uint32_t last_timestamp = 0; for (size_t i = 0; i < kNumPackets; ++i) { std::unique_ptr packet = @@ -144,7 +144,7 @@ TEST_F(UlpfecGeneratorTest, TwoFrameFec) { constexpr size_t kNumFrames = 2; FecProtectionParams params = {15, 3, kFecMaskRandom}; - ulpfec_generator_.SetFecParameters(¶ms); // Expecting one FEC packet. + ulpfec_generator_.SetFecParameters(params); // Expecting one FEC packet. uint32_t last_timestamp = 0; for (size_t i = 0; i < kNumFrames; ++i) { packet_generator_.NewFrame(kNumPackets); diff --git a/webrtc/test/fuzzers/ulpfec_generator_fuzzer.cc b/webrtc/test/fuzzers/ulpfec_generator_fuzzer.cc index fd1adc70c6..ce9e30acca 100644 --- a/webrtc/test/fuzzers/ulpfec_generator_fuzzer.cc +++ b/webrtc/test/fuzzers/ulpfec_generator_fuzzer.cc @@ -29,7 +29,7 @@ void FuzzOneInput(const uint8_t* data, size_t size) { return; FecProtectionParams params = { data[i++] % 128, static_cast(data[i++] % 10), kFecMaskBursty}; - generator.SetFecParameters(¶ms); + generator.SetFecParameters(params); uint16_t seq_num = data[i++]; while (i + 3 < size) { diff --git a/webrtc/video/video_send_stream.cc b/webrtc/video/video_send_stream.cc index 98baf05677..827b54b83f 100644 --- a/webrtc/video/video_send_stream.cc +++ b/webrtc/video/video_send_stream.cc @@ -1112,7 +1112,7 @@ int VideoSendStreamImpl::ProtectionRequest( uint32_t module_video_rate = 0; uint32_t module_fec_rate = 0; uint32_t module_nack_rate = 0; - rtp_rtcp->SetFecParameters(delta_params, key_params); + rtp_rtcp->SetFecParameters(*delta_params, *key_params); rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, &module_nack_rate); *sent_video_rate_bps += module_video_rate;