-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathencoder_rtcp_feedback_unittest.cc
131 lines (114 loc) · 5.08 KB
/
encoder_rtcp_feedback_unittest.cc
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
127
128
129
130
131
/*
* Copyright (c) 2012 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 "video/encoder_rtcp_feedback.h"
#include <memory>
#include "api/environment/environment_factory.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "video/test/mock_video_stream_encoder.h"
using ::testing::_;
using ::testing::ElementsAre;
namespace webrtc {
class VideoEncoderFeedbackKeyframeTestBase : public ::testing::Test {
public:
VideoEncoderFeedbackKeyframeTestBase(bool per_layer_pli_handling,
std::vector<uint32_t> ssrcs)
: simulated_clock_(123456789),
encoder_(),
encoder_rtcp_feedback_(CreateEnvironment(&simulated_clock_),
per_layer_pli_handling,
ssrcs,
&encoder_,
nullptr) {}
protected:
static const uint32_t kSsrc = 1234;
static const uint32_t kOtherSsrc = 4321;
SimulatedClock simulated_clock_;
::testing::StrictMock<MockVideoStreamEncoder> encoder_;
EncoderRtcpFeedback encoder_rtcp_feedback_;
};
class VideoEncoderFeedbackKeyframeTest
: public VideoEncoderFeedbackKeyframeTestBase {
public:
VideoEncoderFeedbackKeyframeTest()
: VideoEncoderFeedbackKeyframeTestBase(
/*per_layer_pli_handling=*/false,
{VideoEncoderFeedbackKeyframeTestBase::kSsrc}) {}
};
TEST_F(VideoEncoderFeedbackKeyframeTest, CreateAndTriggerRequests) {
EXPECT_CALL(encoder_, SendKeyFrame(_)).Times(1);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
}
TEST_F(VideoEncoderFeedbackKeyframeTest, TooManyOnReceivedIntraFrameRequest) {
EXPECT_CALL(encoder_, SendKeyFrame(_)).Times(1);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
simulated_clock_.AdvanceTimeMilliseconds(10);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
EXPECT_CALL(encoder_, SendKeyFrame(_)).Times(1);
simulated_clock_.AdvanceTimeMilliseconds(300);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
}
class VideoEncoderFeedbackKeyframePerLayerPliTest
: public VideoEncoderFeedbackKeyframeTestBase {
public:
VideoEncoderFeedbackKeyframePerLayerPliTest()
: VideoEncoderFeedbackKeyframeTestBase(
/*per_layer_pli_handling=*/true,
{VideoEncoderFeedbackKeyframeTestBase::kSsrc,
VideoEncoderFeedbackKeyframeTestBase::kOtherSsrc}) {}
};
TEST_F(VideoEncoderFeedbackKeyframePerLayerPliTest, CreateAndTriggerRequests) {
EXPECT_CALL(encoder_,
SendKeyFrame(ElementsAre(VideoFrameType::kVideoFrameKey,
VideoFrameType::kVideoFrameDelta)))
.Times(1);
EXPECT_CALL(encoder_,
SendKeyFrame(ElementsAre(VideoFrameType::kVideoFrameDelta,
VideoFrameType::kVideoFrameKey)))
.Times(1);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kOtherSsrc);
}
TEST_F(VideoEncoderFeedbackKeyframePerLayerPliTest,
TooManyOnReceivedIntraFrameRequest) {
EXPECT_CALL(encoder_,
SendKeyFrame(ElementsAre(VideoFrameType::kVideoFrameKey,
VideoFrameType::kVideoFrameDelta)))
.Times(1);
EXPECT_CALL(encoder_,
SendKeyFrame(ElementsAre(VideoFrameType::kVideoFrameDelta,
VideoFrameType::kVideoFrameKey)))
.Times(1);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kOtherSsrc);
simulated_clock_.AdvanceTimeMilliseconds(10);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kOtherSsrc);
EXPECT_CALL(encoder_,
SendKeyFrame(ElementsAre(VideoFrameType::kVideoFrameKey,
VideoFrameType::kVideoFrameDelta)))
.Times(1);
EXPECT_CALL(encoder_,
SendKeyFrame(ElementsAre(VideoFrameType::kVideoFrameDelta,
VideoFrameType::kVideoFrameKey)))
.Times(1);
simulated_clock_.AdvanceTimeMilliseconds(300);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kOtherSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kOtherSsrc);
encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kOtherSsrc);
}
} // namespace webrtc