File: chain_diff_calculator_unittest.cc

package info (click to toggle)
thunderbird 1%3A140.3.1esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,608,628 kB
  • sloc: cpp: 7,671,698; javascript: 5,901,131; ansic: 3,898,955; python: 1,413,270; xml: 653,997; asm: 462,284; java: 180,948; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (126 lines) | stat: -rw-r--r-- 4,952 bytes parent folder | download | duplicates (34)
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