OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include <algorithm> // max | 10 #include <algorithm> // max |
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 private: | 1501 private: |
1502 Call* call_; | 1502 Call* call_; |
1503 int packets_sent_; | 1503 int packets_sent_; |
1504 int transport_overhead_; | 1504 int transport_overhead_; |
1505 const size_t kMaxRtpPacketSize = 1000; | 1505 const size_t kMaxRtpPacketSize = 1000; |
1506 } test; | 1506 } test; |
1507 | 1507 |
1508 RunBaseTest(&test); | 1508 RunBaseTest(&test); |
1509 } | 1509 } |
1510 | 1510 |
| 1511 // Test class takes takes as argument a switch selecting if type switch should |
| 1512 // occur and a function pointer to reset the send stream. This is necessary |
| 1513 // since you cannot change the content type of a VideoSendStream, you need to |
| 1514 // recreate it. Stopping and recreating the stream can only be done on the main |
| 1515 // thread and in the context of VideoSendStreamTest (not BaseTest). |
| 1516 template <typename T> |
1511 class MaxPaddingSetTest : public test::SendTest { | 1517 class MaxPaddingSetTest : public test::SendTest { |
1512 public: | 1518 public: |
1513 static const uint32_t kMinTransmitBitrateBps = 400000; | 1519 static const uint32_t kMinTransmitBitrateBps = 400000; |
1514 static const uint32_t kActualEncodeBitrateBps = 40000; | 1520 static const uint32_t kActualEncodeBitrateBps = 40000; |
1515 static const uint32_t kMinPacketsToSend = 50; | 1521 static const uint32_t kMinPacketsToSend = 50; |
1516 | 1522 |
1517 explicit MaxPaddingSetTest(bool test_switch_content_type) | 1523 explicit MaxPaddingSetTest(bool test_switch_content_type, T* stream_reset_fun) |
1518 : SendTest(test::CallTest::kDefaultTimeoutMs), | 1524 : SendTest(test::CallTest::kDefaultTimeoutMs), |
| 1525 content_switch_event_(false, false), |
1519 call_(nullptr), | 1526 call_(nullptr), |
1520 send_stream_(nullptr), | 1527 send_stream_(nullptr), |
| 1528 send_stream_config_(nullptr), |
1521 packets_sent_(0), | 1529 packets_sent_(0), |
1522 running_without_padding_(test_switch_content_type) {} | 1530 running_without_padding_(test_switch_content_type), |
| 1531 stream_resetter_(stream_reset_fun) {} |
1523 | 1532 |
1524 void OnVideoStreamsCreated( | 1533 void OnVideoStreamsCreated( |
1525 VideoSendStream* send_stream, | 1534 VideoSendStream* send_stream, |
1526 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1535 const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 1536 rtc::CritScope lock(&crit_); |
1527 send_stream_ = send_stream; | 1537 send_stream_ = send_stream; |
1528 } | 1538 } |
1529 | 1539 |
1530 void ModifyVideoConfigs( | 1540 void ModifyVideoConfigs( |
1531 VideoSendStream::Config* send_config, | 1541 VideoSendStream::Config* send_config, |
1532 std::vector<VideoReceiveStream::Config>* receive_configs, | 1542 std::vector<VideoReceiveStream::Config>* receive_configs, |
1533 VideoEncoderConfig* encoder_config) override { | 1543 VideoEncoderConfig* encoder_config) override { |
1534 RTC_DCHECK_EQ(1, encoder_config->number_of_streams); | 1544 RTC_DCHECK_EQ(1, encoder_config->number_of_streams); |
1535 if (running_without_padding_) { | 1545 if (RunningWithoutPadding()) { |
1536 encoder_config->min_transmit_bitrate_bps = 0; | 1546 encoder_config->min_transmit_bitrate_bps = 0; |
1537 encoder_config->content_type = | 1547 encoder_config->content_type = |
1538 VideoEncoderConfig::ContentType::kRealtimeVideo; | 1548 VideoEncoderConfig::ContentType::kRealtimeVideo; |
1539 } else { | 1549 } else { |
1540 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 1550 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
1541 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; | 1551 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
1542 } | 1552 } |
| 1553 send_stream_config_ = send_config->Copy(); |
1543 encoder_config_ = encoder_config->Copy(); | 1554 encoder_config_ = encoder_config->Copy(); |
1544 } | 1555 } |
1545 | 1556 |
1546 void OnCallsCreated(Call* sender_call, Call* receiver_call) override { | 1557 void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
1547 call_ = sender_call; | 1558 call_ = sender_call; |
1548 } | 1559 } |
1549 | 1560 |
1550 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 1561 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
1551 rtc::CritScope lock(&crit_); | 1562 rtc::CritScope lock(&crit_); |
1552 | |
1553 if (running_without_padding_) | 1563 if (running_without_padding_) |
1554 EXPECT_EQ(0, call_->GetStats().max_padding_bitrate_bps); | 1564 EXPECT_EQ(0, call_->GetStats().max_padding_bitrate_bps); |
1555 | 1565 |
1556 // Wait until at least kMinPacketsToSend frames have been encoded, so that | 1566 // Wait until at least kMinPacketsToSend frames have been encoded, so that |
1557 // we have reliable data. | 1567 // we have reliable data. |
1558 if (++packets_sent_ < kMinPacketsToSend) | 1568 if (++packets_sent_ < kMinPacketsToSend) |
1559 return SEND_PACKET; | 1569 return SEND_PACKET; |
1560 | 1570 |
1561 if (running_without_padding_) { | 1571 if (running_without_padding_) { |
1562 // We've sent kMinPacketsToSend packets with default configuration, switch | 1572 // We've sent kMinPacketsToSend packets with default configuration, switch |
1563 // to enabling screen content and setting min transmit bitrate. | 1573 // to enabling screen content and setting min transmit bitrate. |
| 1574 // Note that we need to recreate the stream if changing content type. |
1564 packets_sent_ = 0; | 1575 packets_sent_ = 0; |
1565 encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 1576 encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
1566 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; | 1577 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
1567 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); | |
1568 running_without_padding_ = false; | 1578 running_without_padding_ = false; |
| 1579 content_switch_event_.Set(); |
1569 return SEND_PACKET; | 1580 return SEND_PACKET; |
1570 } | 1581 } |
1571 | 1582 |
1572 // Make sure the pacer has been configured with a min transmit bitrate. | 1583 // Make sure the pacer has been configured with a min transmit bitrate. |
1573 if (call_->GetStats().max_padding_bitrate_bps > 0) | 1584 if (call_->GetStats().max_padding_bitrate_bps > 0) |
1574 observation_complete_.Set(); | 1585 observation_complete_.Set(); |
1575 | 1586 |
1576 return SEND_PACKET; | 1587 return SEND_PACKET; |
1577 } | 1588 } |
1578 | 1589 |
1579 void PerformTest() override { | 1590 void PerformTest() override { |
| 1591 if (RunningWithoutPadding()) { |
| 1592 ASSERT_TRUE( |
| 1593 content_switch_event_.Wait(test::CallTest::kDefaultTimeoutMs)); |
| 1594 rtc::CritScope lock(&crit_); |
| 1595 RTC_DCHECK(stream_resetter_); |
| 1596 (*stream_resetter_)(send_stream_config_, encoder_config_); |
| 1597 } |
| 1598 |
1580 ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate."; | 1599 ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate."; |
1581 } | 1600 } |
1582 | 1601 |
1583 private: | 1602 private: |
| 1603 bool RunningWithoutPadding() const { |
| 1604 rtc::CritScope lock(&crit_); |
| 1605 return running_without_padding_; |
| 1606 } |
| 1607 |
1584 rtc::CriticalSection crit_; | 1608 rtc::CriticalSection crit_; |
| 1609 rtc::Event content_switch_event_; |
1585 Call* call_; | 1610 Call* call_; |
1586 VideoSendStream* send_stream_; | 1611 VideoSendStream* send_stream_ GUARDED_BY(crit_); |
| 1612 VideoSendStream::Config send_stream_config_; |
1587 VideoEncoderConfig encoder_config_; | 1613 VideoEncoderConfig encoder_config_; |
1588 uint32_t packets_sent_ GUARDED_BY(crit_); | 1614 uint32_t packets_sent_ GUARDED_BY(crit_); |
1589 bool running_without_padding_; | 1615 bool running_without_padding_; |
| 1616 T* const stream_resetter_; |
1590 }; | 1617 }; |
1591 | 1618 |
1592 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) { | 1619 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) { |
1593 MaxPaddingSetTest test(false); | 1620 auto reset_fun = [](const VideoSendStream::Config& send_stream_config, |
| 1621 const VideoEncoderConfig& encoder_config) {}; |
| 1622 MaxPaddingSetTest<decltype(reset_fun)> test(false, &reset_fun); |
1594 RunBaseTest(&test); | 1623 RunBaseTest(&test); |
1595 } | 1624 } |
1596 | 1625 |
1597 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) { | 1626 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) { |
1598 MaxPaddingSetTest test(true); | 1627 // Function for removing and recreating the send stream with a new config. |
| 1628 auto reset_fun = [this](const VideoSendStream::Config& send_stream_config, |
| 1629 const VideoEncoderConfig& encoder_config) { |
| 1630 Stop(); |
| 1631 sender_call_->DestroyVideoSendStream(video_send_stream_); |
| 1632 video_send_config_ = send_stream_config.Copy(); |
| 1633 video_encoder_config_ = encoder_config.Copy(); |
| 1634 video_send_stream_ = sender_call_->CreateVideoSendStream( |
| 1635 video_send_config_.Copy(), video_encoder_config_.Copy()); |
| 1636 video_send_stream_->SetSource( |
| 1637 frame_generator_capturer_.get(), |
| 1638 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1639 Start(); |
| 1640 }; |
| 1641 MaxPaddingSetTest<decltype(reset_fun)> test(true, &reset_fun); |
1599 RunBaseTest(&test); | 1642 RunBaseTest(&test); |
1600 } | 1643 } |
1601 | 1644 |
1602 // This test verifies that new frame sizes reconfigures encoders even though not | 1645 // This test verifies that new frame sizes reconfigures encoders even though not |
1603 // (yet) sending. The purpose of this is to permit encoding as quickly as | 1646 // (yet) sending. The purpose of this is to permit encoding as quickly as |
1604 // possible once we start sending. Likely the frames being input are from the | 1647 // possible once we start sending. Likely the frames being input are from the |
1605 // same source that will be sent later, which just means that we're ready | 1648 // same source that will be sent later, which just means that we're ready |
1606 // earlier. | 1649 // earlier. |
1607 TEST_F(VideoSendStreamTest, | 1650 TEST_F(VideoSendStreamTest, |
1608 EncoderReconfigureOnResolutionChangeWhenNotSending) { | 1651 EncoderReconfigureOnResolutionChangeWhenNotSending) { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 init_encode_event_(false, false), | 2101 init_encode_event_(false, false), |
2059 num_initializations_(0), | 2102 num_initializations_(0), |
2060 stream_(nullptr) {} | 2103 stream_(nullptr) {} |
2061 | 2104 |
2062 private: | 2105 private: |
2063 void ModifyVideoConfigs( | 2106 void ModifyVideoConfigs( |
2064 VideoSendStream::Config* send_config, | 2107 VideoSendStream::Config* send_config, |
2065 std::vector<VideoReceiveStream::Config>* receive_configs, | 2108 std::vector<VideoReceiveStream::Config>* receive_configs, |
2066 VideoEncoderConfig* encoder_config) override { | 2109 VideoEncoderConfig* encoder_config) override { |
2067 send_config->encoder_settings.encoder = this; | 2110 send_config->encoder_settings.encoder = this; |
| 2111 encoder_config->max_bitrate_bps = kFirstMaxBitrateBps; |
2068 encoder_config_ = encoder_config->Copy(); | 2112 encoder_config_ = encoder_config->Copy(); |
2069 } | 2113 } |
2070 | 2114 |
2071 void OnVideoStreamsCreated( | 2115 void OnVideoStreamsCreated( |
2072 VideoSendStream* send_stream, | 2116 VideoSendStream* send_stream, |
2073 const std::vector<VideoReceiveStream*>& receive_streams) override { | 2117 const std::vector<VideoReceiveStream*>& receive_streams) override { |
2074 stream_ = send_stream; | 2118 stream_ = send_stream; |
2075 } | 2119 } |
2076 | 2120 |
2077 int32_t InitEncode(const VideoCodec* config, | 2121 int32_t InitEncode(const VideoCodec* config, |
2078 int32_t number_of_cores, | 2122 int32_t number_of_cores, |
2079 size_t max_payload_size) override { | 2123 size_t max_payload_size) override { |
2080 if (num_initializations_ == 0) { | 2124 if (num_initializations_ == 0) { |
2081 // Verify default values. | 2125 // Verify default values. |
2082 EXPECT_EQ(kRealtimeVideo, config->mode); | 2126 EXPECT_EQ(kFirstMaxBitrateBps / 1000, config->maxBitrate); |
2083 } else { | 2127 } else { |
2084 // Verify that changed values are propagated. | 2128 // Verify that changed values are propagated. |
2085 EXPECT_EQ(kScreensharing, config->mode); | 2129 EXPECT_EQ(kSecondMaxBitrateBps / 1000, config->maxBitrate); |
2086 } | 2130 } |
2087 ++num_initializations_; | 2131 ++num_initializations_; |
2088 init_encode_event_.Set(); | 2132 init_encode_event_.Set(); |
2089 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 2133 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
2090 } | 2134 } |
2091 | 2135 |
2092 void PerformTest() override { | 2136 void PerformTest() override { |
2093 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); | 2137 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); |
2094 EXPECT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; | 2138 EXPECT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
2095 | 2139 |
2096 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; | 2140 encoder_config_.max_bitrate_bps = kSecondMaxBitrateBps; |
2097 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); | 2141 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
2098 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); | 2142 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); |
2099 EXPECT_EQ(2u, num_initializations_) | 2143 EXPECT_EQ(2u, num_initializations_) |
2100 << "ReconfigureVideoEncoder did not reinitialize the encoder with " | 2144 << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
2101 "new encoder settings."; | 2145 "new encoder settings."; |
2102 } | 2146 } |
2103 | 2147 |
| 2148 const uint32_t kFirstMaxBitrateBps = 1000000; |
| 2149 const uint32_t kSecondMaxBitrateBps = 2000000; |
| 2150 |
2104 rtc::Event init_encode_event_; | 2151 rtc::Event init_encode_event_; |
2105 size_t num_initializations_; | 2152 size_t num_initializations_; |
2106 VideoSendStream* stream_; | 2153 VideoSendStream* stream_; |
2107 VideoEncoderConfig encoder_config_; | 2154 VideoEncoderConfig encoder_config_; |
2108 } test; | 2155 } test; |
2109 | 2156 |
2110 RunBaseTest(&test); | 2157 RunBaseTest(&test); |
2111 } | 2158 } |
2112 | 2159 |
2113 static const size_t kVideoCodecConfigObserverNumberOfTemporalLayers = 4; | 2160 static const size_t kVideoCodecConfigObserverNumberOfTemporalLayers = 4; |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 rtc::CriticalSection crit_; | 3277 rtc::CriticalSection crit_; |
3231 uint32_t max_bitrate_bps_ GUARDED_BY(&crit_); | 3278 uint32_t max_bitrate_bps_ GUARDED_BY(&crit_); |
3232 bool first_packet_sent_ GUARDED_BY(&crit_); | 3279 bool first_packet_sent_ GUARDED_BY(&crit_); |
3233 rtc::Event bitrate_changed_event_; | 3280 rtc::Event bitrate_changed_event_; |
3234 } test; | 3281 } test; |
3235 | 3282 |
3236 RunBaseTest(&test); | 3283 RunBaseTest(&test); |
3237 } | 3284 } |
3238 | 3285 |
3239 } // namespace webrtc | 3286 } // namespace webrtc |
OLD | NEW |