Replace most explicit new RefCountedObject... with make_ref_counted

Bug: webrtc:12701
Change-Id: Iab91f1e96715eed7f9ddcfe1ca55510a18c817eb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/224544
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35786}
This commit is contained in:
Niels Möller
2022-01-25 13:56:07 +01:00
committed by WebRTC LUCI CQ
parent b428d6bad4
commit 027c793c57
16 changed files with 37 additions and 55 deletions

View File

@ -208,7 +208,7 @@ void AndroidCallClient::CreatePeerConnection() {
void AndroidCallClient::Connect() {
webrtc::MutexLock lock(&pc_mutex_);
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
pc_->CreateOffer(rtc::make_ref_counted<CreateOfferObserver>(pc_),
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
}
@ -258,7 +258,7 @@ void CreateOfferObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
// Ownership of desc was transferred to us, now we transfer it forward.
pc_->SetLocalDescription(
new rtc::RefCountedObject<SetLocalSessionDescriptionObserver>(), desc);
rtc::make_ref_counted<SetLocalSessionDescriptionObserver>(), desc);
// Generate a fake answer.
std::unique_ptr<webrtc::SessionDescriptionInterface> answer(

View File

@ -168,7 +168,7 @@ void ObjCCallClient::CreatePeerConnection() {
void ObjCCallClient::Connect() {
webrtc::MutexLock lock(&pc_mutex_);
pc_->CreateOffer(new rtc::RefCountedObject<CreateOfferObserver>(pc_),
pc_->CreateOffer(rtc::make_ref_counted<CreateOfferObserver>(pc_),
webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
}
@ -214,7 +214,7 @@ void CreateOfferObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
RTC_LOG(LS_INFO) << "Created offer: " << sdp;
// Ownership of desc was transferred to us, now we transfer it forward.
pc_->SetLocalDescription(new rtc::RefCountedObject<SetLocalSessionDescriptionObserver>(), desc);
pc_->SetLocalDescription(rtc::make_ref_counted<SetLocalSessionDescriptionObserver>(), desc);
// Generate a fake answer.
std::unique_ptr<webrtc::SessionDescriptionInterface> answer(

View File

@ -59,7 +59,7 @@ class DummySetSessionDescriptionObserver
: public webrtc::SetSessionDescriptionObserver {
public:
static DummySetSessionDescriptionObserver* Create() {
return new rtc::RefCountedObject<DummySetSessionDescriptionObserver>();
return rtc::make_ref_counted<DummySetSessionDescriptionObserver>();
}
virtual void OnSuccess() { RTC_LOG(LS_INFO) << __FUNCTION__; }
virtual void OnFailure(webrtc::RTCError error) {

View File

@ -101,8 +101,7 @@ int main(int argc, char* argv[]) {
rtc::InitializeSSL();
// Must be constructed after we set the socketserver.
PeerConnectionClient client;
rtc::scoped_refptr<Conductor> conductor(
new rtc::RefCountedObject<Conductor>(&client, &wnd));
auto conductor = rtc::make_ref_counted<Conductor>(&client, &wnd);
socket_server.set_client(&client);
socket_server.set_conductor(conductor);

View File

@ -107,8 +107,7 @@ int PASCAL wWinMain(HINSTANCE instance,
rtc::InitializeSSL();
PeerConnectionClient client;
rtc::scoped_refptr<Conductor> conductor(
new rtc::RefCountedObject<Conductor>(&client, &wnd));
auto conductor = rtc::make_ref_counted<Conductor>(&client, &wnd);
// Main loop.
MSG msg;

View File

@ -99,7 +99,7 @@ class DummySetSessionDescriptionObserver
: public webrtc::SetSessionDescriptionObserver {
public:
static DummySetSessionDescriptionObserver* Create() {
return new rtc::RefCountedObject<DummySetSessionDescriptionObserver>();
return rtc::make_ref_counted<DummySetSessionDescriptionObserver>();
}
virtual void OnSuccess() { RTC_LOG(LS_INFO) << __FUNCTION__; }
virtual void OnFailure(webrtc::RTCError error) {
@ -446,10 +446,9 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
RTC_DCHECK(texture_helper != nullptr)
<< "Cannot get the Surface Texture Helper.";
rtc::scoped_refptr<webrtc::jni::AndroidVideoTrackSource> source(
new rtc::RefCountedObject<webrtc::jni::AndroidVideoTrackSource>(
g_signaling_thread.get(), env, /* is_screencast= */ false,
/* align_timestamps= */ true));
auto source = rtc::make_ref_counted<webrtc::jni::AndroidVideoTrackSource>(
g_signaling_thread.get(), env, /*is_screencast=*/false,
/*align_timestamps=*/true);
// link with VideoCapturer (Camera);
jmethodID link_camera_method = webrtc::GetStaticMethodID(

View File

@ -27,7 +27,7 @@ int CreatePeerConnection(const char** turn_urls,
const char* credential,
bool mandatory_receive_video) {
g_peer_connection_map[g_peer_connection_id] =
new rtc::RefCountedObject<SimplePeerConnection>();
rtc::make_ref_counted<SimplePeerConnection>();
if (!g_peer_connection_map[g_peer_connection_id]->InitializePeerConnection(
turn_urls, no_of_urls, username, credential, mandatory_receive_video))

View File

@ -1051,8 +1051,7 @@ TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) {
rtc::scoped_refptr<AudioDecoderFactory> fact_; // Fallback factory.
};
rtc::scoped_refptr<rtc::RefCountedObject<ADFactory>> factory(
new rtc::RefCountedObject<ADFactory>);
auto factory = rtc::make_ref_counted<ADFactory>();
std::string others_checksum_reference =
GetCPUInfo(kAVX2) != 0 ? "454996a7adb3f62b259a53a09ff624cf"
: "f0148c5ef84e74e019ac7057af839102";
@ -1540,9 +1539,8 @@ TEST_F(AcmSenderBitExactnessNewApi, DISABLED_OpusManyChannels) {
const auto opus_decoder =
AudioDecoderMultiChannelOpus::MakeAudioDecoder(*decoder_config);
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory(
new rtc::RefCountedObject<test::AudioDecoderProxyFactory>(
opus_decoder.get()));
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
rtc::make_ref_counted<test::AudioDecoderProxyFactory>(opus_decoder.get());
// Set up an EXTERNAL DECODER to parse 4 channels.
Run(AcmReceiverBitExactnessOldApi::PlatformChecksum( // audio checksum

View File

@ -775,8 +775,7 @@ TEST_P(RtpSenderVideoTest,
rtp_module_->RegisterRtpHeaderExtension(
RtpDependencyDescriptorExtension::Uri(), kDependencyDescriptorId);
rtc::scoped_refptr<MockFrameEncryptor> encryptor(
new rtc::RefCountedObject<NiceMock<MockFrameEncryptor>>);
auto encryptor = rtc::make_ref_counted<NiceMock<MockFrameEncryptor>>();
ON_CALL(*encryptor, GetMaxCiphertextByteSize).WillByDefault(ReturnArg<1>());
ON_CALL(*encryptor, Encrypt)
.WillByDefault(WithArgs<3, 5>(

View File

@ -1135,7 +1135,7 @@ TEST_F(PeerConnectionSignalingUnifiedPlanTest,
// operation executed immediately.
RTC_DCHECK(!pc->GetTransceivers()[0]->mid().has_value());
pc->SetLocalDescription(
new rtc::RefCountedObject<MockSetSessionDescriptionObserver>(),
rtc::make_ref_counted<MockSetSessionDescriptionObserver>(),
desc);
EXPECT_TRUE(pc->GetTransceivers()[0]->mid().has_value());
});

View File

@ -221,8 +221,7 @@ class FakeAudioTrackForStats : public MediaStreamTrack<AudioTrackInterface> {
const std::string& id,
MediaStreamTrackInterface::TrackState state,
bool create_fake_audio_processor) {
rtc::scoped_refptr<FakeAudioTrackForStats> audio_track_stats(
new rtc::RefCountedObject<FakeAudioTrackForStats>(id));
auto audio_track_stats = rtc::make_ref_counted<FakeAudioTrackForStats>(id);
audio_track_stats->set_state(state);
if (create_fake_audio_processor) {
audio_track_stats->processor_ =
@ -254,9 +253,8 @@ class FakeVideoTrackSourceForStats : public VideoTrackSourceInterface {
static rtc::scoped_refptr<FakeVideoTrackSourceForStats> Create(
int input_width,
int input_height) {
return rtc::scoped_refptr<FakeVideoTrackSourceForStats>(
new rtc::RefCountedObject<FakeVideoTrackSourceForStats>(input_width,
input_height));
return rtc::make_ref_counted<FakeVideoTrackSourceForStats>(input_width,
input_height);
}
FakeVideoTrackSourceForStats(int input_width, int input_height)
@ -301,9 +299,8 @@ class FakeVideoTrackForStats : public MediaStreamTrack<VideoTrackInterface> {
const std::string& id,
MediaStreamTrackInterface::TrackState state,
rtc::scoped_refptr<VideoTrackSourceInterface> source) {
rtc::scoped_refptr<FakeVideoTrackForStats> video_track(
new rtc::RefCountedObject<FakeVideoTrackForStats>(id,
std::move(source)));
auto video_track =
rtc::make_ref_counted<FakeVideoTrackForStats>(id, std::move(source));
video_track->set_state(state);
return video_track;
}
@ -353,8 +350,7 @@ rtc::scoped_refptr<MockRtpSenderInternal> CreateMockSender(
media_type == cricket::MEDIA_TYPE_AUDIO) ||
(track->kind() == MediaStreamTrackInterface::kVideoKind &&
media_type == cricket::MEDIA_TYPE_VIDEO));
rtc::scoped_refptr<MockRtpSenderInternal> sender(
new rtc::RefCountedObject<MockRtpSenderInternal>());
auto sender = rtc::make_ref_counted<MockRtpSenderInternal>();
EXPECT_CALL(*sender, track()).WillRepeatedly(Return(track));
EXPECT_CALL(*sender, ssrc()).WillRepeatedly(Return(ssrc));
EXPECT_CALL(*sender, media_type()).WillRepeatedly(Return(media_type));
@ -375,8 +371,7 @@ rtc::scoped_refptr<MockRtpReceiverInternal> CreateMockReceiver(
const rtc::scoped_refptr<MediaStreamTrackInterface>& track,
uint32_t ssrc,
int attachment_id) {
rtc::scoped_refptr<MockRtpReceiverInternal> receiver(
new rtc::RefCountedObject<MockRtpReceiverInternal>());
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
EXPECT_CALL(*receiver, track()).WillRepeatedly(Return(track));
EXPECT_CALL(*receiver, streams())
.WillRepeatedly(
@ -626,7 +621,7 @@ class RTCStatsCollectorWrapper {
class RTCStatsCollectorTest : public ::testing::Test {
public:
RTCStatsCollectorTest()
: pc_(new rtc::RefCountedObject<FakePeerConnectionForStats>()),
: pc_(rtc::make_ref_counted<FakePeerConnectionForStats>()),
stats_(new RTCStatsCollectorWrapper(pc_)) {}
void ExpectReportContainsCertificateInfo(
@ -3328,10 +3323,8 @@ class RecursiveCallback : public RTCStatsCollectorCallback {
// Test that nothing bad happens if a callback causes GetStatsReport to be
// called again recursively. Regression test for crbug.com/webrtc/8973.
TEST_F(RTCStatsCollectorTest, DoNotCrashWhenGetStatsCalledDuringCallback) {
rtc::scoped_refptr<RecursiveCallback> callback1(
new rtc::RefCountedObject<RecursiveCallback>(stats_.get()));
rtc::scoped_refptr<RecursiveCallback> callback2(
new rtc::RefCountedObject<RecursiveCallback>(stats_.get()));
auto callback1 = rtc::make_ref_counted<RecursiveCallback>(stats_.get());
auto callback2 = rtc::make_ref_counted<RecursiveCallback>(stats_.get());
stats_->stats_collector()->GetStatsReport(callback1);
stats_->stats_collector()->GetStatsReport(callback2);
EXPECT_TRUE_WAIT(callback1->called(), kGetStatsReportTimeoutMs);
@ -3452,8 +3445,7 @@ class FakeRTCStatsCollector : public RTCStatsCollector,
};
TEST(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) {
rtc::scoped_refptr<FakePeerConnectionForStats> pc(
new rtc::RefCountedObject<FakePeerConnectionForStats>());
auto pc = rtc::make_ref_counted<FakePeerConnectionForStats>();
rtc::scoped_refptr<FakeRTCStatsCollector> stats_collector(
FakeRTCStatsCollector::Create(pc, 50 * rtc::kNumMicrosecsPerMillisec));
stats_collector->VerifyThreadUsageAndResultsMerging();

View File

@ -70,7 +70,7 @@ class RTCCertificateGeneratorFixture : public RTCCertificateGeneratorCallback {
class RTCCertificateGeneratorTest : public ::testing::Test {
public:
RTCCertificateGeneratorTest()
: fixture_(new RefCountedObject<RTCCertificateGeneratorFixture>()) {}
: fixture_(make_ref_counted<RTCCertificateGeneratorFixture>()) {}
protected:
static constexpr int kGenerationTimeoutMs = 10000;

View File

@ -66,10 +66,7 @@ int ObjCFrameBuffer::height() const {
}
rtc::scoped_refptr<I420BufferInterface> ObjCFrameBuffer::ToI420() {
rtc::scoped_refptr<I420BufferInterface> buffer =
rtc::make_ref_counted<ObjCI420FrameBuffer>([frame_buffer_ toI420]);
return buffer;
return rtc::make_ref_counted<ObjCI420FrameBuffer>([frame_buffer_ toI420]);
}
id<RTC_OBJC_TYPE(RTCVideoFrameBuffer)> ObjCFrameBuffer::wrapped_frame_buffer() const {

View File

@ -56,8 +56,7 @@ class ObjCVideoDecoder : public VideoDecoder {
int32_t RegisterDecodeCompleteCallback(DecodedImageCallback *callback) override {
[decoder_ setCallback:^(RTC_OBJC_TYPE(RTCVideoFrame) * frame) {
const rtc::scoped_refptr<VideoFrameBuffer> buffer =
rtc::make_ref_counted<ObjCFrameBuffer>(frame.buffer);
const auto buffer = rtc::make_ref_counted<ObjCFrameBuffer>(frame.buffer);
VideoFrame videoFrame =
VideoFrame::Builder()
.set_video_frame_buffer(buffer)

View File

@ -321,9 +321,8 @@ PeerScenarioClient::VideoSendTrack PeerScenarioClient::CreateVideo(
config.generator);
res.capturer = capturer.get();
capturer->Init();
res.source =
new rtc::RefCountedObject<FrameGeneratorCapturerVideoTrackSource>(
std::move(capturer), config.screencast);
res.source = rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
std::move(capturer), config.screencast);
auto track = pc_factory_->CreateVideoTrack(track_id, res.source);
res.track = track;
res.sender = peer_connection_->AddTrack(track, {kCommonStreamId}).MoveValue();

View File

@ -104,10 +104,11 @@ class PeerScenarioClient {
};
struct VideoSendTrack {
// Raw pointer to the capturer owned by `source`.
FrameGeneratorCapturer* capturer;
FrameGeneratorCapturerVideoTrackSource* source;
VideoTrackInterface* track;
RtpSenderInterface* sender;
rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource> source;
rtc::scoped_refptr<VideoTrackInterface> track;
rtc::scoped_refptr<RtpSenderInterface> sender;
};
PeerScenarioClient(