From 7ca522dcecf7853fff2ae37dc5f9fd8447862be0 Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Thu, 10 Nov 2022 08:10:07 +0100 Subject: [PATCH] Try to make PipeWire test more reliable It appears to be still failing occasionally so add one more event to verify streams connected successfully in order to verify whether we sent and received buffers properly in the next step. Bug: webrtc:14644 Change-Id: I08822b15452fc845d68cbff1b01ae6b6f7c1f486 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282842 Reviewed-by: Alexander Cooper Reviewed-by: Jeremy Leconte Commit-Queue: Jan Grulich Cr-Commit-Position: refs/heads/main@{#38598} --- .../linux/wayland/shared_screencast_stream.cc | 4 +++ .../linux/wayland/shared_screencast_stream.h | 1 + .../shared_screencast_stream_unittest.cc | 34 ++++++++++--------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc index 4651486223..1cd5013293 100644 --- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc +++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc @@ -224,6 +224,10 @@ void SharedScreenCastStreamPrivate::OnStreamStateChanged( RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message; break; case PW_STREAM_STATE_PAUSED: + if (that->observer_ && old_state != PW_STREAM_STATE_STREAMING) { + that->observer_->OnStreamConfigured(); + } + break; case PW_STREAM_STATE_STREAMING: case PW_STREAM_STATE_UNCONNECTED: case PW_STREAM_STATE_CONNECTING: diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.h b/modules/desktop_capture/linux/wayland/shared_screencast_stream.h index 8ab951ca37..ba29525224 100644 --- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.h +++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.h @@ -34,6 +34,7 @@ class RTC_EXPORT SharedScreenCastStream virtual void OnCursorShapeChanged() = 0; virtual void OnDesktopFrameChanged() = 0; virtual void OnFailedToProcessBuffer() = 0; + virtual void OnStreamConfigured() = 0; protected: Observer() = default; diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream_unittest.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream_unittest.cc index f4d5351bd9..1de5f19013 100644 --- a/modules/desktop_capture/linux/wayland/shared_screencast_stream_unittest.cc +++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream_unittest.cc @@ -23,6 +23,7 @@ #include "test/gtest.h" using ::testing::_; +using ::testing::AtLeast; using ::testing::Ge; using ::testing::Invoke; @@ -39,16 +40,8 @@ class PipeWireStreamTest : public ::testing::Test, public TestScreenCastStreamProvider::Observer, public SharedScreenCastStream::Observer { public: - PipeWireStreamTest() - : test_screencast_stream_provider_( - std::make_unique(this, - kWidth, - kHeight)) { - shared_screencast_stream_ = SharedScreenCastStream::CreateDefault(); - shared_screencast_stream_->SetObserver(this); - } - - ~PipeWireStreamTest() override {} + PipeWireStreamTest() = default; + ~PipeWireStreamTest() = default; // FakeScreenCastPortal::Observer MOCK_METHOD(void, OnBufferAdded, (), (override)); @@ -62,6 +55,14 @@ class PipeWireStreamTest : public ::testing::Test, MOCK_METHOD(void, OnCursorShapeChanged, (), (override)); MOCK_METHOD(void, OnDesktopFrameChanged, (), (override)); MOCK_METHOD(void, OnFailedToProcessBuffer, (), (override)); + MOCK_METHOD(void, OnStreamConfigured, (), (override)); + + void SetUp() override { + shared_screencast_stream_ = SharedScreenCastStream::CreateDefault(); + shared_screencast_stream_->SetObserver(this); + test_screencast_stream_provider_ = + std::make_unique(this, kWidth, kHeight); + } void StartScreenCastStream(uint32_t stream_node_id) { shared_screencast_stream_->StartScreenCastStream(stream_node_id); @@ -78,23 +79,24 @@ class PipeWireStreamTest : public ::testing::Test, TEST_F(PipeWireStreamTest, TestPipeWire) { // Set expectations for PipeWire to successfully connect both streams rtc::Event waitConnectEvent; - rtc::Event waitAddBufferEvent; + rtc::Event waitStartStreamingEvent; EXPECT_CALL(*this, OnStreamReady(_)) .WillOnce(Invoke(this, &PipeWireStreamTest::StartScreenCastStream)); - EXPECT_CALL(*this, OnStartStreaming).WillOnce([&waitConnectEvent] { + EXPECT_CALL(*this, OnStreamConfigured).WillOnce([&waitConnectEvent] { waitConnectEvent.Set(); }); - EXPECT_CALL(*this, OnBufferAdded).WillRepeatedly([&waitAddBufferEvent] { - waitAddBufferEvent.Set(); + EXPECT_CALL(*this, OnBufferAdded).Times(AtLeast(3)); + EXPECT_CALL(*this, OnStartStreaming).WillOnce([&waitStartStreamingEvent] { + waitStartStreamingEvent.Set(); }); // Give it some time to connect, the order between these shouldn't matter, but // we need to be sure we are connected before we proceed to work with frames. waitConnectEvent.Wait(kLongWait); - // Wait for an empty buffer to be added - waitAddBufferEvent.Wait(kShortWait); + // Wait until we start streaming + waitStartStreamingEvent.Wait(kShortWait); rtc::Event frameRetrievedEvent; EXPECT_CALL(*this, OnFrameRecorded).Times(3);