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 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 image._encodedHeight = height; | 145 image._encodedHeight = height; |
146 CodecSpecificInfo codecSpecificInfo; | 146 CodecSpecificInfo codecSpecificInfo; |
147 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); | 147 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); |
148 callback_->Encoded(image, &codecSpecificInfo, NULL); | 148 callback_->Encoded(image, &codecSpecificInfo, NULL); |
149 } | 149 } |
150 | 150 |
151 void set_supports_native_handle(bool enabled) { | 151 void set_supports_native_handle(bool enabled) { |
152 supports_native_handle_ = enabled; | 152 supports_native_handle_ = enabled; |
153 } | 153 } |
154 | 154 |
| 155 MOCK_CONST_METHOD0(ImplementationName, const char*()); |
| 156 |
155 private: | 157 private: |
156 bool supports_native_handle_ = false; | 158 bool supports_native_handle_ = false; |
157 VideoCodec codec_; | 159 VideoCodec codec_; |
158 EncodedImageCallback* callback_; | 160 EncodedImageCallback* callback_; |
159 }; | 161 }; |
160 | 162 |
161 class MockVideoEncoderFactory : public VideoEncoderFactory { | 163 class MockVideoEncoderFactory : public VideoEncoderFactory { |
162 public: | 164 public: |
163 VideoEncoder* Create() override { | 165 VideoEncoder* Create() override { |
164 MockVideoEncoder* encoder = new MockVideoEncoder(); | 166 MockVideoEncoder* encoder = new MockVideoEncoder(); |
| 167 const char* encoder_name = encoder_names_.empty() |
| 168 ? "codec_implementation_name" |
| 169 : encoder_names_[encoders_.size()]; |
| 170 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); |
165 encoders_.push_back(encoder); | 171 encoders_.push_back(encoder); |
166 return encoder; | 172 return encoder; |
167 } | 173 } |
168 | 174 |
169 void Destroy(VideoEncoder* encoder) override { delete encoder; } | 175 void Destroy(VideoEncoder* encoder) override { delete encoder; } |
170 | 176 |
171 virtual ~MockVideoEncoderFactory() {} | 177 virtual ~MockVideoEncoderFactory() {} |
172 | 178 |
173 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } | 179 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } |
| 180 void SetEncoderNames(const std::vector<const char*>& encoder_names) { |
| 181 encoder_names_ = encoder_names; |
| 182 } |
174 | 183 |
175 private: | 184 private: |
176 std::vector<MockVideoEncoder*> encoders_; | 185 std::vector<MockVideoEncoder*> encoders_; |
| 186 std::vector<const char*> encoder_names_; |
177 }; | 187 }; |
178 | 188 |
179 class TestSimulcastEncoderAdapterFakeHelper { | 189 class TestSimulcastEncoderAdapterFakeHelper { |
180 public: | 190 public: |
181 TestSimulcastEncoderAdapterFakeHelper() | 191 TestSimulcastEncoderAdapterFakeHelper() |
182 : factory_(new MockVideoEncoderFactory()) {} | 192 : factory_(new MockVideoEncoderFactory()) {} |
183 | 193 |
184 // Can only be called once as the SimulcastEncoderAdapter will take the | 194 // Can only be called once as the SimulcastEncoderAdapter will take the |
185 // ownership of |factory_|. | 195 // ownership of |factory_|. |
186 VP8Encoder* CreateMockEncoderAdapter() { | 196 VP8Encoder* CreateMockEncoderAdapter() { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 codec_.numberOfSimulcastStreams = 1; | 400 codec_.numberOfSimulcastStreams = 1; |
391 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 401 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
392 adapter_->RegisterEncodeCompleteCallback(this); | 402 adapter_->RegisterEncodeCompleteCallback(this); |
393 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 403 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
394 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 404 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
395 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 405 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
396 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 406 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
397 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 407 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
398 } | 408 } |
399 | 409 |
| 410 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { |
| 411 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); |
| 412 TestVp8Simulcast::DefaultSettings( |
| 413 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 414 std::vector<const char*> encoder_names; |
| 415 encoder_names.push_back("codec1"); |
| 416 encoder_names.push_back("codec2"); |
| 417 encoder_names.push_back("codec3"); |
| 418 helper_->factory()->SetEncoderNames(encoder_names); |
| 419 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 420 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", |
| 421 adapter_->ImplementationName()); |
| 422 } |
| 423 |
400 TEST_F(TestSimulcastEncoderAdapterFake, | 424 TEST_F(TestSimulcastEncoderAdapterFake, |
401 SupportsNativeHandleDisabledForMultipleStreams) { | 425 SupportsNativeHandleDisabledForMultipleStreams) { |
402 // TODO(pbos): Implement actual test (verify that it works) when implemented | 426 // TODO(pbos): Implement actual test (verify that it works) when implemented |
403 // for multiple streams. | 427 // for multiple streams. |
404 TestVp8Simulcast::DefaultSettings( | 428 TestVp8Simulcast::DefaultSettings( |
405 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 429 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
406 codec_.numberOfSimulcastStreams = 3; | 430 codec_.numberOfSimulcastStreams = 3; |
407 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 431 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
408 adapter_->RegisterEncodeCompleteCallback(this); | 432 adapter_->RegisterEncodeCompleteCallback(this); |
409 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 433 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
410 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 434 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
411 encoder->set_supports_native_handle(true); | 435 encoder->set_supports_native_handle(true); |
412 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 436 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
413 } | 437 } |
414 | 438 |
415 } // namespace testing | 439 } // namespace testing |
416 } // namespace webrtc | 440 } // namespace webrtc |
OLD | NEW |