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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 class MockVideoEncoder : public VideoEncoder { | 102 class MockVideoEncoder : public VideoEncoder { |
103 public: | 103 public: |
104 // TODO(nisse): Valid overrides commented out, because the gmock | 104 // TODO(nisse): Valid overrides commented out, because the gmock |
105 // methods don't use any override declarations, and we want to avoid | 105 // methods don't use any override declarations, and we want to avoid |
106 // warnings from -Winconsistent-missing-override. See | 106 // warnings from -Winconsistent-missing-override. See |
107 // http://crbug.com/428099. | 107 // http://crbug.com/428099. |
108 int32_t InitEncode(const VideoCodec* codecSettings, | 108 int32_t InitEncode(const VideoCodec* codecSettings, |
109 int32_t numberOfCores, | 109 int32_t numberOfCores, |
110 size_t maxPayloadSize) /* override */ { | 110 size_t maxPayloadSize) /* override */ { |
111 codec_ = *codecSettings; | 111 codec_ = *codecSettings; |
112 return 0; | 112 return init_encode_return_value_; |
113 } | 113 } |
114 | 114 |
115 MOCK_METHOD3( | 115 MOCK_METHOD3( |
116 Encode, | 116 Encode, |
117 int32_t(const VideoFrame& inputImage, | 117 int32_t(const VideoFrame& inputImage, |
118 const CodecSpecificInfo* codecSpecificInfo, | 118 const CodecSpecificInfo* codecSpecificInfo, |
119 const std::vector<FrameType>* frame_types) /* override */); | 119 const std::vector<FrameType>* frame_types) /* override */); |
120 | 120 |
121 int32_t RegisterEncodeCompleteCallback( | 121 int32_t RegisterEncodeCompleteCallback( |
122 EncodedImageCallback* callback) /* override */ { | 122 EncodedImageCallback* callback) /* override */ { |
(...skipping 25 matching lines...) Expand all Loading... |
148 image._encodedWidth = width; | 148 image._encodedWidth = width; |
149 image._encodedHeight = height; | 149 image._encodedHeight = height; |
150 CodecSpecificInfo codec_specific_info; | 150 CodecSpecificInfo codec_specific_info; |
151 memset(&codec_specific_info, 0, sizeof(codec_specific_info)); | 151 memset(&codec_specific_info, 0, sizeof(codec_specific_info)); |
152 callback_->OnEncodedImage(image, &codec_specific_info, NULL); | 152 callback_->OnEncodedImage(image, &codec_specific_info, NULL); |
153 } | 153 } |
154 | 154 |
155 void set_supports_native_handle(bool enabled) { | 155 void set_supports_native_handle(bool enabled) { |
156 supports_native_handle_ = enabled; | 156 supports_native_handle_ = enabled; |
157 } | 157 } |
| 158 |
| 159 void set_init_encode_return_value(int32_t value) { |
| 160 init_encode_return_value_ = value; |
| 161 } |
| 162 |
158 BitrateAllocation last_set_bitrate() const { return last_set_bitrate_; } | 163 BitrateAllocation last_set_bitrate() const { return last_set_bitrate_; } |
159 | 164 |
160 MOCK_CONST_METHOD0(ImplementationName, const char*()); | 165 MOCK_CONST_METHOD0(ImplementationName, const char*()); |
161 | 166 |
162 private: | 167 private: |
163 bool supports_native_handle_ = false; | 168 bool supports_native_handle_ = false; |
| 169 int32_t init_encode_return_value_ = 0; |
164 BitrateAllocation last_set_bitrate_; | 170 BitrateAllocation last_set_bitrate_; |
165 | 171 |
166 VideoCodec codec_; | 172 VideoCodec codec_; |
167 EncodedImageCallback* callback_; | 173 EncodedImageCallback* callback_; |
168 }; | 174 }; |
169 | 175 |
170 class MockVideoEncoderFactory : public VideoEncoderFactory { | 176 class MockVideoEncoderFactory : public VideoEncoderFactory { |
171 public: | 177 public: |
172 VideoEncoder* Create() override { | 178 VideoEncoder* Create() override { |
173 MockVideoEncoder* encoder = new | 179 MockVideoEncoder* encoder = new |
174 ::testing::NiceMock<MockVideoEncoder>(); | 180 ::testing::NiceMock<MockVideoEncoder>(); |
| 181 encoder->set_init_encode_return_value(init_encode_return_value_); |
175 const char* encoder_name = encoder_names_.empty() | 182 const char* encoder_name = encoder_names_.empty() |
176 ? "codec_implementation_name" | 183 ? "codec_implementation_name" |
177 : encoder_names_[encoders_.size()]; | 184 : encoder_names_[encoders_.size()]; |
178 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); | 185 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); |
179 encoders_.push_back(encoder); | 186 encoders_.push_back(encoder); |
180 return encoder; | 187 return encoder; |
181 } | 188 } |
182 | 189 |
183 void Destroy(VideoEncoder* encoder) override { | 190 void Destroy(VideoEncoder* encoder) override { |
184 for (size_t i = 0; i < encoders_.size(); ++i) { | 191 for (size_t i = 0; i < encoders_.size(); ++i) { |
185 if (encoders_[i] == encoder) { | 192 if (encoders_[i] == encoder) { |
186 encoders_.erase(encoders_.begin() + i); | 193 encoders_.erase(encoders_.begin() + i); |
187 break; | 194 break; |
188 } | 195 } |
189 } | 196 } |
190 delete encoder; | 197 delete encoder; |
191 } | 198 } |
192 | 199 |
193 virtual ~MockVideoEncoderFactory() {} | 200 virtual ~MockVideoEncoderFactory() {} |
194 | 201 |
195 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } | 202 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } |
196 void SetEncoderNames(const std::vector<const char*>& encoder_names) { | 203 void SetEncoderNames(const std::vector<const char*>& encoder_names) { |
197 encoder_names_ = encoder_names; | 204 encoder_names_ = encoder_names; |
198 } | 205 } |
| 206 void set_init_encode_return_value(int32_t value) { |
| 207 init_encode_return_value_ = value; |
| 208 } |
199 | 209 |
200 private: | 210 private: |
| 211 int32_t init_encode_return_value_ = 0; |
201 std::vector<MockVideoEncoder*> encoders_; | 212 std::vector<MockVideoEncoder*> encoders_; |
202 std::vector<const char*> encoder_names_; | 213 std::vector<const char*> encoder_names_; |
203 }; | 214 }; |
204 | 215 |
205 class TestSimulcastEncoderAdapterFakeHelper { | 216 class TestSimulcastEncoderAdapterFakeHelper { |
206 public: | 217 public: |
207 TestSimulcastEncoderAdapterFakeHelper() | 218 TestSimulcastEncoderAdapterFakeHelper() |
208 : factory_(new MockVideoEncoderFactory()) {} | 219 : factory_(new MockVideoEncoderFactory()) {} |
209 | 220 |
210 // Can only be called once as the SimulcastEncoderAdapter will take the | 221 // Can only be called once as the SimulcastEncoderAdapter will take the |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 int half_width = (kDefaultWidth + 1) / 2; | 554 int half_width = (kDefaultWidth + 1) / 2; |
544 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( | 555 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( |
545 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); | 556 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); |
546 input_buffer->InitializeData(); | 557 input_buffer->InitializeData(); |
547 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); | 558 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); |
548 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 559 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
549 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 560 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
550 adapter_->Encode(input_frame, nullptr, &frame_types)); | 561 adapter_->Encode(input_frame, nullptr, &frame_types)); |
551 } | 562 } |
552 | 563 |
| 564 TEST_F(TestSimulcastEncoderAdapterFake, TestInitFailureCleansUpEncoders) { |
| 565 TestVp8Simulcast::DefaultSettings( |
| 566 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 567 codec_.VP8()->tl_factory = &tl_factory_; |
| 568 codec_.numberOfSimulcastStreams = 3; |
| 569 helper_->factory()->set_init_encode_return_value( |
| 570 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE); |
| 571 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
| 572 adapter_->InitEncode(&codec_, 1, 1200)); |
| 573 EXPECT_TRUE(helper_->factory()->encoders().empty()); |
| 574 } |
| 575 |
553 } // namespace testing | 576 } // namespace testing |
554 } // namespace webrtc | 577 } // namespace webrtc |
OLD | NEW |