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

Side by Side Diff: webrtc/video/video_send_stream_tests.cc

Issue 2510583002: Reland #2 of Issue 2434073003: Extract bitrate allocation ... (Closed)
Patch Set: Bug fixes + rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 1320
1321 RunBaseTest(&test); 1321 RunBaseTest(&test);
1322 } 1322 }
1323 1323
1324 TEST_F(VideoSendStreamTest, ChangingTransportOverhead) { 1324 TEST_F(VideoSendStreamTest, ChangingTransportOverhead) {
1325 class ChangingTransportOverheadTest : public test::EndToEndTest { 1325 class ChangingTransportOverheadTest : public test::EndToEndTest {
1326 public: 1326 public:
1327 ChangingTransportOverheadTest() 1327 ChangingTransportOverheadTest()
1328 : EndToEndTest(test::CallTest::kDefaultTimeoutMs), 1328 : EndToEndTest(test::CallTest::kDefaultTimeoutMs),
1329 call_(nullptr), 1329 call_(nullptr),
1330 packets_sent_(0) {} 1330 packets_sent_(0),
1331 transport_overhead_(0) {}
1331 1332
1332 void OnCallsCreated(Call* sender_call, Call* receiver_call) override { 1333 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
1333 call_ = sender_call; 1334 call_ = sender_call;
1334 } 1335 }
1335 1336
1336 Action OnSendRtp(const uint8_t* packet, size_t length) override { 1337 Action OnSendRtp(const uint8_t* packet, size_t length) override {
1337 EXPECT_LE(length, 1338 EXPECT_LE(length,
1338 IP_PACKET_SIZE - static_cast<size_t>(transport_overhead_)); 1339 IP_PACKET_SIZE - static_cast<size_t>(transport_overhead_));
1339 if (++packets_sent_ < 100) 1340 if (++packets_sent_ < 100)
1340 return SEND_PACKET; 1341 return SEND_PACKET;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 last_initialized_frame_height_(0) {} 1472 last_initialized_frame_height_(0) {}
1472 1473
1473 void WaitForResolution(int width, int height) { 1474 void WaitForResolution(int width, int height) {
1474 { 1475 {
1475 rtc::CritScope lock(&crit_); 1476 rtc::CritScope lock(&crit_);
1476 if (last_initialized_frame_width_ == width && 1477 if (last_initialized_frame_width_ == width &&
1477 last_initialized_frame_height_ == height) { 1478 last_initialized_frame_height_ == height) {
1478 return; 1479 return;
1479 } 1480 }
1480 } 1481 }
1481 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); 1482 EXPECT_TRUE(
1483 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
1482 { 1484 {
1483 rtc::CritScope lock(&crit_); 1485 rtc::CritScope lock(&crit_);
1484 EXPECT_EQ(width, last_initialized_frame_width_); 1486 EXPECT_EQ(width, last_initialized_frame_width_);
1485 EXPECT_EQ(height, last_initialized_frame_height_); 1487 EXPECT_EQ(height, last_initialized_frame_height_);
1486 } 1488 }
1487 } 1489 }
1488 1490
1489 private: 1491 private:
1490 int32_t InitEncode(const VideoCodec* config, 1492 int32_t InitEncode(const VideoCodec* config,
1491 int32_t number_of_cores, 1493 int32_t number_of_cores,
1492 size_t max_payload_size) override { 1494 size_t max_payload_size) override {
1493 rtc::CritScope lock(&crit_); 1495 rtc::CritScope lock(&crit_);
1494 last_initialized_frame_width_ = config->width; 1496 last_initialized_frame_width_ = config->width;
1495 last_initialized_frame_height_ = config->height; 1497 last_initialized_frame_height_ = config->height;
1496 ++number_of_initializations_; 1498 ++number_of_initializations_;
1497 // First time InitEncode is called, the frame size is unknown. 1499 init_encode_called_.Set();
1498 if (number_of_initializations_ > 1)
1499 init_encode_called_.Set();
1500 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); 1500 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1501 } 1501 }
1502 1502
1503 int32_t Encode(const VideoFrame& input_image, 1503 int32_t Encode(const VideoFrame& input_image,
1504 const CodecSpecificInfo* codec_specific_info, 1504 const CodecSpecificInfo* codec_specific_info,
1505 const std::vector<FrameType>* frame_types) override { 1505 const std::vector<FrameType>* frame_types) override {
1506 ADD_FAILURE() 1506 ADD_FAILURE()
1507 << "Unexpected Encode call since the send stream is not started"; 1507 << "Unexpected Encode call since the send stream is not started";
1508 return 0; 1508 return 0;
1509 } 1509 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 // This test that if the encoder use an internal source, VideoEncoder::SetRates 1608 // This test that if the encoder use an internal source, VideoEncoder::SetRates
1609 // will be called with zero bitrate during initialization and that 1609 // will be called with zero bitrate during initialization and that
1610 // VideoSendStream::Stop also triggers VideoEncoder::SetRates Start to be called 1610 // VideoSendStream::Stop also triggers VideoEncoder::SetRates Start to be called
1611 // with zero bitrate. 1611 // with zero bitrate.
1612 TEST_F(VideoSendStreamTest, VideoSendStreamStopSetEncoderRateToZero) { 1612 TEST_F(VideoSendStreamTest, VideoSendStreamStopSetEncoderRateToZero) {
1613 class StartStopBitrateObserver : public test::FakeEncoder { 1613 class StartStopBitrateObserver : public test::FakeEncoder {
1614 public: 1614 public:
1615 StartStopBitrateObserver() 1615 StartStopBitrateObserver()
1616 : FakeEncoder(Clock::GetRealTimeClock()), 1616 : FakeEncoder(Clock::GetRealTimeClock()),
1617 encoder_init_(false, false), 1617 encoder_init_(false, false),
1618 bitrate_changed_(false, false), 1618 bitrate_changed_(false, false) {}
1619 bitrate_kbps_(0) {}
1620 int32_t InitEncode(const VideoCodec* config, 1619 int32_t InitEncode(const VideoCodec* config,
1621 int32_t number_of_cores, 1620 int32_t number_of_cores,
1622 size_t max_payload_size) override { 1621 size_t max_payload_size) override {
1623 rtc::CritScope lock(&crit_); 1622 rtc::CritScope lock(&crit_);
1624 bitrate_kbps_ = config->startBitrate;
1625 encoder_init_.Set(); 1623 encoder_init_.Set();
1626 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); 1624 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1627 } 1625 }
1628 1626
1629 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override { 1627 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
1628 uint32_t framerate) override {
1630 rtc::CritScope lock(&crit_); 1629 rtc::CritScope lock(&crit_);
1631 bitrate_kbps_ = new_target_bitrate; 1630 bitrate_kbps_ = rtc::Optional<int>(bitrate.get_sum_kbps());
1632 bitrate_changed_.Set(); 1631 bitrate_changed_.Set();
1633 return FakeEncoder::SetRates(new_target_bitrate, framerate); 1632 return FakeEncoder::SetRateAllocation(bitrate, framerate);
1634 }
1635
1636 int GetBitrateKbps() const {
1637 rtc::CritScope lock(&crit_);
1638 return bitrate_kbps_;
1639 } 1633 }
1640 1634
1641 bool WaitForEncoderInit() { 1635 bool WaitForEncoderInit() {
1642 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); 1636 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs);
1643 } 1637 }
1644 bool WaitBitrateChanged() { 1638
1645 return bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); 1639 bool WaitBitrateChanged(bool non_zero) {
1640 do {
1641 rtc::Optional<int> bitrate_kbps;
1642 {
1643 rtc::CritScope lock(&crit_);
1644 bitrate_kbps = bitrate_kbps_;
1645 }
1646 if (bitrate_kbps && !(non_zero ^ (*bitrate_kbps > 0)))
stefan-webrtc 2016/11/16 14:55:08 This is really hard to read. Must be possible to s
sprang_webrtc 2016/11/16 15:01:43 Done.
1647 return true;
1648 } while (bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
1649 return false;
1646 } 1650 }
1647 1651
1648 private: 1652 private:
1649 rtc::CriticalSection crit_; 1653 rtc::CriticalSection crit_;
1650 rtc::Event encoder_init_; 1654 rtc::Event encoder_init_;
1651 rtc::Event bitrate_changed_; 1655 rtc::Event bitrate_changed_;
1652 int bitrate_kbps_ GUARDED_BY(crit_); 1656 rtc::Optional<int> bitrate_kbps_ GUARDED_BY(crit_);
1653 }; 1657 };
1654 1658
1655 CreateSenderCall(Call::Config(&event_log_)); 1659 CreateSenderCall(Call::Config(&event_log_));
1656 1660
1657 test::NullTransport transport; 1661 test::NullTransport transport;
1658 CreateSendConfig(1, 0, 0, &transport); 1662 CreateSendConfig(1, 0, 0, &transport);
1659 1663
1660 StartStopBitrateObserver encoder; 1664 StartStopBitrateObserver encoder;
1661 video_send_config_.encoder_settings.encoder = &encoder; 1665 video_send_config_.encoder_settings.encoder = &encoder;
1662 video_send_config_.encoder_settings.internal_source = true; 1666 video_send_config_.encoder_settings.internal_source = true;
1663 1667
1664 CreateVideoStreams(); 1668 CreateVideoStreams();
1665 1669
1666 EXPECT_TRUE(encoder.WaitForEncoderInit()); 1670 EXPECT_TRUE(encoder.WaitForEncoderInit());
1667 EXPECT_GT(encoder.GetBitrateKbps(), 0); 1671
1668 video_send_stream_->Start(); 1672 video_send_stream_->Start();
1669 EXPECT_TRUE(encoder.WaitBitrateChanged()); 1673 EXPECT_TRUE(encoder.WaitBitrateChanged(true));
1670 EXPECT_GT(encoder.GetBitrateKbps(), 0); 1674
1671 video_send_stream_->Stop(); 1675 video_send_stream_->Stop();
1672 EXPECT_TRUE(encoder.WaitBitrateChanged()); 1676 EXPECT_TRUE(encoder.WaitBitrateChanged(false));
1673 EXPECT_EQ(0, encoder.GetBitrateKbps()); 1677
1674 video_send_stream_->Start(); 1678 video_send_stream_->Start();
1675 EXPECT_TRUE(encoder.WaitBitrateChanged()); 1679 EXPECT_TRUE(encoder.WaitBitrateChanged(true));
1676 EXPECT_GT(encoder.GetBitrateKbps(), 0);
1677 1680
1678 DestroyStreams(); 1681 DestroyStreams();
1679 } 1682 }
1680 1683
1681 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { 1684 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) {
1682 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { 1685 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> {
1683 public: 1686 public:
1684 FrameObserver() : output_frame_event_(false, false) {} 1687 FrameObserver() : output_frame_event_(false, false) {}
1685 1688
1686 void OnFrame(const VideoFrame& video_frame) override { 1689 void OnFrame(const VideoFrame& video_frame) override {
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 // VideoCodec. 2081 // VideoCodec.
2079 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, 2082 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
2080 config.VP8().numberOfTemporalLayers); 2083 config.VP8().numberOfTemporalLayers);
2081 2084
2082 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { 2085 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) {
2083 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, 2086 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
2084 config.simulcastStream[i].numberOfTemporalLayers); 2087 config.simulcastStream[i].numberOfTemporalLayers);
2085 } 2088 }
2086 2089
2087 // Set expected temporal layers as they should have been set when 2090 // Set expected temporal layers as they should have been set when
2088 // reconfiguring the encoder and not match the set config. 2091 // reconfiguring the encoder and not match the set config. Also copy the
2092 // TemporalLayersFactory pointer that has been injected by ViEEncoder.
2089 VideoCodecVP8 encoder_settings = encoder_settings_; 2093 VideoCodecVP8 encoder_settings = encoder_settings_;
2090 encoder_settings.numberOfTemporalLayers = 2094 encoder_settings.numberOfTemporalLayers =
2091 kVideoCodecConfigObserverNumberOfTemporalLayers; 2095 kVideoCodecConfigObserverNumberOfTemporalLayers;
2096 encoder_settings.tl_factory = config.VP8().tl_factory;
2092 EXPECT_EQ( 2097 EXPECT_EQ(
2093 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_))); 2098 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_)));
2094 } 2099 }
2095 2100
2096 template <> 2101 template <>
2097 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> 2102 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings>
2098 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { 2103 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const {
2099 return new rtc::RefCountedObject< 2104 return new rtc::RefCountedObject<
2100 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); 2105 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_);
2101 } 2106 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 // has currently configured but in the span of the set max and min 2308 // has currently configured but in the span of the set max and min
2304 // bitrate. 2309 // bitrate.
2305 } 2310 }
2306 ++num_initializations_; 2311 ++num_initializations_;
2307 init_encode_event_.Set(); 2312 init_encode_event_.Set();
2308 2313
2309 return FakeEncoder::InitEncode(codecSettings, numberOfCores, 2314 return FakeEncoder::InitEncode(codecSettings, numberOfCores,
2310 maxPayloadSize); 2315 maxPayloadSize);
2311 } 2316 }
2312 2317
2313 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { 2318 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
2319 uint32_t frameRate) override {
2314 { 2320 {
2315 rtc::CritScope lock(&crit_); 2321 rtc::CritScope lock(&crit_);
2316 if (target_bitrate_ == newBitRate) { 2322 if (target_bitrate_ == bitrate.get_sum_kbps()) {
2317 return FakeEncoder::SetRates(newBitRate, frameRate); 2323 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
2318 } 2324 }
2319 target_bitrate_ = newBitRate; 2325 target_bitrate_ = bitrate.get_sum_kbps();
2320 } 2326 }
2321 bitrate_changed_event_.Set(); 2327 bitrate_changed_event_.Set();
2322 return FakeEncoder::SetRates(newBitRate, frameRate); 2328 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
2323 } 2329 }
2324 2330
2325 void WaitForSetRates(uint32_t expected_bitrate) { 2331 void WaitForSetRates(uint32_t expected_bitrate) {
2326 EXPECT_TRUE( 2332 EXPECT_TRUE(
2327 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) 2333 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs))
2328 << "Timed out while waiting encoder rate to be set."; 2334 << "Timed out while waiting encoder rate to be set.";
2329 rtc::CritScope lock(&crit_); 2335 rtc::CritScope lock(&crit_);
2330 EXPECT_EQ(expected_bitrate, target_bitrate_); 2336 EXPECT_EQ(expected_bitrate, target_bitrate_);
2331 } 2337 }
2332 2338
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2987 RequestSourceRotateIfVideoOrientationExtensionNotSupported) { 2993 RequestSourceRotateIfVideoOrientationExtensionNotSupported) {
2988 TestRequestSourceRotateVideo(false); 2994 TestRequestSourceRotateVideo(false);
2989 } 2995 }
2990 2996
2991 TEST_F(VideoSendStreamTest, 2997 TEST_F(VideoSendStreamTest,
2992 DoNotRequestsRotationIfVideoOrientationExtensionSupported) { 2998 DoNotRequestsRotationIfVideoOrientationExtensionSupported) {
2993 TestRequestSourceRotateVideo(true); 2999 TestRequestSourceRotateVideo(true);
2994 } 3000 }
2995 3001
2996 } // namespace webrtc 3002 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698