mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/encoder_rtcp_feedback.h" |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 12 | |
sprang | fda496a | 2017-06-15 04:21:07 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "test/gmock.h" |
| 16 | #include "test/gtest.h" |
| 17 | #include "video/send_statistics_proxy.h" |
| 18 | #include "video/video_stream_encoder.h" |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 19 | |
wuchengli@chromium.org | 637c55f | 2014-05-28 07:00:51 +0000 | [diff] [blame] | 20 | using ::testing::NiceMock; |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 21 | |
wuchengli@chromium.org | 637c55f | 2014-05-28 07:00:51 +0000 | [diff] [blame] | 22 | namespace webrtc { |
wuchengli@chromium.org | 89e8ffb | 2014-05-27 14:12:58 +0000 | [diff] [blame] | 23 | |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 24 | class MockVideoStreamEncoder : public VideoStreamEncoder { |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 25 | public: |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 26 | explicit MockVideoStreamEncoder(SendStatisticsProxy* send_stats_proxy) |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 27 | : VideoStreamEncoder(1, |
| 28 | send_stats_proxy, |
| 29 | VideoSendStream::Config::EncoderSettings(), |
| 30 | nullptr, |
| 31 | rtc::MakeUnique<OveruseFrameDetector>(nullptr)) {} |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 32 | ~MockVideoStreamEncoder() { Stop(); } |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 33 | |
Niels Möller | 1c9aa1e | 2018-02-16 10:27:23 +0100 | [diff] [blame] | 34 | MOCK_METHOD0(SendKeyFrame, void()); |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 37 | class VieKeyRequestTest : public ::testing::Test { |
| 38 | public: |
| 39 | VieKeyRequestTest() |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 40 | : simulated_clock_(123456789), |
sprang | 552c7c7 | 2017-02-13 04:41:45 -0800 | [diff] [blame] | 41 | send_stats_proxy_(&simulated_clock_, |
| 42 | VideoSendStream::Config(nullptr), |
| 43 | VideoEncoderConfig::ContentType::kRealtimeVideo), |
| 44 | encoder_(&send_stats_proxy_), |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 45 | encoder_rtcp_feedback_( |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 46 | &simulated_clock_, |
| 47 | std::vector<uint32_t>(1, VieKeyRequestTest::kSsrc), |
| 48 | &encoder_) {} |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 49 | |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 50 | protected: |
| 51 | const uint32_t kSsrc = 1234; |
sprang | 552c7c7 | 2017-02-13 04:41:45 -0800 | [diff] [blame] | 52 | |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 53 | SimulatedClock simulated_clock_; |
sprang | 552c7c7 | 2017-02-13 04:41:45 -0800 | [diff] [blame] | 54 | SendStatisticsProxy send_stats_proxy_; |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 55 | MockVideoStreamEncoder encoder_; |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 56 | EncoderRtcpFeedback encoder_rtcp_feedback_; |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 57 | }; |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 58 | |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 59 | TEST_F(VieKeyRequestTest, CreateAndTriggerRequests) { |
Niels Möller | 1c9aa1e | 2018-02-16 10:27:23 +0100 | [diff] [blame] | 60 | EXPECT_CALL(encoder_, SendKeyFrame()).Times(1); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 61 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | TEST_F(VieKeyRequestTest, TooManyOnReceivedIntraFrameRequest) { |
Niels Möller | 1c9aa1e | 2018-02-16 10:27:23 +0100 | [diff] [blame] | 65 | EXPECT_CALL(encoder_, SendKeyFrame()).Times(1); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 66 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
| 67 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 68 | simulated_clock_.AdvanceTimeMilliseconds(10); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 69 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 70 | |
Niels Möller | 1c9aa1e | 2018-02-16 10:27:23 +0100 | [diff] [blame] | 71 | EXPECT_CALL(encoder_, SendKeyFrame()).Times(1); |
perkj | 600246e | 2016-05-04 11:26:51 -0700 | [diff] [blame] | 72 | simulated_clock_.AdvanceTimeMilliseconds(300); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 73 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
| 74 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
| 75 | encoder_rtcp_feedback_.OnReceivedIntraFrameRequest(kSsrc); |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 76 | } |
| 77 | |
mflodman@webrtc.org | 3be5863 | 2012-09-06 08:19:40 +0000 | [diff] [blame] | 78 | } // namespace webrtc |