OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/encoder_state_feedback.h" | 11 #include "webrtc/video/encoder_state_feedback.h" |
12 | 12 |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
17 #include "webrtc/modules/pacing/paced_sender.h" | 17 #include "webrtc/modules/pacing/paced_sender.h" |
18 #include "webrtc/modules/pacing/packet_router.h" | 18 #include "webrtc/modules/pacing/packet_router.h" |
19 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" | 19 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" |
20 #include "webrtc/video/vie_encoder.h" | 20 #include "webrtc/video/vie_encoder.h" |
21 | 21 |
22 using ::testing::NiceMock; | 22 using ::testing::NiceMock; |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 |
26 class MockVieEncoder : public ViEEncoder { | 26 class MockVieEncoder : public ViEEncoder { |
27 public: | 27 public: |
28 explicit MockVieEncoder(ProcessThread* process_thread, PacedSender* pacer) | 28 explicit MockVieEncoder(ProcessThread* process_thread, PacedSender* pacer) |
29 : ViEEncoder(1, | 29 : ViEEncoder(1, |
30 std::vector<uint32_t>(), | |
31 process_thread, | 30 process_thread, |
32 nullptr, | 31 nullptr, |
33 nullptr, | 32 nullptr, |
34 nullptr, | 33 nullptr, |
35 pacer) {} | 34 pacer) {} |
36 ~MockVieEncoder() {} | 35 ~MockVieEncoder() {} |
37 | 36 |
38 MOCK_METHOD1(OnReceivedIntraFrameRequest, | 37 MOCK_METHOD1(OnReceivedIntraFrameRequest, void(size_t)); |
39 void(uint32_t)); | 38 MOCK_METHOD1(OnReceivedSLI, void(uint8_t picture_id)); |
40 MOCK_METHOD2(OnReceivedSLI, | 39 MOCK_METHOD1(OnReceivedRPSI, void(uint64_t picture_id)); |
41 void(uint32_t ssrc, uint8_t picture_id)); | |
42 MOCK_METHOD2(OnReceivedRPSI, | |
43 void(uint32_t ssrc, uint64_t picture_id)); | |
44 }; | 40 }; |
45 | 41 |
46 TEST(VieKeyRequestTest, CreateAndTriggerRequests) { | 42 class VieKeyRequestTest : public ::testing::Test { |
47 static const uint32_t kSsrc = 1234; | 43 public: |
48 NiceMock<MockProcessThread> process_thread; | 44 VieKeyRequestTest() |
49 PacketRouter router; | 45 : pacer_(Clock::GetRealTimeClock(), |
50 PacedSender pacer(Clock::GetRealTimeClock(), &router, | 46 &router_, |
51 BitrateController::kDefaultStartBitrateKbps, | 47 BitrateController::kDefaultStartBitrateKbps, |
52 PacedSender::kDefaultPaceMultiplier * | 48 PacedSender::kDefaultPaceMultiplier * |
53 BitrateController::kDefaultStartBitrateKbps, | 49 BitrateController::kDefaultStartBitrateKbps, |
54 0); | 50 0), |
55 MockVieEncoder encoder(&process_thread, &pacer); | 51 encoder_(&process_thread_, &pacer_), |
52 simulated_clock_(123456789), | |
53 encoder_state_feedback_(&simulated_clock_) { | |
54 encoder_state_feedback_.Init( | |
55 std::vector<uint32_t>(1, VieKeyRequestTest::kSsrc), &encoder_); | |
56 } | |
56 | 57 |
57 EncoderStateFeedback encoder_state_feedback; | 58 protected: |
58 encoder_state_feedback.Init(std::vector<uint32_t>(1, kSsrc), &encoder); | 59 const uint32_t kSsrc = 1234; |
60 NiceMock<MockProcessThread> process_thread_; | |
61 PacketRouter router_; | |
62 PacedSender pacer_; | |
63 MockVieEncoder encoder_; | |
64 SimulatedClock simulated_clock_; | |
65 EncoderStateFeedback encoder_state_feedback_; | |
66 }; | |
59 | 67 |
60 EXPECT_CALL(encoder, OnReceivedIntraFrameRequest(kSsrc)) | 68 TEST_F(VieKeyRequestTest, CreateAndTriggerRequests) { |
61 .Times(1); | 69 EXPECT_CALL(encoder_, OnReceivedIntraFrameRequest(0)).Times(1); |
62 encoder_state_feedback.OnReceivedIntraFrameRequest(kSsrc); | 70 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
63 | 71 |
64 const uint8_t sli_picture_id = 3; | 72 const uint8_t sli_picture_id = 3; |
65 EXPECT_CALL(encoder, OnReceivedSLI(kSsrc, sli_picture_id)) | 73 EXPECT_CALL(encoder_, OnReceivedSLI(sli_picture_id)).Times(1); |
66 .Times(1); | 74 encoder_state_feedback_.OnReceivedSLI(kSsrc, sli_picture_id); |
67 encoder_state_feedback.OnReceivedSLI(kSsrc, sli_picture_id); | |
68 | 75 |
69 const uint64_t rpsi_picture_id = 9; | 76 const uint64_t rpsi_picture_id = 9; |
70 EXPECT_CALL(encoder, OnReceivedRPSI(kSsrc, rpsi_picture_id)) | 77 EXPECT_CALL(encoder_, OnReceivedRPSI(rpsi_picture_id)).Times(1); |
71 .Times(1); | 78 encoder_state_feedback_.OnReceivedRPSI(kSsrc, rpsi_picture_id); |
72 encoder_state_feedback.OnReceivedRPSI(kSsrc, rpsi_picture_id); | 79 } |
80 | |
81 TEST_F(VieKeyRequestTest, TooManyOnReceivedIntraFrameRequest) { | |
82 EXPECT_CALL(encoder_, OnReceivedIntraFrameRequest(0)).Times(1); | |
83 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); | |
84 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); | |
85 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); | |
86 | |
pbos-webrtc
2016/05/03 18:19:59
Try one that's in the future but too soon (e.g adv
perkj_webrtc
2016/05/04 08:31:03
Done.
| |
87 EXPECT_CALL(encoder_, OnReceivedIntraFrameRequest(0)).Times(1); | |
88 simulated_clock_.AdvanceTimeMilliseconds(300); | |
89 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); | |
90 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); | |
91 encoder_state_feedback_.OnReceivedIntraFrameRequest(kSsrc); | |
73 } | 92 } |
74 | 93 |
75 } // namespace webrtc | 94 } // namespace webrtc |
OLD | NEW |