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 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 void ModifyVideoConfigs( | 1778 void ModifyVideoConfigs( |
1779 VideoSendStream::Config* send_config, | 1779 VideoSendStream::Config* send_config, |
1780 std::vector<VideoReceiveStream::Config>* receive_configs, | 1780 std::vector<VideoReceiveStream::Config>* receive_configs, |
1781 VideoEncoderConfig* encoder_config) override { | 1781 VideoEncoderConfig* encoder_config) override { |
1782 send_config->encoder_settings.encoder = this; | 1782 send_config->encoder_settings.encoder = this; |
1783 encoder_config_ = encoder_config->Copy(); | 1783 encoder_config_ = encoder_config->Copy(); |
1784 } | 1784 } |
1785 | 1785 |
1786 void PerformTest() override { | 1786 void PerformTest() override { |
1787 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; | 1787 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; |
1788 // Expect |num_releases| == 1 since the encoder has been reconfigured | 1788 EXPECT_EQ(0u, num_releases()); |
1789 // once when the first frame is encoded. Not until at that point is the | |
1790 // frame size known and the encoder can be properly initialized. | |
1791 EXPECT_EQ(1u, num_releases()); | |
1792 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); | 1789 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
1793 EXPECT_EQ(1u, num_releases()); | 1790 EXPECT_EQ(0u, num_releases()); |
1794 stream_->Stop(); | 1791 stream_->Stop(); |
1795 // Encoder should not be released before destroying the VideoSendStream. | 1792 // Encoder should not be released before destroying the VideoSendStream. |
1796 EXPECT_FALSE(IsReleased()); | 1793 EXPECT_FALSE(IsReleased()); |
1797 EXPECT_TRUE(IsReadyForEncode()); | 1794 EXPECT_TRUE(IsReadyForEncode()); |
1798 stream_->Start(); | 1795 stream_->Start(); |
1799 // Sanity check, make sure we still encode frames with this encoder. | 1796 // Sanity check, make sure we still encode frames with this encoder. |
1800 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; | 1797 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; |
1801 } | 1798 } |
1802 | 1799 |
1803 rtc::CriticalSection crit_; | 1800 rtc::CriticalSection crit_; |
1804 VideoSendStream* stream_; | 1801 VideoSendStream* stream_; |
1805 bool initialized_ GUARDED_BY(crit_); | 1802 bool initialized_ GUARDED_BY(crit_); |
1806 bool callback_registered_ GUARDED_BY(crit_); | 1803 bool callback_registered_ GUARDED_BY(crit_); |
1807 size_t num_releases_ GUARDED_BY(crit_); | 1804 size_t num_releases_ GUARDED_BY(crit_); |
1808 bool released_ GUARDED_BY(crit_); | 1805 bool released_ GUARDED_BY(crit_); |
1809 VideoEncoderConfig encoder_config_; | 1806 VideoEncoderConfig encoder_config_; |
1810 } test_encoder; | 1807 } test_encoder; |
1811 | 1808 |
1812 RunBaseTest(&test_encoder); | 1809 RunBaseTest(&test_encoder); |
1813 | 1810 |
1814 EXPECT_TRUE(test_encoder.IsReleased()); | 1811 EXPECT_TRUE(test_encoder.IsReleased()); |
1815 EXPECT_EQ(2u, test_encoder.num_releases()); | 1812 EXPECT_EQ(1u, test_encoder.num_releases()); |
1816 } | 1813 } |
1817 | 1814 |
1818 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) { | 1815 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) { |
1819 class VideoCodecConfigObserver : public test::SendTest, | 1816 class VideoCodecConfigObserver : public test::SendTest, |
1820 public test::FakeEncoder { | 1817 public test::FakeEncoder { |
1821 public: | 1818 public: |
1822 VideoCodecConfigObserver() | 1819 VideoCodecConfigObserver() |
1823 : SendTest(kDefaultTimeoutMs), | 1820 : SendTest(kDefaultTimeoutMs), |
1824 FakeEncoder(Clock::GetRealTimeClock()), | 1821 FakeEncoder(Clock::GetRealTimeClock()), |
1825 init_encode_event_(false, false), | 1822 init_encode_event_(false, false), |
(...skipping 11 matching lines...) Expand all Loading... |
1837 | 1834 |
1838 void OnVideoStreamsCreated( | 1835 void OnVideoStreamsCreated( |
1839 VideoSendStream* send_stream, | 1836 VideoSendStream* send_stream, |
1840 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1837 const std::vector<VideoReceiveStream*>& receive_streams) override { |
1841 stream_ = send_stream; | 1838 stream_ = send_stream; |
1842 } | 1839 } |
1843 | 1840 |
1844 int32_t InitEncode(const VideoCodec* config, | 1841 int32_t InitEncode(const VideoCodec* config, |
1845 int32_t number_of_cores, | 1842 int32_t number_of_cores, |
1846 size_t max_payload_size) override { | 1843 size_t max_payload_size) override { |
1847 if (num_initializations_ < 2) { | 1844 if (num_initializations_ == 0) { |
1848 // Verify default values. | 1845 // Verify default values. |
1849 EXPECT_EQ(kRealtimeVideo, config->mode); | 1846 EXPECT_EQ(kRealtimeVideo, config->mode); |
1850 } else { | 1847 } else { |
1851 // Verify that changed values are propagated. | 1848 // Verify that changed values are propagated. |
1852 EXPECT_EQ(kScreensharing, config->mode); | 1849 EXPECT_EQ(kScreensharing, config->mode); |
1853 } | 1850 } |
1854 ++num_initializations_; | 1851 ++num_initializations_; |
1855 if (num_initializations_ > 1) { | 1852 init_encode_event_.Set(); |
1856 // Skip the first two InitEncode events: one with QCIF resolution when | |
1857 // the SendStream is created, the other with QVGA when the first frame | |
1858 // is encoded. | |
1859 init_encode_event_.Set(); | |
1860 } | |
1861 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1853 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
1862 } | 1854 } |
1863 | 1855 |
1864 void PerformTest() override { | 1856 void PerformTest() override { |
1865 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); | 1857 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); |
1866 EXPECT_EQ(2u, num_initializations_) << "VideoEncoder not initialized."; | 1858 EXPECT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
1867 | 1859 |
1868 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; | 1860 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
1869 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); | 1861 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
1870 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); | 1862 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); |
1871 EXPECT_EQ(3u, num_initializations_) | 1863 EXPECT_EQ(2u, num_initializations_) |
1872 << "ReconfigureVideoEncoder did not reinitialize the encoder with " | 1864 << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
1873 "new encoder settings."; | 1865 "new encoder settings."; |
1874 } | 1866 } |
1875 | 1867 |
1876 rtc::Event init_encode_event_; | 1868 rtc::Event init_encode_event_; |
1877 size_t num_initializations_; | 1869 size_t num_initializations_; |
1878 VideoSendStream* stream_; | 1870 VideoSendStream* stream_; |
1879 VideoEncoderConfig encoder_config_; | 1871 VideoEncoderConfig encoder_config_; |
1880 } test; | 1872 } test; |
1881 | 1873 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1930 const std::vector<VideoReceiveStream*>& receive_streams) override { |
1939 stream_ = send_stream; | 1931 stream_ = send_stream; |
1940 } | 1932 } |
1941 | 1933 |
1942 int32_t InitEncode(const VideoCodec* config, | 1934 int32_t InitEncode(const VideoCodec* config, |
1943 int32_t number_of_cores, | 1935 int32_t number_of_cores, |
1944 size_t max_payload_size) override { | 1936 size_t max_payload_size) override { |
1945 EXPECT_EQ(video_codec_type_, config->codecType); | 1937 EXPECT_EQ(video_codec_type_, config->codecType); |
1946 VerifyCodecSpecifics(*config); | 1938 VerifyCodecSpecifics(*config); |
1947 ++num_initializations_; | 1939 ++num_initializations_; |
1948 if (num_initializations_ > 1) { | 1940 init_encode_event_.Set(); |
1949 // Skip the first two InitEncode events: one with QCIF resolution when | |
1950 // the SendStream is created, the other with QVGA when the first frame is | |
1951 // encoded. | |
1952 init_encode_event_.Set(); | |
1953 } | |
1954 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1941 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
1955 } | 1942 } |
1956 | 1943 |
1957 void VerifyCodecSpecifics(const VideoCodec& config) const; | 1944 void VerifyCodecSpecifics(const VideoCodec& config) const; |
1958 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> | 1945 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
1959 GetEncoderSpecificSettings() const; | 1946 GetEncoderSpecificSettings() const; |
1960 | 1947 |
1961 void PerformTest() override { | 1948 void PerformTest() override { |
1962 EXPECT_TRUE( | 1949 EXPECT_TRUE( |
1963 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1950 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
1964 ASSERT_EQ(2u, num_initializations_) << "VideoEncoder not initialized."; | 1951 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
1965 | 1952 |
1966 encoder_settings_.frameDroppingOn = true; | 1953 encoder_settings_.frameDroppingOn = true; |
1967 encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings(); | 1954 encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings(); |
1968 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); | 1955 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
1969 ASSERT_TRUE( | 1956 ASSERT_TRUE( |
1970 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1957 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
1971 EXPECT_EQ(3u, num_initializations_) | 1958 EXPECT_EQ(2u, num_initializations_) |
1972 << "ReconfigureVideoEncoder did not reinitialize the encoder with " | 1959 << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
1973 "new encoder settings."; | 1960 "new encoder settings."; |
1974 } | 1961 } |
1975 | 1962 |
1976 int32_t Encode(const VideoFrame& input_image, | 1963 int32_t Encode(const VideoFrame& input_image, |
1977 const CodecSpecificInfo* codec_specific_info, | 1964 const CodecSpecificInfo* codec_specific_info, |
1978 const std::vector<FrameType>* frame_types) override { | 1965 const std::vector<FrameType>* frame_types) override { |
1979 // Silently skip the encode, FakeEncoder::Encode doesn't produce VP8. | 1966 // Silently skip the encode, FakeEncoder::Encode doesn't produce VP8. |
1980 return 0; | 1967 return 0; |
1981 } | 1968 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 num_initializations_(0), | 2195 num_initializations_(0), |
2209 call_(nullptr), | 2196 call_(nullptr), |
2210 send_stream_(nullptr) {} | 2197 send_stream_(nullptr) {} |
2211 | 2198 |
2212 private: | 2199 private: |
2213 int32_t InitEncode(const VideoCodec* codecSettings, | 2200 int32_t InitEncode(const VideoCodec* codecSettings, |
2214 int32_t numberOfCores, | 2201 int32_t numberOfCores, |
2215 size_t maxPayloadSize) override { | 2202 size_t maxPayloadSize) override { |
2216 EXPECT_GE(codecSettings->startBitrate, codecSettings->minBitrate); | 2203 EXPECT_GE(codecSettings->startBitrate, codecSettings->minBitrate); |
2217 EXPECT_LE(codecSettings->startBitrate, codecSettings->maxBitrate); | 2204 EXPECT_LE(codecSettings->startBitrate, codecSettings->maxBitrate); |
2218 // First reinitialization happens due to that the frame size is updated. | 2205 if (num_initializations_ == 0) { |
2219 if (num_initializations_ == 0 || num_initializations_ == 1) { | |
2220 EXPECT_EQ(static_cast<unsigned int>(kMinBitrateKbps), | 2206 EXPECT_EQ(static_cast<unsigned int>(kMinBitrateKbps), |
2221 codecSettings->minBitrate); | 2207 codecSettings->minBitrate); |
2222 EXPECT_EQ(static_cast<unsigned int>(kStartBitrateKbps), | 2208 EXPECT_EQ(static_cast<unsigned int>(kStartBitrateKbps), |
2223 codecSettings->startBitrate); | 2209 codecSettings->startBitrate); |
2224 EXPECT_EQ(static_cast<unsigned int>(kMaxBitrateKbps), | 2210 EXPECT_EQ(static_cast<unsigned int>(kMaxBitrateKbps), |
2225 codecSettings->maxBitrate); | 2211 codecSettings->maxBitrate); |
2226 observation_complete_.Set(); | 2212 observation_complete_.Set(); |
2227 } else if (num_initializations_ == 2) { | 2213 } else if (num_initializations_ == 1) { |
2228 EXPECT_EQ(static_cast<unsigned int>(kLowerMaxBitrateKbps), | 2214 EXPECT_EQ(static_cast<unsigned int>(kLowerMaxBitrateKbps), |
2229 codecSettings->maxBitrate); | 2215 codecSettings->maxBitrate); |
2230 // The start bitrate should be kept (-1) and capped to the max bitrate. | 2216 // The start bitrate should be kept (-1) and capped to the max bitrate. |
2231 // Since this is not an end-to-end call no receiver should have been | 2217 // Since this is not an end-to-end call no receiver should have been |
2232 // returning a REMB that could lower this estimate. | 2218 // returning a REMB that could lower this estimate. |
2233 EXPECT_EQ(codecSettings->startBitrate, codecSettings->maxBitrate); | 2219 EXPECT_EQ(codecSettings->startBitrate, codecSettings->maxBitrate); |
2234 } else if (num_initializations_ == 3) { | 2220 } else if (num_initializations_ == 2) { |
2235 EXPECT_EQ(static_cast<unsigned int>(kIncreasedMaxBitrateKbps), | 2221 EXPECT_EQ(static_cast<unsigned int>(kIncreasedMaxBitrateKbps), |
2236 codecSettings->maxBitrate); | 2222 codecSettings->maxBitrate); |
2237 // The start bitrate will be whatever the rate BitRateController | 2223 // The start bitrate will be whatever the rate BitRateController |
2238 // has currently configured but in the span of the set max and min | 2224 // has currently configured but in the span of the set max and min |
2239 // bitrate. | 2225 // bitrate. |
2240 } | 2226 } |
2241 ++num_initializations_; | 2227 ++num_initializations_; |
2242 if (num_initializations_ > 1) { | 2228 init_encode_event_.Set(); |
2243 init_encode_event_.Set(); | 2229 |
2244 } | |
2245 return FakeEncoder::InitEncode(codecSettings, numberOfCores, | 2230 return FakeEncoder::InitEncode(codecSettings, numberOfCores, |
2246 maxPayloadSize); | 2231 maxPayloadSize); |
2247 } | 2232 } |
2248 | 2233 |
2249 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { | 2234 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { |
2250 { | 2235 { |
2251 rtc::CritScope lock(&crit_); | 2236 rtc::CritScope lock(&crit_); |
2252 if (target_bitrate_ == newBitRate) { | 2237 if (target_bitrate_ == newBitRate) { |
2253 return FakeEncoder::SetRates(newBitRate, frameRate); | 2238 return FakeEncoder::SetRates(newBitRate, frameRate); |
2254 } | 2239 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 Call::Config::BitrateConfig bitrate_config; | 2312 Call::Config::BitrateConfig bitrate_config; |
2328 bitrate_config.start_bitrate_bps = kIncreasedStartBitrateKbps * 1000; | 2313 bitrate_config.start_bitrate_bps = kIncreasedStartBitrateKbps * 1000; |
2329 bitrate_config.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; | 2314 bitrate_config.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; |
2330 call_->SetBitrateConfig(bitrate_config); | 2315 call_->SetBitrateConfig(bitrate_config); |
2331 // Encoder rate is capped by EncoderConfig max_bitrate_bps. | 2316 // Encoder rate is capped by EncoderConfig max_bitrate_bps. |
2332 WaitForSetRates(kMaxBitrateKbps); | 2317 WaitForSetRates(kMaxBitrateKbps); |
2333 encoder_config_.max_bitrate_bps = kLowerMaxBitrateKbps * 1000; | 2318 encoder_config_.max_bitrate_bps = kLowerMaxBitrateKbps * 1000; |
2334 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); | 2319 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
2335 ASSERT_TRUE( | 2320 ASSERT_TRUE( |
2336 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 2321 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
2337 EXPECT_EQ(3, num_initializations_) | 2322 EXPECT_EQ(2, num_initializations_) |
2338 << "Encoder should have been reconfigured with the new value."; | 2323 << "Encoder should have been reconfigured with the new value."; |
2339 WaitForSetRates(kLowerMaxBitrateKbps); | 2324 WaitForSetRates(kLowerMaxBitrateKbps); |
2340 | 2325 |
2341 encoder_config_.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; | 2326 encoder_config_.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; |
2342 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); | 2327 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
2343 ASSERT_TRUE( | 2328 ASSERT_TRUE( |
2344 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 2329 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
2345 EXPECT_EQ(4, num_initializations_) | 2330 EXPECT_EQ(3, num_initializations_) |
2346 << "Encoder should have been reconfigured with the new value."; | 2331 << "Encoder should have been reconfigured with the new value."; |
2347 // Expected target bitrate is the start bitrate set in the call to | 2332 // Expected target bitrate is the start bitrate set in the call to |
2348 // call_->SetBitrateConfig. | 2333 // call_->SetBitrateConfig. |
2349 WaitForSetRates(kIncreasedStartBitrateKbps); | 2334 WaitForSetRates(kIncreasedStartBitrateKbps); |
2350 } | 2335 } |
2351 | 2336 |
2352 rtc::Event init_encode_event_; | 2337 rtc::Event init_encode_event_; |
2353 rtc::Event bitrate_changed_event_; | 2338 rtc::Event bitrate_changed_event_; |
2354 rtc::CriticalSection crit_; | 2339 rtc::CriticalSection crit_; |
2355 uint32_t target_bitrate_ GUARDED_BY(&crit_); | 2340 uint32_t target_bitrate_ GUARDED_BY(&crit_); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2888 observation_complete_.Set(); | 2873 observation_complete_.Set(); |
2889 } | 2874 } |
2890 } | 2875 } |
2891 } test; | 2876 } test; |
2892 | 2877 |
2893 RunBaseTest(&test); | 2878 RunBaseTest(&test); |
2894 } | 2879 } |
2895 #endif // !defined(RTC_DISABLE_VP9) | 2880 #endif // !defined(RTC_DISABLE_VP9) |
2896 | 2881 |
2897 } // namespace webrtc | 2882 } // namespace webrtc |
OLD | NEW |