Step 1: Add RemoveTrackNew which returns an RTCError

Bug: webrtc:9534
Change-Id: I400bdcd0eb2e993b3f2252a2c7606cd105854e6b
Reviewed-on: https://webrtc-review.googlesource.com/89480
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24070}
diff --git a/api/peerconnectioninterface.cc b/api/peerconnectioninterface.cc
index aa23da3..adae14f 100644
--- a/api/peerconnectioninterface.cc
+++ b/api/peerconnectioninterface.cc
@@ -46,6 +46,16 @@
   return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
 }
 
+bool PeerConnectionInterface::RemoveTrack(RtpSenderInterface* sender) {
+  return RemoveTrackNew(sender).ok();
+}
+
+RTCError PeerConnectionInterface::RemoveTrackNew(
+    rtc::scoped_refptr<RtpSenderInterface> sender) {
+  return RTCError(RemoveTrack(sender) ? RTCErrorType::NONE
+                                      : RTCErrorType::INTERNAL_ERROR);
+}
+
 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
 PeerConnectionInterface::AddTransceiver(
     rtc::scoped_refptr<MediaStreamTrackInterface> track) {
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index a320508..4851206 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -664,7 +664,21 @@
 
   // Remove an RtpSender from this PeerConnection.
   // Returns true on success.
-  virtual bool RemoveTrack(RtpSenderInterface* sender) = 0;
+  // TODO(steveanton): Replace with signature that returns RTCError.
+  virtual bool RemoveTrack(RtpSenderInterface* sender);
+
+  // Plan B semantics: Removes the RtpSender from this PeerConnection.
+  // Unified Plan semantics: Stop sending on the RtpSender and mark the
+  // corresponding RtpTransceiver direction as no longer sending.
+  //
+  // Errors:
+  // - INVALID_PARAMETER: |sender| is null or (Plan B only) the sender is not
+  //       associated with this PeerConnection.
+  // - INVALID_STATE: PeerConnection is closed.
+  // TODO(bugs.webrtc.org/9534): Rename to RemoveTrack once the other signature
+  // is removed.
+  virtual RTCError RemoveTrackNew(
+      rtc::scoped_refptr<RtpSenderInterface> sender);
 
   // AddTransceiver creates a new RtpTransceiver and adds it to the set of
   // transceivers. Adding a transceiver will cause future calls to CreateOffer
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index 1064892..6edc19a 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -1294,10 +1294,10 @@
 
 bool PeerConnection::RemoveTrack(RtpSenderInterface* sender) {
   TRACE_EVENT0("webrtc", "PeerConnection::RemoveTrack");
-  return RemoveTrackInternal(sender).ok();
+  return RemoveTrackNew(sender).ok();
 }
 
-RTCError PeerConnection::RemoveTrackInternal(
+RTCError PeerConnection::RemoveTrackNew(
     rtc::scoped_refptr<RtpSenderInterface> sender) {
   if (!sender) {
     LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Sender is null.");
diff --git a/pc/peerconnection.h b/pc/peerconnection.h
index 22f94b0..bb37e9a 100644
--- a/pc/peerconnection.h
+++ b/pc/peerconnection.h
@@ -88,6 +88,8 @@
       rtc::scoped_refptr<MediaStreamTrackInterface> track,
       const std::vector<std::string>& stream_ids) override;
   bool RemoveTrack(RtpSenderInterface* sender) override;
+  RTCError RemoveTrackNew(
+      rtc::scoped_refptr<RtpSenderInterface> sender) override;
 
   RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver(
       rtc::scoped_refptr<MediaStreamTrackInterface> track) override;
@@ -345,9 +347,6 @@
   FindFirstTransceiverForAddedTrack(
       rtc::scoped_refptr<MediaStreamTrackInterface> track);
 
-  // RemoveTrack that returns an RTCError.
-  RTCError RemoveTrackInternal(rtc::scoped_refptr<RtpSenderInterface> sender);
-
   rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
   FindTransceiverBySender(rtc::scoped_refptr<RtpSenderInterface> sender);