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

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

Issue 2106183002: Fix bug where min transmit bitrate wasn't working (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add min transmit bitrate to Call::Stats, update test Created 4 years, 5 months 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> 10 #include <algorithm>
11 #include <list> 11 #include <list>
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/base/event.h" 21 #include "webrtc/base/event.h"
22 #include "webrtc/call.h" 22 #include "webrtc/call.h"
23 #include "webrtc/call/transport_adapter.h" 23 #include "webrtc/call/transport_adapter.h"
24 #include "webrtc/common_video/include/frame_callback.h" 24 #include "webrtc/common_video/include/frame_callback.h"
25 #include "webrtc/modules/include/module_common_types.h" 25 #include "webrtc/modules/include/module_common_types.h"
26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 26 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
27 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 27 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
28 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
28 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
29 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 30 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
30 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 31 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
31 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 32 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
32 #include "webrtc/modules/video_coding/include/video_coding_defines.h" 33 #include "webrtc/modules/video_coding/include/video_coding_defines.h"
33 #include "webrtc/system_wrappers/include/metrics.h" 34 #include "webrtc/system_wrappers/include/metrics.h"
34 #include "webrtc/system_wrappers/include/metrics_default.h" 35 #include "webrtc/system_wrappers/include/metrics_default.h"
35 #include "webrtc/system_wrappers/include/sleep.h" 36 #include "webrtc/system_wrappers/include/sleep.h"
36 #include "webrtc/test/call_test.h" 37 #include "webrtc/test/call_test.h"
37 #include "webrtc/test/direct_transport.h" 38 #include "webrtc/test/direct_transport.h"
(...skipping 2453 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 2492
2492 private: 2493 private:
2493 rtc::CriticalSection crit_; 2494 rtc::CriticalSection crit_;
2494 VideoSendStream* send_stream_; 2495 VideoSendStream* send_stream_;
2495 uint32_t bitrate_kbps_ GUARDED_BY(crit_); 2496 uint32_t bitrate_kbps_ GUARDED_BY(crit_);
2496 } test; 2497 } test;
2497 2498
2498 RunBaseTest(&test); 2499 RunBaseTest(&test);
2499 } 2500 }
2500 2501
2502 class MinTransmitBitrateTest : public test::EndToEndTest,
perkj_webrtc 2016/07/04 07:24:49 Why is this not a VideoSendStream test? What is th
perkj_webrtc 2016/07/04 07:24:49 How about testing padding instead? There are test
sprang_webrtc 2016/07/04 09:08:47 I did that at first, it turned out to flake way to
sprang_webrtc 2016/07/04 09:08:47 I initially had planned to check received padding,
2503 public test::FakeEncoder {
2504 public:
2505 static const uint32_t kMinTransmitBitrateBps = 400000;
2506 static const uint32_t kActualEncodeBitrateBps = 40000;
2507 static const uint32_t kMinFramesToSend = 10;
2508
2509 explicit MinTransmitBitrateTest(bool run_init_phase_without_mtb)
perkj_webrtc 2016/07/04 07:24:49 bool test_switch_content_type ?
sprang_webrtc 2016/07/04 09:08:47 Done.
2510 : EndToEndTest(test::CallTest::kDefaultTimeoutMs),
2511 FakeEncoder(Clock::GetRealTimeClock()),
2512 call_(nullptr),
2513 send_stream_(nullptr),
2514 frames_sent_(0),
2515 in_init_phase_(run_init_phase_without_mtb) {}
2516
2517 void OnVideoStreamsCreated(
2518 VideoSendStream* send_stream,
2519 const std::vector<VideoReceiveStream*>& receive_streams) override {
2520 send_stream_ = send_stream;
2521 }
2522
2523 void ModifyVideoConfigs(
2524 VideoSendStream::Config* send_config,
2525 std::vector<VideoReceiveStream::Config>* receive_configs,
2526 VideoEncoderConfig* encoder_config) override {
2527 send_config->encoder_settings.encoder = this;
2528 RTC_DCHECK_EQ(1u, encoder_config->streams.size());
2529 encoder_config->streams[0].target_bitrate_bps = kMinTransmitBitrateBps * 2;
2530 encoder_config->streams[0].max_bitrate_bps = kMinTransmitBitrateBps * 4;
2531 if (in_init_phase_) {
2532 encoder_config->min_transmit_bitrate_bps = 0;
2533 encoder_config->content_type =
2534 VideoEncoderConfig::ContentType::kRealtimeVideo;
2535 } else {
2536 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps;
2537 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
2538 }
2539 encoder_config_ = *encoder_config;
2540 }
2541
2542 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override {
2543 // Make sure not to trigger on any default zero bitrates.
2544 if (new_target_bitrate == 0)
2545 return 0;
2546 rtc::CritScope lock(&crit_);
2547 return FakeEncoder::SetRates(
2548 std::min<uint32_t>(new_target_bitrate, kActualEncodeBitrateBps / 1000),
2549 framerate);
2550 }
2551
2552 int32_t Encode(const VideoFrame& input_image,
2553 const CodecSpecificInfo* codec_specific_info,
2554 const std::vector<FrameType>* frame_types) override {
2555 int32_t res =
2556 FakeEncoder::Encode(input_image, codec_specific_info, frame_types);
2557 CheckDoneState();
2558 return res;
2559 }
2560
2561 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
2562 call_ = sender_call;
2563 }
2564
2565 void CheckDoneState() {
2566 rtc::CritScope lock(&crit_);
2567
2568 if (in_init_phase_)
2569 EXPECT_EQ(0, call_->GetStats().min_transmit_bitrate_bps);
2570
2571 // Wait until at least kMinFramesToSend frames have been encoded, so that
2572 // we have reliable data.
2573 if (++frames_sent_ < kMinFramesToSend)
2574 return;
2575
2576 if (in_init_phase_) {
2577 // We've sent kMinFramesToSend frames with default configuration, switch
2578 // to enabling screen content and setting min transmit bitrate.
2579 frames_sent_ = 0;
2580 encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps;
2581 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
2582 send_stream_->ReconfigureVideoEncoder(encoder_config_);
2583 in_init_phase_ = false;
2584 return;
2585 }
2586
2587 // Make sure the pacer has been configured with a min transmit bitrate.
2588 if (call_->GetStats().min_transmit_bitrate_bps > 0)
2589 observation_complete_.Set();
2590 }
2591
2592 void PerformTest() override {
2593 ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate.";
2594 }
2595
2596 private:
2597 rtc::CriticalSection crit_;
2598 Call* call_;
2599 VideoSendStream* send_stream_;
2600 VideoEncoderConfig encoder_config_;
2601 uint32_t frames_sent_ GUARDED_BY(crit_);
2602 bool in_init_phase_;
2603 };
2604
2605 TEST_F(EndToEndTest, RespectsMinTransmitBitrate) {
2606 MinTransmitBitrateTest test(false);
2607 RunBaseTest(&test);
2608 }
2609
2610 TEST_F(EndToEndTest, RespectsMinTransmitBitrateAfterContentSwitch) {
2611 MinTransmitBitrateTest test(true);
2612 RunBaseTest(&test);
2613 }
2614
2501 TEST_F(EndToEndTest, GetStats) { 2615 TEST_F(EndToEndTest, GetStats) {
2502 static const int kStartBitrateBps = 3000000; 2616 static const int kStartBitrateBps = 3000000;
2503 static const int kExpectedRenderDelayMs = 20; 2617 static const int kExpectedRenderDelayMs = 20;
2504 2618
2505 class ReceiveStreamRenderer : public rtc::VideoSinkInterface<VideoFrame> { 2619 class ReceiveStreamRenderer : public rtc::VideoSinkInterface<VideoFrame> {
2506 public: 2620 public:
2507 ReceiveStreamRenderer() {} 2621 ReceiveStreamRenderer() {}
2508 2622
2509 private: 2623 private:
2510 void OnFrame(const VideoFrame& video_frame) override {} 2624 void OnFrame(const VideoFrame& video_frame) override {}
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after
3558 private: 3672 private:
3559 bool video_observed_; 3673 bool video_observed_;
3560 bool audio_observed_; 3674 bool audio_observed_;
3561 SequenceNumberUnwrapper unwrapper_; 3675 SequenceNumberUnwrapper unwrapper_;
3562 std::set<int64_t> received_packet_ids_; 3676 std::set<int64_t> received_packet_ids_;
3563 } test; 3677 } test;
3564 3678
3565 RunBaseTest(&test); 3679 RunBaseTest(&test);
3566 } 3680 }
3567 } // namespace webrtc 3681 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698