Move initialization of WebRtcSessionDescriptionFactory to SdpHandler

Also move ssrc_generator and audio/video options, as well as some
signal handling that's related.

These variables were not referenced in peer_connection.cc any more.

Bug: webrtc:11995
Change-Id: I29f8661afad488380d256220b35330233e8233e8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/189967
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32471}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 8a72bcf..e6e8c7f 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -13,23 +13,22 @@
 #include <limits.h>
 #include <stddef.h>
 #include <algorithm>
-#include <limits>
 #include <memory>
-#include <queue>
 #include <set>
 #include <utility>
 
 #include "absl/algorithm/container.h"
 #include "absl/strings/match.h"
 #include "api/jsep_ice_candidate.h"
+#include "api/rtp_parameters.h"
 #include "api/rtp_transceiver_direction.h"
 #include "api/task_queue/queued_task.h"
 #include "api/transport/webrtc_key_value_config.h"
 #include "api/uma_metrics.h"
-#include "api/video/builtin_video_bitrate_allocator_factory.h"
 #include "api/video/video_codec_constants.h"
 #include "call/audio_state.h"
 #include "call/packet_receiver.h"
+#include "media/base/media_channel.h"
 #include "media/base/media_config.h"
 #include "media/base/rid_description.h"
 #include "media/base/stream_params.h"
@@ -40,11 +39,11 @@
 #include "p2p/base/p2p_constants.h"
 #include "p2p/base/p2p_transport_channel.h"
 #include "p2p/base/transport_info.h"
-#include "pc/audio_rtp_receiver.h"
 #include "pc/ice_server_parsing.h"
+#include "pc/rtp_receiver.h"
+#include "pc/rtp_sender.h"
 #include "pc/sctp_transport.h"
 #include "pc/simulcast_description.h"
-#include "pc/video_rtp_receiver.h"
 #include "pc/webrtc_session_description_factory.h"
 #include "rtc_base/bind.h"
 #include "rtc_base/helpers.h"
@@ -54,11 +53,11 @@
 #include "rtc_base/net_helper.h"
 #include "rtc_base/network_constants.h"
 #include "rtc_base/robo_caller.h"
-#include "rtc_base/rtc_certificate_generator.h"
 #include "rtc_base/socket_address.h"
 #include "rtc_base/string_encode.h"
 #include "rtc_base/task_utils/to_queued_task.h"
 #include "rtc_base/trace_event.h"
+#include "rtc_base/unique_id_generator.h"
 #include "system_wrappers/include/metrics.h"
 
 using cricket::ContentInfo;
@@ -417,7 +416,6 @@
   observer_ = dependencies.observer;
   async_resolver_factory_ = std::move(dependencies.async_resolver_factory);
   port_allocator_ = std::move(dependencies.allocator);
-  packet_socket_factory_ = std::move(dependencies.packet_socket_factory);
   ice_transport_factory_ = std::move(dependencies.ice_transport_factory);
   tls_cert_verifier_ = std::move(dependencies.tls_cert_verifier);
 
@@ -564,40 +562,6 @@
         sdp_handler_.UpdateNegotiationNeeded();
       });
 
-  video_options_.screencast_min_bitrate_kbps =
-      configuration.screencast_min_bitrate;
-  audio_options_.combined_audio_video_bwe =
-      configuration.combined_audio_video_bwe;
-
-  audio_options_.audio_jitter_buffer_max_packets =
-      configuration.audio_jitter_buffer_max_packets;
-
-  audio_options_.audio_jitter_buffer_fast_accelerate =
-      configuration.audio_jitter_buffer_fast_accelerate;
-
-  audio_options_.audio_jitter_buffer_min_delay_ms =
-      configuration.audio_jitter_buffer_min_delay_ms;
-
-  audio_options_.audio_jitter_buffer_enable_rtx_handling =
-      configuration.audio_jitter_buffer_enable_rtx_handling;
-
-  auto webrtc_session_desc_factory =
-      std::make_unique<WebRtcSessionDescriptionFactory>(
-          signaling_thread(), channel_manager(), &sdp_handler_, session_id(),
-          dtls_enabled_, std::move(dependencies.cert_generator), certificate,
-          &ssrc_generator_);
-  webrtc_session_desc_factory->SignalCertificateReady.connect(
-      this, &PeerConnection::OnCertificateReady);
-
-  if (options.disable_encryption) {
-    webrtc_session_desc_factory->SetSdesPolicy(cricket::SEC_DISABLED);
-  }
-
-  webrtc_session_desc_factory->set_enable_encrypted_rtp_header_extensions(
-      GetCryptoOptions().srtp.enable_encrypted_rtp_header_extensions);
-  webrtc_session_desc_factory->set_is_unified_plan(IsUnifiedPlan());
-  sdp_handler_.SetSessionDescFactory(std::move(webrtc_session_desc_factory));
-
   // Add default audio/video transceivers for Plan B SDP.
   if (!IsUnifiedPlan()) {
     rtp_manager()->transceivers()->Add(
@@ -610,6 +574,8 @@
   int delay_ms =
       return_histogram_very_quickly_ ? 0 : REPORT_USAGE_PATTERN_DELAY_MS;
 
+  sdp_handler_.Initialize(configuration, &dependencies);
+
   message_handler_.RequestUsagePatternReport(
       [this]() {
         RTC_DCHECK_RUN_ON(signaling_thread());
@@ -617,13 +583,6 @@
       },
       delay_ms);
 
-  if (dependencies.video_bitrate_allocator_factory) {
-    video_bitrate_allocator_factory_ =
-        std::move(dependencies.video_bitrate_allocator_factory);
-  } else {
-    video_bitrate_allocator_factory_ =
-        CreateBuiltinVideoBitrateAllocatorFactory();
-  }
   return true;
 }
 
@@ -1734,42 +1693,6 @@
   Observer()->OnIceSelectedCandidatePairChanged(event);
 }
 
-void PeerConnection::OnAudioTrackAdded(AudioTrackInterface* track,
-                                       MediaStreamInterface* stream) {
-  if (IsClosed()) {
-    return;
-  }
-  rtp_manager()->AddAudioTrack(track, stream);
-  sdp_handler_.UpdateNegotiationNeeded();
-}
-
-void PeerConnection::OnAudioTrackRemoved(AudioTrackInterface* track,
-                                         MediaStreamInterface* stream) {
-  if (IsClosed()) {
-    return;
-  }
-  rtp_manager()->RemoveAudioTrack(track, stream);
-  sdp_handler_.UpdateNegotiationNeeded();
-}
-
-void PeerConnection::OnVideoTrackAdded(VideoTrackInterface* track,
-                                       MediaStreamInterface* stream) {
-  if (IsClosed()) {
-    return;
-  }
-  rtp_manager()->AddVideoTrack(track, stream);
-  sdp_handler_.UpdateNegotiationNeeded();
-}
-
-void PeerConnection::OnVideoTrackRemoved(VideoTrackInterface* track,
-                                         MediaStreamInterface* stream) {
-  if (IsClosed()) {
-    return;
-  }
-  rtp_manager()->RemoveVideoTrack(track, stream);
-  sdp_handler_.UpdateNegotiationNeeded();
-}
-
 absl::optional<std::string> PeerConnection::GetDataMid() const {
   RTC_DCHECK_RUN_ON(signaling_thread());
   switch (data_channel_type()) {
@@ -2133,11 +2056,6 @@
   return transport_controller_->NeedsIceRestart(content_name);
 }
 
-void PeerConnection::OnCertificateReady(
-    const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
-  transport_controller_->SetLocalCertificate(certificate);
-}
-
 void PeerConnection::OnTransportControllerConnectionState(
     cricket::IceConnectionState state) {
   switch (state) {
diff --git a/pc/peer_connection.h b/pc/peer_connection.h
index dd7a3b4a..9edc43a 100644
--- a/pc/peer_connection.h
+++ b/pc/peer_connection.h
@@ -378,12 +378,8 @@
   }
   cricket::PortAllocator* port_allocator() { return port_allocator_.get(); }
   Call* call_ptr() { return call_ptr_; }
-  rtc::UniqueRandomIdGenerator* ssrc_generator() { return &ssrc_generator_; }
-  const cricket::AudioOptions& audio_options() { return audio_options_; }
-  const cricket::VideoOptions& video_options() { return video_options_; }
-  VideoBitrateAllocatorFactory* video_bitrate_allocator_factory() {
-    return video_bitrate_allocator_factory_.get();
-  }
+
+  ConnectionContext* context() { return context_.get(); }
 
   cricket::DataChannelType data_channel_type() const;
   void SetIceConnectionState(IceConnectionState new_state);
@@ -391,19 +387,6 @@
 
   // Report the UMA metric SdpFormatReceived for the given remote offer.
   void ReportSdpFormatReceived(const SessionDescriptionInterface& remote_offer);
-  // Signals from MediaStreamObserver.
-  void OnAudioTrackAdded(AudioTrackInterface* track,
-                         MediaStreamInterface* stream)
-      RTC_RUN_ON(signaling_thread());
-  void OnAudioTrackRemoved(AudioTrackInterface* track,
-                           MediaStreamInterface* stream)
-      RTC_RUN_ON(signaling_thread());
-  void OnVideoTrackAdded(VideoTrackInterface* track,
-                         MediaStreamInterface* stream)
-      RTC_RUN_ON(signaling_thread());
-  void OnVideoTrackRemoved(VideoTrackInterface* track,
-                           MediaStreamInterface* stream)
-      RTC_RUN_ON(signaling_thread());
 
   // Returns true if the PeerConnection is configured to use Unified Plan
   // semantics for creating offers/answers and setting local/remote
@@ -554,11 +537,6 @@
       const PeerConnectionInterface::RTCConfiguration& config) const;
 
 
-  // Called when an RTCCertificate is generated or retrieved by
-  // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
-  void OnCertificateReady(
-      const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
-
   // Returns true and the TransportInfo of the given |content_name|
   // from |description|. Returns false if it's not available.
   static bool GetTransportDescription(
@@ -663,7 +641,6 @@
   // is not injected. It should be required once chromium supplies it.
   std::unique_ptr<AsyncResolverFactory> async_resolver_factory_
       RTC_GUARDED_BY(signaling_thread());
-  std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
   std::unique_ptr<cricket::PortAllocator>
       port_allocator_;  // TODO(bugs.webrtc.org/9987): Accessed on both
                         // signaling and network thread.
@@ -715,29 +692,10 @@
 
   bool dtls_enabled_ RTC_GUARDED_BY(signaling_thread()) = false;
 
-  // Member variables for caching global options.
-  cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread());
-  cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread());
-
   UsagePattern usage_pattern_ RTC_GUARDED_BY(signaling_thread());
   bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) =
       false;
 
-  // This object should be used to generate any SSRC that is not explicitly
-  // specified by the user (or by the remote party).
-  // The generator is not used directly, instead it is passed on to the
-  // channel manager and the session description factory.
-  rtc::UniqueRandomIdGenerator ssrc_generator_
-      RTC_GUARDED_BY(signaling_thread());
-
-  // A video bitrate allocator factory.
-  // This can injected using the PeerConnectionDependencies,
-  // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called.
-  // Note that one can still choose to override this in a MediaEngine
-  // if one wants too.
-  std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
-      video_bitrate_allocator_factory_;
-
   DataChannelController data_channel_controller_;
 
   // Machinery for handling messages posted to oneself
diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc
index 81df99a..d9337f4 100644
--- a/pc/sdp_offer_answer.cc
+++ b/pc/sdp_offer_answer.cc
@@ -27,6 +27,7 @@
 #include "api/rtp_receiver_interface.h"
 #include "api/rtp_sender_interface.h"
 #include "api/uma_metrics.h"
+#include "api/video/builtin_video_bitrate_allocator_factory.h"
 #include "media/base/codec.h"
 #include "media/base/media_engine.h"
 #include "media/base/rid_description.h"
@@ -36,6 +37,7 @@
 #include "p2p/base/transport_description.h"
 #include "p2p/base/transport_description_factory.h"
 #include "p2p/base/transport_info.h"
+#include "pc/connection_context.h"
 #include "pc/data_channel_utils.h"
 #include "pc/media_protocol_names.h"
 #include "pc/media_stream.h"
@@ -49,11 +51,13 @@
 #include "pc/simulcast_description.h"
 #include "pc/stats_collector.h"
 #include "pc/usage_pattern.h"
+#include "pc/webrtc_session_description_factory.h"
 #include "rtc_base/bind.h"
 #include "rtc_base/helpers.h"
 #include "rtc_base/location.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/ref_counted_object.h"
+#include "rtc_base/rtc_certificate.h"
 #include "rtc_base/socket_address.h"
 #include "rtc_base/ssl_stream_adapter.h"
 #include "rtc_base/string_encode.h"
@@ -944,6 +948,61 @@
 
 SdpOfferAnswerHandler::~SdpOfferAnswerHandler() {}
 
+void SdpOfferAnswerHandler::Initialize(
+    const PeerConnectionInterface::RTCConfiguration& configuration,
+    PeerConnectionDependencies* dependencies) {
+  RTC_DCHECK_RUN_ON(signaling_thread());
+  video_options_.screencast_min_bitrate_kbps =
+      configuration.screencast_min_bitrate;
+  audio_options_.combined_audio_video_bwe =
+      configuration.combined_audio_video_bwe;
+
+  audio_options_.audio_jitter_buffer_max_packets =
+      configuration.audio_jitter_buffer_max_packets;
+
+  audio_options_.audio_jitter_buffer_fast_accelerate =
+      configuration.audio_jitter_buffer_fast_accelerate;
+
+  audio_options_.audio_jitter_buffer_min_delay_ms =
+      configuration.audio_jitter_buffer_min_delay_ms;
+
+  audio_options_.audio_jitter_buffer_enable_rtx_handling =
+      configuration.audio_jitter_buffer_enable_rtx_handling;
+
+  // Obtain a certificate from RTCConfiguration if any were provided (optional).
+  rtc::scoped_refptr<rtc::RTCCertificate> certificate;
+  if (!configuration.certificates.empty()) {
+    // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of
+    // just picking the first one. The decision should be made based on the DTLS
+    // handshake. The DTLS negotiations need to know about all certificates.
+    certificate = configuration.certificates[0];
+  }
+
+  webrtc_session_desc_factory_ =
+      std::make_unique<WebRtcSessionDescriptionFactory>(
+          signaling_thread(), channel_manager(), this, pc_->session_id(),
+          pc_->dtls_enabled(), std::move(dependencies->cert_generator),
+          certificate, &ssrc_generator_);
+  webrtc_session_desc_factory_->SignalCertificateReady.connect(
+      this, &SdpOfferAnswerHandler::OnCertificateReady);
+
+  if (pc_->context()->options().disable_encryption) {
+    webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
+  }
+
+  webrtc_session_desc_factory_->set_enable_encrypted_rtp_header_extensions(
+      pc_->GetCryptoOptions().srtp.enable_encrypted_rtp_header_extensions);
+  webrtc_session_desc_factory_->set_is_unified_plan(IsUnifiedPlan());
+
+  if (dependencies->video_bitrate_allocator_factory) {
+    video_bitrate_allocator_factory_ =
+        std::move(dependencies->video_bitrate_allocator_factory);
+  } else {
+    video_bitrate_allocator_factory_ =
+        CreateBuiltinVideoBitrateAllocatorFactory();
+  }
+}
+
 // ==================================================================
 // Access to pc_ variables
 cricket::ChannelManager* SdpOfferAnswerHandler::channel_manager() const {
@@ -986,6 +1045,11 @@
 
 // ===================================================================
 
+void SdpOfferAnswerHandler::OnCertificateReady(
+    const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
+  transport_controller()->SetLocalCertificate(certificate);
+}
+
 void SdpOfferAnswerHandler::PrepareForShutdown() {
   RTC_DCHECK_RUN_ON(signaling_thread());
   weak_ptr_factory_.InvalidateWeakPtrs();
@@ -2495,14 +2559,14 @@
 
   local_streams_->AddStream(local_stream);
   MediaStreamObserver* observer = new MediaStreamObserver(local_stream);
-  observer->SignalAudioTrackAdded.connect(pc_,
-                                          &PeerConnection::OnAudioTrackAdded);
+  observer->SignalAudioTrackAdded.connect(
+      this, &SdpOfferAnswerHandler::OnAudioTrackAdded);
   observer->SignalAudioTrackRemoved.connect(
-      pc_, &PeerConnection::OnAudioTrackRemoved);
-  observer->SignalVideoTrackAdded.connect(pc_,
-                                          &PeerConnection::OnVideoTrackAdded);
+      this, &SdpOfferAnswerHandler::OnAudioTrackRemoved);
+  observer->SignalVideoTrackAdded.connect(
+      this, &SdpOfferAnswerHandler::OnVideoTrackAdded);
   observer->SignalVideoTrackRemoved.connect(
-      pc_, &PeerConnection::OnVideoTrackRemoved);
+      this, &SdpOfferAnswerHandler::OnVideoTrackRemoved);
   stream_observers_.push_back(std::unique_ptr<MediaStreamObserver>(observer));
 
   for (const auto& track : local_stream->GetAudioTracks()) {
@@ -2546,6 +2610,42 @@
   UpdateNegotiationNeeded();
 }
 
+void SdpOfferAnswerHandler::OnAudioTrackAdded(AudioTrackInterface* track,
+                                              MediaStreamInterface* stream) {
+  if (pc_->IsClosed()) {
+    return;
+  }
+  rtp_manager()->AddAudioTrack(track, stream);
+  UpdateNegotiationNeeded();
+}
+
+void SdpOfferAnswerHandler::OnAudioTrackRemoved(AudioTrackInterface* track,
+                                                MediaStreamInterface* stream) {
+  if (pc_->IsClosed()) {
+    return;
+  }
+  rtp_manager()->RemoveAudioTrack(track, stream);
+  UpdateNegotiationNeeded();
+}
+
+void SdpOfferAnswerHandler::OnVideoTrackAdded(VideoTrackInterface* track,
+                                              MediaStreamInterface* stream) {
+  if (pc_->IsClosed()) {
+    return;
+  }
+  rtp_manager()->AddVideoTrack(track, stream);
+  UpdateNegotiationNeeded();
+}
+
+void SdpOfferAnswerHandler::OnVideoTrackRemoved(VideoTrackInterface* track,
+                                                MediaStreamInterface* stream) {
+  if (pc_->IsClosed()) {
+    return;
+  }
+  rtp_manager()->RemoveVideoTrack(track, stream);
+  UpdateNegotiationNeeded();
+}
+
 RTCError SdpOfferAnswerHandler::Rollback(SdpType desc_type) {
   auto state = signaling_state();
   if (state != PeerConnectionInterface::kHaveLocalOffer &&
@@ -4511,7 +4611,7 @@
     voice_channel = channel_manager()->CreateVoiceChannel(
         pc_->call_ptr(), pc_->configuration()->media_config, rtp_transport,
         signaling_thread(), mid, pc_->SrtpRequired(), pc_->GetCryptoOptions(),
-        pc_->ssrc_generator(), pc_->audio_options());
+        &ssrc_generator_, audio_options());
   }
   if (!voice_channel) {
     return nullptr;
@@ -4538,8 +4638,8 @@
     video_channel = channel_manager()->CreateVideoChannel(
         pc_->call_ptr(), pc_->configuration()->media_config, rtp_transport,
         signaling_thread(), mid, pc_->SrtpRequired(), pc_->GetCryptoOptions(),
-        pc_->ssrc_generator(), pc_->video_options(),
-        pc_->video_bitrate_allocator_factory());
+        &ssrc_generator_, video_options(),
+        video_bitrate_allocator_factory_.get());
   }
   if (!video_channel) {
     return nullptr;
@@ -4575,7 +4675,7 @@
             channel_manager()->CreateRtpDataChannel(
                 pc_->configuration()->media_config, rtp_transport,
                 signaling_thread(), mid, pc_->SrtpRequired(),
-                pc_->GetCryptoOptions(), pc_->ssrc_generator()));
+                pc_->GetCryptoOptions(), &ssrc_generator_));
       }
       if (!data_channel_controller()->rtp_data_channel()) {
         return false;
diff --git a/pc/sdp_offer_answer.h b/pc/sdp_offer_answer.h
index 0880c1d..873c24b 100644
--- a/pc/sdp_offer_answer.h
+++ b/pc/sdp_offer_answer.h
@@ -22,6 +22,7 @@
 #include <vector>
 
 #include "absl/types/optional.h"
+#include "api/audio_options.h"
 #include "api/candidate.h"
 #include "api/jsep.h"
 #include "api/jsep_ice_candidate.h"
@@ -36,6 +37,7 @@
 #include "api/set_remote_description_observer_interface.h"
 #include "api/transport/data_channel_transport_interface.h"
 #include "api/turn_customizer.h"
+#include "media/base/media_channel.h"
 #include "media/base/stream_params.h"
 #include "p2p/base/port_allocator.h"
 #include "pc/channel.h"
@@ -52,6 +54,7 @@
 #include "pc/rtp_receiver.h"
 #include "pc/rtp_sender.h"
 #include "pc/rtp_transceiver.h"
+#include "pc/rtp_transmission_manager.h"
 #include "pc/sctp_transport.h"
 #include "pc/session_description.h"
 #include "pc/stats_collector.h"
@@ -85,16 +88,17 @@
 // - Parsing and interpreting SDP.
 // - Generating offers and answers based on the current state.
 // This class lives on the signaling thread.
-class SdpOfferAnswerHandler {
+class SdpOfferAnswerHandler : public sigslot::has_slots<> {
  public:
   explicit SdpOfferAnswerHandler(PeerConnection* pc);
   ~SdpOfferAnswerHandler();
 
-  void SetSessionDescFactory(
-      std::unique_ptr<WebRtcSessionDescriptionFactory> factory) {
-    RTC_DCHECK_RUN_ON(signaling_thread());
-    webrtc_session_desc_factory_ = std::move(factory);
-  }
+  // Called from PeerConnection's Initialize() function. Can only be called
+  // once. Modifies dependencies.
+  void Initialize(
+      const PeerConnectionInterface::RTCConfiguration& configuration,
+      PeerConnectionDependencies* dependencies);
+
   void ResetSessionDescFactory() {
     RTC_DCHECK_RUN_ON(signaling_thread());
     webrtc_session_desc_factory_.reset();
@@ -255,6 +259,20 @@
 
   bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread());
 
+  // Signals from MediaStreamObserver.
+  void OnAudioTrackAdded(AudioTrackInterface* track,
+                         MediaStreamInterface* stream)
+      RTC_RUN_ON(signaling_thread());
+  void OnAudioTrackRemoved(AudioTrackInterface* track,
+                           MediaStreamInterface* stream)
+      RTC_RUN_ON(signaling_thread());
+  void OnVideoTrackAdded(VideoTrackInterface* track,
+                         MediaStreamInterface* stream)
+      RTC_RUN_ON(signaling_thread());
+  void OnVideoTrackRemoved(VideoTrackInterface* track,
+                           MediaStreamInterface* stream)
+      RTC_RUN_ON(signaling_thread());
+
   // | desc_type | is the type of the description that caused the rollback.
   RTCError Rollback(SdpType desc_type);
   void OnOperationsChainEmpty();
@@ -526,6 +544,11 @@
   // payload type based demuxing in the affected channels.
   bool UpdatePayloadTypeDemuxingState(cricket::ContentSource source);
 
+  // Called when an RTCCertificate is generated or retrieved by
+  // WebRTCSessionDescriptionFactory. Should happen before setLocalDescription.
+  void OnCertificateReady(
+      const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
+
   // ==================================================================
   // Access to pc_ variables
   cricket::ChannelManager* channel_manager() const;
@@ -538,6 +561,8 @@
   RtpTransmissionManager* rtp_manager();
   const RtpTransmissionManager* rtp_manager() const;
   // ===================================================================
+  const cricket::AudioOptions& audio_options() { return audio_options_; }
+  const cricket::VideoOptions& video_options() { return video_options_; }
 
   PeerConnection* const pc_;
 
@@ -616,6 +641,25 @@
       SessionError::kNone;
   std::string session_error_desc_ RTC_GUARDED_BY(signaling_thread());
 
+  // Member variables for caching global options.
+  cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread());
+  cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread());
+
+  // This object should be used to generate any SSRC that is not explicitly
+  // specified by the user (or by the remote party).
+  // The generator is not used directly, instead it is passed on to the
+  // channel manager and the session description factory.
+  rtc::UniqueRandomIdGenerator ssrc_generator_
+      RTC_GUARDED_BY(signaling_thread());
+
+  // A video bitrate allocator factory.
+  // This can be injected using the PeerConnectionDependencies,
+  // or else the CreateBuiltinVideoBitrateAllocatorFactory() will be called.
+  // Note that one can still choose to override this in a MediaEngine
+  // if one wants too.
+  std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
+      video_bitrate_allocator_factory_;
+
   rtc::WeakPtrFactory<SdpOfferAnswerHandler> weak_ptr_factory_
       RTC_GUARDED_BY(signaling_thread());
 };