Replace more instances of rtc::RefCountedObject with make_ref_counted.
This is essentially replacing `new rtc::RefCountedObject` with
`rtc::make_ref_counted` in many files. In a couple of places I
made minor tweaks to make things compile such as adding parenthesis
when they were missing.
Bug: webrtc:12701
Change-Id: I3828dbf3ee0eb0232f3a47067474484ac2f4aed2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215973
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33852}
diff --git a/modules/audio_coding/neteq/decoder_database_unittest.cc b/modules/audio_coding/neteq/decoder_database_unittest.cc
index c1b92b5..33bee8d 100644
--- a/modules/audio_coding/neteq/decoder_database_unittest.cc
+++ b/modules/audio_coding/neteq/decoder_database_unittest.cc
@@ -27,15 +27,14 @@
namespace webrtc {
TEST(DecoderDatabase, CreateAndDestroy) {
- DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>,
+ DecoderDatabase db(rtc::make_ref_counted<MockAudioDecoderFactory>(),
absl::nullopt);
EXPECT_EQ(0, db.Size());
EXPECT_TRUE(db.Empty());
}
TEST(DecoderDatabase, InsertAndRemove) {
- rtc::scoped_refptr<MockAudioDecoderFactory> factory(
- new rtc::RefCountedObject<MockAudioDecoderFactory>);
+ auto factory = rtc::make_ref_counted<MockAudioDecoderFactory>();
DecoderDatabase db(factory, absl::nullopt);
const uint8_t kPayloadType = 0;
const std::string kCodecName = "Robert\'); DROP TABLE Students;";
@@ -50,8 +49,7 @@
}
TEST(DecoderDatabase, InsertAndRemoveAll) {
- rtc::scoped_refptr<MockAudioDecoderFactory> factory(
- new rtc::RefCountedObject<MockAudioDecoderFactory>);
+ auto factory = rtc::make_ref_counted<MockAudioDecoderFactory>();
DecoderDatabase db(factory, absl::nullopt);
const std::string kCodecName1 = "Robert\'); DROP TABLE Students;";
const std::string kCodecName2 = "https://xkcd.com/327/";
@@ -67,8 +65,7 @@
}
TEST(DecoderDatabase, GetDecoderInfo) {
- rtc::scoped_refptr<MockAudioDecoderFactory> factory(
- new rtc::RefCountedObject<MockAudioDecoderFactory>);
+ auto factory = rtc::make_ref_counted<MockAudioDecoderFactory>();
auto* decoder = new MockAudioDecoder;
EXPECT_CALL(*factory, MakeAudioDecoderMock(_, _, _))
.WillOnce(Invoke([decoder](const SdpAudioFormat& format,
@@ -103,8 +100,7 @@
}
TEST(DecoderDatabase, TypeTests) {
- rtc::scoped_refptr<MockAudioDecoderFactory> factory(
- new rtc::RefCountedObject<MockAudioDecoderFactory>);
+ auto factory = rtc::make_ref_counted<MockAudioDecoderFactory>();
DecoderDatabase db(factory, absl::nullopt);
const uint8_t kPayloadTypePcmU = 0;
const uint8_t kPayloadTypeCng = 13;
@@ -140,8 +136,7 @@
TEST(DecoderDatabase, CheckPayloadTypes) {
constexpr int kNumPayloads = 10;
- rtc::scoped_refptr<MockAudioDecoderFactory> factory(
- new rtc::RefCountedObject<MockAudioDecoderFactory>);
+ auto factory = rtc::make_ref_counted<MockAudioDecoderFactory>();
DecoderDatabase db(factory, absl::nullopt);
// Load a number of payloads into the database. Payload types are 0, 1, ...,
// while the decoder type is the same for all payload types (this does not
diff --git a/modules/audio_coding/neteq/neteq_decoder_plc_unittest.cc b/modules/audio_coding/neteq/neteq_decoder_plc_unittest.cc
index cb0a3d8..2b4ae7e 100644
--- a/modules/audio_coding/neteq/neteq_decoder_plc_unittest.cc
+++ b/modules/audio_coding/neteq/neteq_decoder_plc_unittest.cc
@@ -208,7 +208,7 @@
NetEqTest neteq_test(
config, /*decoder_factory=*/
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&dec),
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&dec),
/*codecs=*/decoders, /*text_log=*/nullptr, /*neteq_factory=*/nullptr,
/*input=*/std::move(lossy_input), std::move(output), callbacks);
EXPECT_LE(kRunTimeMs, neteq_test.Run());
diff --git a/modules/audio_coding/neteq/neteq_impl_unittest.cc b/modules/audio_coding/neteq/neteq_impl_unittest.cc
index a073d82..c2a2bee 100644
--- a/modules/audio_coding/neteq/neteq_impl_unittest.cc
+++ b/modules/audio_coding/neteq/neteq_impl_unittest.cc
@@ -303,8 +303,7 @@
fake_packet.sequence_number = kFirstSequenceNumber;
fake_packet.timestamp = kFirstTimestamp;
- rtc::scoped_refptr<MockAudioDecoderFactory> mock_decoder_factory(
- new rtc::RefCountedObject<MockAudioDecoderFactory>);
+ auto mock_decoder_factory = rtc::make_ref_counted<MockAudioDecoderFactory>();
EXPECT_CALL(*mock_decoder_factory, MakeAudioDecoderMock(_, _, _))
.WillOnce(Invoke([&](const SdpAudioFormat& format,
absl::optional<AudioCodecPairId> codec_pair_id,
@@ -487,8 +486,8 @@
int16_t next_value_;
} decoder_;
- rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&decoder_);
+ auto decoder_factory =
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&decoder_);
UseNoMocks();
CreateInstance(decoder_factory);
@@ -555,7 +554,7 @@
MockAudioDecoder mock_decoder;
CreateInstance(
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&mock_decoder));
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&mock_decoder));
const uint8_t kPayloadType = 17; // Just an arbitrary number.
const int kSampleRateHz = 8000;
@@ -927,7 +926,7 @@
// Create a mock decoder object.
MockAudioDecoder mock_decoder;
CreateInstance(
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&mock_decoder));
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&mock_decoder));
const uint8_t kPayloadType = 17; // Just an arbitrary number.
const int kSampleRateKhz = 48;
@@ -1066,7 +1065,7 @@
::testing::NiceMock<MockAudioDecoder> decoder;
CreateInstance(
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&decoder));
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&decoder));
static const size_t kNetEqMaxFrameSize = 5760; // 120 ms @ 48 kHz.
static const size_t kChannels = 2;
@@ -1193,7 +1192,7 @@
MockAudioDecoder mock_decoder;
CreateInstance(
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&mock_decoder));
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&mock_decoder));
const uint8_t kPayloadType = 17; // Just an arbitrary number.
const int kSampleRateHz = 8000;
@@ -1252,7 +1251,7 @@
MockAudioDecoder mock_decoder;
CreateInstance(
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&mock_decoder));
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&mock_decoder));
const uint8_t kPayloadType = 17; // Just an arbitrary number.
const int kSampleRateHz = 8000;
@@ -1364,7 +1363,7 @@
// Create a mock decoder object.
MockAudioDecoder mock_decoder;
CreateInstance(
- new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(&mock_decoder));
+ rtc::make_ref_counted<test::AudioDecoderProxyFactory>(&mock_decoder));
const uint8_t kPayloadType = 17; // Just an arbitrary number.
const int kSampleRateHz = 8000;
@@ -1658,14 +1657,13 @@
void Register120msCodec(AudioDecoder::SpeechType speech_type) {
const uint32_t sampling_freq = kSamplingFreq_;
- decoder_factory_ =
- new rtc::RefCountedObject<test::FunctionAudioDecoderFactory>(
- [sampling_freq, speech_type]() {
- std::unique_ptr<AudioDecoder> decoder =
- std::make_unique<Decoder120ms>(sampling_freq, speech_type);
- RTC_CHECK_EQ(2, decoder->Channels());
- return decoder;
- });
+ decoder_factory_ = rtc::make_ref_counted<test::FunctionAudioDecoderFactory>(
+ [sampling_freq, speech_type]() {
+ std::unique_ptr<AudioDecoder> decoder =
+ std::make_unique<Decoder120ms>(sampling_freq, speech_type);
+ RTC_CHECK_EQ(2, decoder->Channels());
+ return decoder;
+ });
}
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
diff --git a/modules/audio_coding/neteq/neteq_network_stats_unittest.cc b/modules/audio_coding/neteq/neteq_network_stats_unittest.cc
index 5f15bab..8f72734 100644
--- a/modules/audio_coding/neteq/neteq_network_stats_unittest.cc
+++ b/modules/audio_coding/neteq/neteq_network_stats_unittest.cc
@@ -162,7 +162,7 @@
NetEqNetworkStatsTest(const SdpAudioFormat& format, MockAudioDecoder* decoder)
: decoder_(decoder),
decoder_factory_(
- new rtc::RefCountedObject<AudioDecoderProxyFactory>(decoder)),
+ rtc::make_ref_counted<AudioDecoderProxyFactory>(decoder)),
samples_per_ms_(format.clockrate_hz / 1000),
frame_size_samples_(kFrameSizeMs * samples_per_ms_),
rtp_generator_(new RtpGenerator(samples_per_ms_)),
diff --git a/modules/audio_coding/neteq/red_payload_splitter_unittest.cc b/modules/audio_coding/neteq/red_payload_splitter_unittest.cc
index 5956971..1cf6167 100644
--- a/modules/audio_coding/neteq/red_payload_splitter_unittest.cc
+++ b/modules/audio_coding/neteq/red_payload_splitter_unittest.cc
@@ -298,7 +298,7 @@
// easier to just register the payload types and let the actual implementation
// do its job.
DecoderDatabase decoder_database(
- new rtc::RefCountedObject<MockAudioDecoderFactory>, absl::nullopt);
+ rtc::make_ref_counted<MockAudioDecoderFactory>(), absl::nullopt);
decoder_database.RegisterPayload(0, SdpAudioFormat("cn", 8000, 1));
decoder_database.RegisterPayload(1, SdpAudioFormat("pcmu", 8000, 1));
decoder_database.RegisterPayload(2,
@@ -333,7 +333,7 @@
// easier to just register the payload types and let the actual implementation
// do its job.
DecoderDatabase decoder_database(
- new rtc::RefCountedObject<MockAudioDecoderFactory>, absl::nullopt);
+ rtc::make_ref_counted<MockAudioDecoderFactory>(), absl::nullopt);
decoder_database.RegisterPayload(kRedPayloadType,
SdpAudioFormat("red", 8000, 1));
diff --git a/modules/audio_coding/neteq/tools/neteq_test_factory.cc b/modules/audio_coding/neteq/tools/neteq_test_factory.cc
index f8ec36b..1a0ea15 100644
--- a/modules/audio_coding/neteq/tools/neteq_test_factory.cc
+++ b/modules/audio_coding/neteq/tools/neteq_test_factory.cc
@@ -285,7 +285,7 @@
// Note that capture-by-copy implies that the lambda captures the value of
// decoder_factory before it's reassigned on the left-hand side.
- decoder_factory = new rtc::RefCountedObject<FunctionAudioDecoderFactory>(
+ decoder_factory = rtc::make_ref_counted<FunctionAudioDecoderFactory>(
[decoder_factory, config](
const SdpAudioFormat& format,
absl::optional<AudioCodecPairId> codec_pair_id) {