blob: dcb4e1bd939954cfbaf8d7ba8dead216267a4699 [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 {
Sebastian Janssond37307c2019-02-22 17:07:49 +010018using Capture = VideoStreamConfig::Source::Capture;
19using ContentType = VideoStreamConfig::Encoder::ContentType;
Sebastian Jansson5fbebd52019-02-20 11:16:19 +010020using Codec = VideoStreamConfig::Encoder::Codec;
21using CodecImpl = VideoStreamConfig::Encoder::Implementation;
22} // namespace
23
Sebastian Janssond37307c2019-02-22 17:07:49 +010024// TODO(srte): Enable this after resolving flakiness issues.
25TEST(VideoStreamTest, DISABLED_ReceivesFramesFromFileBasedStreams) {
26 TimeDelta kRunTime = TimeDelta::ms(500);
27 std::vector<int> kFrameRates = {15, 30};
28 std::deque<std::atomic<int>> frame_counts(2);
29 frame_counts[0] = 0;
30 frame_counts[1] = 0;
31 {
32 Scenario s;
33 auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
34 {s.CreateSimulationNode(NetworkNodeConfig())},
35 s.CreateClient("callee", CallClientConfig()),
36 {s.CreateSimulationNode(NetworkNodeConfig())});
37
38 s.CreateVideoStream(route->forward(), [&](VideoStreamConfig* c) {
39 c->analyzer.frame_quality_handler = [&](const VideoFrameQualityInfo&) {
40 frame_counts[0]++;
41 };
42 c->source.capture = Capture::kVideoFile;
43 c->source.video_file.name = "foreman_cif";
44 c->source.video_file.width = 352;
45 c->source.video_file.height = 288;
46 c->source.framerate = kFrameRates[0];
47 c->encoder.implementation = CodecImpl::kSoftware;
48 c->encoder.codec = Codec::kVideoCodecVP8;
49 });
50 s.CreateVideoStream(route->forward(), [&](VideoStreamConfig* c) {
51 c->analyzer.frame_quality_handler = [&](const VideoFrameQualityInfo&) {
52 frame_counts[1]++;
53 };
54 c->source.capture = Capture::kImageSlides;
55 c->source.slides.images.crop.width = 320;
56 c->source.slides.images.crop.height = 240;
57 c->source.framerate = kFrameRates[1];
58 c->encoder.implementation = CodecImpl::kSoftware;
59 c->encoder.codec = Codec::kVideoCodecVP9;
60 });
61 s.RunFor(kRunTime);
62 }
63 std::vector<int> expected_counts;
64 for (int fps : kFrameRates)
65 expected_counts.push_back(
66 static_cast<int>(kRunTime.seconds<double>() * fps * 0.8));
67
68 EXPECT_GE(frame_counts[0], expected_counts[0]);
69 EXPECT_GE(frame_counts[1], expected_counts[1]);
70}
71
72// TODO(srte): Enable this after resolving flakiness issues.
Sergey Silkin45af00f2019-02-22 08:11:43 +000073TEST(VideoStreamTest, DISABLED_RecievesVp8SimulcastFrames) {
Sebastian Jansson5fbebd52019-02-20 11:16:19 +010074 TimeDelta kRunTime = TimeDelta::ms(500);
75 int kFrameRate = 30;
76
77 std::atomic<int> frame_count(0);
78 {
79 Scenario s;
80 auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
81 {s.CreateSimulationNode(NetworkNodeConfig())},
82 s.CreateClient("callee", CallClientConfig()),
83 {s.CreateSimulationNode(NetworkNodeConfig())});
84 s.CreateVideoStream(route->forward(), [&](VideoStreamConfig* c) {
85 // TODO(srte): Replace with code checking for all simulcast streams when
86 // there's a hook available for that.
87 c->analyzer.frame_quality_handler = [&](const VideoFrameQualityInfo&) {
88 frame_count++;
89 };
90 c->source.framerate = kFrameRate;
91 // The resolution must be high enough to allow smaller layers to be
92 // created.
93 c->source.generator.width = 1024;
94 c->source.generator.height = 768;
95
96 c->encoder.implementation = CodecImpl::kSoftware;
97 c->encoder.codec = Codec::kVideoCodecVP8;
98 // By enabling multiple spatial layers, simulcast will be enabled for VP8.
99 c->encoder.layers.spatial = 3;
100 });
101 s.RunFor(kRunTime);
102 }
103
104 // Using 20% error margin to avoid flakyness.
105 const int kExpectedCount =
106 static_cast<int>(kRunTime.seconds<double>() * kFrameRate * 0.8);
107
108 EXPECT_GE(frame_count, kExpectedCount);
109}
110} // namespace test
111} // namespace webrtc