| 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 |
| 11 #include "webrtc/video_encoder.h" | 11 #include "webrtc/video_encoder.h" |
| 12 | 12 |
| 13 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 13 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 14 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 14 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 15 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
| 15 #include "webrtc/test/gtest.h" | 16 #include "webrtc/test/gtest.h" |
| 16 | 17 |
| 17 namespace webrtc { | 18 namespace webrtc { |
| 18 | 19 |
| 19 const int kWidth = 320; | 20 const int kWidth = 320; |
| 20 const int kHeight = 240; | 21 const int kHeight = 240; |
| 21 const size_t kMaxPayloadSize = 800; | 22 const size_t kMaxPayloadSize = 800; |
| 22 | 23 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void EncodeFrame(); | 111 void EncodeFrame(); |
| 111 void CheckLastEncoderName(const char* expected_name) { | 112 void CheckLastEncoderName(const char* expected_name) { |
| 112 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); | 113 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); |
| 113 } | 114 } |
| 114 | 115 |
| 115 FakeEncodedImageCallback callback_; | 116 FakeEncodedImageCallback callback_; |
| 116 CountingFakeEncoder fake_encoder_; | 117 CountingFakeEncoder fake_encoder_; |
| 117 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; | 118 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; |
| 118 VideoCodec codec_ = {}; | 119 VideoCodec codec_ = {}; |
| 119 std::unique_ptr<VideoFrame> frame_; | 120 std::unique_ptr<VideoFrame> frame_; |
| 121 TemporalLayersFactory tl_factory_; |
| 120 }; | 122 }; |
| 121 | 123 |
| 122 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { | 124 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { |
| 123 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( | 125 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( |
| 124 kWidth, kHeight, kWidth, (kWidth + 1) / 2, (kWidth + 1) / 2); | 126 kWidth, kHeight, kWidth, (kWidth + 1) / 2, (kWidth + 1) / 2); |
| 125 buffer->SetToBlack(); | 127 buffer->SetToBlack(); |
| 126 std::vector<FrameType> types(1, kVideoFrameKey); | 128 std::vector<FrameType> types(1, kVideoFrameKey); |
| 127 | 129 |
| 128 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | 130 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
| 129 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 131 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 130 fallback_wrapper_.Encode(*frame_, nullptr, &types)); | 132 fallback_wrapper_.Encode(*frame_, nullptr, &types)); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() { | 135 void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() { |
| 134 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); | 136 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
| 135 EXPECT_EQ(&callback_, fake_encoder_.encode_complete_callback_); | 137 EXPECT_EQ(&callback_, fake_encoder_.encode_complete_callback_); |
| 136 | 138 |
| 137 // Register with failing fake encoder. Should succeed with VP8 fallback. | 139 // Register with failing fake encoder. Should succeed with VP8 fallback. |
| 138 codec_.codecType = kVideoCodecVP8; | 140 codec_.codecType = kVideoCodecVP8; |
| 139 codec_.maxFramerate = 30; | 141 codec_.maxFramerate = 30; |
| 140 codec_.width = kWidth; | 142 codec_.width = kWidth; |
| 141 codec_.height = kHeight; | 143 codec_.height = kHeight; |
| 144 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 142 fake_encoder_.init_encode_return_code_ = WEBRTC_VIDEO_CODEC_ERROR; | 145 fake_encoder_.init_encode_return_code_ = WEBRTC_VIDEO_CODEC_ERROR; |
| 143 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 146 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 144 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize)); | 147 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize)); |
| 145 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRates(300, 30)); | 148 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRates(300, 30)); |
| 146 | 149 |
| 147 int callback_count = callback_.callback_count_; | 150 int callback_count = callback_.callback_count_; |
| 148 int encode_count = fake_encoder_.encode_count_; | 151 int encode_count = fake_encoder_.encode_count_; |
| 149 EncodeFrame(); | 152 EncodeFrame(); |
| 150 EXPECT_EQ(encode_count, fake_encoder_.encode_count_); | 153 EXPECT_EQ(encode_count, fake_encoder_.encode_count_); |
| 151 EXPECT_EQ(callback_count + 1, callback_.callback_count_); | 154 EXPECT_EQ(callback_count + 1, callback_.callback_count_); |
| 152 } | 155 } |
| 153 | 156 |
| 154 void VideoEncoderSoftwareFallbackWrapperTest::FallbackFromEncodeRequest() { | 157 void VideoEncoderSoftwareFallbackWrapperTest::FallbackFromEncodeRequest() { |
| 155 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); | 158 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
| 156 codec_.codecType = kVideoCodecVP8; | 159 codec_.codecType = kVideoCodecVP8; |
| 157 codec_.maxFramerate = 30; | 160 codec_.maxFramerate = 30; |
| 158 codec_.width = kWidth; | 161 codec_.width = kWidth; |
| 159 codec_.height = kHeight; | 162 codec_.height = kHeight; |
| 163 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 160 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize); | 164 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize); |
| 161 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRates(300, 30)); | 165 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRates(300, 30)); |
| 162 EXPECT_EQ(1, fake_encoder_.init_encode_count_); | 166 EXPECT_EQ(1, fake_encoder_.init_encode_count_); |
| 163 | 167 |
| 164 // Have the non-fallback encoder request a software fallback. | 168 // Have the non-fallback encoder request a software fallback. |
| 165 fake_encoder_.encode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; | 169 fake_encoder_.encode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; |
| 166 int callback_count = callback_.callback_count_; | 170 int callback_count = callback_.callback_count_; |
| 167 int encode_count = fake_encoder_.encode_count_; | 171 int encode_count = fake_encoder_.encode_count_; |
| 168 EncodeFrame(); | 172 EncodeFrame(); |
| 169 // Single encode request, which returned failure. | 173 // Single encode request, which returned failure. |
| (...skipping 114 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 |