1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/video_coding/chain_diff_calculator.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
using ::testing::ElementsAre;
using ::testing::SizeIs;
TEST(ChainDiffCalculatorTest, SingleChain) {
// Simulate a stream with 2 temporal layer where chain
// protects temporal layer 0.
ChainDiffCalculator calculator;
// Key frame.
calculator.Reset({true});
EXPECT_THAT(calculator.From(1, {true}), ElementsAre(0));
// T1 delta frame.
EXPECT_THAT(calculator.From(2, {false}), ElementsAre(1));
// T0 delta frame.
EXPECT_THAT(calculator.From(3, {true}), ElementsAre(2));
}
TEST(ChainDiffCalculatorTest, TwoChainsFullSvc) {
// Simulate a full svc stream with 2 spatial and 2 temporal layers.
// chains are protecting temporal layers 0.
ChainDiffCalculator calculator;
// S0 Key frame.
calculator.Reset({true, true});
EXPECT_THAT(calculator.From(1, {true, true}), ElementsAre(0, 0));
// S1 Key frame.
EXPECT_THAT(calculator.From(2, {false, true}), ElementsAre(1, 1));
// S0T1 delta frame.
EXPECT_THAT(calculator.From(3, {false, false}), ElementsAre(2, 1));
// S1T1 delta frame.
EXPECT_THAT(calculator.From(4, {false, false}), ElementsAre(3, 2));
// S0T0 delta frame.
EXPECT_THAT(calculator.From(5, {true, true}), ElementsAre(4, 3));
// S1T0 delta frame.
EXPECT_THAT(calculator.From(6, {false, true}), ElementsAre(1, 1));
}
TEST(ChainDiffCalculatorTest, TwoChainsKSvc) {
// Simulate a k-svc stream with 2 spatial and 2 temporal layers.
// chains are protecting temporal layers 0.
ChainDiffCalculator calculator;
// S0 Key frame.
calculator.Reset({true, true});
EXPECT_THAT(calculator.From(1, {true, true}), ElementsAre(0, 0));
// S1 Key frame.
EXPECT_THAT(calculator.From(2, {false, true}), ElementsAre(1, 1));
// S0T1 delta frame.
EXPECT_THAT(calculator.From(3, {false, false}), ElementsAre(2, 1));
// S1T1 delta frame.
EXPECT_THAT(calculator.From(4, {false, false}), ElementsAre(3, 2));
// S0T0 delta frame.
EXPECT_THAT(calculator.From(5, {true, false}), ElementsAre(4, 3));
// S1T0 delta frame.
EXPECT_THAT(calculator.From(6, {false, true}), ElementsAre(1, 4));
}
TEST(ChainDiffCalculatorTest, TwoChainsSimulcast) {
// Simulate a k-svc stream with 2 spatial and 2 temporal layers.
// chains are protecting temporal layers 0.
ChainDiffCalculator calculator;
// S0 Key frame.
calculator.Reset({true, false});
EXPECT_THAT(calculator.From(1, {true, false}), ElementsAre(0, 0));
// S1 Key frame.
calculator.Reset({false, true});
EXPECT_THAT(calculator.From(2, {false, true}), ElementsAre(1, 0));
// S0T1 delta frame.
EXPECT_THAT(calculator.From(3, {false, false}), ElementsAre(2, 1));
// S1T1 delta frame.
EXPECT_THAT(calculator.From(4, {false, false}), ElementsAre(3, 2));
// S0T0 delta frame.
EXPECT_THAT(calculator.From(5, {true, false}), ElementsAre(4, 3));
// S1T0 delta frame.
EXPECT_THAT(calculator.From(6, {false, true}), ElementsAre(1, 4));
}
TEST(ChainDiffCalculatorTest, ResilentToAbsentChainConfig) {
ChainDiffCalculator calculator;
// Key frame.
calculator.Reset({true, false});
EXPECT_THAT(calculator.From(1, {true, false}), ElementsAre(0, 0));
// Forgot to set chains. should still return 2 chain_diffs.
EXPECT_THAT(calculator.From(2, {}), ElementsAre(1, 0));
// chain diffs for next frame(s) are undefined, but still there should be
// correct number of them.
EXPECT_THAT(calculator.From(3, {true, false}), SizeIs(2));
EXPECT_THAT(calculator.From(4, {false, true}), SizeIs(2));
// Since previous two frames updated all the chains, can expect what
// chain_diffs would be.
EXPECT_THAT(calculator.From(5, {false, false}), ElementsAre(2, 1));
}
TEST(ChainDiffCalculatorTest, ResilentToTooMainChains) {
ChainDiffCalculator calculator;
// Key frame.
calculator.Reset({true, false});
EXPECT_THAT(calculator.From(1, {true, false}), ElementsAre(0, 0));
// Set wrong number of chains. Expect number of chain_diffs is not changed.
EXPECT_THAT(calculator.From(2, {true, true, true}), ElementsAre(1, 0));
// chain diffs for next frame(s) are undefined, but still there should be
// correct number of them.
EXPECT_THAT(calculator.From(3, {true, false}), SizeIs(2));
EXPECT_THAT(calculator.From(4, {false, true}), SizeIs(2));
// Since previous two frames updated all the chains, can expect what
// chain_diffs would be.
EXPECT_THAT(calculator.From(5, {false, false}), ElementsAre(2, 1));
}
} // namespace
} // namespace webrtc
|