Expose new video codec factories in the PeerConnectionFactory API

This CL exposes the new type of video codec factories that represent all
video codecs in the PeerConnectionFactory API, i.e. no extra internal SW
video codecs will be added. Clients of the new functions will be
responsible for adding all SW video codecs themselves, and also handling
SW fallback and simulcast.

BUG=webrtc:7925
R=deadbeef@webrtc.org

Review-Url: https://codereview.webrtc.org/3004353002 .
Cr-Commit-Position: refs/heads/master@{#19866}
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index 13e78e6..3753da4 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -112,6 +112,8 @@
 class AudioMixer;
 class CallFactoryInterface;
 class MediaConstraintsInterface;
+class VideoDecoderFactory;
+class VideoEncoderFactory;
 
 // MediaStream container interface.
 class StreamCollectionInterface : public rtc::RefCountInterface {
@@ -1116,6 +1118,21 @@
     rtc::scoped_refptr<AudioMixer> audio_mixer,
     rtc::scoped_refptr<AudioProcessing> audio_processing);
 
+// Create a new instance of PeerConnectionFactoryInterface with optional video
+// codec factories. These video factories represents all video codecs, i.e. no
+// extra internal video codecs will be added.
+rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
+    rtc::Thread* network_thread,
+    rtc::Thread* worker_thread,
+    rtc::Thread* signaling_thread,
+    rtc::scoped_refptr<AudioDeviceModule> default_adm,
+    rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+    rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+    std::unique_ptr<VideoEncoderFactory> video_encoder_factory,
+    std::unique_ptr<VideoDecoderFactory> video_decoder_factory,
+    rtc::scoped_refptr<AudioMixer> audio_mixer,
+    rtc::scoped_refptr<AudioProcessing> audio_processing);
+
 // Create a new instance of PeerConnectionFactoryInterface with external audio
 // mixer.
 //
diff --git a/media/engine/webrtcmediaengine.cc b/media/engine/webrtcmediaengine.cc
index 99b6041..888b6a9 100644
--- a/media/engine/webrtcmediaengine.cc
+++ b/media/engine/webrtcmediaengine.cc
@@ -14,6 +14,8 @@
 
 #include "api/audio_codecs/builtin_audio_decoder_factory.h"
 #include "api/audio_codecs/builtin_audio_encoder_factory.h"
+#include "api/video_codecs/video_decoder_factory.h"
+#include "api/video_codecs/video_encoder_factory.h"
 #include "media/engine/webrtcvoiceengine.h"
 
 #ifdef HAVE_WEBRTC_VIDEO
@@ -121,6 +123,32 @@
       video_decoder_factory, audio_mixer, audio_processing);
 }
 
+std::unique_ptr<MediaEngineInterface> WebRtcMediaEngineFactory::Create(
+    rtc::scoped_refptr<webrtc::AudioDeviceModule> adm,
+    rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+    rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
+    std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
+    std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory,
+    rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
+    rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) {
+#ifdef HAVE_WEBRTC_VIDEO
+  typedef WebRtcVideoEngine VideoEngine;
+  std::tuple<std::unique_ptr<webrtc::VideoEncoderFactory>,
+             std::unique_ptr<webrtc::VideoDecoderFactory>>
+      video_args(std::move(video_encoder_factory),
+                 std::move(video_decoder_factory));
+#else
+  typedef NullWebRtcVideoEngine VideoEngine;
+  std::tuple<> video_args;
+#endif
+  return std::unique_ptr<MediaEngineInterface>(
+      new CompositeMediaEngine<WebRtcVoiceEngine, VideoEngine>(
+          std::forward_as_tuple(adm, audio_encoder_factory,
+                                audio_decoder_factory, audio_mixer,
+                                audio_processing),
+          std::move(video_args)));
+}
+
 namespace {
 // Remove mutually exclusive extensions with lower priority.
 void DiscardRedundantExtensions(
diff --git a/media/engine/webrtcmediaengine.h b/media/engine/webrtcmediaengine.h
index f24f7c7..b9713e9 100644
--- a/media/engine/webrtcmediaengine.h
+++ b/media/engine/webrtcmediaengine.h
@@ -22,6 +22,8 @@
 class AudioDeviceModule;
 class AudioMixer;
 class AudioProcessing;
+class VideoDecoderFactory;
+class VideoEncoderFactory;
 }
 namespace cricket {
 class WebRtcVideoDecoderFactory;
@@ -81,6 +83,18 @@
       WebRtcVideoDecoderFactory* video_decoder_factory,
       rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
       rtc::scoped_refptr<webrtc::AudioProcessing> apm);
+
+  // Create a MediaEngineInterface with optional video codec factories. These
+  // video factories represents all video codecs, i.e. no extra internal video
+  // codecs will be added.
+  static std::unique_ptr<MediaEngineInterface> Create(
+      rtc::scoped_refptr<webrtc::AudioDeviceModule> adm,
+      rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+      rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
+      std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
+      std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory,
+      rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
+      rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing);
 };
 
 // Verify that extension IDs are within 1-byte extension range and are not
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 8c6b5a6..6339ffb 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -203,6 +203,7 @@
     "../api/audio_codecs:audio_codecs_api",
     "../api/audio_codecs:builtin_audio_decoder_factory",
     "../api/audio_codecs:builtin_audio_encoder_factory",
+    "../api/video_codecs:video_codecs_api",
     "../call",
     "../call:call_interfaces",
     "../logging:rtc_event_log_api",
diff --git a/pc/createpeerconnectionfactory.cc b/pc/createpeerconnectionfactory.cc
index a62a7ae..ed0ff2a 100644
--- a/pc/createpeerconnectionfactory.cc
+++ b/pc/createpeerconnectionfactory.cc
@@ -11,9 +11,12 @@
 #include "api/audio_codecs/builtin_audio_decoder_factory.h"
 #include "api/audio_codecs/builtin_audio_encoder_factory.h"
 #include "api/peerconnectioninterface.h"
+#include "api/video_codecs/video_decoder_factory.h"
+#include "api/video_codecs/video_encoder_factory.h"
 #include "call/callfactoryinterface.h"
 #include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
 #include "media/engine/webrtcmediaengine.h"
+#include "modules/audio_device/include/audio_device.h"
 #include "modules/audio_processing/include/audio_processing.h"
 #include "rtc_base/bind.h"
 #include "rtc_base/scoped_ref_ptr.h"
@@ -74,6 +77,40 @@
       std::move(call_factory), std::move(event_log_factory));
 }
 
+rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
+    rtc::Thread* network_thread,
+    rtc::Thread* worker_thread,
+    rtc::Thread* signaling_thread,
+    rtc::scoped_refptr<AudioDeviceModule> default_adm,
+    rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+    rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+    std::unique_ptr<VideoEncoderFactory> video_encoder_factory,
+    std::unique_ptr<VideoDecoderFactory> video_decoder_factory,
+    rtc::scoped_refptr<AudioMixer> audio_mixer,
+    rtc::scoped_refptr<AudioProcessing> audio_processing) {
+  if (!audio_processing)
+    audio_processing = AudioProcessing::Create();
+
+  std::unique_ptr<cricket::MediaEngineInterface> media_engine =
+      cricket::WebRtcMediaEngineFactory::Create(
+          default_adm, audio_encoder_factory, audio_decoder_factory,
+          std::move(video_encoder_factory), std::move(video_decoder_factory),
+          audio_mixer, audio_processing);
+
+  std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory();
+
+  std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory =
+      CreateRtcEventLogFactory();
+
+  return CreateModularPeerConnectionFactory(
+      network_thread, worker_thread, signaling_thread, default_adm,
+      audio_encoder_factory, audio_decoder_factory,
+      nullptr /* external_video_encoder_factory */,
+      nullptr /* external_video_decoder_factory */, audio_mixer,
+      std::move(media_engine), std::move(call_factory),
+      std::move(event_log_factory));
+}
+
 rtc::scoped_refptr<PeerConnectionFactoryInterface>
 CreatePeerConnectionFactoryWithAudioMixer(
     rtc::Thread* network_thread,