OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 void FallbackFromEncodeRequest(); | 109 void FallbackFromEncodeRequest(); |
110 void EncodeFrame(); | 110 void EncodeFrame(); |
111 void CheckLastEncoderName(const char* expected_name) { | 111 void CheckLastEncoderName(const char* expected_name) { |
112 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); | 112 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); |
113 } | 113 } |
114 | 114 |
115 FakeEncodedImageCallback callback_; | 115 FakeEncodedImageCallback callback_; |
116 CountingFakeEncoder fake_encoder_; | 116 CountingFakeEncoder fake_encoder_; |
117 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; | 117 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; |
118 VideoCodec codec_ = {}; | 118 VideoCodec codec_ = {}; |
119 std::unique_ptr<VideoFrame> frame_; | 119 VideoFrame frame_; |
120 }; | 120 }; |
121 | 121 |
122 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { | 122 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { |
123 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( | 123 frame_.CreateEmptyFrame(kWidth, kHeight, kWidth, (kWidth + 1) / 2, |
124 kWidth, kHeight, kWidth, (kWidth + 1) / 2, (kWidth + 1) / 2); | 124 (kWidth + 1) / 2); |
125 buffer->SetToBlack(); | 125 memset(frame_.video_frame_buffer()->MutableDataY(), 16, |
| 126 frame_.allocated_size(webrtc::kYPlane)); |
| 127 memset(frame_.video_frame_buffer()->MutableDataU(), 128, |
| 128 frame_.allocated_size(webrtc::kUPlane)); |
| 129 memset(frame_.video_frame_buffer()->MutableDataV(), 128, |
| 130 frame_.allocated_size(webrtc::kVPlane)); |
| 131 |
126 std::vector<FrameType> types(1, kVideoFrameKey); | 132 std::vector<FrameType> types(1, kVideoFrameKey); |
127 | |
128 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | |
129 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 133 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
130 fallback_wrapper_.Encode(*frame_, nullptr, &types)); | 134 fallback_wrapper_.Encode(frame_, nullptr, &types)); |
131 } | 135 } |
132 | 136 |
133 void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() { | 137 void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() { |
134 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); | 138 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
135 EXPECT_EQ(&callback_, fake_encoder_.encode_complete_callback_); | 139 EXPECT_EQ(&callback_, fake_encoder_.encode_complete_callback_); |
136 | 140 |
137 // Register with failing fake encoder. Should succeed with VP8 fallback. | 141 // Register with failing fake encoder. Should succeed with VP8 fallback. |
138 codec_.codecType = kVideoCodecVP8; | 142 codec_.codecType = kVideoCodecVP8; |
139 codec_.maxFramerate = 30; | 143 codec_.maxFramerate = 30; |
140 codec_.width = kWidth; | 144 codec_.width = kWidth; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 CanRegisterCallbackWhileUsingFallbackEncoder) { | 218 CanRegisterCallbackWhileUsingFallbackEncoder) { |
215 UtilizeFallbackEncoder(); | 219 UtilizeFallbackEncoder(); |
216 // Registering an encode-complete callback should still work when fallback | 220 // Registering an encode-complete callback should still work when fallback |
217 // encoder is being used. | 221 // encoder is being used. |
218 FakeEncodedImageCallback callback2; | 222 FakeEncodedImageCallback callback2; |
219 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback2); | 223 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback2); |
220 EXPECT_EQ(&callback2, fake_encoder_.encode_complete_callback_); | 224 EXPECT_EQ(&callback2, fake_encoder_.encode_complete_callback_); |
221 | 225 |
222 // Encoding a frame using the fallback should arrive at the new callback. | 226 // Encoding a frame using the fallback should arrive at the new callback. |
223 std::vector<FrameType> types(1, kVideoFrameKey); | 227 std::vector<FrameType> types(1, kVideoFrameKey); |
224 frame_->set_timestamp(frame_->timestamp() + 1000); | 228 frame_.set_timestamp(frame_.timestamp() + 1000); |
225 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 229 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
226 fallback_wrapper_.Encode(*frame_, nullptr, &types)); | 230 fallback_wrapper_.Encode(frame_, nullptr, &types)); |
227 | 231 |
228 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); | 232 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); |
229 } | 233 } |
230 | 234 |
231 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 235 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
232 SetChannelParametersForwardedDuringFallback) { | 236 SetChannelParametersForwardedDuringFallback) { |
233 UtilizeFallbackEncoder(); | 237 UtilizeFallbackEncoder(); |
234 EXPECT_EQ(0, fake_encoder_.set_channel_parameters_count_); | 238 EXPECT_EQ(0, fake_encoder_.set_channel_parameters_count_); |
235 fallback_wrapper_.SetChannelParameters(1, 1); | 239 fallback_wrapper_.SetChannelParameters(1, 1); |
236 EXPECT_EQ(1, fake_encoder_.set_channel_parameters_count_); | 240 EXPECT_EQ(1, fake_encoder_.set_channel_parameters_count_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 288 |
285 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 289 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
286 ReportsFallbackImplementationName) { | 290 ReportsFallbackImplementationName) { |
287 UtilizeFallbackEncoder(); | 291 UtilizeFallbackEncoder(); |
288 // Hard coded expected value since libvpx is the software implementation name | 292 // Hard coded expected value since libvpx is the software implementation name |
289 // for VP8. Change accordingly if the underlying implementation does. | 293 // for VP8. Change accordingly if the underlying implementation does. |
290 CheckLastEncoderName("libvpx"); | 294 CheckLastEncoderName("libvpx"); |
291 } | 295 } |
292 | 296 |
293 } // namespace webrtc | 297 } // namespace webrtc |
OLD | NEW |