Change stream.AddTrack/RemoveTrack to take a scoped_refptr argument

This better reflects the ownership passing of AddTrack, and is more
consistent for RemoveTrack.

Bug: webrtc:13980
Change-Id: Ide5baccf15fc687a4e092f8831ce8c0fea46604e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/259740
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36603}
diff --git a/api/media_stream_interface.h b/api/media_stream_interface.h
index 7e01028..9d33673 100644
--- a/api/media_stream_interface.h
+++ b/api/media_stream_interface.h
@@ -334,11 +334,38 @@
       const std::string& track_id) = 0;
 
   // Takes ownership of added tracks.
-  // TODO(hta): Should take scoped_refptr rather than raw pointer.
-  virtual bool AddTrack(AudioTrackInterface* track) = 0;
-  virtual bool AddTrack(VideoTrackInterface* track) = 0;
-  virtual bool RemoveTrack(AudioTrackInterface* track) = 0;
-  virtual bool RemoveTrack(VideoTrackInterface* track) = 0;
+  // Note: Default implementations are for avoiding link time errors in
+  // implementations that mock this API.
+  // TODO(bugs.webrtc.org/13980): Remove default implementations.
+  virtual bool AddTrack(rtc::scoped_refptr<AudioTrackInterface> track) {
+    RTC_CHECK_NOTREACHED();
+  }
+  virtual bool AddTrack(rtc::scoped_refptr<VideoTrackInterface> track) {
+    RTC_CHECK_NOTREACHED();
+  }
+  virtual bool RemoveTrack(rtc::scoped_refptr<AudioTrackInterface> track) {
+    RTC_CHECK_NOTREACHED();
+  }
+  virtual bool RemoveTrack(rtc::scoped_refptr<VideoTrackInterface> track) {
+    RTC_CHECK_NOTREACHED();
+  }
+  // Deprecated: Should use scoped_refptr versions rather than pointers.
+  [[deprecated("Pass a scoped_refptr")]] virtual bool AddTrack(
+      AudioTrackInterface* track) {
+    return AddTrack(rtc::scoped_refptr<AudioTrackInterface>(track));
+  }
+  [[deprecated("Pass a scoped_refptr")]] virtual bool AddTrack(
+      VideoTrackInterface* track) {
+    return AddTrack(rtc::scoped_refptr<VideoTrackInterface>(track));
+  }
+  [[deprecated("Pass a scoped_refptr")]] virtual bool RemoveTrack(
+      AudioTrackInterface* track) {
+    return RemoveTrack(rtc::scoped_refptr<AudioTrackInterface>(track));
+  }
+  [[deprecated("Pass a scoped_refptr")]] virtual bool RemoveTrack(
+      VideoTrackInterface* track) {
+    return RemoveTrack(rtc::scoped_refptr<VideoTrackInterface>(track));
+  }
 
  protected:
   ~MediaStreamInterface() override = default;