Add support for JSEP offer/answer with transceivers

This change adds support to PeerConnection's CreateOffer/
CreateAnswer/SetLocalDescription/SetRemoteDescription for
Unified Plan SDP mapping to/from RtpTransceivers. This behavior
is enabled using the kUnifiedPlan SDP semantics in the
PeerConnection configuration.

Bug: webrtc:7600
Change-Id: I4b44f5d3690887d387bf9c47eac00db8ec974571
Reviewed-on: https://webrtc-review.googlesource.com/28341
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21442}
diff --git a/pc/rtptransceiver.h b/pc/rtptransceiver.h
index 19f393f..9e8565b 100644
--- a/pc/rtptransceiver.h
+++ b/pc/rtptransceiver.h
@@ -115,6 +115,33 @@
   // Returns the backing object for the transceiver's Unified Plan receiver.
   rtc::scoped_refptr<RtpReceiverInternal> receiver_internal() const;
 
+  // RtpTransceivers are not associated until they have a corresponding media
+  // section set in SetLocalDescription or SetRemoteDescription. Therefore,
+  // when setting a local offer we need a way to remember which transceiver was
+  // used to create which media section in the offer. Storing the mline index
+  // in CreateOffer is specified in JSEP to allow us to do that.
+  rtc::Optional<size_t> mline_index() const { return mline_index_; }
+  void set_mline_index(rtc::Optional<size_t> mline_index) {
+    mline_index_ = mline_index;
+  }
+
+  // Sets the MID for this transceiver. If the MID is not null, then the
+  // transceiver is considered "associated" with the media section that has the
+  // same MID.
+  void set_mid(const rtc::Optional<std::string>& mid) { mid_ = mid; }
+
+  // Sets the intended direction for this transceiver. Intended to be used
+  // internally over SetDirection since this does not trigger a negotiation
+  // needed callback.
+  void set_direction(RtpTransceiverDirection direction) {
+    direction_ = direction;
+  }
+
+  // Sets the current direction for this transceiver as negotiated in an offer/
+  // answer exchange. The current direction is null before an answer with this
+  // transceiver has been set.
+  void set_current_direction(RtpTransceiverDirection direction);
+
   // According to JSEP rules for SetRemoteDescription, RtpTransceivers can be
   // reused only if they were added by AddTrack.
   void set_created_by_addtrack(bool created_by_addtrack) {
@@ -152,9 +179,8 @@
   RtpTransceiverDirection direction_ = RtpTransceiverDirection::kInactive;
   rtc::Optional<RtpTransceiverDirection> current_direction_;
   rtc::Optional<std::string> mid_;
+  rtc::Optional<size_t> mline_index_;
   bool created_by_addtrack_ = false;
-  // TODO(steveanton): Implement this once there is a mechanism to set the
-  // current direction.
   bool has_ever_been_used_to_send_ = false;
 
   cricket::BaseChannel* channel_ = nullptr;