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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -27,7 +27,7 @@ int CreatePeerConnection(const char** turn_urls,
const char* credential, const char* credential,
bool mandatory_receive_video) { bool mandatory_receive_video) {
g_peer_connection_map[g_peer_connection_id] = 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( if (!g_peer_connection_map[g_peer_connection_id]->InitializePeerConnection(
turn_urls, no_of_urls, username, credential, mandatory_receive_video)) 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<AudioDecoderFactory> fact_; // Fallback factory.
}; };
rtc::scoped_refptr<rtc::RefCountedObject<ADFactory>> factory( auto factory = rtc::make_ref_counted<ADFactory>();
new rtc::RefCountedObject<ADFactory>);
std::string others_checksum_reference = std::string others_checksum_reference =
GetCPUInfo(kAVX2) != 0 ? "454996a7adb3f62b259a53a09ff624cf" GetCPUInfo(kAVX2) != 0 ? "454996a7adb3f62b259a53a09ff624cf"
: "f0148c5ef84e74e019ac7057af839102"; : "f0148c5ef84e74e019ac7057af839102";
@ -1540,9 +1539,8 @@ TEST_F(AcmSenderBitExactnessNewApi, DISABLED_OpusManyChannels) {
const auto opus_decoder = const auto opus_decoder =
AudioDecoderMultiChannelOpus::MakeAudioDecoder(*decoder_config); AudioDecoderMultiChannelOpus::MakeAudioDecoder(*decoder_config);
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory( rtc::scoped_refptr<AudioDecoderFactory> decoder_factory =
new rtc::RefCountedObject<test::AudioDecoderProxyFactory>( rtc::make_ref_counted<test::AudioDecoderProxyFactory>(opus_decoder.get());
opus_decoder.get()));
// Set up an EXTERNAL DECODER to parse 4 channels. // Set up an EXTERNAL DECODER to parse 4 channels.
Run(AcmReceiverBitExactnessOldApi::PlatformChecksum( // audio checksum Run(AcmReceiverBitExactnessOldApi::PlatformChecksum( // audio checksum

View File

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

View File

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

View File

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

View File

@ -70,7 +70,7 @@ class RTCCertificateGeneratorFixture : public RTCCertificateGeneratorCallback {
class RTCCertificateGeneratorTest : public ::testing::Test { class RTCCertificateGeneratorTest : public ::testing::Test {
public: public:
RTCCertificateGeneratorTest() RTCCertificateGeneratorTest()
: fixture_(new RefCountedObject<RTCCertificateGeneratorFixture>()) {} : fixture_(make_ref_counted<RTCCertificateGeneratorFixture>()) {}
protected: protected:
static constexpr int kGenerationTimeoutMs = 10000; 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> ObjCFrameBuffer::ToI420() {
rtc::scoped_refptr<I420BufferInterface> buffer = return rtc::make_ref_counted<ObjCI420FrameBuffer>([frame_buffer_ toI420]);
rtc::make_ref_counted<ObjCI420FrameBuffer>([frame_buffer_ toI420]);
return buffer;
} }
id<RTC_OBJC_TYPE(RTCVideoFrameBuffer)> ObjCFrameBuffer::wrapped_frame_buffer() const { 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 { int32_t RegisterDecodeCompleteCallback(DecodedImageCallback *callback) override {
[decoder_ setCallback:^(RTC_OBJC_TYPE(RTCVideoFrame) * frame) { [decoder_ setCallback:^(RTC_OBJC_TYPE(RTCVideoFrame) * frame) {
const rtc::scoped_refptr<VideoFrameBuffer> buffer = const auto buffer = rtc::make_ref_counted<ObjCFrameBuffer>(frame.buffer);
rtc::make_ref_counted<ObjCFrameBuffer>(frame.buffer);
VideoFrame videoFrame = VideoFrame videoFrame =
VideoFrame::Builder() VideoFrame::Builder()
.set_video_frame_buffer(buffer) .set_video_frame_buffer(buffer)

View File

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

View File

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