| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 | 10 |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 | 12 |
| 13 #include <map> | |
| 14 | |
| 15 #include "gflags/gflags.h" | 13 #include "gflags/gflags.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 15 |
| 18 #include "webrtc/base/checks.h" | |
| 19 #include "webrtc/test/field_trial.h" | 16 #include "webrtc/test/field_trial.h" |
| 20 #include "webrtc/test/frame_generator.h" | |
| 21 #include "webrtc/test/frame_generator_capturer.h" | |
| 22 #include "webrtc/test/run_test.h" | 17 #include "webrtc/test/run_test.h" |
| 23 #include "webrtc/test/testsupport/fileutils.h" | 18 #include "webrtc/video/video_quality_test.h" |
| 24 #include "webrtc/typedefs.h" | |
| 25 #include "webrtc/video/loopback.h" | |
| 26 #include "webrtc/video/video_send_stream.h" | |
| 27 | 19 |
| 28 namespace webrtc { | 20 namespace webrtc { |
| 29 namespace flags { | 21 namespace flags { |
| 30 | 22 |
| 31 DEFINE_int32(width, 1850, "Video width (crops source)."); | 23 DEFINE_int32(width, 1850, "Video width (crops source)."); |
| 32 size_t Width() { | 24 size_t Width() { |
| 33 return static_cast<size_t>(FLAGS_width); | 25 return static_cast<size_t>(FLAGS_width); |
| 34 } | 26 } |
| 35 | 27 |
| 36 DEFINE_int32(height, 1110, "Video height (crops source)."); | 28 DEFINE_int32(height, 1110, "Video height (crops source)."); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 52 | 44 |
| 53 DEFINE_int32( | 45 DEFINE_int32( |
| 54 scroll_duration, | 46 scroll_duration, |
| 55 0, | 47 0, |
| 56 "Duration (in seconds) during which a slide will be scrolled into place."); | 48 "Duration (in seconds) during which a slide will be scrolled into place."); |
| 57 int ScrollDuration() { | 49 int ScrollDuration() { |
| 58 return static_cast<int>(FLAGS_scroll_duration); | 50 return static_cast<int>(FLAGS_scroll_duration); |
| 59 } | 51 } |
| 60 | 52 |
| 61 DEFINE_int32(min_bitrate, 50, "Minimum video bitrate."); | 53 DEFINE_int32(min_bitrate, 50, "Minimum video bitrate."); |
| 62 size_t MinBitrate() { | 54 size_t MinBitrateKbps() { |
| 63 return static_cast<size_t>(FLAGS_min_bitrate); | 55 return static_cast<size_t>(FLAGS_min_bitrate); |
| 64 } | 56 } |
| 65 | 57 |
| 66 DEFINE_int32(tl0_bitrate, 200, "Temporal layer 0 target bitrate."); | 58 DEFINE_int32(tl0_bitrate, 200, "Temporal layer 0 target bitrate."); |
| 67 size_t StartBitrate() { | 59 size_t StartBitrateKbps() { |
| 68 return static_cast<size_t>(FLAGS_tl0_bitrate); | 60 return static_cast<size_t>(FLAGS_tl0_bitrate); |
| 69 } | 61 } |
| 70 | 62 |
| 71 DEFINE_int32(tl1_bitrate, 2000, "Temporal layer 1 target bitrate."); | 63 DEFINE_int32(tl1_bitrate, 2000, "Temporal layer 1 target bitrate."); |
| 72 size_t MaxBitrate() { | 64 size_t MaxBitrateKbps() { |
| 73 return static_cast<size_t>(FLAGS_tl1_bitrate); | 65 return static_cast<size_t>(FLAGS_tl1_bitrate); |
| 74 } | 66 } |
| 75 | 67 |
| 76 DEFINE_int32(num_temporal_layers, 2, "Number of temporal layers to use."); | 68 DEFINE_int32(num_temporal_layers, 2, "Number of temporal layers to use."); |
| 77 int NumTemporalLayers() { | 69 size_t NumTemporalLayers() { |
| 78 return static_cast<int>(FLAGS_num_temporal_layers); | 70 return static_cast<size_t>(FLAGS_num_temporal_layers); |
| 79 } | |
| 80 | |
| 81 DEFINE_int32(num_spatial_layers, 1, "Number of spatial layers to use."); | |
| 82 int NumSpatialLayers() { | |
| 83 return static_cast<int>(FLAGS_num_spatial_layers); | |
| 84 } | 71 } |
| 85 | 72 |
| 86 DEFINE_int32( | 73 DEFINE_int32( |
| 87 tl_discard_threshold, | 74 tl_discard_threshold, |
| 88 0, | 75 0, |
| 89 "Discard TLs with id greater or equal the threshold. 0 to disable."); | 76 "Discard TLs with id greater or equal the threshold. 0 to disable."); |
| 90 int TLDiscardThreshold() { | 77 size_t TLDiscardThreshold() { |
| 91 return static_cast<int>(FLAGS_tl_discard_threshold); | 78 return static_cast<size_t>(FLAGS_tl_discard_threshold); |
| 92 } | |
| 93 | |
| 94 DEFINE_int32( | |
| 95 sl_discard_threshold, | |
| 96 0, | |
| 97 "Discard SLs with id greater or equal the threshold. 0 to disable."); | |
| 98 int SLDiscardThreshold() { | |
| 99 return static_cast<int>(FLAGS_sl_discard_threshold); | |
| 100 } | 79 } |
| 101 | 80 |
| 102 DEFINE_int32(min_transmit_bitrate, 400, "Min transmit bitrate incl. padding."); | 81 DEFINE_int32(min_transmit_bitrate, 400, "Min transmit bitrate incl. padding."); |
| 103 int MinTransmitBitrate() { | 82 int MinTransmitBitrateKbps() { |
| 104 return FLAGS_min_transmit_bitrate; | 83 return FLAGS_min_transmit_bitrate; |
| 105 } | 84 } |
| 106 | 85 |
| 107 DEFINE_string(codec, "VP8", "Video codec to use."); | 86 DEFINE_string(codec, "VP8", "Video codec to use."); |
| 108 std::string Codec() { | 87 std::string Codec() { |
| 109 return static_cast<std::string>(FLAGS_codec); | 88 return static_cast<std::string>(FLAGS_codec); |
| 110 } | 89 } |
| 111 | 90 |
| 112 DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost."); | 91 DEFINE_int32(loss_percent, 0, "Percentage of packets randomly lost."); |
| 113 int LossPercent() { | 92 int LossPercent() { |
| 114 return static_cast<int>(FLAGS_loss_percent); | 93 return static_cast<int>(FLAGS_loss_percent); |
| 115 } | 94 } |
| 116 | 95 |
| 117 DEFINE_int32(link_capacity, | 96 DEFINE_int32(link_capacity, |
| 118 0, | 97 0, |
| 119 "Capacity (kbps) of the fake link. 0 means infinite."); | 98 "Capacity (kbps) of the fake link. 0 means infinite."); |
| 120 int LinkCapacity() { | 99 int LinkCapacityKbps() { |
| 121 return static_cast<int>(FLAGS_link_capacity); | 100 return static_cast<int>(FLAGS_link_capacity); |
| 122 } | 101 } |
| 123 | 102 |
| 124 DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets."); | 103 DEFINE_int32(queue_size, 0, "Size of the bottleneck link queue in packets."); |
| 125 int QueueSize() { | 104 int QueueSize() { |
| 126 return static_cast<int>(FLAGS_queue_size); | 105 return static_cast<int>(FLAGS_queue_size); |
| 127 } | 106 } |
| 128 | 107 |
| 129 DEFINE_int32(avg_propagation_delay_ms, | 108 DEFINE_int32(avg_propagation_delay_ms, |
| 130 0, | 109 0, |
| 131 "Average link propagation delay in ms."); | 110 "Average link propagation delay in ms."); |
| 132 int AvgPropagationDelayMs() { | 111 int AvgPropagationDelayMs() { |
| 133 return static_cast<int>(FLAGS_avg_propagation_delay_ms); | 112 return static_cast<int>(FLAGS_avg_propagation_delay_ms); |
| 134 } | 113 } |
| 135 | 114 |
| 136 DEFINE_int32(std_propagation_delay_ms, | 115 DEFINE_int32(std_propagation_delay_ms, |
| 137 0, | 116 0, |
| 138 "Link propagation delay standard deviation in ms."); | 117 "Link propagation delay standard deviation in ms."); |
| 139 int StdPropagationDelayMs() { | 118 int StdPropagationDelayMs() { |
| 140 return static_cast<int>(FLAGS_std_propagation_delay_ms); | 119 return static_cast<int>(FLAGS_std_propagation_delay_ms); |
| 141 } | 120 } |
| 142 | 121 |
| 143 DEFINE_bool(logs, false, "print logs to stderr"); | 122 DEFINE_bool(logs, false, "print logs to stderr"); |
| 144 | 123 |
| 145 DEFINE_string( | 124 DEFINE_string( |
| 125 output_filename, |
| 126 "", |
| 127 "Name of a target graph data file. If set, no preview will be shown."); |
| 128 std::string OutputFilename() { |
| 129 return static_cast<std::string>(FLAGS_output_filename); |
| 130 } |
| 131 |
| 132 DEFINE_int32(duration, 60, "Duration of the test in seconds."); |
| 133 int DurationSecs() { |
| 134 return static_cast<int>(FLAGS_duration); |
| 135 } |
| 136 |
| 137 DEFINE_string( |
| 146 force_fieldtrials, | 138 force_fieldtrials, |
| 147 "", | 139 "", |
| 148 "Field trials control experimental feature code which can be forced. " | 140 "Field trials control experimental feature code which can be forced. " |
| 149 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" | 141 "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" |
| 150 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple " | 142 " will assign the group Enable to field trial WebRTC-FooFeature. Multiple " |
| 151 "trials are separated by \"/\""); | 143 "trials are separated by \"/\""); |
| 152 } // namespace flags | 144 } // namespace flags |
| 153 | 145 |
| 154 class ScreenshareLoopback : public test::Loopback { | 146 void Loopback() { |
| 155 public: | 147 FakeNetworkPipe::Config pipe_config; |
| 156 explicit ScreenshareLoopback(const Config& config) : Loopback(config) { | 148 pipe_config.loss_percent = flags::LossPercent(); |
| 157 CHECK_GE(config.num_temporal_layers, 1u); | 149 pipe_config.link_capacity_kbps = flags::LinkCapacityKbps(); |
| 158 CHECK_LE(config.num_temporal_layers, 2u); | 150 pipe_config.queue_length_packets = flags::QueueSize(); |
| 159 CHECK_GE(config.num_spatial_layers, 1u); | 151 pipe_config.queue_delay_ms = flags::AvgPropagationDelayMs(); |
| 160 CHECK_LE(config.num_spatial_layers, 5u); | 152 pipe_config.delay_standard_deviation_ms = flags::StdPropagationDelayMs(); |
| 161 CHECK(config.num_spatial_layers == 1 || config.codec == "VP9"); | |
| 162 CHECK(config.num_spatial_layers == 1 || config.num_temporal_layers == 1); | |
| 163 CHECK_LT(config.tl_discard_threshold, config.num_temporal_layers); | |
| 164 CHECK_LT(config.sl_discard_threshold, config.num_spatial_layers); | |
| 165 | 153 |
| 166 vp8_settings_ = VideoEncoder::GetDefaultVp8Settings(); | 154 VideoQualityTest::Params params{ |
| 167 vp8_settings_.denoisingOn = false; | 155 { |
| 168 vp8_settings_.frameDroppingOn = false; | 156 flags::Width(), |
| 169 vp8_settings_.numberOfTemporalLayers = | 157 flags::Height(), |
| 170 static_cast<unsigned char>(config.num_temporal_layers); | 158 flags::Fps(), |
| 159 flags::MinBitrateKbps() * 1000, |
| 160 flags::StartBitrateKbps() * 1000, // TODO(ivica): target |
| 161 flags::MaxBitrateKbps() * 1000, |
| 162 flags::Codec(), |
| 163 flags::NumTemporalLayers(), |
| 164 flags::StartBitrateKbps() * 1000, |
| 165 flags::MinTransmitBitrateKbps() * 1000, |
| 166 flags::TLDiscardThreshold() |
| 167 }, |
| 168 {}, // Video specific. |
| 169 {true, flags::SlideChangeInterval(), flags::ScrollDuration()}, |
| 170 {"screenshare", 0.0, 0.0, flags::DurationSecs(), flags::OutputFilename()}, |
| 171 pipe_config, |
| 172 flags::FLAGS_logs}; |
| 171 | 173 |
| 172 vp9_settings_ = VideoEncoder::GetDefaultVp9Settings(); | 174 VideoQualityTest test; |
| 173 vp9_settings_.denoisingOn = false; | 175 if (flags::OutputFilename().empty()) |
| 174 vp9_settings_.frameDroppingOn = false; | 176 test.RunWithVideoRenderer(params); |
| 175 vp9_settings_.numberOfTemporalLayers = | 177 else |
| 176 static_cast<unsigned char>(config.num_temporal_layers); | 178 test.RunWithAnalyzer(params); |
| 177 vp9_settings_.numberOfSpatialLayers = | |
| 178 static_cast<unsigned char>(config.num_spatial_layers); | |
| 179 } | |
| 180 virtual ~ScreenshareLoopback() {} | |
| 181 | |
| 182 protected: | |
| 183 VideoEncoderConfig CreateEncoderConfig() override { | |
| 184 VideoEncoderConfig encoder_config(test::Loopback::CreateEncoderConfig()); | |
| 185 VideoStream* stream = &encoder_config.streams[0]; | |
| 186 encoder_config.content_type = VideoEncoderConfig::ContentType::kScreen; | |
| 187 encoder_config.min_transmit_bitrate_bps = flags::MinTransmitBitrate(); | |
| 188 int num_temporal_layers; | |
| 189 if (config_.codec == "VP8") { | |
| 190 encoder_config.encoder_specific_settings = &vp8_settings_; | |
| 191 num_temporal_layers = vp8_settings_.numberOfTemporalLayers; | |
| 192 } else if (config_.codec == "VP9") { | |
| 193 encoder_config.encoder_specific_settings = &vp9_settings_; | |
| 194 num_temporal_layers = vp9_settings_.numberOfTemporalLayers; | |
| 195 } else { | |
| 196 RTC_NOTREACHED() << "Codec not supported!"; | |
| 197 abort(); | |
| 198 } | |
| 199 stream->temporal_layer_thresholds_bps.clear(); | |
| 200 stream->target_bitrate_bps = | |
| 201 static_cast<int>(config_.start_bitrate_kbps) * 1000; | |
| 202 if (num_temporal_layers == 2) { | |
| 203 stream->temporal_layer_thresholds_bps.push_back( | |
| 204 stream->target_bitrate_bps); | |
| 205 } | |
| 206 return encoder_config; | |
| 207 } | |
| 208 | |
| 209 test::VideoCapturer* CreateCapturer(VideoSendStream* send_stream) override { | |
| 210 std::vector<std::string> slides; | |
| 211 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); | |
| 212 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); | |
| 213 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); | |
| 214 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); | |
| 215 | |
| 216 // Fixed for input resolution for prerecorded screenshare content. | |
| 217 const size_t kWidth = 1850; | |
| 218 const size_t kHeight = 1110; | |
| 219 CHECK_LE(flags::Width(), kWidth); | |
| 220 CHECK_LE(flags::Height(), kHeight); | |
| 221 CHECK_GT(flags::SlideChangeInterval(), 0); | |
| 222 const int kPauseDurationMs = | |
| 223 (flags::SlideChangeInterval() - flags::ScrollDuration()) * 1000; | |
| 224 CHECK_LE(flags::ScrollDuration(), flags::SlideChangeInterval()); | |
| 225 | |
| 226 test::FrameGenerator* frame_generator = | |
| 227 test::FrameGenerator::CreateScrollingInputFromYuvFiles( | |
| 228 Clock::GetRealTimeClock(), slides, kWidth, kHeight, flags::Width(), | |
| 229 flags::Height(), flags::ScrollDuration() * 1000, kPauseDurationMs); | |
| 230 | |
| 231 test::FrameGeneratorCapturer* capturer(new test::FrameGeneratorCapturer( | |
| 232 clock_, send_stream->Input(), frame_generator, flags::Fps())); | |
| 233 EXPECT_TRUE(capturer->Init()); | |
| 234 return capturer; | |
| 235 } | |
| 236 | |
| 237 VideoCodecVP8 vp8_settings_; | |
| 238 VideoCodecVP9 vp9_settings_; | |
| 239 }; | |
| 240 | |
| 241 void Loopback() { | |
| 242 test::Loopback::Config config{flags::Width(), | |
| 243 flags::Height(), | |
| 244 flags::Fps(), | |
| 245 flags::MinBitrate(), | |
| 246 flags::StartBitrate(), | |
| 247 flags::MaxBitrate(), | |
| 248 flags::MinTransmitBitrate(), | |
| 249 flags::Codec(), | |
| 250 flags::NumTemporalLayers(), | |
| 251 flags::NumSpatialLayers(), | |
| 252 flags::TLDiscardThreshold(), | |
| 253 flags::SLDiscardThreshold(), | |
| 254 flags::LossPercent(), | |
| 255 flags::LinkCapacity(), | |
| 256 flags::QueueSize(), | |
| 257 flags::AvgPropagationDelayMs(), | |
| 258 flags::StdPropagationDelayMs(), | |
| 259 flags::FLAGS_logs}; | |
| 260 ScreenshareLoopback loopback(config); | |
| 261 loopback.Run(); | |
| 262 } | 179 } |
| 263 } // namespace webrtc | 180 } // namespace webrtc |
| 264 | 181 |
| 265 int main(int argc, char* argv[]) { | 182 int main(int argc, char* argv[]) { |
| 266 ::testing::InitGoogleTest(&argc, argv); | 183 ::testing::InitGoogleTest(&argc, argv); |
| 267 google::ParseCommandLineFlags(&argc, &argv, true); | 184 google::ParseCommandLineFlags(&argc, &argv, true); |
| 268 webrtc::test::InitFieldTrialsFromString( | 185 webrtc::test::InitFieldTrialsFromString( |
| 269 webrtc::flags::FLAGS_force_fieldtrials); | 186 webrtc::flags::FLAGS_force_fieldtrials); |
| 270 webrtc::test::RunTest(webrtc::Loopback); | 187 webrtc::test::RunTest(webrtc::Loopback); |
| 271 return 0; | 188 return 0; |
| 272 } | 189 } |
| OLD | NEW |