Update sdk/ to not use implicit conversion from scoped_refptr<T> to T*.

Bug: webrtc:13464
Change-Id: I6944106ddc99c043825fad077bfcedc051c67d8f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/259772
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Peter Hanspers <peterhanspers@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36682}
diff --git a/sdk/android/native_unittests/peerconnection/peer_connection_factory_unittest.cc b/sdk/android/native_unittests/peerconnection/peer_connection_factory_unittest.cc
index fd988a5..8bb6e33 100644
--- a/sdk/android/native_unittests/peerconnection/peer_connection_factory_unittest.cc
+++ b/sdk/android/native_unittests/peerconnection/peer_connection_factory_unittest.cc
@@ -67,7 +67,7 @@
   RTC_LOG(LS_INFO) << "Media engine created: " << pcf_deps.media_engine.get();
 
   auto factory = CreateModularPeerConnectionFactory(std::move(pcf_deps));
-  RTC_LOG(LS_INFO) << "PeerConnectionFactory created: " << factory;
+  RTC_LOG(LS_INFO) << "PeerConnectionFactory created: " << factory.get();
   RTC_CHECK(factory) << "Failed to create the peer connection factory; "
                         "WebRTC/libjingle init likely failed on this device";
 
diff --git a/sdk/android/src/jni/pc/media_stream.cc b/sdk/android/src/jni/pc/media_stream.cc
index 2f0be5d..20d59a6 100644
--- a/sdk/android/src/jni/pc/media_stream.cc
+++ b/sdk/android/src/jni/pc/media_stream.cc
@@ -29,7 +29,7 @@
   // Create an observer to update the Java stream when the native stream's set
   // of tracks changes.
   observer_.reset(new MediaStreamObserver(
-      media_stream,
+      media_stream.get(),
       [this](AudioTrackInterface* audio_track,
              MediaStreamInterface* media_stream) {
         OnAudioTrackAddedToStream(audio_track, media_stream);
diff --git a/sdk/android/src/jni/pc/peer_connection.cc b/sdk/android/src/jni/pc/peer_connection.cc
index 2aa1c9e..502763a 100644
--- a/sdk/android/src/jni/pc/peer_connection.cc
+++ b/sdk/android/src/jni/pc/peer_connection.cc
@@ -391,8 +391,9 @@
 void PeerConnectionObserverJni::OnRemoveStream(
     rtc::scoped_refptr<MediaStreamInterface> stream) {
   JNIEnv* env = AttachCurrentThreadIfNeeded();
-  NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream);
-  RTC_CHECK(it != remote_streams_.end()) << "unexpected stream: " << stream;
+  NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream.get());
+  RTC_CHECK(it != remote_streams_.end())
+      << "unexpected stream: " << stream.get();
   Java_Observer_onRemoveStream(env, j_observer_global_,
                                it->second.j_media_stream());
   remote_streams_.erase(it);
@@ -447,7 +448,7 @@
 JavaMediaStream& PeerConnectionObserverJni::GetOrCreateJavaStream(
     JNIEnv* env,
     const rtc::scoped_refptr<MediaStreamInterface>& stream) {
-  NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream);
+  NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream.get());
   if (it == remote_streams_.end()) {
     it = remote_streams_
              .emplace(std::piecewise_construct,
@@ -579,7 +580,7 @@
       jni, j_observer, std::move(constraints));
   PeerConnectionInterface::RTCOfferAnswerOptions options;
   CopyConstraintsIntoOfferAnswerOptions(observer->constraints(), &options);
-  ExtractNativePC(jni, j_pc)->CreateOffer(observer, options);
+  ExtractNativePC(jni, j_pc)->CreateOffer(observer.get(), options);
 }
 
 static void JNI_PeerConnection_CreateAnswer(
@@ -593,7 +594,7 @@
       jni, j_observer, std::move(constraints));
   PeerConnectionInterface::RTCOfferAnswerOptions options;
   CopyConstraintsIntoOfferAnswerOptions(observer->constraints(), &options);
-  ExtractNativePC(jni, j_pc)->CreateAnswer(observer, options);
+  ExtractNativePC(jni, j_pc)->CreateAnswer(observer.get(), options);
 }
 
 static void JNI_PeerConnection_SetLocalDescriptionAutomatically(
@@ -827,7 +828,8 @@
     jlong native_track) {
   auto observer = rtc::make_ref_counted<StatsObserverJni>(jni, j_observer);
   return ExtractNativePC(jni, j_pc)->GetStats(
-      observer, reinterpret_cast<MediaStreamTrackInterface*>(native_track),
+      observer.get(),
+      reinterpret_cast<MediaStreamTrackInterface*>(native_track),
       PeerConnectionInterface::kStatsOutputLevelStandard);
 }
 
@@ -837,7 +839,7 @@
     const JavaParamRef<jobject>& j_callback) {
   auto callback =
       rtc::make_ref_counted<RTCStatsCollectorCallbackWrapper>(jni, j_callback);
-  ExtractNativePC(jni, j_pc)->GetStats(callback);
+  ExtractNativePC(jni, j_pc)->GetStats(callback.get());
 }
 
 static jboolean JNI_PeerConnection_SetBitrate(
diff --git a/sdk/objc/api/peerconnection/RTCAudioTrack.mm b/sdk/objc/api/peerconnection/RTCAudioTrack.mm
index 73ec98f..5c1736f 100644
--- a/sdk/objc/api/peerconnection/RTCAudioTrack.mm
+++ b/sdk/objc/api/peerconnection/RTCAudioTrack.mm
@@ -30,7 +30,7 @@
 
   std::string nativeId = [NSString stdStringForString:trackId];
   rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
-      factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource);
+      factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource.get());
   if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]) {
     _source = source;
   }
diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection+Stats.mm b/sdk/objc/api/peerconnection/RTCPeerConnection+Stats.mm
index 7f8b123..f8d3814 100644
--- a/sdk/objc/api/peerconnection/RTCPeerConnection+Stats.mm
+++ b/sdk/objc/api/peerconnection/RTCPeerConnection+Stats.mm
@@ -84,7 +84,7 @@
 - (void)statisticsWithCompletionHandler:(RTCStatisticsCompletionHandler)completionHandler {
   rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector =
       rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(completionHandler);
-  self.nativePeerConnection->GetStats(collector);
+  self.nativePeerConnection->GetStats(collector.get());
 }
 
 - (void)statsForTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)mediaStreamTrack
@@ -96,7 +96,7 @@
   webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel =
       [[self class] nativeStatsOutputLevelForLevel:statsOutputLevel];
   self.nativePeerConnection->GetStats(
-      observer, mediaStreamTrack.nativeTrack, nativeOutputLevel);
+      observer.get(), mediaStreamTrack.nativeTrack.get(), nativeOutputLevel);
 }
 
 @end
diff --git a/sdk/objc/api/peerconnection/RTCPeerConnection.mm b/sdk/objc/api/peerconnection/RTCPeerConnection.mm
index 203fa4a..f4db472 100644
--- a/sdk/objc/api/peerconnection/RTCPeerConnection.mm
+++ b/sdk/objc/api/peerconnection/RTCPeerConnection.mm
@@ -492,7 +492,7 @@
 }
 
 - (void)addStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream {
-  if (!_peerConnection->AddStream(stream.nativeMediaStream)) {
+  if (!_peerConnection->AddStream(stream.nativeMediaStream.get())) {
     RTCLogError(@"Failed to add stream: %@", stream);
     return;
   }
@@ -500,7 +500,7 @@
 }
 
 - (void)removeStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream {
-  _peerConnection->RemoveStream(stream.nativeMediaStream);
+  _peerConnection->RemoveStream(stream.nativeMediaStream.get());
   [_localStreams removeObject:stream];
 }
 
@@ -583,7 +583,7 @@
   webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options;
   CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options);
 
-  _peerConnection->CreateOffer(observer, options);
+  _peerConnection->CreateOffer(observer.get(), options);
 }
 
 - (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
@@ -594,7 +594,7 @@
   webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options;
   CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options);
 
-  _peerConnection->CreateAnswer(observer, options);
+  _peerConnection->CreateAnswer(observer.get(), options);
 }
 
 - (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
index f7a1755..4e5aa19 100644
--- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
+++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
@@ -88,7 +88,7 @@
                                             RTCVideoEncoderFactoryH264) alloc] init])
               nativeVideoDecoderFactory:webrtc::ObjCToNativeVideoDecoderFactory([[RTC_OBJC_TYPE(
                                             RTCVideoDecoderFactoryH264) alloc] init])
-                      audioDeviceModule:[self audioDeviceModule]
+                      audioDeviceModule:[self audioDeviceModule].get()
                   audioProcessingModule:nullptr];
 #endif
 }
@@ -111,7 +111,7 @@
                        nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
                        nativeVideoEncoderFactory:std::move(native_encoder_factory)
                        nativeVideoDecoderFactory:std::move(native_decoder_factory)
-                               audioDeviceModule:[self audioDeviceModule]
+                               audioDeviceModule:[self audioDeviceModule].get()
                            audioProcessingModule:nullptr];
 #endif
 }
diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactoryBuilder.mm b/sdk/objc/api/peerconnection/RTCPeerConnectionFactoryBuilder.mm
index 991ec5a..627909a 100644
--- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactoryBuilder.mm
+++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactoryBuilder.mm
@@ -38,7 +38,7 @@
                           nativeAudioDecoderFactory:_audioDecoderFactory
                           nativeVideoEncoderFactory:std::move(_videoEncoderFactory)
                           nativeVideoDecoderFactory:std::move(_videoDecoderFactory)
-                                  audioDeviceModule:_audioDeviceModule
+                                  audioDeviceModule:_audioDeviceModule.get()
                               audioProcessingModule:_audioProcessingModule];
 }
 
diff --git a/sdk/objc/api/peerconnection/RTCRtpSender.mm b/sdk/objc/api/peerconnection/RTCRtpSender.mm
index 12566ec..4fadb30 100644
--- a/sdk/objc/api/peerconnection/RTCRtpSender.mm
+++ b/sdk/objc/api/peerconnection/RTCRtpSender.mm
@@ -52,7 +52,7 @@
 }
 
 - (void)setTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track {
-  if (!_nativeRtpSender->SetTrack(track.nativeTrack)) {
+  if (!_nativeRtpSender->SetTrack(track.nativeTrack.get())) {
     RTCLogError(@"RTC_OBJC_TYPE(RTCRtpSender)(%p): Failed to set track %@", self, track);
   }
 }
diff --git a/sdk/objc/api/peerconnection/RTCVideoTrack.mm b/sdk/objc/api/peerconnection/RTCVideoTrack.mm
index d9eddde..8944d26 100644
--- a/sdk/objc/api/peerconnection/RTCVideoTrack.mm
+++ b/sdk/objc/api/peerconnection/RTCVideoTrack.mm
@@ -30,8 +30,7 @@
   NSParameterAssert(trackId.length);
   std::string nativeId = [NSString stdStringForString:trackId];
   rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
-      factory.nativeFactory->CreateVideoTrack(nativeId,
-                                              source.nativeVideoSource);
+      factory.nativeFactory->CreateVideoTrack(nativeId, source.nativeVideoSource.get());
   if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeVideo]) {
     _source = source;
   }
diff --git a/sdk/objc/native/api/video_capturer.mm b/sdk/objc/native/api/video_capturer.mm
index 0101c79..4b065b5 100644
--- a/sdk/objc/native/api/video_capturer.mm
+++ b/sdk/objc/native/api/video_capturer.mm
@@ -25,7 +25,8 @@
   rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objc_video_track_source =
       rtc::make_ref_counted<webrtc::ObjCVideoTrackSource>(adapter);
   rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source =
-      webrtc::CreateVideoTrackSourceProxy(signaling_thread, worker_thread, objc_video_track_source);
+      webrtc::CreateVideoTrackSourceProxy(
+          signaling_thread, worker_thread, objc_video_track_source.get());
 
   objc_video_capturer.delegate = adapter;
 
diff --git a/sdk/objc/unittests/ObjCVideoTrackSource_xctest.mm b/sdk/objc/unittests/ObjCVideoTrackSource_xctest.mm
index 8bd1f1a..ffa8a6c 100644
--- a/sdk/objc/unittests/ObjCVideoTrackSource_xctest.mm
+++ b/sdk/objc/unittests/ObjCVideoTrackSource_xctest.mm
@@ -73,7 +73,7 @@
 
   cricket::FakeVideoRenderer *video_renderer = new cricket::FakeVideoRenderer();
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(video_renderer, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -105,7 +105,7 @@
 
   cricket::FakeVideoRenderer *video_renderer = new cricket::FakeVideoRenderer();
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(video_renderer, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(912, 514, 30);
@@ -135,7 +135,7 @@
 
   cricket::FakeVideoRenderer *video_renderer = new cricket::FakeVideoRenderer();
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(video_renderer, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -188,7 +188,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -224,7 +224,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -260,7 +260,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -305,7 +305,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(480, 270, 30);
@@ -349,7 +349,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -393,7 +393,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -426,7 +426,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);
@@ -458,7 +458,7 @@
   });
 
   const rtc::VideoSinkWants video_sink_wants;
-  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source;
+  rtc::VideoSourceInterface<webrtc::VideoFrame> *video_source_interface = _video_source.get();
   video_source_interface->AddOrUpdateSink(&callback_video_sink, video_sink_wants);
 
   _video_source->OnOutputFormatRequest(640, 360, 30);