sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | #include <map> |
| 14 | |
| 15 | #include "gflags/gflags.h" |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
| 18 | #include "webrtc/test/field_trial.h" |
| 19 | #include "webrtc/test/frame_generator.h" |
| 20 | #include "webrtc/test/frame_generator_capturer.h" |
| 21 | #include "webrtc/test/run_test.h" |
| 22 | #include "webrtc/test/testsupport/fileutils.h" |
| 23 | #include "webrtc/typedefs.h" |
| 24 | #include "webrtc/video/loopback.h" |
| 25 | #include "webrtc/video/video_send_stream.h" |
| 26 | |
| 27 | namespace webrtc { |
| 28 | namespace flags { |
| 29 | |
| 30 | // Fixed for prerecorded screenshare content. |
| 31 | size_t Width() { |
| 32 | return 1850; |
| 33 | } |
| 34 | size_t Height() { |
| 35 | return 1110; |
| 36 | } |
| 37 | |
| 38 | DEFINE_int32(fps, 5, "Frames per second."); |
| 39 | int Fps() { |
| 40 | return static_cast<int>(FLAGS_fps); |
| 41 | } |
| 42 | |
| 43 | DEFINE_int32(min_bitrate, 50, "Minimum video bitrate."); |
| 44 | size_t MinBitrate() { |
| 45 | return static_cast<size_t>(FLAGS_min_bitrate); |
| 46 | } |
| 47 | |
| 48 | DEFINE_int32(tl0_bitrate, 100, "Temporal layer 0 target bitrate."); |
| 49 | size_t StartBitrate() { |
| 50 | return static_cast<size_t>(FLAGS_tl0_bitrate); |
| 51 | } |
| 52 | |
| 53 | DEFINE_int32(tl1_bitrate, 1000, "Temporal layer 1 target bitrate."); |
| 54 | size_t MaxBitrate() { |
| 55 | return static_cast<size_t>(FLAGS_tl1_bitrate); |
| 56 | } |
| 57 | |
| 58 | DEFINE_int32(min_transmit_bitrate, 400, "Min transmit bitrate incl. padding."); |
| 59 | int MinTransmitBitrate() { |
| 60 | return FLAGS_min_transmit_bitrate; |
| 61 | } |
| 62 | |
| 63 | DEFINE_string(codec, "VP8", "Video codec to use."); |
| 64 | std::string Codec() { |
| 65 | return static_cast<std::string>(FLAGS_codec); |
| 66 | } |
| 67 | |
| 68 | DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost."); |
| 69 | int LossPercent() { |
| 70 | return static_cast<int>(FLAGS_loss_percent); |
| 71 | } |
| 72 | |
| 73 | DEFINE_int32(link_capacity, |
| 74 | 0, |
| 75 | "Capacity (kbps) of the fake link. 0 means infinite."); |
| 76 | int LinkCapacity() { |
| 77 | return static_cast<int>(FLAGS_link_capacity); |
| 78 | } |
| 79 | |
| 80 | DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets."); |
| 81 | int QueueSize() { |
| 82 | return static_cast<int>(FLAGS_queue_size); |
| 83 | } |
| 84 | |
| 85 | DEFINE_int32(avg_propagation_delay_ms, |
| 86 | 0, |
| 87 | "Average link propagation delay in ms."); |
| 88 | int AvgPropagationDelayMs() { |
| 89 | return static_cast<int>(FLAGS_avg_propagation_delay_ms); |
| 90 | } |
| 91 | |
| 92 | DEFINE_int32(std_propagation_delay_ms, |
| 93 | 0, |
| 94 | "Link propagation delay standard deviation in ms."); |
| 95 | int StdPropagationDelayMs() { |
| 96 | return static_cast<int>(FLAGS_std_propagation_delay_ms); |
| 97 | } |
| 98 | |
| 99 | DEFINE_bool(logs, false, "print logs to stderr"); |
| 100 | |
| 101 | DEFINE_string( |
| 102 | force_fieldtrials, |
| 103 | "", |
| 104 | "Field trials control experimental feature code which can be forced. " |
| 105 | "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" |
| 106 | " will assign the group Enable to field trial WebRTC-FooFeature. Multiple " |
| 107 | "trials are separated by \"/\""); |
| 108 | } // namespace flags |
| 109 | |
| 110 | class ScreenshareLoopback : public test::Loopback { |
| 111 | public: |
| 112 | explicit ScreenshareLoopback(const Config& config) : Loopback(config) {} |
| 113 | virtual ~ScreenshareLoopback() {} |
| 114 | |
| 115 | protected: |
| 116 | VideoEncoderConfig CreateEncoderConfig() override { |
| 117 | VideoEncoderConfig encoder_config(test::Loopback::CreateEncoderConfig()); |
| 118 | VideoStream* stream = &encoder_config.streams[0]; |
| 119 | encoder_config.content_type = VideoEncoderConfig::kScreenshare; |
| 120 | encoder_config.min_transmit_bitrate_bps = flags::MinTransmitBitrate(); |
| 121 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 122 | vp8_settings.denoisingOn = false; |
| 123 | vp8_settings.frameDroppingOn = false; |
| 124 | vp8_settings.numberOfTemporalLayers = 2; |
| 125 | encoder_config.encoder_specific_settings = &vp8_settings; |
| 126 | stream->temporal_layer_thresholds_bps.clear(); |
| 127 | stream->temporal_layer_thresholds_bps.push_back(stream->target_bitrate_bps); |
| 128 | stream->target_bitrate_bps = |
| 129 | static_cast<int>(config_.start_bitrate_kbps) * 1000; |
| 130 | return encoder_config; |
| 131 | } |
| 132 | |
| 133 | test::VideoCapturer* CreateCapturer(VideoSendStream* send_stream) override { |
| 134 | std::vector<std::string> slides; |
| 135 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 136 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 137 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 138 | slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
| 139 | |
| 140 | test::FrameGenerator* frame_generator = |
| 141 | test::FrameGenerator::CreateFromYuvFile( |
| 142 | slides, flags::Width(), flags::Height(), 10 * flags::Fps()); |
| 143 | test::FrameGeneratorCapturer* capturer(new test::FrameGeneratorCapturer( |
| 144 | clock_, send_stream->Input(), frame_generator, flags::Fps())); |
| 145 | EXPECT_TRUE(capturer->Init()); |
| 146 | return capturer; |
| 147 | } |
| 148 | }; |
| 149 | |
| 150 | void Loopback() { |
| 151 | test::Loopback::Config config{flags::Width(), |
| 152 | flags::Height(), |
| 153 | flags::Fps(), |
| 154 | flags::MinBitrate(), |
| 155 | flags::StartBitrate(), |
| 156 | flags::MaxBitrate(), |
| 157 | flags::MinTransmitBitrate(), |
| 158 | flags::Codec(), |
| 159 | flags::LossPercent(), |
| 160 | flags::LinkCapacity(), |
| 161 | flags::QueueSize(), |
| 162 | flags::AvgPropagationDelayMs(), |
| 163 | flags::StdPropagationDelayMs(), |
| 164 | flags::FLAGS_logs}; |
| 165 | ScreenshareLoopback loopback(config); |
| 166 | loopback.Run(); |
| 167 | } |
| 168 | } // namespace webrtc |
| 169 | |
| 170 | int main(int argc, char* argv[]) { |
| 171 | ::testing::InitGoogleTest(&argc, argv); |
| 172 | google::ParseCommandLineFlags(&argc, &argv, true); |
| 173 | webrtc::test::InitFieldTrialsFromString( |
| 174 | webrtc::flags::FLAGS_force_fieldtrials); |
| 175 | webrtc::test::RunTest(webrtc::Loopback); |
| 176 | return 0; |
| 177 | } |