diff --git a/examples/androidnativeapi/jni/android_call_client.cc b/examples/androidnativeapi/jni/android_call_client.cc index 3c7c86d7ef..2c5e1af108 100644 --- a/examples/androidnativeapi/jni/android_call_client.cc +++ b/examples/androidnativeapi/jni/android_call_client.cc @@ -208,7 +208,7 @@ void AndroidCallClient::CreatePeerConnection() { void AndroidCallClient::Connect() { webrtc::MutexLock lock(&pc_mutex_); - pc_->CreateOffer(new rtc::RefCountedObject(pc_), + pc_->CreateOffer(rtc::make_ref_counted(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(), desc); + rtc::make_ref_counted(), desc); // Generate a fake answer. std::unique_ptr answer( diff --git a/examples/objcnativeapi/objc/objc_call_client.mm b/examples/objcnativeapi/objc/objc_call_client.mm index c1d84f7ce7..081b5bc44b 100644 --- a/examples/objcnativeapi/objc/objc_call_client.mm +++ b/examples/objcnativeapi/objc/objc_call_client.mm @@ -168,7 +168,7 @@ void ObjCCallClient::CreatePeerConnection() { void ObjCCallClient::Connect() { webrtc::MutexLock lock(&pc_mutex_); - pc_->CreateOffer(new rtc::RefCountedObject(pc_), + pc_->CreateOffer(rtc::make_ref_counted(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(), desc); + pc_->SetLocalDescription(rtc::make_ref_counted(), desc); // Generate a fake answer. std::unique_ptr answer( diff --git a/examples/peerconnection/client/conductor.cc b/examples/peerconnection/client/conductor.cc index 65958a445d..93e95b6583 100644 --- a/examples/peerconnection/client/conductor.cc +++ b/examples/peerconnection/client/conductor.cc @@ -59,7 +59,7 @@ class DummySetSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver { public: static DummySetSessionDescriptionObserver* Create() { - return new rtc::RefCountedObject(); + return rtc::make_ref_counted(); } virtual void OnSuccess() { RTC_LOG(LS_INFO) << __FUNCTION__; } virtual void OnFailure(webrtc::RTCError error) { diff --git a/examples/peerconnection/client/linux/main.cc b/examples/peerconnection/client/linux/main.cc index ccca7b1c7c..47f4f3618e 100644 --- a/examples/peerconnection/client/linux/main.cc +++ b/examples/peerconnection/client/linux/main.cc @@ -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( - new rtc::RefCountedObject(&client, &wnd)); + auto conductor = rtc::make_ref_counted(&client, &wnd); socket_server.set_client(&client); socket_server.set_conductor(conductor); diff --git a/examples/peerconnection/client/main.cc b/examples/peerconnection/client/main.cc index 3ab4176083..04a331d2bd 100644 --- a/examples/peerconnection/client/main.cc +++ b/examples/peerconnection/client/main.cc @@ -107,8 +107,7 @@ int PASCAL wWinMain(HINSTANCE instance, rtc::InitializeSSL(); PeerConnectionClient client; - rtc::scoped_refptr conductor( - new rtc::RefCountedObject(&client, &wnd)); + auto conductor = rtc::make_ref_counted(&client, &wnd); // Main loop. MSG msg; diff --git a/examples/unityplugin/simple_peer_connection.cc b/examples/unityplugin/simple_peer_connection.cc index 34abbe294e..16c580e767 100644 --- a/examples/unityplugin/simple_peer_connection.cc +++ b/examples/unityplugin/simple_peer_connection.cc @@ -99,7 +99,7 @@ class DummySetSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver { public: static DummySetSessionDescriptionObserver* Create() { - return new rtc::RefCountedObject(); + return rtc::make_ref_counted(); } 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 source( - new rtc::RefCountedObject( - g_signaling_thread.get(), env, /* is_screencast= */ false, - /* align_timestamps= */ true)); + auto source = rtc::make_ref_counted( + g_signaling_thread.get(), env, /*is_screencast=*/false, + /*align_timestamps=*/true); // link with VideoCapturer (Camera); jmethodID link_camera_method = webrtc::GetStaticMethodID( diff --git a/examples/unityplugin/unity_plugin_apis.cc b/examples/unityplugin/unity_plugin_apis.cc index 34c28d926a..672330faec 100644 --- a/examples/unityplugin/unity_plugin_apis.cc +++ b/examples/unityplugin/unity_plugin_apis.cc @@ -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(); + rtc::make_ref_counted(); if (!g_peer_connection_map[g_peer_connection_id]->InitializePeerConnection( turn_urls, no_of_urls, username, credential, mandatory_receive_video)) diff --git a/modules/audio_coding/acm2/audio_coding_module_unittest.cc b/modules/audio_coding/acm2/audio_coding_module_unittest.cc index 7ddb3ed0c7..e401e93a08 100644 --- a/modules/audio_coding/acm2/audio_coding_module_unittest.cc +++ b/modules/audio_coding/acm2/audio_coding_module_unittest.cc @@ -1051,8 +1051,7 @@ TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) { rtc::scoped_refptr fact_; // Fallback factory. }; - rtc::scoped_refptr> factory( - new rtc::RefCountedObject); + auto factory = rtc::make_ref_counted(); 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 decoder_factory( - new rtc::RefCountedObject( - opus_decoder.get())); + rtc::scoped_refptr decoder_factory = + rtc::make_ref_counted(opus_decoder.get()); // Set up an EXTERNAL DECODER to parse 4 channels. Run(AcmReceiverBitExactnessOldApi::PlatformChecksum( // audio checksum diff --git a/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc index e337c334e0..dc845e4d24 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video_unittest.cc @@ -775,8 +775,7 @@ TEST_P(RtpSenderVideoTest, rtp_module_->RegisterRtpHeaderExtension( RtpDependencyDescriptorExtension::Uri(), kDependencyDescriptorId); - rtc::scoped_refptr encryptor( - new rtc::RefCountedObject>); + auto encryptor = rtc::make_ref_counted>(); ON_CALL(*encryptor, GetMaxCiphertextByteSize).WillByDefault(ReturnArg<1>()); ON_CALL(*encryptor, Encrypt) .WillByDefault(WithArgs<3, 5>( diff --git a/pc/peer_connection_signaling_unittest.cc b/pc/peer_connection_signaling_unittest.cc index 71ef51f559..48a99883c0 100644 --- a/pc/peer_connection_signaling_unittest.cc +++ b/pc/peer_connection_signaling_unittest.cc @@ -1135,7 +1135,7 @@ TEST_F(PeerConnectionSignalingUnifiedPlanTest, // operation executed immediately. RTC_DCHECK(!pc->GetTransceivers()[0]->mid().has_value()); pc->SetLocalDescription( - new rtc::RefCountedObject(), + rtc::make_ref_counted(), desc); EXPECT_TRUE(pc->GetTransceivers()[0]->mid().has_value()); }); diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index 971d8d3b7f..cbb17c0732 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -221,8 +221,7 @@ class FakeAudioTrackForStats : public MediaStreamTrack { const std::string& id, MediaStreamTrackInterface::TrackState state, bool create_fake_audio_processor) { - rtc::scoped_refptr audio_track_stats( - new rtc::RefCountedObject(id)); + auto audio_track_stats = rtc::make_ref_counted(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 Create( int input_width, int input_height) { - return rtc::scoped_refptr( - new rtc::RefCountedObject(input_width, - input_height)); + return rtc::make_ref_counted(input_width, + input_height); } FakeVideoTrackSourceForStats(int input_width, int input_height) @@ -301,9 +299,8 @@ class FakeVideoTrackForStats : public MediaStreamTrack { const std::string& id, MediaStreamTrackInterface::TrackState state, rtc::scoped_refptr source) { - rtc::scoped_refptr video_track( - new rtc::RefCountedObject(id, - std::move(source))); + auto video_track = + rtc::make_ref_counted(id, std::move(source)); video_track->set_state(state); return video_track; } @@ -353,8 +350,7 @@ rtc::scoped_refptr CreateMockSender( media_type == cricket::MEDIA_TYPE_AUDIO) || (track->kind() == MediaStreamTrackInterface::kVideoKind && media_type == cricket::MEDIA_TYPE_VIDEO)); - rtc::scoped_refptr sender( - new rtc::RefCountedObject()); + auto sender = rtc::make_ref_counted(); 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 CreateMockReceiver( const rtc::scoped_refptr& track, uint32_t ssrc, int attachment_id) { - rtc::scoped_refptr receiver( - new rtc::RefCountedObject()); + auto receiver = rtc::make_ref_counted(); 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()), + : pc_(rtc::make_ref_counted()), 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 callback1( - new rtc::RefCountedObject(stats_.get())); - rtc::scoped_refptr callback2( - new rtc::RefCountedObject(stats_.get())); + auto callback1 = rtc::make_ref_counted(stats_.get()); + auto callback2 = rtc::make_ref_counted(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 pc( - new rtc::RefCountedObject()); + auto pc = rtc::make_ref_counted(); rtc::scoped_refptr stats_collector( FakeRTCStatsCollector::Create(pc, 50 * rtc::kNumMicrosecsPerMillisec)); stats_collector->VerifyThreadUsageAndResultsMerging(); diff --git a/rtc_base/rtc_certificate_generator_unittest.cc b/rtc_base/rtc_certificate_generator_unittest.cc index bef85f25e6..076f643091 100644 --- a/rtc_base/rtc_certificate_generator_unittest.cc +++ b/rtc_base/rtc_certificate_generator_unittest.cc @@ -70,7 +70,7 @@ class RTCCertificateGeneratorFixture : public RTCCertificateGeneratorCallback { class RTCCertificateGeneratorTest : public ::testing::Test { public: RTCCertificateGeneratorTest() - : fixture_(new RefCountedObject()) {} + : fixture_(make_ref_counted()) {} protected: static constexpr int kGenerationTimeoutMs = 10000; diff --git a/sdk/objc/native/src/objc_frame_buffer.mm b/sdk/objc/native/src/objc_frame_buffer.mm index 34d5d4e429..e156c34dac 100644 --- a/sdk/objc/native/src/objc_frame_buffer.mm +++ b/sdk/objc/native/src/objc_frame_buffer.mm @@ -66,10 +66,7 @@ int ObjCFrameBuffer::height() const { } rtc::scoped_refptr ObjCFrameBuffer::ToI420() { - rtc::scoped_refptr buffer = - rtc::make_ref_counted([frame_buffer_ toI420]); - - return buffer; + return rtc::make_ref_counted([frame_buffer_ toI420]); } id ObjCFrameBuffer::wrapped_frame_buffer() const { diff --git a/sdk/objc/native/src/objc_video_decoder_factory.mm b/sdk/objc/native/src/objc_video_decoder_factory.mm index e144fda54f..da3b302275 100644 --- a/sdk/objc/native/src/objc_video_decoder_factory.mm +++ b/sdk/objc/native/src/objc_video_decoder_factory.mm @@ -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 buffer = - rtc::make_ref_counted(frame.buffer); + const auto buffer = rtc::make_ref_counted(frame.buffer); VideoFrame videoFrame = VideoFrame::Builder() .set_video_frame_buffer(buffer) diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc index e6fadc7b57..2767de210f 100644 --- a/test/peer_scenario/peer_scenario_client.cc +++ b/test/peer_scenario/peer_scenario_client.cc @@ -321,9 +321,8 @@ PeerScenarioClient::VideoSendTrack PeerScenarioClient::CreateVideo( config.generator); res.capturer = capturer.get(); capturer->Init(); - res.source = - new rtc::RefCountedObject( - std::move(capturer), config.screencast); + res.source = rtc::make_ref_counted( + 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(); diff --git a/test/peer_scenario/peer_scenario_client.h b/test/peer_scenario/peer_scenario_client.h index 91ce1e414a..ab6aac9cf8 100644 --- a/test/peer_scenario/peer_scenario_client.h +++ b/test/peer_scenario/peer_scenario_client.h @@ -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 source; + rtc::scoped_refptr track; + rtc::scoped_refptr sender; }; PeerScenarioClient(