andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +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 | |
| 11 | |
| 12 | // This file includes unit tests for EncoderStateFeedback. |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 13 | #include "webrtc/video_engine/encoder_state_feedback.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 14 | |
pbos@webrtc.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 15 | #include "testing/gmock/include/gmock/gmock.h" |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 17 | |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 18 | #include "webrtc/common.h" |
| 19 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
| 20 | #include "webrtc/modules/utility/interface/process_thread.h" |
| 21 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 22 | #include "webrtc/video_engine/vie_encoder.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | // TODO(mflodman) Create a common mock in module utility. |
| 27 | class TestProcessThread : public ProcessThread { |
| 28 | public: |
| 29 | TestProcessThread() {} |
| 30 | ~TestProcessThread() {} |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 31 | virtual int32_t Start() { return 0; } |
| 32 | virtual int32_t Stop() { return 0; } |
| 33 | virtual int32_t RegisterModule(const Module* module) { return 0; } |
| 34 | virtual int32_t DeRegisterModule(const Module* module) { return 0; } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | class MockVieEncoder : public ViEEncoder { |
| 38 | public: |
| 39 | explicit MockVieEncoder(TestProcessThread* process_thread) |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 40 | : ViEEncoder(1, 1, 1, config_, *process_thread, NULL) {} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 41 | ~MockVieEncoder() {} |
| 42 | |
| 43 | MOCK_METHOD1(OnReceivedIntraFrameRequest, |
| 44 | void(uint32_t)); |
| 45 | MOCK_METHOD2(OnReceivedSLI, |
| 46 | void(uint32_t ssrc, uint8_t picture_id)); |
| 47 | MOCK_METHOD2(OnReceivedRPSI, |
| 48 | void(uint32_t ssrc, uint64_t picture_id)); |
| 49 | MOCK_METHOD2(OnLocalSsrcChanged, |
| 50 | void(uint32_t old_ssrc, uint32_t new_ssrc)); |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 51 | |
| 52 | const Config config_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | class VieKeyRequestTest : public ::testing::Test { |
| 56 | protected: |
| 57 | virtual void SetUp() { |
| 58 | process_thread_.reset(new TestProcessThread()); |
| 59 | encoder_state_feedback_.reset(new EncoderStateFeedback()); |
| 60 | } |
| 61 | scoped_ptr<TestProcessThread> process_thread_; |
| 62 | scoped_ptr<EncoderStateFeedback> encoder_state_feedback_; |
| 63 | }; |
| 64 | |
| 65 | TEST_F(VieKeyRequestTest, CreateAndTriggerRequests) { |
| 66 | const int ssrc = 1234; |
| 67 | MockVieEncoder encoder(process_thread_.get()); |
| 68 | EXPECT_TRUE(encoder_state_feedback_->AddEncoder(ssrc, &encoder)); |
| 69 | |
| 70 | EXPECT_CALL(encoder, OnReceivedIntraFrameRequest(ssrc)) |
| 71 | .Times(1); |
| 72 | encoder_state_feedback_->GetRtcpIntraFrameObserver()-> |
| 73 | OnReceivedIntraFrameRequest(ssrc); |
| 74 | |
| 75 | const uint8_t sli_picture_id = 3; |
| 76 | EXPECT_CALL(encoder, OnReceivedSLI(ssrc, sli_picture_id)) |
| 77 | .Times(1); |
| 78 | encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedSLI( |
| 79 | ssrc, sli_picture_id); |
| 80 | |
| 81 | const uint64_t rpsi_picture_id = 9; |
| 82 | EXPECT_CALL(encoder, OnReceivedRPSI(ssrc, rpsi_picture_id)) |
| 83 | .Times(1); |
| 84 | encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedRPSI( |
| 85 | ssrc, rpsi_picture_id); |
| 86 | |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 87 | encoder_state_feedback_->RemoveEncoder(&encoder); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Register multiple encoders and make sure the request is relayed to correct |
| 91 | // ViEEncoder. |
| 92 | TEST_F(VieKeyRequestTest, MultipleEncoders) { |
| 93 | const int ssrc_1 = 1234; |
| 94 | const int ssrc_2 = 5678; |
| 95 | MockVieEncoder encoder_1(process_thread_.get()); |
| 96 | MockVieEncoder encoder_2(process_thread_.get()); |
| 97 | EXPECT_TRUE(encoder_state_feedback_->AddEncoder(ssrc_1, &encoder_1)); |
| 98 | EXPECT_TRUE(encoder_state_feedback_->AddEncoder(ssrc_2, &encoder_2)); |
| 99 | |
| 100 | EXPECT_CALL(encoder_1, OnReceivedIntraFrameRequest(ssrc_1)) |
| 101 | .Times(1); |
| 102 | EXPECT_CALL(encoder_2, OnReceivedIntraFrameRequest(ssrc_2)) |
| 103 | .Times(1); |
| 104 | encoder_state_feedback_->GetRtcpIntraFrameObserver()-> |
| 105 | OnReceivedIntraFrameRequest(ssrc_1); |
| 106 | encoder_state_feedback_->GetRtcpIntraFrameObserver()-> |
| 107 | OnReceivedIntraFrameRequest(ssrc_2); |
| 108 | |
| 109 | const uint8_t sli_pid_1 = 3; |
| 110 | const uint8_t sli_pid_2 = 4; |
| 111 | EXPECT_CALL(encoder_1, OnReceivedSLI(ssrc_1, sli_pid_1)) |
| 112 | .Times(1); |
| 113 | EXPECT_CALL(encoder_2, OnReceivedSLI(ssrc_2, sli_pid_2)) |
| 114 | .Times(1); |
| 115 | encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedSLI( |
| 116 | ssrc_1, sli_pid_1); |
| 117 | encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedSLI( |
| 118 | ssrc_2, sli_pid_2); |
| 119 | |
| 120 | const uint64_t rpsi_pid_1 = 9; |
| 121 | const uint64_t rpsi_pid_2 = 10; |
| 122 | EXPECT_CALL(encoder_1, OnReceivedRPSI(ssrc_1, rpsi_pid_1)) |
| 123 | .Times(1); |
| 124 | EXPECT_CALL(encoder_2, OnReceivedRPSI(ssrc_2, rpsi_pid_2)) |
| 125 | .Times(1); |
| 126 | encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedRPSI( |
| 127 | ssrc_1, rpsi_pid_1); |
| 128 | encoder_state_feedback_->GetRtcpIntraFrameObserver()->OnReceivedRPSI( |
| 129 | ssrc_2, rpsi_pid_2); |
| 130 | |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 131 | encoder_state_feedback_->RemoveEncoder(&encoder_1); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 132 | EXPECT_CALL(encoder_2, OnReceivedIntraFrameRequest(ssrc_2)) |
| 133 | .Times(1); |
| 134 | encoder_state_feedback_->GetRtcpIntraFrameObserver()-> |
| 135 | OnReceivedIntraFrameRequest(ssrc_2); |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 136 | encoder_state_feedback_->RemoveEncoder(&encoder_2); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | TEST_F(VieKeyRequestTest, AddTwiceError) { |
| 140 | const int ssrc = 1234; |
| 141 | MockVieEncoder encoder(process_thread_.get()); |
| 142 | EXPECT_TRUE(encoder_state_feedback_->AddEncoder(ssrc, &encoder)); |
| 143 | EXPECT_FALSE(encoder_state_feedback_->AddEncoder(ssrc, &encoder)); |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 144 | encoder_state_feedback_->RemoveEncoder(&encoder); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | } // namespace webrtc |