| 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/base/checks.h" | |
| 14 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | |
| 15 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 13 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 16 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 14 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
| 17 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | |
| 18 #include "webrtc/test/gtest.h" | 15 #include "webrtc/test/gtest.h" |
| 19 | 16 |
| 20 namespace webrtc { | 17 namespace webrtc { |
| 21 | 18 |
| 22 const int kWidth = 320; | 19 const int kWidth = 320; |
| 23 const int kHeight = 240; | 20 const int kHeight = 240; |
| 24 const size_t kMaxPayloadSize = 800; | 21 const size_t kMaxPayloadSize = 800; |
| 25 | 22 |
| 26 class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { | 23 class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { |
| 27 protected: | 24 protected: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 int32_t Release() override { | 56 int32_t Release() override { |
| 60 ++release_count_; | 57 ++release_count_; |
| 61 return WEBRTC_VIDEO_CODEC_OK; | 58 return WEBRTC_VIDEO_CODEC_OK; |
| 62 } | 59 } |
| 63 | 60 |
| 64 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override { | 61 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override { |
| 65 ++set_channel_parameters_count_; | 62 ++set_channel_parameters_count_; |
| 66 return WEBRTC_VIDEO_CODEC_OK; | 63 return WEBRTC_VIDEO_CODEC_OK; |
| 67 } | 64 } |
| 68 | 65 |
| 69 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, | 66 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override { |
| 70 uint32_t framerate) override { | |
| 71 ++set_rates_count_; | 67 ++set_rates_count_; |
| 72 return WEBRTC_VIDEO_CODEC_OK; | 68 return WEBRTC_VIDEO_CODEC_OK; |
| 73 } | 69 } |
| 74 | 70 |
| 75 void OnDroppedFrame() override { ++on_dropped_frame_count_; } | 71 void OnDroppedFrame() override { ++on_dropped_frame_count_; } |
| 76 | 72 |
| 77 bool SupportsNativeHandle() const override { | 73 bool SupportsNativeHandle() const override { |
| 78 ++supports_native_handle_count_; | 74 ++supports_native_handle_count_; |
| 79 return false; | 75 return false; |
| 80 } | 76 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void EncodeFrame(); | 110 void EncodeFrame(); |
| 115 void CheckLastEncoderName(const char* expected_name) { | 111 void CheckLastEncoderName(const char* expected_name) { |
| 116 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); | 112 EXPECT_STREQ(expected_name, callback_.last_codec_name_.c_str()); |
| 117 } | 113 } |
| 118 | 114 |
| 119 FakeEncodedImageCallback callback_; | 115 FakeEncodedImageCallback callback_; |
| 120 CountingFakeEncoder fake_encoder_; | 116 CountingFakeEncoder fake_encoder_; |
| 121 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; | 117 VideoEncoderSoftwareFallbackWrapper fallback_wrapper_; |
| 122 VideoCodec codec_ = {}; | 118 VideoCodec codec_ = {}; |
| 123 std::unique_ptr<VideoFrame> frame_; | 119 std::unique_ptr<VideoFrame> frame_; |
| 124 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; | |
| 125 }; | 120 }; |
| 126 | 121 |
| 127 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { | 122 void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { |
| 128 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( | 123 rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create( |
| 129 kWidth, kHeight, kWidth, (kWidth + 1) / 2, (kWidth + 1) / 2); | 124 kWidth, kHeight, kWidth, (kWidth + 1) / 2, (kWidth + 1) / 2); |
| 130 buffer->SetToBlack(); | 125 buffer->SetToBlack(); |
| 131 std::vector<FrameType> types(1, kVideoFrameKey); | 126 std::vector<FrameType> types(1, kVideoFrameKey); |
| 132 | 127 |
| 133 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | 128 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
| 134 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 129 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 135 fallback_wrapper_.Encode(*frame_, nullptr, &types)); | 130 fallback_wrapper_.Encode(*frame_, nullptr, &types)); |
| 136 } | 131 } |
| 137 | 132 |
| 138 void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() { | 133 void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() { |
| 139 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); | 134 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
| 140 EXPECT_EQ(&callback_, fake_encoder_.encode_complete_callback_); | 135 EXPECT_EQ(&callback_, fake_encoder_.encode_complete_callback_); |
| 141 | 136 |
| 142 // Register with failing fake encoder. Should succeed with VP8 fallback. | 137 // Register with failing fake encoder. Should succeed with VP8 fallback. |
| 143 codec_.codecType = kVideoCodecVP8; | 138 codec_.codecType = kVideoCodecVP8; |
| 144 codec_.maxFramerate = 30; | 139 codec_.maxFramerate = 30; |
| 145 codec_.width = kWidth; | 140 codec_.width = kWidth; |
| 146 codec_.height = kHeight; | 141 codec_.height = kHeight; |
| 147 codec_.codecSpecific.VP8.numberOfTemporalLayers = 1; | |
| 148 std::unique_ptr<TemporalLayersFactory> tl_factory( | |
| 149 new TemporalLayersFactory()); | |
| 150 codec_.codecSpecific.VP8.tl_factory = tl_factory.get(); | |
| 151 rate_allocator_.reset( | |
| 152 new SimulcastRateAllocator(codec_, std::move(tl_factory))); | |
| 153 | |
| 154 fake_encoder_.init_encode_return_code_ = WEBRTC_VIDEO_CODEC_ERROR; | 142 fake_encoder_.init_encode_return_code_ = WEBRTC_VIDEO_CODEC_ERROR; |
| 155 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 143 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 156 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize)); | 144 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize)); |
| 157 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 145 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRates(300, 30)); |
| 158 fallback_wrapper_.SetRateAllocation( | |
| 159 rate_allocator_->GetAllocation(300000, 30), 30)); | |
| 160 | 146 |
| 161 int callback_count = callback_.callback_count_; | 147 int callback_count = callback_.callback_count_; |
| 162 int encode_count = fake_encoder_.encode_count_; | 148 int encode_count = fake_encoder_.encode_count_; |
| 163 EncodeFrame(); | 149 EncodeFrame(); |
| 164 EXPECT_EQ(encode_count, fake_encoder_.encode_count_); | 150 EXPECT_EQ(encode_count, fake_encoder_.encode_count_); |
| 165 EXPECT_EQ(callback_count + 1, callback_.callback_count_); | 151 EXPECT_EQ(callback_count + 1, callback_.callback_count_); |
| 166 } | 152 } |
| 167 | 153 |
| 168 void VideoEncoderSoftwareFallbackWrapperTest::FallbackFromEncodeRequest() { | 154 void VideoEncoderSoftwareFallbackWrapperTest::FallbackFromEncodeRequest() { |
| 169 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); | 155 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
| 170 codec_.codecType = kVideoCodecVP8; | 156 codec_.codecType = kVideoCodecVP8; |
| 171 codec_.maxFramerate = 30; | 157 codec_.maxFramerate = 30; |
| 172 codec_.width = kWidth; | 158 codec_.width = kWidth; |
| 173 codec_.height = kHeight; | 159 codec_.height = kHeight; |
| 174 codec_.codecSpecific.VP8.numberOfTemporalLayers = 1; | |
| 175 std::unique_ptr<TemporalLayersFactory> tl_factory( | |
| 176 new TemporalLayersFactory()); | |
| 177 codec_.codecSpecific.VP8.tl_factory = tl_factory.get(); | |
| 178 rate_allocator_.reset( | |
| 179 new SimulcastRateAllocator(codec_, std::move(tl_factory))); | |
| 180 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize); | 160 fallback_wrapper_.InitEncode(&codec_, 2, kMaxPayloadSize); |
| 181 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 161 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRates(300, 30)); |
| 182 fallback_wrapper_.SetRateAllocation( | |
| 183 rate_allocator_->GetAllocation(300000, 30), 30)); | |
| 184 EXPECT_EQ(1, fake_encoder_.init_encode_count_); | 162 EXPECT_EQ(1, fake_encoder_.init_encode_count_); |
| 185 | 163 |
| 186 // Have the non-fallback encoder request a software fallback. | 164 // Have the non-fallback encoder request a software fallback. |
| 187 fake_encoder_.encode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; | 165 fake_encoder_.encode_return_code_ = WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE; |
| 188 int callback_count = callback_.callback_count_; | 166 int callback_count = callback_.callback_count_; |
| 189 int encode_count = fake_encoder_.encode_count_; | 167 int encode_count = fake_encoder_.encode_count_; |
| 190 EncodeFrame(); | 168 EncodeFrame(); |
| 191 // Single encode request, which returned failure. | 169 // Single encode request, which returned failure. |
| 192 EXPECT_EQ(encode_count + 1, fake_encoder_.encode_count_); | 170 EXPECT_EQ(encode_count + 1, fake_encoder_.encode_count_); |
| 193 EXPECT_EQ(callback_count + 1, callback_.callback_count_); | 171 EXPECT_EQ(callback_count + 1, callback_.callback_count_); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_EQ(0, fake_encoder_.set_channel_parameters_count_); | 234 EXPECT_EQ(0, fake_encoder_.set_channel_parameters_count_); |
| 257 fallback_wrapper_.SetChannelParameters(1, 1); | 235 fallback_wrapper_.SetChannelParameters(1, 1); |
| 258 EXPECT_EQ(1, fake_encoder_.set_channel_parameters_count_); | 236 EXPECT_EQ(1, fake_encoder_.set_channel_parameters_count_); |
| 259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); | 237 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); |
| 260 } | 238 } |
| 261 | 239 |
| 262 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 240 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
| 263 SetRatesForwardedDuringFallback) { | 241 SetRatesForwardedDuringFallback) { |
| 264 UtilizeFallbackEncoder(); | 242 UtilizeFallbackEncoder(); |
| 265 EXPECT_EQ(1, fake_encoder_.set_rates_count_); | 243 EXPECT_EQ(1, fake_encoder_.set_rates_count_); |
| 266 fallback_wrapper_.SetRateAllocation(BitrateAllocation(), 1); | 244 fallback_wrapper_.SetRates(1, 1); |
| 267 EXPECT_EQ(2, fake_encoder_.set_rates_count_); | 245 EXPECT_EQ(2, fake_encoder_.set_rates_count_); |
| 268 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); | 246 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.Release()); |
| 269 } | 247 } |
| 270 | 248 |
| 271 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 249 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
| 272 OnDroppedFrameForwardedWithoutFallback) { | 250 OnDroppedFrameForwardedWithoutFallback) { |
| 273 fallback_wrapper_.OnDroppedFrame(); | 251 fallback_wrapper_.OnDroppedFrame(); |
| 274 EXPECT_EQ(1, fake_encoder_.on_dropped_frame_count_); | 252 EXPECT_EQ(1, fake_encoder_.on_dropped_frame_count_); |
| 275 } | 253 } |
| 276 | 254 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 306 | 284 |
| 307 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, | 285 TEST_F(VideoEncoderSoftwareFallbackWrapperTest, |
| 308 ReportsFallbackImplementationName) { | 286 ReportsFallbackImplementationName) { |
| 309 UtilizeFallbackEncoder(); | 287 UtilizeFallbackEncoder(); |
| 310 // Hard coded expected value since libvpx is the software implementation name | 288 // Hard coded expected value since libvpx is the software implementation name |
| 311 // for VP8. Change accordingly if the underlying implementation does. | 289 // for VP8. Change accordingly if the underlying implementation does. |
| 312 CheckLastEncoderName("libvpx"); | 290 CheckLastEncoderName("libvpx"); |
| 313 } | 291 } |
| 314 | 292 |
| 315 } // namespace webrtc | 293 } // namespace webrtc |
| OLD | NEW |