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}
This commit is contained in:
Artem Titov 2023-08-16 10:09:19 +02:00 committed by WebRTC LUCI CQ
parent 952e0b75f9
commit 1997837d16
5 changed files with 25 additions and 6 deletions

View File

@ -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();
}

View File

@ -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 @@ namespace test {
// 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 @@ class TestVideoTrackSource : public Notifier<VideoTrackSourceInterface> {
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_);

View File

@ -130,6 +130,7 @@ if (!build_with_chromium) {
"../../../api/test/video:test_video_track_source",
"../../../api/video:video_frame",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("media_helper") {

View File

@ -59,7 +59,7 @@ MediaHelper::MaybeAddVideo(TestPeer* peer) {
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();

View File

@ -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 @@ class TestVideoCapturerVideoTrackSource : public test::TestVideoTrackSource {
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();