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