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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 int32_t Encode(const VideoFrame& inputImage, |
122 const CodecSpecificInfo* codecSpecificInfo, | 122 const CodecSpecificInfo* codecSpecificInfo, |
123 const std::vector<FrameType>* frame_types) /* override */ { | 123 const std::vector<FrameType>* frame_types) /* override */ { |
124 return 0; | 124 return encode_return_value_; |
125 } | 125 } |
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 |
(...skipping 18 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 | |
163 MOCK_CONST_METHOD0(ImplementationName, const char*()); | 167 MOCK_CONST_METHOD0(ImplementationName, const char*()); |
164 | 168 |
165 private: | 169 private: |
166 bool supports_native_handle_ = false; | 170 bool supports_native_handle_ = false; |
171 int encode_return_value_ = WEBRTC_VIDEO_CODEC_OK; | |
167 VideoCodec codec_; | 172 VideoCodec codec_; |
168 EncodedImageCallback* callback_; | 173 EncodedImageCallback* callback_; |
169 }; | 174 }; |
170 | 175 |
171 class MockVideoEncoderFactory : public VideoEncoderFactory { | 176 class MockVideoEncoderFactory : public VideoEncoderFactory { |
172 public: | 177 public: |
173 VideoEncoder* Create() override { | 178 VideoEncoder* Create() override { |
174 MockVideoEncoder* encoder = new MockVideoEncoder(); | 179 MockVideoEncoder* encoder = new |
180 ::testing::NiceMock<MockVideoEncoder>(); | |
175 const char* encoder_name = encoder_names_.empty() | 181 const char* encoder_name = encoder_names_.empty() |
176 ? "codec_implementation_name" | 182 ? "codec_implementation_name" |
177 : encoder_names_[encoders_.size()]; | 183 : encoder_names_[encoders_.size()]; |
178 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); | 184 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); |
179 encoders_.push_back(encoder); | 185 encoders_.push_back(encoder); |
180 return encoder; | 186 return encoder; |
181 } | 187 } |
182 | 188 |
183 void Destroy(VideoEncoder* encoder) override { | 189 void Destroy(VideoEncoder* encoder) override { |
184 for (size_t i = 0; i < encoders_.size(); ++i) { | 190 for (size_t i = 0; i < encoders_.size(); ++i) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 459 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
454 codec_.numberOfSimulcastStreams = 3; | 460 codec_.numberOfSimulcastStreams = 3; |
455 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 461 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
456 adapter_->RegisterEncodeCompleteCallback(this); | 462 adapter_->RegisterEncodeCompleteCallback(this); |
457 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 463 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
458 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 464 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
459 encoder->set_supports_native_handle(true); | 465 encoder->set_supports_native_handle(true); |
460 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 466 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
461 } | 467 } |
462 | 468 |
469 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { | |
470 TestVp8Simulcast::DefaultSettings( | |
471 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | |
472 codec_.numberOfSimulcastStreams = 3; | |
473 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | |
474 adapter_->RegisterEncodeCompleteCallback(this); | |
475 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | |
476 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | |
477 encoder->set_encode_return_value(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); | |
pbos-webrtc
2016/05/24 13:26:33
Set only one of them (like encoders()[1]) to make
noahric
2016/05/24 18:31:09
Done.
| |
478 | |
479 // Send a fake frame and assert the return is software fallback. | |
480 VideoFrame input_frame; | |
481 int half_width = (kDefaultWidth + 1) / 2; | |
482 input_frame.CreateEmptyFrame(kDefaultWidth, kDefaultHeight, kDefaultWidth, | |
483 half_width, half_width); | |
484 memset(input_frame.video_frame_buffer()->MutableDataY(), 0, | |
485 input_frame.allocated_size(kYPlane)); | |
486 memset(input_frame.video_frame_buffer()->MutableDataU(), 0, | |
487 input_frame.allocated_size(kUPlane)); | |
488 memset(input_frame.video_frame_buffer()->MutableDataV(), 0, | |
489 input_frame.allocated_size(kVPlane)); | |
490 | |
491 std::vector<FrameType> frame_types(3, kVideoFrameKey); | |
492 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | |
493 adapter_->Encode(input_frame, nullptr, &frame_types)); | |
494 } | |
495 | |
463 } // namespace testing | 496 } // namespace testing |
464 } // namespace webrtc | 497 } // namespace webrtc |
OLD | NEW |