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 19 matching lines...) Expand all Loading... |
30 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h" |
31 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | 31 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
32 #include "webrtc/system_wrappers/include/sleep.h" | 32 #include "webrtc/system_wrappers/include/sleep.h" |
33 #include "webrtc/test/call_test.h" | 33 #include "webrtc/test/call_test.h" |
34 #include "webrtc/test/configurable_frame_size_encoder.h" | 34 #include "webrtc/test/configurable_frame_size_encoder.h" |
35 #include "webrtc/test/fake_texture_frame.h" | 35 #include "webrtc/test/fake_texture_frame.h" |
36 #include "webrtc/test/frame_generator.h" | 36 #include "webrtc/test/frame_generator.h" |
37 #include "webrtc/test/frame_utils.h" | 37 #include "webrtc/test/frame_utils.h" |
38 #include "webrtc/test/null_transport.h" | 38 #include "webrtc/test/null_transport.h" |
39 #include "webrtc/test/testsupport/perf_test.h" | 39 #include "webrtc/test/testsupport/perf_test.h" |
| 40 |
40 #include "webrtc/video/send_statistics_proxy.h" | 41 #include "webrtc/video/send_statistics_proxy.h" |
41 #include "webrtc/video_frame.h" | 42 #include "webrtc/video_frame.h" |
42 #include "webrtc/video_send_stream.h" | 43 #include "webrtc/video_send_stream.h" |
43 | 44 |
44 namespace webrtc { | 45 namespace webrtc { |
45 | 46 |
46 enum VideoFormat { kGeneric, kVP8, }; | 47 enum VideoFormat { kGeneric, kVP8, }; |
47 | 48 |
48 void ExpectEqualFramesVector(const std::vector<VideoFrame>& frames1, | 49 void ExpectEqualFramesVector(const std::vector<VideoFrame>& frames1, |
49 const std::vector<VideoFrame>& frames2); | 50 const std::vector<VideoFrame>& frames2); |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 void OnVideoStreamsCreated( | 902 void OnVideoStreamsCreated( |
902 VideoSendStream* send_stream, | 903 VideoSendStream* send_stream, |
903 const std::vector<VideoReceiveStream*>& receive_streams) override { | 904 const std::vector<VideoReceiveStream*>& receive_streams) override { |
904 stream_ = send_stream; | 905 stream_ = send_stream; |
905 } | 906 } |
906 | 907 |
907 void ModifyVideoConfigs( | 908 void ModifyVideoConfigs( |
908 VideoSendStream::Config* send_config, | 909 VideoSendStream::Config* send_config, |
909 std::vector<VideoReceiveStream::Config>* receive_configs, | 910 std::vector<VideoReceiveStream::Config>* receive_configs, |
910 VideoEncoderConfig* encoder_config) override { | 911 VideoEncoderConfig* encoder_config) override { |
| 912 RTC_DCHECK_EQ(1u, encoder_config->number_of_streams); |
911 transport_adapter_.reset( | 913 transport_adapter_.reset( |
912 new internal::TransportAdapter(send_config->send_transport)); | 914 new internal::TransportAdapter(send_config->send_transport)); |
913 transport_adapter_->Enable(); | 915 transport_adapter_->Enable(); |
914 send_config->rtp.nack.rtp_history_ms = kNackRtpHistoryMs; | 916 send_config->rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
915 send_config->pre_encode_callback = this; | 917 send_config->pre_encode_callback = this; |
916 send_config->suspend_below_min_bitrate = true; | 918 send_config->suspend_below_min_bitrate = true; |
917 int min_bitrate_bps = encoder_config->streams[0].min_bitrate_bps; | 919 int min_bitrate_bps = |
| 920 test::DefaultVideoStreamFactory::kDefaultMinBitratePerStream[0]; |
918 set_low_remb_bps(min_bitrate_bps - 10000); | 921 set_low_remb_bps(min_bitrate_bps - 10000); |
919 int threshold_window = std::max(min_bitrate_bps / 10, 20000); | 922 int threshold_window = std::max(min_bitrate_bps / 10, 20000); |
920 ASSERT_GT(encoder_config->streams[0].max_bitrate_bps, | 923 ASSERT_GT(encoder_config->max_bitrate_bps, |
921 min_bitrate_bps + threshold_window + 5000); | 924 min_bitrate_bps + threshold_window + 5000); |
922 set_high_remb_bps(min_bitrate_bps + threshold_window + 5000); | 925 set_high_remb_bps(min_bitrate_bps + threshold_window + 5000); |
923 } | 926 } |
924 | 927 |
925 void PerformTest() override { | 928 void PerformTest() override { |
926 EXPECT_TRUE(Wait()) << "Timed out during suspend-below-min-bitrate test."; | 929 EXPECT_TRUE(Wait()) << "Timed out during suspend-below-min-bitrate test."; |
927 } | 930 } |
928 | 931 |
929 enum TestState { | 932 enum TestState { |
930 kBeforeSuspend, | 933 kBeforeSuspend, |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 void OnVideoStreamsCreated( | 1202 void OnVideoStreamsCreated( |
1200 VideoSendStream* send_stream, | 1203 VideoSendStream* send_stream, |
1201 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1204 const std::vector<VideoReceiveStream*>& receive_streams) override { |
1202 send_stream_ = send_stream; | 1205 send_stream_ = send_stream; |
1203 } | 1206 } |
1204 | 1207 |
1205 void ModifyVideoConfigs( | 1208 void ModifyVideoConfigs( |
1206 VideoSendStream::Config* send_config, | 1209 VideoSendStream::Config* send_config, |
1207 std::vector<VideoReceiveStream::Config>* receive_configs, | 1210 std::vector<VideoReceiveStream::Config>* receive_configs, |
1208 VideoEncoderConfig* encoder_config) override { | 1211 VideoEncoderConfig* encoder_config) override { |
1209 RTC_DCHECK_EQ(1u, encoder_config->streams.size()); | 1212 RTC_DCHECK_EQ(1u, encoder_config->number_of_streams); |
1210 if (running_without_padding_) { | 1213 if (running_without_padding_) { |
1211 encoder_config->min_transmit_bitrate_bps = 0; | 1214 encoder_config->min_transmit_bitrate_bps = 0; |
1212 encoder_config->content_type = | 1215 encoder_config->content_type = |
1213 VideoEncoderConfig::ContentType::kRealtimeVideo; | 1216 VideoEncoderConfig::ContentType::kRealtimeVideo; |
1214 } else { | 1217 } else { |
1215 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 1218 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
1216 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; | 1219 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
1217 } | 1220 } |
1218 encoder_config_ = encoder_config->Copy(); | 1221 encoder_config_ = encoder_config->Copy(); |
1219 } | 1222 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 rtc::Event start_bitrate_changed_; | 1315 rtc::Event start_bitrate_changed_; |
1313 int start_bitrate_kbps_ GUARDED_BY(crit_); | 1316 int start_bitrate_kbps_ GUARDED_BY(crit_); |
1314 }; | 1317 }; |
1315 | 1318 |
1316 CreateSenderCall(Call::Config()); | 1319 CreateSenderCall(Call::Config()); |
1317 | 1320 |
1318 test::NullTransport transport; | 1321 test::NullTransport transport; |
1319 CreateSendConfig(1, 0, &transport); | 1322 CreateSendConfig(1, 0, &transport); |
1320 | 1323 |
1321 Call::Config::BitrateConfig bitrate_config; | 1324 Call::Config::BitrateConfig bitrate_config; |
1322 bitrate_config.start_bitrate_bps = | 1325 bitrate_config.start_bitrate_bps = 2 * video_encoder_config_.max_bitrate_bps; |
1323 2 * video_encoder_config_.streams[0].max_bitrate_bps; | |
1324 sender_call_->SetBitrateConfig(bitrate_config); | 1326 sender_call_->SetBitrateConfig(bitrate_config); |
1325 | 1327 |
1326 StartBitrateObserver encoder; | 1328 StartBitrateObserver encoder; |
1327 video_send_config_.encoder_settings.encoder = &encoder; | 1329 video_send_config_.encoder_settings.encoder = &encoder; |
| 1330 // Since this test does not use a capturer, set |internal_source| = true. |
| 1331 // Encoder configuration is otherwise updated on the next video frame. |
| 1332 video_send_config_.encoder_settings.internal_source = true; |
1328 | 1333 |
1329 CreateVideoStreams(); | 1334 CreateVideoStreams(); |
1330 | 1335 |
1331 EXPECT_TRUE(encoder.WaitForStartBitrate()); | 1336 EXPECT_TRUE(encoder.WaitForStartBitrate()); |
1332 EXPECT_EQ(video_encoder_config_.streams[0].max_bitrate_bps / 1000, | 1337 EXPECT_EQ(video_encoder_config_.max_bitrate_bps / 1000, |
1333 encoder.GetStartBitrateKbps()); | 1338 encoder.GetStartBitrateKbps()); |
1334 | 1339 |
1335 video_encoder_config_.streams[0].max_bitrate_bps = | 1340 video_encoder_config_.max_bitrate_bps = 2 * bitrate_config.start_bitrate_bps; |
1336 2 * bitrate_config.start_bitrate_bps; | |
1337 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_.Copy()); | 1341 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_.Copy()); |
1338 | 1342 |
1339 // New bitrate should be reconfigured above the previous max. As there's no | 1343 // New bitrate should be reconfigured above the previous max. As there's no |
1340 // network connection this shouldn't be flaky, as no bitrate should've been | 1344 // network connection this shouldn't be flaky, as no bitrate should've been |
1341 // reported in between. | 1345 // reported in between. |
1342 EXPECT_TRUE(encoder.WaitForStartBitrate()); | 1346 EXPECT_TRUE(encoder.WaitForStartBitrate()); |
1343 EXPECT_EQ(bitrate_config.start_bitrate_bps / 1000, | 1347 EXPECT_EQ(bitrate_config.start_bitrate_bps / 1000, |
1344 encoder.GetStartBitrateKbps()); | 1348 encoder.GetStartBitrateKbps()); |
1345 | 1349 |
1346 DestroyStreams(); | 1350 DestroyStreams(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1456 |
1453 test::NullTransport transport; | 1457 test::NullTransport transport; |
1454 CreateSendConfig(1, 0, &transport); | 1458 CreateSendConfig(1, 0, &transport); |
1455 FrameObserver observer; | 1459 FrameObserver observer; |
1456 video_send_config_.pre_encode_callback = &observer; | 1460 video_send_config_.pre_encode_callback = &observer; |
1457 CreateVideoStreams(); | 1461 CreateVideoStreams(); |
1458 | 1462 |
1459 // Prepare five input frames. Send ordinary VideoFrame and texture frames | 1463 // Prepare five input frames. Send ordinary VideoFrame and texture frames |
1460 // alternatively. | 1464 // alternatively. |
1461 std::vector<VideoFrame> input_frames; | 1465 std::vector<VideoFrame> input_frames; |
1462 int width = static_cast<int>(video_encoder_config_.streams[0].width); | 1466 int width = 168; |
1463 int height = static_cast<int>(video_encoder_config_.streams[0].height); | 1467 int height = 132; |
| 1468 |
1464 test::FakeNativeHandle* handle1 = new test::FakeNativeHandle(); | 1469 test::FakeNativeHandle* handle1 = new test::FakeNativeHandle(); |
1465 test::FakeNativeHandle* handle2 = new test::FakeNativeHandle(); | 1470 test::FakeNativeHandle* handle2 = new test::FakeNativeHandle(); |
1466 test::FakeNativeHandle* handle3 = new test::FakeNativeHandle(); | 1471 test::FakeNativeHandle* handle3 = new test::FakeNativeHandle(); |
1467 input_frames.push_back(test::FakeNativeHandle::CreateFrame( | 1472 input_frames.push_back(test::FakeNativeHandle::CreateFrame( |
1468 handle1, width, height, 1, 1, kVideoRotation_0)); | 1473 handle1, width, height, 1, 1, kVideoRotation_0)); |
1469 input_frames.push_back(test::FakeNativeHandle::CreateFrame( | 1474 input_frames.push_back(test::FakeNativeHandle::CreateFrame( |
1470 handle2, width, height, 2, 2, kVideoRotation_0)); | 1475 handle2, width, height, 2, 2, kVideoRotation_0)); |
1471 input_frames.push_back(CreateVideoFrame(width, height, 3)); | 1476 input_frames.push_back(CreateVideoFrame(width, height, 3)); |
1472 input_frames.push_back(CreateVideoFrame(width, height, 4)); | 1477 input_frames.push_back(CreateVideoFrame(width, height, 4)); |
1473 input_frames.push_back(test::FakeNativeHandle::CreateFrame( | 1478 input_frames.push_back(test::FakeNativeHandle::CreateFrame( |
1474 handle3, width, height, 5, 5, kVideoRotation_0)); | 1479 handle3, width, height, 5, 5, kVideoRotation_0)); |
1475 | 1480 |
1476 video_send_stream_->Start(); | 1481 video_send_stream_->Start(); |
1477 test::FrameForwarder forwarder; | 1482 test::FrameForwarder forwarder; |
1478 video_send_stream_->SetSource(&forwarder); | 1483 video_send_stream_->SetSource(&forwarder); |
1479 for (size_t i = 0; i < input_frames.size(); i++) { | 1484 for (size_t i = 0; i < input_frames.size(); i++) { |
1480 forwarder.IncomingCapturedFrame(input_frames[i]); | 1485 forwarder.IncomingCapturedFrame(input_frames[i]); |
1481 // Do not send the next frame too fast, so the frame dropper won't drop it. | |
1482 if (i < input_frames.size() - 1) | |
1483 SleepMs(1000 / video_encoder_config_.streams[0].max_framerate); | |
1484 // Wait until the output frame is received before sending the next input | 1486 // Wait until the output frame is received before sending the next input |
1485 // frame. Or the previous input frame may be replaced without delivering. | 1487 // frame. Or the previous input frame may be replaced without delivering. |
1486 observer.WaitOutputFrame(); | 1488 observer.WaitOutputFrame(); |
1487 } | 1489 } |
1488 video_send_stream_->Stop(); | 1490 video_send_stream_->Stop(); |
1489 video_send_stream_->SetSource(nullptr); | 1491 video_send_stream_->SetSource(nullptr); |
1490 | 1492 |
1491 // Test if the input and output frames are the same. render_time_ms and | 1493 // Test if the input and output frames are the same. render_time_ms and |
1492 // timestamp are not compared because capturer sets those values. | 1494 // timestamp are not compared because capturer sets those values. |
1493 ExpectEqualFramesVector(input_frames, observer.output_frames()); | 1495 ExpectEqualFramesVector(input_frames, observer.output_frames()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 void ModifyVideoConfigs( | 1602 void ModifyVideoConfigs( |
1601 VideoSendStream::Config* send_config, | 1603 VideoSendStream::Config* send_config, |
1602 std::vector<VideoReceiveStream::Config>* receive_configs, | 1604 std::vector<VideoReceiveStream::Config>* receive_configs, |
1603 VideoEncoderConfig* encoder_config) override { | 1605 VideoEncoderConfig* encoder_config) override { |
1604 send_config->encoder_settings.encoder = this; | 1606 send_config->encoder_settings.encoder = this; |
1605 encoder_config_ = encoder_config->Copy(); | 1607 encoder_config_ = encoder_config->Copy(); |
1606 } | 1608 } |
1607 | 1609 |
1608 void PerformTest() override { | 1610 void PerformTest() override { |
1609 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; | 1611 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; |
1610 EXPECT_EQ(0u, num_releases()); | 1612 // Expect |num_releases| == 1 since the encoder has been reconfigured |
| 1613 // once when the first frame is encoded. Not until at that point is the |
| 1614 // frame size known and the encoder can be properly initialized. |
| 1615 EXPECT_EQ(1u, num_releases()); |
1611 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); | 1616 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
1612 EXPECT_EQ(0u, num_releases()); | 1617 EXPECT_EQ(1u, num_releases()); |
1613 stream_->Stop(); | 1618 stream_->Stop(); |
1614 // Encoder should not be released before destroying the VideoSendStream. | 1619 // Encoder should not be released before destroying the VideoSendStream. |
1615 EXPECT_FALSE(IsReleased()); | 1620 EXPECT_FALSE(IsReleased()); |
1616 EXPECT_TRUE(IsReadyForEncode()); | 1621 EXPECT_TRUE(IsReadyForEncode()); |
1617 stream_->Start(); | 1622 stream_->Start(); |
1618 // Sanity check, make sure we still encode frames with this encoder. | 1623 // Sanity check, make sure we still encode frames with this encoder. |
1619 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; | 1624 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; |
1620 } | 1625 } |
1621 | 1626 |
1622 rtc::CriticalSection crit_; | 1627 rtc::CriticalSection crit_; |
1623 VideoSendStream* stream_; | 1628 VideoSendStream* stream_; |
1624 bool initialized_ GUARDED_BY(crit_); | 1629 bool initialized_ GUARDED_BY(crit_); |
1625 bool callback_registered_ GUARDED_BY(crit_); | 1630 bool callback_registered_ GUARDED_BY(crit_); |
1626 size_t num_releases_ GUARDED_BY(crit_); | 1631 size_t num_releases_ GUARDED_BY(crit_); |
1627 bool released_ GUARDED_BY(crit_); | 1632 bool released_ GUARDED_BY(crit_); |
1628 VideoEncoderConfig encoder_config_; | 1633 VideoEncoderConfig encoder_config_; |
1629 } test_encoder; | 1634 } test_encoder; |
1630 | 1635 |
1631 RunBaseTest(&test_encoder); | 1636 RunBaseTest(&test_encoder); |
1632 | 1637 |
1633 EXPECT_TRUE(test_encoder.IsReleased()); | 1638 EXPECT_TRUE(test_encoder.IsReleased()); |
1634 EXPECT_EQ(1u, test_encoder.num_releases()); | 1639 EXPECT_EQ(2u, test_encoder.num_releases()); |
1635 } | 1640 } |
1636 | 1641 |
1637 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) { | 1642 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) { |
1638 class VideoCodecConfigObserver : public test::SendTest, | 1643 class VideoCodecConfigObserver : public test::SendTest, |
1639 public test::FakeEncoder { | 1644 public test::FakeEncoder { |
1640 public: | 1645 public: |
1641 VideoCodecConfigObserver() | 1646 VideoCodecConfigObserver() |
1642 : SendTest(kDefaultTimeoutMs), | 1647 : SendTest(kDefaultTimeoutMs), |
1643 FakeEncoder(Clock::GetRealTimeClock()), | 1648 FakeEncoder(Clock::GetRealTimeClock()), |
1644 init_encode_event_(false, false), | 1649 init_encode_event_(false, false), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 FakeEncoder(Clock::GetRealTimeClock()), | 1712 FakeEncoder(Clock::GetRealTimeClock()), |
1708 video_codec_type_(video_codec_type), | 1713 video_codec_type_(video_codec_type), |
1709 codec_name_(codec_name), | 1714 codec_name_(codec_name), |
1710 init_encode_event_(false, false), | 1715 init_encode_event_(false, false), |
1711 num_initializations_(0), | 1716 num_initializations_(0), |
1712 stream_(nullptr) { | 1717 stream_(nullptr) { |
1713 memset(&encoder_settings_, 0, sizeof(encoder_settings_)); | 1718 memset(&encoder_settings_, 0, sizeof(encoder_settings_)); |
1714 } | 1719 } |
1715 | 1720 |
1716 private: | 1721 private: |
| 1722 class VideoStreamFactory |
| 1723 : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 1724 public: |
| 1725 VideoStreamFactory() {} |
| 1726 |
| 1727 private: |
| 1728 std::vector<VideoStream> CreateEncoderStreams( |
| 1729 int width, |
| 1730 int height, |
| 1731 const VideoEncoderConfig& encoder_config) override { |
| 1732 std::vector<VideoStream> streams = |
| 1733 test::CreateVideoStreams(width, height, encoder_config); |
| 1734 for (size_t i = 0; i < streams.size(); ++i) { |
| 1735 streams[i].temporal_layer_thresholds_bps.resize( |
| 1736 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); |
| 1737 } |
| 1738 return streams; |
| 1739 } |
| 1740 }; |
| 1741 |
1717 void ModifyVideoConfigs( | 1742 void ModifyVideoConfigs( |
1718 VideoSendStream::Config* send_config, | 1743 VideoSendStream::Config* send_config, |
1719 std::vector<VideoReceiveStream::Config>* receive_configs, | 1744 std::vector<VideoReceiveStream::Config>* receive_configs, |
1720 VideoEncoderConfig* encoder_config) override { | 1745 VideoEncoderConfig* encoder_config) override { |
1721 send_config->encoder_settings.encoder = this; | 1746 send_config->encoder_settings.encoder = this; |
1722 send_config->encoder_settings.payload_name = codec_name_; | 1747 send_config->encoder_settings.payload_name = codec_name_; |
1723 | 1748 |
1724 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { | |
1725 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( | |
1726 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); | |
1727 } | |
1728 | |
1729 encoder_config->encoder_specific_settings = &encoder_settings_; | 1749 encoder_config->encoder_specific_settings = &encoder_settings_; |
| 1750 encoder_config->encoder_stream_factory = |
| 1751 new rtc::RefCountedObject<VideoStreamFactory>(); |
1730 encoder_config_ = encoder_config->Copy(); | 1752 encoder_config_ = encoder_config->Copy(); |
1731 } | 1753 } |
1732 | 1754 |
1733 void OnVideoStreamsCreated( | 1755 void OnVideoStreamsCreated( |
1734 VideoSendStream* send_stream, | 1756 VideoSendStream* send_stream, |
1735 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1757 const std::vector<VideoReceiveStream*>& receive_streams) override { |
1736 stream_ = send_stream; | 1758 stream_ = send_stream; |
1737 } | 1759 } |
1738 | 1760 |
1739 int32_t InitEncode(const VideoCodec* config, | 1761 int32_t InitEncode(const VideoCodec* config, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 rtc::CriticalSection crit_; | 1911 rtc::CriticalSection crit_; |
1890 size_t rtp_packets_sent_ GUARDED_BY(&crit_); | 1912 size_t rtp_packets_sent_ GUARDED_BY(&crit_); |
1891 size_t media_bytes_sent_ GUARDED_BY(&crit_); | 1913 size_t media_bytes_sent_ GUARDED_BY(&crit_); |
1892 } test; | 1914 } test; |
1893 | 1915 |
1894 RunBaseTest(&test); | 1916 RunBaseTest(&test); |
1895 } | 1917 } |
1896 | 1918 |
1897 TEST_F(VideoSendStreamTest, TranslatesTwoLayerScreencastToTargetBitrate) { | 1919 TEST_F(VideoSendStreamTest, TranslatesTwoLayerScreencastToTargetBitrate) { |
1898 static const int kScreencastTargetBitrateKbps = 200; | 1920 static const int kScreencastTargetBitrateKbps = 200; |
| 1921 |
| 1922 class VideoStreamFactory |
| 1923 : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 1924 public: |
| 1925 VideoStreamFactory() {} |
| 1926 |
| 1927 private: |
| 1928 std::vector<VideoStream> CreateEncoderStreams( |
| 1929 int width, |
| 1930 int height, |
| 1931 const VideoEncoderConfig& encoder_config) override { |
| 1932 std::vector<VideoStream> streams = |
| 1933 test::CreateVideoStreams(width, height, encoder_config); |
| 1934 EXPECT_TRUE(streams[0].temporal_layer_thresholds_bps.empty()); |
| 1935 streams[0].temporal_layer_thresholds_bps.push_back( |
| 1936 kScreencastTargetBitrateKbps * 1000); |
| 1937 return streams; |
| 1938 } |
| 1939 }; |
| 1940 |
1899 class ScreencastTargetBitrateTest : public test::SendTest, | 1941 class ScreencastTargetBitrateTest : public test::SendTest, |
1900 public test::FakeEncoder { | 1942 public test::FakeEncoder { |
1901 public: | 1943 public: |
1902 ScreencastTargetBitrateTest() | 1944 ScreencastTargetBitrateTest() |
1903 : SendTest(kDefaultTimeoutMs), | 1945 : SendTest(kDefaultTimeoutMs), |
1904 test::FakeEncoder(Clock::GetRealTimeClock()) {} | 1946 test::FakeEncoder(Clock::GetRealTimeClock()) {} |
1905 | 1947 |
1906 private: | 1948 private: |
1907 int32_t InitEncode(const VideoCodec* config, | 1949 int32_t InitEncode(const VideoCodec* config, |
1908 int32_t number_of_cores, | 1950 int32_t number_of_cores, |
1909 size_t max_payload_size) override { | 1951 size_t max_payload_size) override { |
1910 EXPECT_EQ(static_cast<unsigned int>(kScreencastTargetBitrateKbps), | 1952 EXPECT_EQ(static_cast<unsigned int>(kScreencastTargetBitrateKbps), |
1911 config->targetBitrate); | 1953 config->targetBitrate); |
1912 observation_complete_.Set(); | 1954 observation_complete_.Set(); |
1913 return test::FakeEncoder::InitEncode( | 1955 return test::FakeEncoder::InitEncode( |
1914 config, number_of_cores, max_payload_size); | 1956 config, number_of_cores, max_payload_size); |
1915 } | 1957 } |
1916 void ModifyVideoConfigs( | 1958 void ModifyVideoConfigs( |
1917 VideoSendStream::Config* send_config, | 1959 VideoSendStream::Config* send_config, |
1918 std::vector<VideoReceiveStream::Config>* receive_configs, | 1960 std::vector<VideoReceiveStream::Config>* receive_configs, |
1919 VideoEncoderConfig* encoder_config) override { | 1961 VideoEncoderConfig* encoder_config) override { |
1920 send_config->encoder_settings.encoder = this; | 1962 send_config->encoder_settings.encoder = this; |
1921 EXPECT_EQ(1u, encoder_config->streams.size()); | 1963 EXPECT_EQ(1u, encoder_config->number_of_streams); |
1922 EXPECT_TRUE( | 1964 encoder_config->encoder_stream_factory = |
1923 encoder_config->streams[0].temporal_layer_thresholds_bps.empty()); | 1965 new rtc::RefCountedObject<VideoStreamFactory>(); |
1924 encoder_config->streams[0].temporal_layer_thresholds_bps.push_back( | |
1925 kScreencastTargetBitrateKbps * 1000); | |
1926 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; | 1966 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
1927 } | 1967 } |
1928 | 1968 |
1929 void PerformTest() override { | 1969 void PerformTest() override { |
1930 EXPECT_TRUE(Wait()) | 1970 EXPECT_TRUE(Wait()) |
1931 << "Timed out while waiting for the encoder to be initialized."; | 1971 << "Timed out while waiting for the encoder to be initialized."; |
1932 } | 1972 } |
1933 } test; | 1973 } test; |
1934 | 1974 |
1935 RunBaseTest(&test); | 1975 RunBaseTest(&test); |
(...skipping 20 matching lines...) Expand all Loading... |
1956 num_initializations_(0), | 1996 num_initializations_(0), |
1957 call_(nullptr), | 1997 call_(nullptr), |
1958 send_stream_(nullptr) {} | 1998 send_stream_(nullptr) {} |
1959 | 1999 |
1960 private: | 2000 private: |
1961 int32_t InitEncode(const VideoCodec* codecSettings, | 2001 int32_t InitEncode(const VideoCodec* codecSettings, |
1962 int32_t numberOfCores, | 2002 int32_t numberOfCores, |
1963 size_t maxPayloadSize) override { | 2003 size_t maxPayloadSize) override { |
1964 EXPECT_GE(codecSettings->startBitrate, codecSettings->minBitrate); | 2004 EXPECT_GE(codecSettings->startBitrate, codecSettings->minBitrate); |
1965 EXPECT_LE(codecSettings->startBitrate, codecSettings->maxBitrate); | 2005 EXPECT_LE(codecSettings->startBitrate, codecSettings->maxBitrate); |
1966 if (num_initializations_ == 0) { | 2006 // First reinitialization happens due to that the frame size is updated. |
| 2007 if (num_initializations_ == 0 || num_initializations_ == 1) { |
1967 EXPECT_EQ(static_cast<unsigned int>(kMinBitrateKbps), | 2008 EXPECT_EQ(static_cast<unsigned int>(kMinBitrateKbps), |
1968 codecSettings->minBitrate); | 2009 codecSettings->minBitrate); |
1969 EXPECT_EQ(static_cast<unsigned int>(kStartBitrateKbps), | 2010 EXPECT_EQ(static_cast<unsigned int>(kStartBitrateKbps), |
1970 codecSettings->startBitrate); | 2011 codecSettings->startBitrate); |
1971 EXPECT_EQ(static_cast<unsigned int>(kMaxBitrateKbps), | 2012 EXPECT_EQ(static_cast<unsigned int>(kMaxBitrateKbps), |
1972 codecSettings->maxBitrate); | 2013 codecSettings->maxBitrate); |
1973 observation_complete_.Set(); | 2014 observation_complete_.Set(); |
1974 } else if (num_initializations_ == 1) { | 2015 } else if (num_initializations_ == 2) { |
1975 EXPECT_EQ(static_cast<unsigned int>(kLowerMaxBitrateKbps), | 2016 EXPECT_EQ(static_cast<unsigned int>(kLowerMaxBitrateKbps), |
1976 codecSettings->maxBitrate); | 2017 codecSettings->maxBitrate); |
1977 // The start bitrate should be kept (-1) and capped to the max bitrate. | 2018 // The start bitrate should be kept (-1) and capped to the max bitrate. |
1978 // Since this is not an end-to-end call no receiver should have been | 2019 // Since this is not an end-to-end call no receiver should have been |
1979 // returning a REMB that could lower this estimate. | 2020 // returning a REMB that could lower this estimate. |
1980 EXPECT_EQ(codecSettings->startBitrate, codecSettings->maxBitrate); | 2021 EXPECT_EQ(codecSettings->startBitrate, codecSettings->maxBitrate); |
1981 } else if (num_initializations_ == 2) { | 2022 } else if (num_initializations_ == 3) { |
1982 EXPECT_EQ(static_cast<unsigned int>(kIncreasedMaxBitrateKbps), | 2023 EXPECT_EQ(static_cast<unsigned int>(kIncreasedMaxBitrateKbps), |
1983 codecSettings->maxBitrate); | 2024 codecSettings->maxBitrate); |
1984 // The start bitrate will be whatever the rate BitRateController | 2025 // The start bitrate will be whatever the rate BitRateController |
1985 // has currently configured but in the span of the set max and min | 2026 // has currently configured but in the span of the set max and min |
1986 // bitrate. | 2027 // bitrate. |
1987 } | 2028 } |
1988 ++num_initializations_; | 2029 ++num_initializations_; |
1989 init_encode_event_.Set(); | 2030 init_encode_event_.Set(); |
1990 return FakeEncoder::InitEncode(codecSettings, numberOfCores, | 2031 return FakeEncoder::InitEncode(codecSettings, numberOfCores, |
1991 maxPayloadSize); | 2032 maxPayloadSize); |
1992 } | 2033 } |
1993 | 2034 |
1994 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { | 2035 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { |
1995 { | 2036 { |
1996 rtc::CritScope lock(&crit_); | 2037 rtc::CritScope lock(&crit_); |
| 2038 if (target_bitrate_ == newBitRate) { |
| 2039 return FakeEncoder::SetRates(newBitRate, frameRate); |
| 2040 } |
1997 target_bitrate_ = newBitRate; | 2041 target_bitrate_ = newBitRate; |
1998 } | 2042 } |
1999 bitrate_changed_event_.Set(); | 2043 bitrate_changed_event_.Set(); |
2000 return FakeEncoder::SetRates(newBitRate, frameRate); | 2044 return FakeEncoder::SetRates(newBitRate, frameRate); |
2001 } | 2045 } |
2002 | 2046 |
2003 void WaitForSetRates(uint32_t expected_bitrate) { | 2047 void WaitForSetRates(uint32_t expected_bitrate) { |
2004 EXPECT_TRUE( | 2048 EXPECT_TRUE( |
2005 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) | 2049 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) |
2006 << "Timed out while waiting encoder rate to be set."; | 2050 << "Timed out while waiting encoder rate to be set."; |
2007 rtc::CritScope lock(&crit_); | 2051 rtc::CritScope lock(&crit_); |
2008 EXPECT_EQ(expected_bitrate, target_bitrate_); | 2052 EXPECT_EQ(expected_bitrate, target_bitrate_); |
2009 } | 2053 } |
2010 | 2054 |
2011 Call::Config GetSenderCallConfig() override { | 2055 Call::Config GetSenderCallConfig() override { |
2012 Call::Config config; | 2056 Call::Config config; |
2013 config.bitrate_config.min_bitrate_bps = kMinBitrateKbps * 1000; | 2057 config.bitrate_config.min_bitrate_bps = kMinBitrateKbps * 1000; |
2014 config.bitrate_config.start_bitrate_bps = kStartBitrateKbps * 1000; | 2058 config.bitrate_config.start_bitrate_bps = kStartBitrateKbps * 1000; |
2015 config.bitrate_config.max_bitrate_bps = kMaxBitrateKbps * 1000; | 2059 config.bitrate_config.max_bitrate_bps = kMaxBitrateKbps * 1000; |
2016 return config; | 2060 return config; |
2017 } | 2061 } |
2018 | 2062 |
| 2063 class VideoStreamFactory |
| 2064 : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 2065 public: |
| 2066 explicit VideoStreamFactory(int min_bitrate_bps) |
| 2067 : min_bitrate_bps_(min_bitrate_bps) {} |
| 2068 |
| 2069 private: |
| 2070 std::vector<VideoStream> CreateEncoderStreams( |
| 2071 int width, |
| 2072 int height, |
| 2073 const VideoEncoderConfig& encoder_config) override { |
| 2074 std::vector<VideoStream> streams = |
| 2075 test::CreateVideoStreams(width, height, encoder_config); |
| 2076 streams[0].min_bitrate_bps = min_bitrate_bps_; |
| 2077 return streams; |
| 2078 } |
| 2079 |
| 2080 const int min_bitrate_bps_; |
| 2081 }; |
| 2082 |
2019 void ModifyVideoConfigs( | 2083 void ModifyVideoConfigs( |
2020 VideoSendStream::Config* send_config, | 2084 VideoSendStream::Config* send_config, |
2021 std::vector<VideoReceiveStream::Config>* receive_configs, | 2085 std::vector<VideoReceiveStream::Config>* receive_configs, |
2022 VideoEncoderConfig* encoder_config) override { | 2086 VideoEncoderConfig* encoder_config) override { |
2023 send_config->encoder_settings.encoder = this; | 2087 send_config->encoder_settings.encoder = this; |
2024 // Set bitrates lower/higher than min/max to make sure they are properly | 2088 // Set bitrates lower/higher than min/max to make sure they are properly |
2025 // capped. | 2089 // capped. |
2026 encoder_config->streams.front().min_bitrate_bps = kMinBitrateKbps * 1000; | 2090 encoder_config->max_bitrate_bps = kMaxBitrateKbps * 1000; |
2027 encoder_config->streams.front().max_bitrate_bps = kMaxBitrateKbps * 1000; | 2091 // Create a new StreamFactory to be able to set |
| 2092 // |VideoStream.min_bitrate_bps|. |
| 2093 encoder_config->encoder_stream_factory = |
| 2094 new rtc::RefCountedObject<VideoStreamFactory>(kMinBitrateKbps * 1000); |
2028 encoder_config_ = encoder_config->Copy(); | 2095 encoder_config_ = encoder_config->Copy(); |
2029 } | 2096 } |
2030 | 2097 |
2031 void OnCallsCreated(Call* sender_call, Call* receiver_call) override { | 2098 void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
2032 call_ = sender_call; | 2099 call_ = sender_call; |
2033 } | 2100 } |
2034 | 2101 |
2035 void OnVideoStreamsCreated( | 2102 void OnVideoStreamsCreated( |
2036 VideoSendStream* send_stream, | 2103 VideoSendStream* send_stream, |
2037 const std::vector<VideoReceiveStream*>& receive_streams) override { | 2104 const std::vector<VideoReceiveStream*>& receive_streams) override { |
2038 send_stream_ = send_stream; | 2105 send_stream_ = send_stream; |
2039 } | 2106 } |
2040 | 2107 |
2041 void PerformTest() override { | 2108 void PerformTest() override { |
2042 ASSERT_TRUE( | 2109 ASSERT_TRUE( |
2043 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) | 2110 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) |
2044 << "Timed out while waiting for encoder to be configured."; | 2111 << "Timed out while waiting for encoder to be configured."; |
2045 WaitForSetRates(kStartBitrateKbps); | 2112 WaitForSetRates(kStartBitrateKbps); |
2046 Call::Config::BitrateConfig bitrate_config; | 2113 Call::Config::BitrateConfig bitrate_config; |
2047 bitrate_config.start_bitrate_bps = kIncreasedStartBitrateKbps * 1000; | 2114 bitrate_config.start_bitrate_bps = kIncreasedStartBitrateKbps * 1000; |
2048 bitrate_config.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; | 2115 bitrate_config.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; |
2049 call_->SetBitrateConfig(bitrate_config); | 2116 call_->SetBitrateConfig(bitrate_config); |
2050 // Encoder rate is capped by EncoderConfig max_bitrate_bps. | 2117 // Encoder rate is capped by EncoderConfig max_bitrate_bps. |
2051 WaitForSetRates(kMaxBitrateKbps); | 2118 WaitForSetRates(kMaxBitrateKbps); |
2052 | 2119 encoder_config_.max_bitrate_bps = kLowerMaxBitrateKbps * 1000; |
2053 encoder_config_.streams[0].min_bitrate_bps = 0; | |
2054 encoder_config_.streams[0].max_bitrate_bps = kLowerMaxBitrateKbps * 1000; | |
2055 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); | 2120 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
2056 ASSERT_TRUE( | 2121 ASSERT_TRUE( |
2057 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 2122 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
2058 EXPECT_EQ(2, num_initializations_) | 2123 EXPECT_EQ(2, num_initializations_) |
2059 << "Encoder should have been reconfigured with the new value."; | 2124 << "Encoder should have been reconfigured with the new value."; |
2060 WaitForSetRates(kLowerMaxBitrateKbps); | 2125 WaitForSetRates(kLowerMaxBitrateKbps); |
2061 | 2126 |
2062 encoder_config_.streams[0].target_bitrate_bps = | 2127 encoder_config_.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; |
2063 encoder_config_.streams[0].min_bitrate_bps; | |
2064 encoder_config_.streams[0].max_bitrate_bps = | |
2065 kIncreasedMaxBitrateKbps * 1000; | |
2066 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); | 2128 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
2067 ASSERT_TRUE( | 2129 ASSERT_TRUE( |
2068 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 2130 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
2069 EXPECT_EQ(3, num_initializations_) | 2131 EXPECT_EQ(3, num_initializations_) |
2070 << "Encoder should have been reconfigured with the new value."; | 2132 << "Encoder should have been reconfigured with the new value."; |
2071 // Expected target bitrate is the start bitrate set in the call to | 2133 // Expected target bitrate is the start bitrate set in the call to |
2072 // call_->SetBitrateConfig. | 2134 // call_->SetBitrateConfig. |
2073 WaitForSetRates(kIncreasedStartBitrateKbps); | 2135 WaitForSetRates(kIncreasedStartBitrateKbps); |
2074 } | 2136 } |
2075 | 2137 |
2076 rtc::Event init_encode_event_; | 2138 rtc::Event init_encode_event_; |
2077 rtc::Event bitrate_changed_event_; | 2139 rtc::Event bitrate_changed_event_; |
2078 rtc::CriticalSection crit_; | 2140 rtc::CriticalSection crit_; |
2079 uint32_t target_bitrate_ GUARDED_BY(&crit_); | 2141 uint32_t target_bitrate_ GUARDED_BY(&crit_); |
| 2142 |
2080 int num_initializations_; | 2143 int num_initializations_; |
2081 webrtc::Call* call_; | 2144 webrtc::Call* call_; |
2082 webrtc::VideoSendStream* send_stream_; | 2145 webrtc::VideoSendStream* send_stream_; |
2083 webrtc::VideoEncoderConfig encoder_config_; | 2146 webrtc::VideoEncoderConfig encoder_config_; |
2084 } test; | 2147 } test; |
2085 | 2148 |
2086 RunBaseTest(&test); | 2149 RunBaseTest(&test); |
2087 } | 2150 } |
2088 | 2151 |
2089 TEST_F(VideoSendStreamTest, ReportsSentResolution) { | 2152 TEST_F(VideoSendStreamTest, ReportsSentResolution) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 } | 2188 } |
2126 | 2189 |
2127 observation_complete_.Set(); | 2190 observation_complete_.Set(); |
2128 return 0; | 2191 return 0; |
2129 } | 2192 } |
2130 void ModifyVideoConfigs( | 2193 void ModifyVideoConfigs( |
2131 VideoSendStream::Config* send_config, | 2194 VideoSendStream::Config* send_config, |
2132 std::vector<VideoReceiveStream::Config>* receive_configs, | 2195 std::vector<VideoReceiveStream::Config>* receive_configs, |
2133 VideoEncoderConfig* encoder_config) override { | 2196 VideoEncoderConfig* encoder_config) override { |
2134 send_config->encoder_settings.encoder = this; | 2197 send_config->encoder_settings.encoder = this; |
2135 EXPECT_EQ(kNumStreams, encoder_config->streams.size()); | 2198 EXPECT_EQ(kNumStreams, encoder_config->number_of_streams); |
2136 } | 2199 } |
2137 | 2200 |
2138 size_t GetNumVideoStreams() const override { return kNumStreams; } | 2201 size_t GetNumVideoStreams() const override { return kNumStreams; } |
2139 | 2202 |
2140 void PerformTest() override { | 2203 void PerformTest() override { |
2141 EXPECT_TRUE(Wait()) | 2204 EXPECT_TRUE(Wait()) |
2142 << "Timed out while waiting for the encoder to send one frame."; | 2205 << "Timed out while waiting for the encoder to send one frame."; |
2143 VideoSendStream::Stats stats = send_stream_->GetStats(); | 2206 VideoSendStream::Stats stats = send_stream_->GetStats(); |
2144 | 2207 |
2145 for (size_t i = 0; i < kNumStreams; ++i) { | 2208 for (size_t i = 0; i < kNumStreams; ++i) { |
(...skipping 21 matching lines...) Expand all Loading... |
2167 } | 2230 } |
2168 | 2231 |
2169 #if !defined(RTC_DISABLE_VP9) | 2232 #if !defined(RTC_DISABLE_VP9) |
2170 class Vp9HeaderObserver : public test::SendTest { | 2233 class Vp9HeaderObserver : public test::SendTest { |
2171 public: | 2234 public: |
2172 Vp9HeaderObserver() | 2235 Vp9HeaderObserver() |
2173 : SendTest(VideoSendStreamTest::kLongTimeoutMs), | 2236 : SendTest(VideoSendStreamTest::kLongTimeoutMs), |
2174 vp9_encoder_(VP9Encoder::Create()), | 2237 vp9_encoder_(VP9Encoder::Create()), |
2175 vp9_settings_(VideoEncoder::GetDefaultVp9Settings()), | 2238 vp9_settings_(VideoEncoder::GetDefaultVp9Settings()), |
2176 packets_sent_(0), | 2239 packets_sent_(0), |
2177 frames_sent_(0) {} | 2240 frames_sent_(0), |
| 2241 expected_width_(0), |
| 2242 expected_height_(0) {} |
2178 | 2243 |
2179 virtual void ModifyVideoConfigsHook( | 2244 virtual void ModifyVideoConfigsHook( |
2180 VideoSendStream::Config* send_config, | 2245 VideoSendStream::Config* send_config, |
2181 std::vector<VideoReceiveStream::Config>* receive_configs, | 2246 std::vector<VideoReceiveStream::Config>* receive_configs, |
2182 VideoEncoderConfig* encoder_config) {} | 2247 VideoEncoderConfig* encoder_config) {} |
2183 | 2248 |
2184 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; | 2249 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; |
2185 | 2250 |
2186 private: | 2251 private: |
2187 const int kVp9PayloadType = 105; | 2252 const int kVp9PayloadType = 105; |
2188 | 2253 |
| 2254 class VideoStreamFactory |
| 2255 : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 2256 public: |
| 2257 explicit VideoStreamFactory(size_t number_of_temporal_layers) |
| 2258 : number_of_temporal_layers_(number_of_temporal_layers) {} |
| 2259 |
| 2260 private: |
| 2261 std::vector<VideoStream> CreateEncoderStreams( |
| 2262 int width, |
| 2263 int height, |
| 2264 const VideoEncoderConfig& encoder_config) override { |
| 2265 std::vector<VideoStream> streams = |
| 2266 test::CreateVideoStreams(width, height, encoder_config); |
| 2267 streams[0].temporal_layer_thresholds_bps.resize( |
| 2268 number_of_temporal_layers_ - 1); |
| 2269 return streams; |
| 2270 } |
| 2271 |
| 2272 const size_t number_of_temporal_layers_; |
| 2273 }; |
| 2274 |
2189 void ModifyVideoConfigs( | 2275 void ModifyVideoConfigs( |
2190 VideoSendStream::Config* send_config, | 2276 VideoSendStream::Config* send_config, |
2191 std::vector<VideoReceiveStream::Config>* receive_configs, | 2277 std::vector<VideoReceiveStream::Config>* receive_configs, |
2192 VideoEncoderConfig* encoder_config) override { | 2278 VideoEncoderConfig* encoder_config) override { |
2193 encoder_config->encoder_specific_settings = &vp9_settings_; | 2279 encoder_config->encoder_specific_settings = &vp9_settings_; |
2194 send_config->encoder_settings.encoder = vp9_encoder_.get(); | 2280 send_config->encoder_settings.encoder = vp9_encoder_.get(); |
2195 send_config->encoder_settings.payload_name = "VP9"; | 2281 send_config->encoder_settings.payload_name = "VP9"; |
2196 send_config->encoder_settings.payload_type = kVp9PayloadType; | 2282 send_config->encoder_settings.payload_type = kVp9PayloadType; |
2197 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); | 2283 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); |
2198 EXPECT_EQ(1u, encoder_config->streams.size()); | 2284 EXPECT_EQ(1u, encoder_config->number_of_streams); |
2199 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( | 2285 encoder_config->encoder_stream_factory = |
2200 vp9_settings_.numberOfTemporalLayers - 1); | 2286 new rtc::RefCountedObject<VideoStreamFactory>( |
| 2287 vp9_settings_.numberOfTemporalLayers); |
2201 encoder_config_ = encoder_config->Copy(); | 2288 encoder_config_ = encoder_config->Copy(); |
2202 } | 2289 } |
2203 | 2290 |
| 2291 void ModifyVideoCaptureStartResolution(int* width, |
| 2292 int* height, |
| 2293 int* frame_rate) override { |
| 2294 expected_width_ = *width; |
| 2295 expected_height_ = *height; |
| 2296 } |
| 2297 |
2204 void PerformTest() override { | 2298 void PerformTest() override { |
2205 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " | 2299 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " |
2206 << frames_sent_; | 2300 << frames_sent_; |
2207 } | 2301 } |
2208 | 2302 |
2209 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 2303 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
2210 RTPHeader header; | 2304 RTPHeader header; |
2211 EXPECT_TRUE(parser_->Parse(packet, length, &header)); | 2305 EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
2212 | 2306 |
2213 EXPECT_EQ(kVp9PayloadType, header.payloadType); | 2307 EXPECT_EQ(kVp9PayloadType, header.payloadType); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 // +-+-+-+-+-+-+-+-+ | 2477 // +-+-+-+-+-+-+-+-+ |
2384 // N_G: | T |U| R |-|-| N_G times | 2478 // N_G: | T |U| R |-|-| N_G times |
2385 // +-+-+-+-+-+-+-+-+ | 2479 // +-+-+-+-+-+-+-+-+ |
2386 // | P_DIFF | R times | 2480 // | P_DIFF | R times |
2387 // +-+-+-+-+-+-+-+-+ | 2481 // +-+-+-+-+-+-+-+-+ |
2388 void VerifySsData(const RTPVideoHeaderVP9& vp9) const { | 2482 void VerifySsData(const RTPVideoHeaderVP9& vp9) const { |
2389 EXPECT_TRUE(vp9.ss_data_available); // V | 2483 EXPECT_TRUE(vp9.ss_data_available); // V |
2390 EXPECT_EQ(vp9_settings_.numberOfSpatialLayers, // N_S + 1 | 2484 EXPECT_EQ(vp9_settings_.numberOfSpatialLayers, // N_S + 1 |
2391 vp9.num_spatial_layers); | 2485 vp9.num_spatial_layers); |
2392 EXPECT_TRUE(vp9.spatial_layer_resolution_present); // Y:1 | 2486 EXPECT_TRUE(vp9.spatial_layer_resolution_present); // Y:1 |
2393 size_t expected_width = encoder_config_.streams[0].width; | 2487 int expected_width = expected_width_; |
2394 size_t expected_height = encoder_config_.streams[0].height; | 2488 int expected_height = expected_height_; |
2395 for (int i = static_cast<int>(vp9.num_spatial_layers) - 1; i >= 0; --i) { | 2489 for (int i = static_cast<int>(vp9.num_spatial_layers) - 1; i >= 0; --i) { |
2396 EXPECT_EQ(expected_width, vp9.width[i]); // WIDTH | 2490 EXPECT_EQ(expected_width, vp9.width[i]); // WIDTH |
2397 EXPECT_EQ(expected_height, vp9.height[i]); // HEIGHT | 2491 EXPECT_EQ(expected_height, vp9.height[i]); // HEIGHT |
2398 expected_width /= 2; | 2492 expected_width /= 2; |
2399 expected_height /= 2; | 2493 expected_height /= 2; |
2400 } | 2494 } |
2401 } | 2495 } |
2402 | 2496 |
2403 void CompareConsecutiveFrames(const RTPHeader& header, | 2497 void CompareConsecutiveFrames(const RTPHeader& header, |
2404 const RTPVideoHeader& video) const { | 2498 const RTPVideoHeader& video) const { |
(...skipping 23 matching lines...) Expand all Loading... |
2428 VerifyTl0Idx(vp9); | 2522 VerifyTl0Idx(vp9); |
2429 } | 2523 } |
2430 | 2524 |
2431 std::unique_ptr<VP9Encoder> vp9_encoder_; | 2525 std::unique_ptr<VP9Encoder> vp9_encoder_; |
2432 VideoCodecVP9 vp9_settings_; | 2526 VideoCodecVP9 vp9_settings_; |
2433 webrtc::VideoEncoderConfig encoder_config_; | 2527 webrtc::VideoEncoderConfig encoder_config_; |
2434 RTPHeader last_header_; | 2528 RTPHeader last_header_; |
2435 RTPVideoHeaderVP9 last_vp9_; | 2529 RTPVideoHeaderVP9 last_vp9_; |
2436 size_t packets_sent_; | 2530 size_t packets_sent_; |
2437 size_t frames_sent_; | 2531 size_t frames_sent_; |
| 2532 int expected_width_; |
| 2533 int expected_height_; |
2438 }; | 2534 }; |
2439 | 2535 |
2440 TEST_F(VideoSendStreamTest, Vp9NonFlexMode_1Tl1SLayers) { | 2536 TEST_F(VideoSendStreamTest, Vp9NonFlexMode_1Tl1SLayers) { |
2441 const uint8_t kNumTemporalLayers = 1; | 2537 const uint8_t kNumTemporalLayers = 1; |
2442 const uint8_t kNumSpatialLayers = 1; | 2538 const uint8_t kNumSpatialLayers = 1; |
2443 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); | 2539 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
2444 } | 2540 } |
2445 | 2541 |
2446 TEST_F(VideoSendStreamTest, Vp9NonFlexMode_2Tl1SLayers) { | 2542 TEST_F(VideoSendStreamTest, Vp9NonFlexMode_2Tl1SLayers) { |
2447 const uint8_t kNumTemporalLayers = 2; | 2543 const uint8_t kNumTemporalLayers = 2; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2529 static const int kHeight = 4; | 2625 static const int kHeight = 4; |
2530 class NonFlexibleModeResolution : public Vp9HeaderObserver { | 2626 class NonFlexibleModeResolution : public Vp9HeaderObserver { |
2531 void ModifyVideoConfigsHook( | 2627 void ModifyVideoConfigsHook( |
2532 VideoSendStream::Config* send_config, | 2628 VideoSendStream::Config* send_config, |
2533 std::vector<VideoReceiveStream::Config>* receive_configs, | 2629 std::vector<VideoReceiveStream::Config>* receive_configs, |
2534 VideoEncoderConfig* encoder_config) override { | 2630 VideoEncoderConfig* encoder_config) override { |
2535 vp9_settings_.flexibleMode = false; | 2631 vp9_settings_.flexibleMode = false; |
2536 vp9_settings_.numberOfTemporalLayers = 1; | 2632 vp9_settings_.numberOfTemporalLayers = 1; |
2537 vp9_settings_.numberOfSpatialLayers = 1; | 2633 vp9_settings_.numberOfSpatialLayers = 1; |
2538 | 2634 |
2539 EXPECT_EQ(1u, encoder_config->streams.size()); | 2635 EXPECT_EQ(1u, encoder_config->number_of_streams); |
2540 encoder_config->streams[0].width = kWidth; | |
2541 encoder_config->streams[0].height = kHeight; | |
2542 } | 2636 } |
2543 | 2637 |
2544 void InspectHeader(const RTPVideoHeaderVP9& vp9_header) override { | 2638 void InspectHeader(const RTPVideoHeaderVP9& vp9_header) override { |
2545 if (frames_sent_ > kNumFramesToSend) | 2639 if (frames_sent_ > kNumFramesToSend) |
2546 observation_complete_.Set(); | 2640 observation_complete_.Set(); |
2547 } | 2641 } |
| 2642 |
| 2643 void ModifyVideoCaptureStartResolution(int* width, |
| 2644 int* height, |
| 2645 int* frame_rate) override { |
| 2646 expected_width_ = kWidth; |
| 2647 expected_height_ = kHeight; |
| 2648 *width = kWidth; |
| 2649 *height = kHeight; |
| 2650 } |
2548 } test; | 2651 } test; |
2549 | 2652 |
2550 RunBaseTest(&test); | 2653 RunBaseTest(&test); |
2551 } | 2654 } |
2552 | 2655 |
2553 TEST_F(VideoSendStreamTest, Vp9FlexModeRefCount) { | 2656 TEST_F(VideoSendStreamTest, Vp9FlexModeRefCount) { |
2554 class FlexibleMode : public Vp9HeaderObserver { | 2657 class FlexibleMode : public Vp9HeaderObserver { |
2555 void ModifyVideoConfigsHook( | 2658 void ModifyVideoConfigsHook( |
2556 VideoSendStream::Config* send_config, | 2659 VideoSendStream::Config* send_config, |
2557 std::vector<VideoReceiveStream::Config>* receive_configs, | 2660 std::vector<VideoReceiveStream::Config>* receive_configs, |
(...skipping 12 matching lines...) Expand all Loading... |
2570 observation_complete_.Set(); | 2673 observation_complete_.Set(); |
2571 } | 2674 } |
2572 } | 2675 } |
2573 } test; | 2676 } test; |
2574 | 2677 |
2575 RunBaseTest(&test); | 2678 RunBaseTest(&test); |
2576 } | 2679 } |
2577 #endif // !defined(RTC_DISABLE_VP9) | 2680 #endif // !defined(RTC_DISABLE_VP9) |
2578 | 2681 |
2579 } // namespace webrtc | 2682 } // namespace webrtc |
OLD | NEW |