MediaSession: ensure transport description factory exists

BUG=None

Change-Id: Ic29526c0c182257331d81ff3e66c5ae91ddf4ce1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/321186
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#40826}
diff --git a/pc/media_session.cc b/pc/media_session.cc
index 2a8a22b..27d718b 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -1566,17 +1566,13 @@
 }
 
 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory(
-    const TransportDescriptionFactory* transport_desc_factory,
-    rtc::UniqueRandomIdGenerator* ssrc_generator)
-    : ssrc_generator_(ssrc_generator),
-      transport_desc_factory_(transport_desc_factory) {}
-
-MediaSessionDescriptionFactory::MediaSessionDescriptionFactory(
     cricket::MediaEngineInterface* media_engine,
     bool rtx_enabled,
     rtc::UniqueRandomIdGenerator* ssrc_generator,
     const TransportDescriptionFactory* transport_desc_factory)
-    : MediaSessionDescriptionFactory(transport_desc_factory, ssrc_generator) {
+    : ssrc_generator_(ssrc_generator),
+      transport_desc_factory_(transport_desc_factory) {
+  RTC_CHECK(transport_desc_factory_);
   if (media_engine) {
     audio_send_codecs_ = media_engine->voice().send_codecs();
     audio_recv_codecs_ = media_engine->voice().recv_codecs();
@@ -2227,10 +2223,6 @@
     const SessionDescription* current_desc,
     SessionDescription* offer_desc,
     IceCredentialsIterator* ice_credentials) const {
-  if (!transport_desc_factory_) {
-    LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
-                         "Missing transport description factory");
-  }
   const TransportDescription* current_tdesc =
       GetTransportDescription(content_name, current_desc);
   std::unique_ptr<TransportDescription> new_tdesc(
@@ -2252,9 +2244,6 @@
     const SessionDescription* current_desc,
     bool require_transport_attributes,
     IceCredentialsIterator* ice_credentials) const {
-  if (!transport_desc_factory_) {
-    return nullptr;
-  }
   const TransportDescription* offer_tdesc =
       GetTransportDescription(content_name, offer_desc);
   const TransportDescription* current_tdesc =
diff --git a/pc/media_session.h b/pc/media_session.h
index 25adeed..3100fb6 100644
--- a/pc/media_session.h
+++ b/pc/media_session.h
@@ -139,16 +139,11 @@
 // of the various fields to determine the proper result.
 class MediaSessionDescriptionFactory {
  public:
-  // Simple constructor that does not set any configuration for the factory.
-  // When using this constructor, the methods below can be used to set the
-  // configuration.
+  // This constructor automatically sets up the factory to get its configuration
+  // from the specified MediaEngine (when provided).
   // The TransportDescriptionFactory and the UniqueRandomIdGenerator are not
   // owned by MediaSessionDescriptionFactory, so they must be kept alive by the
   // user of this class.
-  MediaSessionDescriptionFactory(const TransportDescriptionFactory* factory,
-                                 rtc::UniqueRandomIdGenerator* ssrc_generator);
-  // This helper automatically sets up the factory to get its configuration
-  // from the specified MediaEngine
   MediaSessionDescriptionFactory(cricket::MediaEngineInterface* media_engine,
                                  bool rtx_enabled,
                                  rtc::UniqueRandomIdGenerator* ssrc_generator,
diff --git a/pc/media_session_unittest.cc b/pc/media_session_unittest.cc
index 3f52d5c..753e8cd 100644
--- a/pc/media_session_unittest.cc
+++ b/pc/media_session_unittest.cc
@@ -438,8 +438,8 @@
   MediaSessionDescriptionFactoryTest()
       : tdf1_(field_trials),
         tdf2_(field_trials),
-        f1_(&tdf1_, &ssrc_generator1),
-        f2_(&tdf2_, &ssrc_generator2) {
+        f1_(nullptr, false, &ssrc_generator1, &tdf1_),
+        f2_(nullptr, false, &ssrc_generator2, &tdf2_) {
     f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1),
                          MAKE_VECTOR(kAudioCodecs1));
     f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1),
@@ -4589,8 +4589,8 @@
   MediaProtocolTest()
       : tdf1_(field_trials_),
         tdf2_(field_trials_),
-        f1_(&tdf1_, &ssrc_generator1),
-        f2_(&tdf2_, &ssrc_generator2) {
+        f1_(nullptr, false, &ssrc_generator1, &tdf1_),
+        f2_(nullptr, false, &ssrc_generator2, &tdf2_) {
     f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1),
                          MAKE_VECTOR(kAudioCodecs1));
     f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1),
@@ -4654,7 +4654,7 @@
   webrtc::test::ScopedKeyValueConfig field_trials;
   TransportDescriptionFactory tdf(field_trials);
   UniqueRandomIdGenerator ssrc_generator;
-  MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator);
+  MediaSessionDescriptionFactory sf(nullptr, false, &ssrc_generator, &tdf);
   std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1);
   std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2);
 
@@ -4726,7 +4726,7 @@
   webrtc::test::ScopedKeyValueConfig field_trials;
   TransportDescriptionFactory tdf(field_trials);
   UniqueRandomIdGenerator ssrc_generator;
-  MediaSessionDescriptionFactory sf(&tdf, &ssrc_generator);
+  MediaSessionDescriptionFactory sf(nullptr, false, &ssrc_generator, &tdf);
   const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1);
   const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2);
   const std::vector<AudioCodec> sendrecv_codecs =
@@ -4829,8 +4829,10 @@
   TransportDescriptionFactory offer_tdf(field_trials);
   TransportDescriptionFactory answer_tdf(field_trials);
   UniqueRandomIdGenerator ssrc_generator1, ssrc_generator2;
-  MediaSessionDescriptionFactory offer_factory(&offer_tdf, &ssrc_generator1);
-  MediaSessionDescriptionFactory answer_factory(&answer_tdf, &ssrc_generator2);
+  MediaSessionDescriptionFactory offer_factory(nullptr, false, &ssrc_generator1,
+                                               &offer_tdf);
+  MediaSessionDescriptionFactory answer_factory(nullptr, false,
+                                                &ssrc_generator2, &answer_tdf);
 
   offer_factory.set_audio_codecs(
       VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs),