Make rtp_generator buildable from Chromium.

Bug: chromium:942546
Change-Id: I90d077eca55f6cbae119c576d1ba1ec456858377
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168245
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30470}
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index bffa033..30c0cf5 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -138,9 +138,10 @@
   }
 }
 
-# Only expose the targets needed by Chromium (e.g. frame_analyzer) to avoid
-# building a lot of redundant code as part of Chromium builds.
-if (!build_with_chromium) {
+if (!is_component_build) {
+  # This target can be built from Chromium but it doesn't support
+  # is_component_build=true because it depends on WebRTC testonly code
+  # which is not part of //third_party/webrtc_overrides:webrtc_component.
   rtc_executable("rtp_generator") {
     visibility = [ "*" ]
     testonly = true
@@ -183,8 +184,17 @@
       "//third_party/abseil-cpp/absl/flags:usage",
       "//third_party/abseil-cpp/absl/strings",
     ]
+    if (build_with_chromium) {
+      # When building from Chromium, WebRTC's metrics and field trial
+      # implementations need to be replaced by the Chromium ones.
+      deps += [ "//third_party/webrtc_overrides:webrtc_component" ]
+    }
   }
+}
 
+# Only expose the targets needed by Chromium (e.g. frame_analyzer) to avoid
+# building a lot of redundant code as part of Chromium builds.
+if (!build_with_chromium) {
   rtc_executable("psnr_ssim_analyzer") {
     testonly = true
     sources = [ "psnr_ssim_analyzer/psnr_ssim_analyzer.cc" ]