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