Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1290)

Unified Diff: webrtc/video/video_send_stream_tests.cc

Issue 2710493008: Recreate WebrtcVideoSendStream if screen content setting is changed. (Closed)
Patch Set: readability Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/video/video_send_stream.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/video/video_send_stream_tests.cc
diff --git a/webrtc/video/video_send_stream_tests.cc b/webrtc/video/video_send_stream_tests.cc
index 196918a4eb4695d162e95e645ffa579cc51c728a..ed3d281ce209f9c276d601274a6c07a4f059f0a2 100644
--- a/webrtc/video/video_send_stream_tests.cc
+++ b/webrtc/video/video_send_stream_tests.cc
@@ -1508,22 +1508,32 @@ TEST_F(VideoSendStreamTest, ChangingTransportOverhead) {
RunBaseTest(&test);
}
+// Test class takes takes as argument a switch selecting if type switch should
+// occur and a function pointer to reset the send stream. This is necessary
+// since you cannot change the content type of a VideoSendStream, you need to
+// recreate it. Stopping and recreating the stream can only be done on the main
+// thread and in the context of VideoSendStreamTest (not BaseTest).
+template <typename T>
class MaxPaddingSetTest : public test::SendTest {
public:
static const uint32_t kMinTransmitBitrateBps = 400000;
static const uint32_t kActualEncodeBitrateBps = 40000;
static const uint32_t kMinPacketsToSend = 50;
- explicit MaxPaddingSetTest(bool test_switch_content_type)
+ explicit MaxPaddingSetTest(bool test_switch_content_type, T* stream_reset_fun)
: SendTest(test::CallTest::kDefaultTimeoutMs),
+ content_switch_event_(false, false),
call_(nullptr),
send_stream_(nullptr),
+ send_stream_config_(nullptr),
packets_sent_(0),
- running_without_padding_(test_switch_content_type) {}
+ running_without_padding_(test_switch_content_type),
+ stream_resetter_(stream_reset_fun) {}
void OnVideoStreamsCreated(
VideoSendStream* send_stream,
const std::vector<VideoReceiveStream*>& receive_streams) override {
+ rtc::CritScope lock(&crit_);
send_stream_ = send_stream;
}
@@ -1532,7 +1542,7 @@ class MaxPaddingSetTest : public test::SendTest {
std::vector<VideoReceiveStream::Config>* receive_configs,
VideoEncoderConfig* encoder_config) override {
RTC_DCHECK_EQ(1, encoder_config->number_of_streams);
- if (running_without_padding_) {
+ if (RunningWithoutPadding()) {
encoder_config->min_transmit_bitrate_bps = 0;
encoder_config->content_type =
VideoEncoderConfig::ContentType::kRealtimeVideo;
@@ -1540,6 +1550,7 @@ class MaxPaddingSetTest : public test::SendTest {
encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps;
encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
}
+ send_stream_config_ = send_config->Copy();
encoder_config_ = encoder_config->Copy();
}
@@ -1549,7 +1560,6 @@ class MaxPaddingSetTest : public test::SendTest {
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
-
if (running_without_padding_)
EXPECT_EQ(0, call_->GetStats().max_padding_bitrate_bps);
@@ -1561,11 +1571,12 @@ class MaxPaddingSetTest : public test::SendTest {
if (running_without_padding_) {
// We've sent kMinPacketsToSend packets with default configuration, switch
// to enabling screen content and setting min transmit bitrate.
+ // Note that we need to recreate the stream if changing content type.
packets_sent_ = 0;
encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps;
encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
- send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy());
running_without_padding_ = false;
+ content_switch_event_.Set();
return SEND_PACKET;
}
@@ -1577,25 +1588,57 @@ class MaxPaddingSetTest : public test::SendTest {
}
void PerformTest() override {
+ if (RunningWithoutPadding()) {
+ ASSERT_TRUE(
+ content_switch_event_.Wait(test::CallTest::kDefaultTimeoutMs));
+ rtc::CritScope lock(&crit_);
+ RTC_DCHECK(stream_resetter_);
+ (*stream_resetter_)(send_stream_config_, encoder_config_);
+ }
+
ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate.";
}
private:
+ bool RunningWithoutPadding() const {
+ rtc::CritScope lock(&crit_);
+ return running_without_padding_;
+ }
+
rtc::CriticalSection crit_;
+ rtc::Event content_switch_event_;
Call* call_;
- VideoSendStream* send_stream_;
+ VideoSendStream* send_stream_ GUARDED_BY(crit_);
+ VideoSendStream::Config send_stream_config_;
VideoEncoderConfig encoder_config_;
uint32_t packets_sent_ GUARDED_BY(crit_);
bool running_without_padding_;
+ T* const stream_resetter_;
};
TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) {
- MaxPaddingSetTest test(false);
+ auto reset_fun = [](const VideoSendStream::Config& send_stream_config,
+ const VideoEncoderConfig& encoder_config) {};
+ MaxPaddingSetTest<decltype(reset_fun)> test(false, &reset_fun);
RunBaseTest(&test);
}
TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) {
- MaxPaddingSetTest test(true);
+ // Function for removing and recreating the send stream with a new config.
+ auto reset_fun = [this](const VideoSendStream::Config& send_stream_config,
+ const VideoEncoderConfig& encoder_config) {
+ Stop();
+ sender_call_->DestroyVideoSendStream(video_send_stream_);
+ video_send_config_ = send_stream_config.Copy();
+ video_encoder_config_ = encoder_config.Copy();
+ video_send_stream_ = sender_call_->CreateVideoSendStream(
+ video_send_config_.Copy(), video_encoder_config_.Copy());
+ video_send_stream_->SetSource(
+ frame_generator_capturer_.get(),
+ VideoSendStream::DegradationPreference::kMaintainResolution);
+ Start();
+ };
+ MaxPaddingSetTest<decltype(reset_fun)> test(true, &reset_fun);
RunBaseTest(&test);
}
@@ -2065,6 +2108,7 @@ TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) {
std::vector<VideoReceiveStream::Config>* receive_configs,
VideoEncoderConfig* encoder_config) override {
send_config->encoder_settings.encoder = this;
+ encoder_config->max_bitrate_bps = kFirstMaxBitrateBps;
encoder_config_ = encoder_config->Copy();
}
@@ -2079,10 +2123,10 @@ TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) {
size_t max_payload_size) override {
if (num_initializations_ == 0) {
// Verify default values.
- EXPECT_EQ(kRealtimeVideo, config->mode);
+ EXPECT_EQ(kFirstMaxBitrateBps / 1000, config->maxBitrate);
} else {
// Verify that changed values are propagated.
- EXPECT_EQ(kScreensharing, config->mode);
+ EXPECT_EQ(kSecondMaxBitrateBps / 1000, config->maxBitrate);
}
++num_initializations_;
init_encode_event_.Set();
@@ -2093,7 +2137,7 @@ TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) {
EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs));
EXPECT_EQ(1u, num_initializations_) << "VideoEncoder not initialized.";
- encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
+ encoder_config_.max_bitrate_bps = kSecondMaxBitrateBps;
stream_->ReconfigureVideoEncoder(std::move(encoder_config_));
EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs));
EXPECT_EQ(2u, num_initializations_)
@@ -2101,6 +2145,9 @@ TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) {
"new encoder settings.";
}
+ const uint32_t kFirstMaxBitrateBps = 1000000;
+ const uint32_t kSecondMaxBitrateBps = 2000000;
+
rtc::Event init_encode_event_;
size_t num_initializations_;
VideoSendStream* stream_;
« no previous file with comments | « webrtc/video/video_send_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698