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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // methods don't use any override declarations, and we want to avoid | 111 // methods don't use any override declarations, and we want to avoid |
112 // warnings from -Winconsistent-missing-override. See | 112 // warnings from -Winconsistent-missing-override. See |
113 // http://crbug.com/428099. | 113 // http://crbug.com/428099. |
114 int32_t InitEncode(const VideoCodec* codecSettings, | 114 int32_t InitEncode(const VideoCodec* codecSettings, |
115 int32_t numberOfCores, | 115 int32_t numberOfCores, |
116 size_t maxPayloadSize) /* override */ { | 116 size_t maxPayloadSize) /* override */ { |
117 codec_ = *codecSettings; | 117 codec_ = *codecSettings; |
118 return 0; | 118 return 0; |
119 } | 119 } |
120 | 120 |
121 int32_t Encode(const VideoFrame& inputImage, | 121 MOCK_METHOD3( |
122 const CodecSpecificInfo* codecSpecificInfo, | 122 Encode, |
123 const std::vector<FrameType>* frame_types) /* override */ { | 123 int32_t(const VideoFrame& inputImage, |
124 return encode_return_value_; | 124 const CodecSpecificInfo* codecSpecificInfo, |
125 } | 125 const std::vector<FrameType>* frame_types) /* override */); |
126 | 126 |
127 int32_t RegisterEncodeCompleteCallback( | 127 int32_t RegisterEncodeCompleteCallback( |
128 EncodedImageCallback* callback) /* override */ { | 128 EncodedImageCallback* callback) /* override */ { |
129 callback_ = callback; | 129 callback_ = callback; |
130 return 0; | 130 return 0; |
131 } | 131 } |
132 | 132 |
133 int32_t Release() /* override */ { return 0; } | 133 int32_t Release() /* override */ { return 0; } |
134 | 134 |
135 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ { | 135 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ { |
(...skipping 17 matching lines...) Expand all Loading... |
153 image._encodedHeight = height; | 153 image._encodedHeight = height; |
154 CodecSpecificInfo codecSpecificInfo; | 154 CodecSpecificInfo codecSpecificInfo; |
155 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); | 155 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); |
156 callback_->Encoded(image, &codecSpecificInfo, NULL); | 156 callback_->Encoded(image, &codecSpecificInfo, NULL); |
157 } | 157 } |
158 | 158 |
159 void set_supports_native_handle(bool enabled) { | 159 void set_supports_native_handle(bool enabled) { |
160 supports_native_handle_ = enabled; | 160 supports_native_handle_ = enabled; |
161 } | 161 } |
162 | 162 |
163 void set_encode_return_value(int value) { | |
164 encode_return_value_ = value; | |
165 } | |
166 | |
167 MOCK_CONST_METHOD0(ImplementationName, const char*()); | 163 MOCK_CONST_METHOD0(ImplementationName, const char*()); |
168 | 164 |
169 private: | 165 private: |
170 bool supports_native_handle_ = false; | 166 bool supports_native_handle_ = false; |
171 int encode_return_value_ = WEBRTC_VIDEO_CODEC_OK; | |
172 VideoCodec codec_; | 167 VideoCodec codec_; |
173 EncodedImageCallback* callback_; | 168 EncodedImageCallback* callback_; |
174 }; | 169 }; |
175 | 170 |
176 class MockVideoEncoderFactory : public VideoEncoderFactory { | 171 class MockVideoEncoderFactory : public VideoEncoderFactory { |
177 public: | 172 public: |
178 VideoEncoder* Create() override { | 173 VideoEncoder* Create() override { |
179 MockVideoEncoder* encoder = new | 174 MockVideoEncoder* encoder = new |
180 ::testing::NiceMock<MockVideoEncoder>(); | 175 ::testing::NiceMock<MockVideoEncoder>(); |
181 const char* encoder_name = encoder_names_.empty() | 176 const char* encoder_name = encoder_names_.empty() |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // Single streams should not expose "SimulcastEncoderAdapter" in name. | 440 // Single streams should not expose "SimulcastEncoderAdapter" in name. |
446 adapter_->Release(); | 441 adapter_->Release(); |
447 codec_.numberOfSimulcastStreams = 1; | 442 codec_.numberOfSimulcastStreams = 1; |
448 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 443 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
449 adapter_->RegisterEncodeCompleteCallback(this); | 444 adapter_->RegisterEncodeCompleteCallback(this); |
450 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 445 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
451 EXPECT_STREQ("codec1", adapter_->ImplementationName()); | 446 EXPECT_STREQ("codec1", adapter_->ImplementationName()); |
452 } | 447 } |
453 | 448 |
454 TEST_F(TestSimulcastEncoderAdapterFake, | 449 TEST_F(TestSimulcastEncoderAdapterFake, |
455 SupportsNativeHandleDisabledForMultipleStreams) { | 450 SupportsNativeHandleForMultipleStreams) { |
456 // TODO(pbos): Implement actual test (verify that it works) when implemented | |
457 // for multiple streams. | |
458 TestVp8Simulcast::DefaultSettings( | 451 TestVp8Simulcast::DefaultSettings( |
459 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 452 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
460 codec_.numberOfSimulcastStreams = 3; | 453 codec_.numberOfSimulcastStreams = 3; |
461 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 454 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
462 adapter_->RegisterEncodeCompleteCallback(this); | 455 adapter_->RegisterEncodeCompleteCallback(this); |
463 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 456 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
464 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 457 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
465 encoder->set_supports_native_handle(true); | 458 encoder->set_supports_native_handle(true); |
| 459 // If one encoder doesn't support it, then overall support is disabled. |
| 460 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
466 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 461 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
| 462 // Once all do, then the adapter claims support. |
| 463 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
| 464 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
| 465 } |
| 466 |
| 467 class FakeNativeHandleBuffer : public NativeHandleBuffer { |
| 468 public: |
| 469 FakeNativeHandleBuffer(void* native_handle, int width, int height) |
| 470 : NativeHandleBuffer(native_handle, width, height) {} |
| 471 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
| 472 RTC_NOTREACHED(); |
| 473 return nullptr; |
| 474 } |
| 475 }; |
| 476 |
| 477 TEST_F(TestSimulcastEncoderAdapterFake, |
| 478 NativeHandleForwardingForMultipleStreams) { |
| 479 TestVp8Simulcast::DefaultSettings( |
| 480 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 481 codec_.numberOfSimulcastStreams = 3; |
| 482 // High start bitrate, so all streams are enabled. |
| 483 codec_.startBitrate = 3000; |
| 484 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 485 adapter_->RegisterEncodeCompleteCallback(this); |
| 486 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
| 487 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
| 488 encoder->set_supports_native_handle(true); |
| 489 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
| 490 |
| 491 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
| 492 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); |
| 493 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); |
| 494 // Expect calls with the given video frame verbatim, since it's a texture |
| 495 // frame and can't otherwise be modified/resized. |
| 496 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
| 497 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); |
| 498 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
| 499 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); |
467 } | 500 } |
468 | 501 |
469 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { | 502 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { |
470 TestVp8Simulcast::DefaultSettings( | 503 TestVp8Simulcast::DefaultSettings( |
471 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 504 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
472 codec_.numberOfSimulcastStreams = 3; | 505 codec_.numberOfSimulcastStreams = 3; |
473 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 506 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
474 adapter_->RegisterEncodeCompleteCallback(this); | 507 adapter_->RegisterEncodeCompleteCallback(this); |
475 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 508 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
476 // Tell the 2nd encoder to request software fallback. | 509 // Tell the 2nd encoder to request software fallback. |
477 helper_->factory()->encoders()[1]->set_encode_return_value( | 510 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) |
478 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); | 511 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); |
479 | 512 |
480 // Send a fake frame and assert the return is software fallback. | 513 // Send a fake frame and assert the return is software fallback. |
481 VideoFrame input_frame; | 514 VideoFrame input_frame; |
482 int half_width = (kDefaultWidth + 1) / 2; | 515 int half_width = (kDefaultWidth + 1) / 2; |
483 input_frame.CreateEmptyFrame(kDefaultWidth, kDefaultHeight, kDefaultWidth, | 516 input_frame.CreateEmptyFrame(kDefaultWidth, kDefaultHeight, kDefaultWidth, |
484 half_width, half_width); | 517 half_width, half_width); |
485 memset(input_frame.video_frame_buffer()->MutableDataY(), 0, | 518 memset(input_frame.video_frame_buffer()->MutableDataY(), 0, |
486 input_frame.allocated_size(kYPlane)); | 519 input_frame.allocated_size(kYPlane)); |
487 memset(input_frame.video_frame_buffer()->MutableDataU(), 0, | 520 memset(input_frame.video_frame_buffer()->MutableDataU(), 0, |
488 input_frame.allocated_size(kUPlane)); | 521 input_frame.allocated_size(kUPlane)); |
489 memset(input_frame.video_frame_buffer()->MutableDataV(), 0, | 522 memset(input_frame.video_frame_buffer()->MutableDataV(), 0, |
490 input_frame.allocated_size(kVPlane)); | 523 input_frame.allocated_size(kVPlane)); |
491 | 524 |
492 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 525 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
493 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 526 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
494 adapter_->Encode(input_frame, nullptr, &frame_types)); | 527 adapter_->Encode(input_frame, nullptr, &frame_types)); |
495 } | 528 } |
496 | 529 |
497 } // namespace testing | 530 } // namespace testing |
498 } // namespace webrtc | 531 } // namespace webrtc |
OLD | NEW |