Make VideoBitrateAllocatorFactory injectable.

This patch makes VideoBitrateAllocatorFactory injectable
by adding to PeerConnectionDependencies instead of allowing it to be
overridden using MediaEngine (on PeerConnectionFactory).

With this patch VideoBitrateAllocatorFactory is owned
by the PeerConnection.

WANT_LGTM (examples) : sakal@
WANT_LGTM (api/pc) : steveanton@

Bug: webrtc:10547
Change-Id: I768d400a621f2b7a98795eb7f410adb48651bfd6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132706
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27654}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 8ac1e83..129eed6 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -27,6 +27,7 @@
 #include "api/rtc_error.h"
 #include "api/rtp_parameters.h"
 #include "api/uma_metrics.h"
+#include "api/video/builtin_video_bitrate_allocator_factory.h"
 #include "call/call.h"
 #include "logging/rtc_event_log/ice_logger.h"
 #include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
@@ -1199,6 +1200,14 @@
       return_histogram_very_quickly_ ? 0 : REPORT_USAGE_PATTERN_DELAY_MS;
   signaling_thread()->PostDelayed(RTC_FROM_HERE, delay_ms, this,
                                   MSG_REPORT_USAGE_PATTERN, nullptr);
+
+  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;
 }
 
@@ -6311,7 +6320,7 @@
   cricket::VideoChannel* video_channel = channel_manager()->CreateVideoChannel(
       call_ptr_, configuration_.media_config, rtp_transport, media_transport,
       signaling_thread(), mid, SrtpRequired(), GetCryptoOptions(),
-      &ssrc_generator_, video_options_);
+      &ssrc_generator_, video_options_, video_bitrate_allocator_factory_.get());
   if (!video_channel) {
     return nullptr;
   }