blob: 199c8c16fed3de0a9dbfeac90c7ee6d49cc271db [file] [log] [blame]
Sebastian Jansson5fbebd52019-02-20 11:16:19 +01001/*
2 * Copyright 2019 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#include <atomic>
11
12#include "test/gtest.h"
13#include "test/scenario/scenario.h"
14
15namespace webrtc {
16namespace test {
17namespace {
18using Codec = VideoStreamConfig::Encoder::Codec;
19using CodecImpl = VideoStreamConfig::Encoder::Implementation;
20} // namespace
21
22TEST(VideoStreamTest, RecievesVp8SimulcastFrames) {
23 TimeDelta kRunTime = TimeDelta::ms(500);
24 int kFrameRate = 30;
25
26 std::atomic<int> frame_count(0);
27 {
28 Scenario s;
29 auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
30 {s.CreateSimulationNode(NetworkNodeConfig())},
31 s.CreateClient("callee", CallClientConfig()),
32 {s.CreateSimulationNode(NetworkNodeConfig())});
33 s.CreateVideoStream(route->forward(), [&](VideoStreamConfig* c) {
34 // TODO(srte): Replace with code checking for all simulcast streams when
35 // there's a hook available for that.
36 c->analyzer.frame_quality_handler = [&](const VideoFrameQualityInfo&) {
37 frame_count++;
38 };
39 c->source.framerate = kFrameRate;
40 // The resolution must be high enough to allow smaller layers to be
41 // created.
42 c->source.generator.width = 1024;
43 c->source.generator.height = 768;
44
45 c->encoder.implementation = CodecImpl::kSoftware;
46 c->encoder.codec = Codec::kVideoCodecVP8;
47 // By enabling multiple spatial layers, simulcast will be enabled for VP8.
48 c->encoder.layers.spatial = 3;
49 });
50 s.RunFor(kRunTime);
51 }
52
53 // Using 20% error margin to avoid flakyness.
54 const int kExpectedCount =
55 static_cast<int>(kRunTime.seconds<double>() * kFrameRate * 0.8);
56
57 EXPECT_GE(frame_count, kExpectedCount);
58}
59} // namespace test
60} // namespace webrtc