Simplify SetFecParameters signature.

- Change const ptr to const ref in parameter list.
  Using nullptr as argument was invalid, so no need to send
  pointer instead of reference.
- Change return type to void or bool, where appropriate

BUG=webrtc:5654

Review-Url: https://codereview.webrtc.org/2455963003
Cr-Commit-Position: refs/heads/master@{#14945}
This commit is contained in:
brandtr 2016-11-07 03:36:05 -08:00 committed by Commit bot
parent f1bb476050
commit 1743a19183
15 changed files with 52 additions and 39 deletions

View File

@ -17,6 +17,7 @@
#include <vector>
#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.

View File

@ -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());

View File

@ -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(&params);
ulpfec_generator_.SetFecParameters(params);
}
bool FlexfecSender::AddRtpPacketAndGenerateFec(

View File

@ -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);
}

View File

@ -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,

View File

@ -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<RtpPacketToSend> RTPSender::BuildRtxPacket(

View File

@ -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,

View File

@ -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));

View File

@ -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();

View File

@ -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;

View File

@ -120,13 +120,13 @@ std::unique_ptr<RedPacket> 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;

View File

@ -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.

View File

@ -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(&params);
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(&params); // 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<AugmentedPacket> packet =
@ -144,7 +144,7 @@ TEST_F(UlpfecGeneratorTest, TwoFrameFec) {
constexpr size_t kNumFrames = 2;
FecProtectionParams params = {15, 3, kFecMaskRandom};
ulpfec_generator_.SetFecParameters(&params); // 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);

View File

@ -29,7 +29,7 @@ void FuzzOneInput(const uint8_t* data, size_t size) {
return;
FecProtectionParams params = {
data[i++] % 128, static_cast<int>(data[i++] % 10), kFecMaskBursty};
generator.SetFecParameters(&params);
generator.SetFecParameters(params);
uint16_t seq_num = data[i++];
while (i + 3 < size) {

View File

@ -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(&not_used, &module_video_rate, &module_fec_rate,
&module_nack_rate);
*sent_video_rate_bps += module_video_rate;