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 <array> | 11 #include <array> |
12 #include <memory> | 12 #include <memory> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "webrtc/common_video/include/video_frame_buffer.h" | 15 #include "webrtc/common_video/include/video_frame_buffer.h" |
16 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | 16 #include "webrtc/media/engine/simulcast_encoder_adapter.h" |
17 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_test_utility.h" |
18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
19 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 namespace testing { | 22 namespace testing { |
23 | 23 |
24 class TestSimulcastEncoderAdapter : public TestVp8Simulcast { | 24 class TestSimulcastEncoderAdapter : public TestVp8Simulcast { |
25 public: | 25 public: |
26 TestSimulcastEncoderAdapter() | 26 TestSimulcastEncoderAdapter() : factory_(new Vp8EncoderFactory()) {} |
27 : TestVp8Simulcast(new SimulcastEncoderAdapter(new Vp8EncoderFactory()), | |
28 VP8Decoder::Create()) {} | |
29 | 27 |
30 protected: | 28 protected: |
31 class Vp8EncoderFactory : public VideoEncoderFactory { | 29 class Vp8EncoderFactory : public cricket::WebRtcVideoEncoderFactory { |
32 public: | 30 public: |
33 VideoEncoder* Create() override { return VP8Encoder::Create(); } | 31 Vp8EncoderFactory() { |
| 32 supported_codecs_.push_back(cricket::VideoCodec("VP8")); |
| 33 } |
34 | 34 |
35 void Destroy(VideoEncoder* encoder) override { delete encoder; } | 35 const std::vector<cricket::VideoCodec>& supported_codecs() const override { |
| 36 return supported_codecs_; |
| 37 } |
| 38 |
| 39 VideoEncoder* CreateVideoEncoder( |
| 40 const cricket::VideoCodec& codec) override { |
| 41 return VP8Encoder::Create(); |
| 42 } |
| 43 |
| 44 void DestroyVideoEncoder(VideoEncoder* encoder) override { delete encoder; } |
36 | 45 |
37 virtual ~Vp8EncoderFactory() {} | 46 virtual ~Vp8EncoderFactory() {} |
| 47 |
| 48 private: |
| 49 std::vector<cricket::VideoCodec> supported_codecs_; |
38 }; | 50 }; |
39 | 51 |
40 virtual void SetUp() { TestVp8Simulcast::SetUp(); } | 52 VP8Encoder* CreateEncoder() override { |
41 virtual void TearDown() { TestVp8Simulcast::TearDown(); } | 53 return new SimulcastEncoderAdapter(factory_.get()); |
| 54 } |
| 55 VP8Decoder* CreateDecoder() override { return VP8Decoder::Create(); } |
| 56 |
| 57 private: |
| 58 std::unique_ptr<Vp8EncoderFactory> factory_; |
42 }; | 59 }; |
43 | 60 |
44 TEST_F(TestSimulcastEncoderAdapter, TestKeyFrameRequestsOnAllStreams) { | 61 TEST_F(TestSimulcastEncoderAdapter, TestKeyFrameRequestsOnAllStreams) { |
45 TestVp8Simulcast::TestKeyFrameRequestsOnAllStreams(); | 62 TestVp8Simulcast::TestKeyFrameRequestsOnAllStreams(); |
46 } | 63 } |
47 | 64 |
48 TEST_F(TestSimulcastEncoderAdapter, TestPaddingAllStreams) { | 65 TEST_F(TestSimulcastEncoderAdapter, TestPaddingAllStreams) { |
49 TestVp8Simulcast::TestPaddingAllStreams(); | 66 TestVp8Simulcast::TestPaddingAllStreams(); |
50 } | 67 } |
51 | 68 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 177 |
161 private: | 178 private: |
162 bool supports_native_handle_ = false; | 179 bool supports_native_handle_ = false; |
163 int32_t init_encode_return_value_ = 0; | 180 int32_t init_encode_return_value_ = 0; |
164 BitrateAllocation last_set_bitrate_; | 181 BitrateAllocation last_set_bitrate_; |
165 | 182 |
166 VideoCodec codec_; | 183 VideoCodec codec_; |
167 EncodedImageCallback* callback_; | 184 EncodedImageCallback* callback_; |
168 }; | 185 }; |
169 | 186 |
170 class MockVideoEncoderFactory : public VideoEncoderFactory { | 187 class MockVideoEncoderFactory : public cricket::WebRtcVideoEncoderFactory { |
171 public: | 188 public: |
172 VideoEncoder* Create() override { | 189 MockVideoEncoderFactory() { |
173 MockVideoEncoder* encoder = new | 190 supported_codecs_.push_back(cricket::VideoCodec("VP8")); |
174 ::testing::NiceMock<MockVideoEncoder>(); | 191 } |
| 192 |
| 193 const std::vector<cricket::VideoCodec>& supported_codecs() const override { |
| 194 return supported_codecs_; |
| 195 } |
| 196 |
| 197 VideoEncoder* CreateVideoEncoder(const cricket::VideoCodec& codec) override { |
| 198 MockVideoEncoder* encoder = new ::testing::NiceMock<MockVideoEncoder>(); |
175 encoder->set_init_encode_return_value(init_encode_return_value_); | 199 encoder->set_init_encode_return_value(init_encode_return_value_); |
176 const char* encoder_name = encoder_names_.empty() | 200 const char* encoder_name = encoder_names_.empty() |
177 ? "codec_implementation_name" | 201 ? "codec_implementation_name" |
178 : encoder_names_[encoders_.size()]; | 202 : encoder_names_[encoders_.size()]; |
179 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); | 203 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); |
180 encoders_.push_back(encoder); | 204 encoders_.push_back(encoder); |
181 return encoder; | 205 return encoder; |
182 } | 206 } |
183 | 207 |
184 void Destroy(VideoEncoder* encoder) override { | 208 void DestroyVideoEncoder(VideoEncoder* encoder) override { |
185 for (size_t i = 0; i < encoders_.size(); ++i) { | 209 for (size_t i = 0; i < encoders_.size(); ++i) { |
186 if (encoders_[i] == encoder) { | 210 if (encoders_[i] == encoder) { |
187 encoders_.erase(encoders_.begin() + i); | 211 encoders_.erase(encoders_.begin() + i); |
188 break; | 212 break; |
189 } | 213 } |
190 } | 214 } |
191 delete encoder; | 215 delete encoder; |
192 } | 216 } |
193 | 217 |
194 virtual ~MockVideoEncoderFactory() {} | 218 virtual ~MockVideoEncoderFactory() {} |
195 | 219 |
196 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } | 220 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } |
197 void SetEncoderNames(const std::vector<const char*>& encoder_names) { | 221 void SetEncoderNames(const std::vector<const char*>& encoder_names) { |
198 encoder_names_ = encoder_names; | 222 encoder_names_ = encoder_names; |
199 } | 223 } |
200 void set_init_encode_return_value(int32_t value) { | 224 void set_init_encode_return_value(int32_t value) { |
201 init_encode_return_value_ = value; | 225 init_encode_return_value_ = value; |
202 } | 226 } |
203 | 227 |
204 private: | 228 private: |
| 229 std::vector<cricket::VideoCodec> supported_codecs_; |
205 int32_t init_encode_return_value_ = 0; | 230 int32_t init_encode_return_value_ = 0; |
206 std::vector<MockVideoEncoder*> encoders_; | 231 std::vector<MockVideoEncoder*> encoders_; |
207 std::vector<const char*> encoder_names_; | 232 std::vector<const char*> encoder_names_; |
208 }; | 233 }; |
209 | 234 |
210 class TestSimulcastEncoderAdapterFakeHelper { | 235 class TestSimulcastEncoderAdapterFakeHelper { |
211 public: | 236 public: |
212 TestSimulcastEncoderAdapterFakeHelper() | 237 TestSimulcastEncoderAdapterFakeHelper() |
213 : factory_(new MockVideoEncoderFactory()) {} | 238 : factory_(new MockVideoEncoderFactory()) {} |
214 | 239 |
215 // Can only be called once as the SimulcastEncoderAdapter will take the | 240 // Can only be called once as the SimulcastEncoderAdapter will take the |
216 // ownership of |factory_|. | 241 // ownership of |factory_|. |
217 VP8Encoder* CreateMockEncoderAdapter() { | 242 VP8Encoder* CreateMockEncoderAdapter() { |
218 return new SimulcastEncoderAdapter(factory_); | 243 return new SimulcastEncoderAdapter(factory_.get()); |
219 } | 244 } |
220 | 245 |
221 void ExpectCallSetChannelParameters(uint32_t packetLoss, int64_t rtt) { | 246 void ExpectCallSetChannelParameters(uint32_t packetLoss, int64_t rtt) { |
222 EXPECT_TRUE(!factory_->encoders().empty()); | 247 EXPECT_TRUE(!factory_->encoders().empty()); |
223 for (size_t i = 0; i < factory_->encoders().size(); ++i) { | 248 for (size_t i = 0; i < factory_->encoders().size(); ++i) { |
224 EXPECT_CALL(*factory_->encoders()[i], | 249 EXPECT_CALL(*factory_->encoders()[i], |
225 SetChannelParameters(packetLoss, rtt)) | 250 SetChannelParameters(packetLoss, rtt)) |
226 .Times(1); | 251 .Times(1); |
227 } | 252 } |
228 } | 253 } |
229 | 254 |
230 MockVideoEncoderFactory* factory() { return factory_; } | 255 MockVideoEncoderFactory* factory() { return factory_.get(); } |
231 | 256 |
232 private: | 257 private: |
233 MockVideoEncoderFactory* factory_; | 258 std::unique_ptr<MockVideoEncoderFactory> factory_; |
234 }; | 259 }; |
235 | 260 |
236 static const int kTestTemporalLayerProfile[3] = {3, 2, 1}; | 261 static const int kTestTemporalLayerProfile[3] = {3, 2, 1}; |
237 | 262 |
238 class TestSimulcastEncoderAdapterFake : public ::testing::Test, | 263 class TestSimulcastEncoderAdapterFake : public ::testing::Test, |
239 public EncodedImageCallback { | 264 public EncodedImageCallback { |
240 public: | 265 public: |
241 TestSimulcastEncoderAdapterFake() | 266 TestSimulcastEncoderAdapterFake() |
242 : helper_(new TestSimulcastEncoderAdapterFakeHelper()), | 267 : helper_(new TestSimulcastEncoderAdapterFakeHelper()), |
243 adapter_(helper_->CreateMockEncoderAdapter()), | 268 adapter_(helper_->CreateMockEncoderAdapter()), |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 codec_.numberOfSimulcastStreams = 3; | 815 codec_.numberOfSimulcastStreams = 3; |
791 helper_->factory()->set_init_encode_return_value( | 816 helper_->factory()->set_init_encode_return_value( |
792 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); | 817 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); |
793 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 818 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
794 adapter_->InitEncode(&codec_, 1, 1200)); | 819 adapter_->InitEncode(&codec_, 1, 1200)); |
795 EXPECT_TRUE(helper_->factory()->encoders().empty()); | 820 EXPECT_TRUE(helper_->factory()->encoders().empty()); |
796 } | 821 } |
797 | 822 |
798 } // namespace testing | 823 } // namespace testing |
799 } // namespace webrtc | 824 } // namespace webrtc |
OLD | NEW |