Relanding: Adding support for Unified Plan offer/answer negotiation to the mediasession layer.

This layer takes in a simplified "options" struct and the current local description,
and generates a new offer/answer. Previously the options struct assumed there would
only be one media description per media type (audio/video), but it now supports
N number of audio/video descriptions.

The |add_legacy_stream| options is removed from the mediasession.cc/.h
in this CL.

The next step is to add the ability for PeerConnection/WebRtcSession to create
"options" to represent multiple RtpTransceivers, and apply the Unified Plan
descriptions correctly. Right now, only Plan B descriptions will be
generated in unit tests.

BUG=chromium:465349

Review-Url: https://codereview.webrtc.org/2991693002
Cr-Original-Commit-Position: refs/heads/master@{#19343}
Committed: https://chromium.googlesource.com/external/webrtc/+/a77e6bbd30276bdc5b30f2cbc1e92ca181ae76f0
Review-Url: https://codereview.webrtc.org/2991693002
Cr-Commit-Position: refs/heads/master@{#19394}
diff --git a/webrtc/pc/peerconnection.h b/webrtc/pc/peerconnection.h
index f8b6a54..5889629 100644
--- a/webrtc/pc/peerconnection.h
+++ b/webrtc/pc/peerconnection.h
@@ -32,28 +32,12 @@
 class VideoRtpReceiver;
 class RtcEventLog;
 
-// Populates |session_options| from |rtc_options|, and returns true if options
-// are valid.
-// |session_options|->transport_options map entries must exist in order for
-// them to be populated from |rtc_options|.
-bool ExtractMediaSessionOptions(
+// TODO(zhihuang): Remove this declaration when the WebRtcSession tests don't
+// need it.
+void ExtractSharedMediaSessionOptions(
     const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
-    bool is_offer,
     cricket::MediaSessionOptions* session_options);
 
-// Populates |session_options| from |constraints|, and returns true if all
-// mandatory constraints are satisfied.
-// Assumes that |session_options|->transport_options map entries exist.
-// Will also set defaults if corresponding constraints are not present:
-// recv_audio=true, recv_video=true, bundle_enabled=true.
-// Other fields will be left with existing values.
-//
-// Deprecated. Will be removed once callers that use constraints are gone.
-// TODO(hta): Remove when callers are gone.
-// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
-bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints,
-                               cricket::MediaSessionOptions* session_options);
-
 // PeerConnection implements the PeerConnectionInterface interface.
 // It uses WebRtcSession to implement the PeerConnection functionality.
 class PeerConnection : public PeerConnectionInterface,
@@ -244,26 +228,24 @@
 
   // Returns a MediaSessionOptions struct with options decided by |options|,
   // the local MediaStreams and DataChannels.
-  virtual bool GetOptionsForOffer(
+  void GetOptionsForOffer(
       const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
       cricket::MediaSessionOptions* session_options);
 
   // Returns a MediaSessionOptions struct with options decided by
   // |constraints|, the local MediaStreams and DataChannels.
-  // Deprecated, use version without constraints.
-  virtual bool GetOptionsForAnswer(
-      const MediaConstraintsInterface* constraints,
-      cricket::MediaSessionOptions* session_options);
-  virtual bool GetOptionsForAnswer(
-      const RTCOfferAnswerOptions& options,
-      cricket::MediaSessionOptions* session_options);
+  void GetOptionsForAnswer(const RTCOfferAnswerOptions& options,
+                           cricket::MediaSessionOptions* session_options);
 
-  void InitializeOptionsForAnswer(
-      cricket::MediaSessionOptions* session_options);
-
-  // Helper function for options processing.
-  // Deprecated.
-  virtual void FinishOptionsForAnswer(
+  // Generates MediaDescriptionOptions for the |session_opts| based on existing
+  // local description or remote description.
+  void GenerateMediaDescriptionOptions(
+      const SessionDescriptionInterface* session_desc,
+      cricket::RtpTransceiverDirection audio_direction,
+      cricket::RtpTransceiverDirection video_direction,
+      rtc::Optional<size_t>* audio_index,
+      rtc::Optional<size_t>* video_index,
+      rtc::Optional<size_t>* data_index,
       cricket::MediaSessionOptions* session_options);
 
   // Remove all local and remote tracks of type |media_type|.
@@ -361,6 +343,7 @@
   void OnDataChannelOpenMessage(const std::string& label,
                                 const InternalDataChannelInit& config);
 
+  bool HasRtpSender(cricket::MediaType type) const;
   RtpSenderInternal* FindSenderById(const std::string& id);
 
   std::vector<rtc::scoped_refptr<