OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 <vector> | 11 #include <vector> |
12 | 12 |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 14 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
15 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | 15 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" |
16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" | 16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" |
17 #include "webrtc/modules/video_coding/codecs/vp8/vp8_factory.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/vp8_factory.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace testing { | 20 namespace testing { |
21 | 21 |
22 static VP8Encoder* CreateTestEncoderAdapter() { | 22 static VP8Encoder* CreateTestEncoderAdapter() { |
23 VP8EncoderFactoryConfig::set_use_simulcast_adapter(true); | 23 VP8EncoderFactoryConfig::set_use_simulcast_adapter(true); |
24 return VP8Encoder::Create(); | 24 return VP8Encoder::Create(); |
25 } | 25 } |
26 | 26 |
27 class TestSimulcastEncoderAdapter : public TestVp8Simulcast { | 27 class TestSimulcastEncoderAdapter : public TestVp8Simulcast { |
28 public: | 28 public: |
29 TestSimulcastEncoderAdapter() | 29 TestSimulcastEncoderAdapter() |
30 : TestVp8Simulcast(CreateTestEncoderAdapter(), | 30 : TestVp8Simulcast(CreateTestEncoderAdapter(), VP8Decoder::Create()) {} |
31 VP8Decoder::Create()) {} | 31 |
32 protected: | 32 protected: |
33 virtual void SetUp() { | 33 virtual void SetUp() { TestVp8Simulcast::SetUp(); } |
34 TestVp8Simulcast::SetUp(); | |
35 } | |
36 virtual void TearDown() { | 34 virtual void TearDown() { |
37 TestVp8Simulcast::TearDown(); | 35 TestVp8Simulcast::TearDown(); |
38 VP8EncoderFactoryConfig::set_use_simulcast_adapter(false); | 36 VP8EncoderFactoryConfig::set_use_simulcast_adapter(false); |
39 } | 37 } |
40 }; | 38 }; |
41 | 39 |
42 TEST_F(TestSimulcastEncoderAdapter, TestKeyFrameRequestsOnAllStreams) { | 40 TEST_F(TestSimulcastEncoderAdapter, TestKeyFrameRequestsOnAllStreams) { |
43 TestVp8Simulcast::TestKeyFrameRequestsOnAllStreams(); | 41 TestVp8Simulcast::TestKeyFrameRequestsOnAllStreams(); |
44 } | 42 } |
45 | 43 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 TEST_F(TestSimulcastEncoderAdapter, TestSaptioTemporalLayers333PatternEncoder) { | 88 TEST_F(TestSimulcastEncoderAdapter, TestSaptioTemporalLayers333PatternEncoder) { |
91 TestVp8Simulcast::TestSaptioTemporalLayers333PatternEncoder(); | 89 TestVp8Simulcast::TestSaptioTemporalLayers333PatternEncoder(); |
92 } | 90 } |
93 | 91 |
94 TEST_F(TestSimulcastEncoderAdapter, TestSpatioTemporalLayers321PatternEncoder) { | 92 TEST_F(TestSimulcastEncoderAdapter, TestSpatioTemporalLayers321PatternEncoder) { |
95 TestVp8Simulcast::TestSpatioTemporalLayers321PatternEncoder(); | 93 TestVp8Simulcast::TestSpatioTemporalLayers321PatternEncoder(); |
96 } | 94 } |
97 | 95 |
98 // TODO(ronghuawu): Enable this test when SkipEncodingUnusedStreams option is | 96 // TODO(ronghuawu): Enable this test when SkipEncodingUnusedStreams option is |
99 // implemented for SimulcastEncoderAdapter. | 97 // implemented for SimulcastEncoderAdapter. |
100 TEST_F(TestSimulcastEncoderAdapter, | 98 TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestSkipEncodingUnusedStreams) { |
101 DISABLED_TestSkipEncodingUnusedStreams) { | |
102 TestVp8Simulcast::TestSkipEncodingUnusedStreams(); | 99 TestVp8Simulcast::TestSkipEncodingUnusedStreams(); |
103 } | 100 } |
104 | 101 |
105 TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestRPSIEncoder) { | 102 TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestRPSIEncoder) { |
106 TestVp8Simulcast::TestRPSIEncoder(); | 103 TestVp8Simulcast::TestRPSIEncoder(); |
107 } | 104 } |
108 | 105 |
109 class MockVideoEncoder : public VideoEncoder { | 106 class MockVideoEncoder : public VideoEncoder { |
110 public: | 107 public: |
111 int32_t InitEncode(const VideoCodec* codecSettings, | 108 int32_t InitEncode(const VideoCodec* codecSettings, |
112 int32_t numberOfCores, | 109 int32_t numberOfCores, |
113 size_t maxPayloadSize) override { | 110 size_t maxPayloadSize) override { |
114 codec_ = *codecSettings; | 111 codec_ = *codecSettings; |
115 return 0; | 112 return 0; |
116 } | 113 } |
117 | 114 |
118 int32_t Encode(const VideoFrame& inputImage, | 115 int32_t Encode(const VideoFrame& inputImage, |
119 const CodecSpecificInfo* codecSpecificInfo, | 116 const CodecSpecificInfo* codecSpecificInfo, |
120 const std::vector<FrameType>* frame_types) override { | 117 const std::vector<FrameType>* frame_types) override { |
121 return 0; | 118 return 0; |
122 } | 119 } |
123 | 120 |
124 int32_t RegisterEncodeCompleteCallback( | 121 int32_t RegisterEncodeCompleteCallback( |
125 EncodedImageCallback* callback) override { | 122 EncodedImageCallback* callback) override { |
126 callback_ = callback; | 123 callback_ = callback; |
127 return 0; | 124 return 0; |
128 } | 125 } |
129 | 126 |
130 int32_t Release() override { | 127 int32_t Release() override { return 0; } |
131 return 0; | |
132 } | |
133 | 128 |
134 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { | 129 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { |
135 return 0; | 130 return 0; |
136 } | 131 } |
137 | 132 |
138 MOCK_METHOD2(SetChannelParameters, | 133 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); |
139 int32_t(uint32_t packetLoss, int64_t rtt)); | |
140 | 134 |
141 bool SupportsNativeHandle() const override { | 135 bool SupportsNativeHandle() const override { return supports_native_handle_; } |
142 return supports_native_handle_; | |
143 } | |
144 | 136 |
145 virtual ~MockVideoEncoder() { | 137 virtual ~MockVideoEncoder() {} |
146 } | |
147 | 138 |
148 const VideoCodec& codec() const { return codec_; } | 139 const VideoCodec& codec() const { return codec_; } |
149 | 140 |
150 void SendEncodedImage(int width, int height) { | 141 void SendEncodedImage(int width, int height) { |
151 // Sends a fake image of the given width/height. | 142 // Sends a fake image of the given width/height. |
152 EncodedImage image; | 143 EncodedImage image; |
153 image._encodedWidth = width; | 144 image._encodedWidth = width; |
154 image._encodedHeight = height; | 145 image._encodedHeight = height; |
155 CodecSpecificInfo codecSpecificInfo; | 146 CodecSpecificInfo codecSpecificInfo; |
156 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); | 147 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Can only be called once as the SimulcastEncoderAdapter will take the | 184 // Can only be called once as the SimulcastEncoderAdapter will take the |
194 // ownership of |factory_|. | 185 // ownership of |factory_|. |
195 VP8Encoder* CreateMockEncoderAdapter() { | 186 VP8Encoder* CreateMockEncoderAdapter() { |
196 return new SimulcastEncoderAdapter(factory_); | 187 return new SimulcastEncoderAdapter(factory_); |
197 } | 188 } |
198 | 189 |
199 void ExpectCallSetChannelParameters(uint32_t packetLoss, int64_t rtt) { | 190 void ExpectCallSetChannelParameters(uint32_t packetLoss, int64_t rtt) { |
200 EXPECT_TRUE(!factory_->encoders().empty()); | 191 EXPECT_TRUE(!factory_->encoders().empty()); |
201 for (size_t i = 0; i < factory_->encoders().size(); ++i) { | 192 for (size_t i = 0; i < factory_->encoders().size(); ++i) { |
202 EXPECT_CALL(*factory_->encoders()[i], | 193 EXPECT_CALL(*factory_->encoders()[i], |
203 SetChannelParameters(packetLoss, rtt)).Times(1); | 194 SetChannelParameters(packetLoss, rtt)) |
| 195 .Times(1); |
204 } | 196 } |
205 } | 197 } |
206 | 198 |
207 MockVideoEncoderFactory* factory() { return factory_; } | 199 MockVideoEncoderFactory* factory() { return factory_; } |
208 | 200 |
209 private: | 201 private: |
210 MockVideoEncoderFactory* factory_; | 202 MockVideoEncoderFactory* factory_; |
211 }; | 203 }; |
212 | 204 |
213 static const int kTestTemporalLayerProfile[3] = {3, 2, 1}; | 205 static const int kTestTemporalLayerProfile[3] = {3, 2, 1}; |
(...skipping 28 matching lines...) Expand all Loading... |
242 return false; | 234 return false; |
243 } | 235 } |
244 *out_width = last_encoded_image_width_; | 236 *out_width = last_encoded_image_width_; |
245 *out_height = last_encoded_image_height_; | 237 *out_height = last_encoded_image_height_; |
246 *out_simulcast_index = last_encoded_image_simulcast_index_; | 238 *out_simulcast_index = last_encoded_image_simulcast_index_; |
247 return true; | 239 return true; |
248 } | 240 } |
249 | 241 |
250 void SetupCodec() { | 242 void SetupCodec() { |
251 TestVp8Simulcast::DefaultSettings( | 243 TestVp8Simulcast::DefaultSettings( |
252 &codec_, | 244 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
253 static_cast<const int*>(kTestTemporalLayerProfile)); | |
254 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 245 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
255 adapter_->RegisterEncodeCompleteCallback(this); | 246 adapter_->RegisterEncodeCompleteCallback(this); |
256 } | 247 } |
257 | 248 |
258 void VerifyCodec(const VideoCodec& ref, int stream_index) { | 249 void VerifyCodec(const VideoCodec& ref, int stream_index) { |
259 const VideoCodec& target = | 250 const VideoCodec& target = |
260 helper_->factory()->encoders()[stream_index]->codec(); | 251 helper_->factory()->encoders()[stream_index]->codec(); |
261 EXPECT_EQ(ref.codecType, target.codecType); | 252 EXPECT_EQ(ref.codecType, target.codecType); |
262 EXPECT_EQ(0, strcmp(ref.plName, target.plName)); | 253 EXPECT_EQ(0, strcmp(ref.plName, target.plName)); |
263 EXPECT_EQ(ref.plType, target.plType); | 254 EXPECT_EQ(ref.plType, target.plType); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 406 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
416 adapter_->RegisterEncodeCompleteCallback(this); | 407 adapter_->RegisterEncodeCompleteCallback(this); |
417 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 408 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
418 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 409 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
419 encoder->set_supports_native_handle(true); | 410 encoder->set_supports_native_handle(true); |
420 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 411 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
421 } | 412 } |
422 | 413 |
423 } // namespace testing | 414 } // namespace testing |
424 } // namespace webrtc | 415 } // namespace webrtc |
OLD | NEW |