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