Add stream label to test video source for better debugablity and testability

Bug: b/294812400
Change-Id: I830515b797100ca2dc0e68dd3b79d5a1bb4068da
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/316221
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40581}
diff --git a/api/test/video/test_video_track_source.cc b/api/test/video/test_video_track_source.cc
index a7ec448..56d70d1 100644
--- a/api/test/video/test_video_track_source.cc
+++ b/api/test/video/test_video_track_source.cc
@@ -9,6 +9,9 @@
  */
 #include "api/test/video/test_video_track_source.h"
 
+#include <utility>
+
+#include "absl/types/optional.h"
 #include "api/media_stream_interface.h"
 #include "api/sequence_checker.h"
 #include "api/video/video_frame.h"
@@ -19,8 +22,12 @@
 namespace webrtc {
 namespace test {
 
-TestVideoTrackSource::TestVideoTrackSource(bool remote)
-    : state_(kInitializing), remote_(remote) {
+TestVideoTrackSource::TestVideoTrackSource(
+    bool remote,
+    absl::optional<std::string> stream_label)
+    : stream_label_(std::move(stream_label)),
+      state_(kInitializing),
+      remote_(remote) {
   worker_thread_checker_.Detach();
   signaling_thread_checker_.Detach();
 }
diff --git a/api/test/video/test_video_track_source.h b/api/test/video/test_video_track_source.h
index 449228f..173bb64 100644
--- a/api/test/video/test_video_track_source.h
+++ b/api/test/video/test_video_track_source.h
@@ -11,6 +11,8 @@
 #ifndef API_TEST_VIDEO_TEST_VIDEO_TRACK_SOURCE_H_
 #define API_TEST_VIDEO_TEST_VIDEO_TRACK_SOURCE_H_
 
+#include <string>
+
 #include "absl/types/optional.h"
 #include "api/media_stream_interface.h"
 #include "api/notifier.h"
@@ -28,7 +30,9 @@
 // Video source that can be used as input for tests.
 class TestVideoTrackSource : public Notifier<VideoTrackSourceInterface> {
  public:
-  explicit TestVideoTrackSource(bool remote);
+  explicit TestVideoTrackSource(
+      bool remote,
+      absl::optional<std::string> stream_label = absl::nullopt);
   ~TestVideoTrackSource() override = default;
 
   void SetState(SourceState new_state);
@@ -72,10 +76,15 @@
                                      int height,
                                      const absl::optional<int>& max_fps) {}
 
+  // Returns stream label for this video source if present. Implementations
+  // may override this method to increase debugability and testability.
+  virtual absl::optional<std::string> GetStreamLabel() { return stream_label_; }
+
  protected:
   virtual rtc::VideoSourceInterface<VideoFrame>* source() = 0;
 
  private:
+  const absl::optional<std::string> stream_label_;
   RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_thread_checker_;
   RTC_NO_UNIQUE_ADDRESS SequenceChecker signaling_thread_checker_;
   SourceState state_ RTC_GUARDED_BY(&signaling_thread_checker_);
diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn
index ebe4d9b..75db40e 100644
--- a/test/pc/e2e/BUILD.gn
+++ b/test/pc/e2e/BUILD.gn
@@ -130,6 +130,7 @@
         "../../../api/test/video:test_video_track_source",
         "../../../api/video:video_frame",
       ]
+      absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
     }
 
     rtc_library("media_helper") {
diff --git a/test/pc/e2e/media/media_helper.cc b/test/pc/e2e/media/media_helper.cc
index d14dcdd..35eae68 100644
--- a/test/pc/e2e/media/media_helper.cc
+++ b/test/pc/e2e/media/media_helper.cc
@@ -59,7 +59,7 @@
             VideoTrackInterface::ContentHint::kDetailed;
     rtc::scoped_refptr<TestVideoCapturerVideoTrackSource> source =
         rtc::make_ref_counted<TestVideoCapturerVideoTrackSource>(
-            std::move(capturer), is_screencast);
+            std::move(capturer), is_screencast, video_config.stream_label);
     out.push_back(source);
     RTC_LOG(LS_INFO) << "Adding video with video_config.stream_label="
                      << video_config.stream_label.value();
diff --git a/test/pc/e2e/media/test_video_capturer_video_track_source.h b/test/pc/e2e/media/test_video_capturer_video_track_source.h
index 846721d..abcdc6c 100644
--- a/test/pc/e2e/media/test_video_capturer_video_track_source.h
+++ b/test/pc/e2e/media/test_video_capturer_video_track_source.h
@@ -14,6 +14,7 @@
 #include <memory>
 #include <utility>
 
+#include "absl/types/optional.h"
 #include "api/sequence_checker.h"
 #include "api/test/video/test_video_track_source.h"
 #include "api/video/video_frame.h"
@@ -27,8 +28,9 @@
  public:
   TestVideoCapturerVideoTrackSource(
       std::unique_ptr<test::TestVideoCapturer> video_capturer,
-      bool is_screencast)
-      : TestVideoTrackSource(/*remote=*/false),
+      bool is_screencast,
+      absl::optional<std::string> stream_label = absl::nullopt)
+      : TestVideoTrackSource(/*remote=*/false, std::move(stream_label)),
         video_capturer_(std::move(video_capturer)),
         is_screencast_(is_screencast) {
     sequence_checker_.Detach();