OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <map> | |
15 #include <memory> | 16 #include <memory> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
20 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 21 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
21 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 22 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
22 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" | 23 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" |
23 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
24 #include "webrtc/video_frame.h" | 25 #include "webrtc/video_frame.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 | 146 |
146 private: | 147 private: |
147 int decoded_frames_; | 148 int decoded_frames_; |
148 }; | 149 }; |
149 | 150 |
150 class SkipEncodingUnusedStreamsTest { | 151 class SkipEncodingUnusedStreamsTest { |
151 public: | 152 public: |
152 std::vector<unsigned int> RunTest(VP8Encoder* encoder, | 153 std::vector<unsigned int> RunTest(VP8Encoder* encoder, |
153 VideoCodec* settings, | 154 VideoCodec* settings, |
154 uint32_t target_bitrate) { | 155 uint32_t target_bitrate) { |
156 class TemporalLayersIndex : public TemporalLayersListener { | |
157 public: | |
158 TemporalLayersIndex() {} | |
159 ~TemporalLayersIndex() override {} | |
160 | |
161 void OnTemporalLayersCreated(int simulcast_id, | |
162 TemporalLayers* layers) override { | |
163 temporal_layers_[simulcast_id] = layers; | |
164 } | |
165 | |
166 std::map<int, TemporalLayers*> temporal_layers_; | |
167 } tl_index; | |
168 | |
155 SpyingTemporalLayersFactory spy_factory; | 169 SpyingTemporalLayersFactory spy_factory; |
170 spy_factory.SetListener(&tl_index); | |
156 settings->codecSpecific.VP8.tl_factory = &spy_factory; | 171 settings->codecSpecific.VP8.tl_factory = &spy_factory; |
157 EXPECT_EQ(0, encoder->InitEncode(settings, 1, 1200)); | 172 EXPECT_EQ(0, encoder->InitEncode(settings, 1, 1200)); |
158 | 173 |
159 encoder->SetRates(target_bitrate, 30); | 174 encoder->SetRates(target_bitrate, 30); |
160 | 175 |
176 int expected_index = 0; | |
161 std::vector<unsigned int> configured_bitrates; | 177 std::vector<unsigned int> configured_bitrates; |
162 for (std::vector<TemporalLayers*>::const_iterator it = | 178 for (auto it : tl_index.temporal_layers_) { |
163 spy_factory.spying_layers_.begin(); | 179 EXPECT_EQ(expected_index++, it.first); |
164 it != spy_factory.spying_layers_.end(); ++it) { | |
165 configured_bitrates.push_back( | 180 configured_bitrates.push_back( |
166 static_cast<SpyingTemporalLayers*>(*it)->configured_bitrate_); | 181 static_cast<SpyingTemporalLayers*>(it.second)->configured_bitrate_); |
167 } | 182 } |
168 return configured_bitrates; | 183 return configured_bitrates; |
169 } | 184 } |
170 | 185 |
171 class SpyingTemporalLayers : public TemporalLayers { | 186 class SpyingTemporalLayers : public TemporalLayers { |
172 public: | 187 public: |
173 explicit SpyingTemporalLayers(TemporalLayers* layers) | 188 explicit SpyingTemporalLayers(TemporalLayers* layers) |
174 : configured_bitrate_(0), layers_(layers) {} | 189 : configured_bitrate_(0), layers_(layers) {} |
175 | 190 |
176 virtual ~SpyingTemporalLayers() { delete layers_; } | 191 virtual ~SpyingTemporalLayers() { delete layers_; } |
177 | 192 |
178 int EncodeFlags(uint32_t timestamp) override { | 193 int EncodeFlags(uint32_t timestamp) override { |
179 return layers_->EncodeFlags(timestamp); | 194 return layers_->EncodeFlags(timestamp); |
180 } | 195 } |
181 | 196 |
182 bool ConfigureBitrates(int bitrate_kbit, | 197 std::vector<uint32_t> OnRatesUpdated(int bitrate_kbit, |
183 int max_bitrate_kbit, | 198 int max_bitrate_kbit, |
184 int framerate, | 199 int framerate) override { |
185 vpx_codec_enc_cfg_t* cfg) override { | |
186 configured_bitrate_ = bitrate_kbit; | 200 configured_bitrate_ = bitrate_kbit; |
187 return layers_->ConfigureBitrates(bitrate_kbit, max_bitrate_kbit, | 201 return layers_->OnRatesUpdated(bitrate_kbit, max_bitrate_kbit, framerate); |
188 framerate, cfg); | |
189 } | 202 } |
190 | 203 |
191 void PopulateCodecSpecific(bool base_layer_sync, | 204 void PopulateCodecSpecific(bool base_layer_sync, |
192 CodecSpecificInfoVP8* vp8_info, | 205 CodecSpecificInfoVP8* vp8_info, |
193 uint32_t timestamp) override { | 206 uint32_t timestamp) override { |
194 layers_->PopulateCodecSpecific(base_layer_sync, vp8_info, timestamp); | 207 layers_->PopulateCodecSpecific(base_layer_sync, vp8_info, timestamp); |
195 } | 208 } |
196 | 209 |
197 void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override { | 210 void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override { |
198 layers_->FrameEncoded(size, timestamp, qp); | 211 layers_->FrameEncoded(size, timestamp, qp); |
199 } | 212 } |
200 | 213 |
201 int CurrentLayerId() const override { return layers_->CurrentLayerId(); } | 214 int CurrentLayerId() const override { return layers_->CurrentLayerId(); } |
202 | 215 |
203 bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override { | 216 bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override { |
204 return false; | 217 return false; |
205 } | 218 } |
206 | 219 |
207 int configured_bitrate_; | 220 int configured_bitrate_; |
208 TemporalLayers* layers_; | 221 TemporalLayers* layers_; |
209 }; | 222 }; |
210 | 223 |
211 class SpyingTemporalLayersFactory : public TemporalLayersFactory { | 224 class SpyingTemporalLayersFactory : public TemporalLayersFactory { |
212 public: | 225 public: |
226 SpyingTemporalLayersFactory() {} | |
213 virtual ~SpyingTemporalLayersFactory() {} | 227 virtual ~SpyingTemporalLayersFactory() {} |
214 TemporalLayers* Create(int temporal_layers, | 228 TemporalLayers* Create(int simulcast_id, |
229 int temporal_layers, | |
215 uint8_t initial_tl0_pic_idx) const override { | 230 uint8_t initial_tl0_pic_idx) const override { |
216 SpyingTemporalLayers* layers = | 231 SpyingTemporalLayers* layers = |
217 new SpyingTemporalLayers(TemporalLayersFactory::Create( | 232 new SpyingTemporalLayers(TemporalLayersFactory::Create( |
218 temporal_layers, initial_tl0_pic_idx)); | 233 simulcast_id, temporal_layers, initial_tl0_pic_idx)); |
219 spying_layers_.push_back(layers); | 234 if (listener_) |
235 listener_->OnTemporalLayersCreated(simulcast_id, layers); | |
220 return layers; | 236 return layers; |
221 } | 237 } |
222 | |
223 mutable std::vector<TemporalLayers*> spying_layers_; | |
224 }; | 238 }; |
225 }; | 239 }; |
226 | 240 |
227 class TestVp8Simulcast : public ::testing::Test { | 241 class TestVp8Simulcast : public ::testing::Test { |
228 public: | 242 public: |
229 TestVp8Simulcast(VP8Encoder* encoder, VP8Decoder* decoder) | 243 TestVp8Simulcast(VP8Encoder* encoder, VP8Decoder* decoder) |
230 : encoder_(encoder), decoder_(decoder) {} | 244 : encoder_(encoder), decoder_(decoder) {} |
231 | 245 |
232 static void SetPlane(uint8_t* data, | 246 static void SetPlane(uint8_t* data, |
233 uint8_t value, | 247 uint8_t value, |
(...skipping 24 matching lines...) Expand all Loading... | |
258 chroma_width, chroma_height, | 272 chroma_width, chroma_height, |
259 buffer->StrideU()); | 273 buffer->StrideU()); |
260 | 274 |
261 SetPlane(buffer->MutableDataV(), plane_colors[2], | 275 SetPlane(buffer->MutableDataV(), plane_colors[2], |
262 chroma_width, chroma_height, | 276 chroma_width, chroma_height, |
263 buffer->StrideV()); | 277 buffer->StrideV()); |
264 } | 278 } |
265 | 279 |
266 static void DefaultSettings(VideoCodec* settings, | 280 static void DefaultSettings(VideoCodec* settings, |
267 const int* temporal_layer_profile) { | 281 const int* temporal_layer_profile) { |
268 assert(settings); | 282 ASSERT_TRUE(settings); |
perkj_webrtc
2016/10/21 08:24:28
DCHECK or CHECK
sprang_webrtc
2016/10/25 10:44:25
Done.
| |
269 memset(settings, 0, sizeof(VideoCodec)); | 283 memset(settings, 0, sizeof(VideoCodec)); |
270 strncpy(settings->plName, "VP8", 4); | 284 strncpy(settings->plName, "VP8", 4); |
271 settings->codecType = kVideoCodecVP8; | 285 settings->codecType = kVideoCodecVP8; |
272 // 96 to 127 dynamic payload types for video codecs | 286 // 96 to 127 dynamic payload types for video codecs |
273 settings->plType = 120; | 287 settings->plType = 120; |
274 settings->startBitrate = 300; | 288 settings->startBitrate = 300; |
275 settings->minBitrate = 30; | 289 settings->minBitrate = 30; |
276 settings->maxBitrate = 0; | 290 settings->maxBitrate = 0; |
277 settings->maxFramerate = 30; | 291 settings->maxFramerate = 30; |
278 settings->width = kDefaultWidth; | 292 settings->width = kDefaultWidth; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 stream->qpMax = 45; | 328 stream->qpMax = 45; |
315 } | 329 } |
316 | 330 |
317 protected: | 331 protected: |
318 virtual void SetUp() { SetUpCodec(kDefaultTemporalLayerProfile); } | 332 virtual void SetUp() { SetUpCodec(kDefaultTemporalLayerProfile); } |
319 | 333 |
320 virtual void SetUpCodec(const int* temporal_layer_profile) { | 334 virtual void SetUpCodec(const int* temporal_layer_profile) { |
321 encoder_->RegisterEncodeCompleteCallback(&encoder_callback_); | 335 encoder_->RegisterEncodeCompleteCallback(&encoder_callback_); |
322 decoder_->RegisterDecodeCompleteCallback(&decoder_callback_); | 336 decoder_->RegisterDecodeCompleteCallback(&decoder_callback_); |
323 DefaultSettings(&settings_, temporal_layer_profile); | 337 DefaultSettings(&settings_, temporal_layer_profile); |
338 settings_.codecSpecific.VP8.tl_factory = &tl_factory_; | |
324 EXPECT_EQ(0, encoder_->InitEncode(&settings_, 1, 1200)); | 339 EXPECT_EQ(0, encoder_->InitEncode(&settings_, 1, 1200)); |
325 EXPECT_EQ(0, decoder_->InitDecode(&settings_, 1)); | 340 EXPECT_EQ(0, decoder_->InitDecode(&settings_, 1)); |
326 int half_width = (kDefaultWidth + 1) / 2; | 341 int half_width = (kDefaultWidth + 1) / 2; |
327 input_buffer_ = I420Buffer::Create(kDefaultWidth, kDefaultHeight, | 342 input_buffer_ = I420Buffer::Create(kDefaultWidth, kDefaultHeight, |
328 kDefaultWidth, half_width, half_width); | 343 kDefaultWidth, half_width, half_width); |
329 input_buffer_->InitializeData(); | 344 input_buffer_->InitializeData(); |
330 input_frame_.reset( | 345 input_frame_.reset( |
331 new VideoFrame(input_buffer_, 0, 0, webrtc::kVideoRotation_0)); | 346 new VideoFrame(input_buffer_, 0, 0, webrtc::kVideoRotation_0)); |
332 } | 347 } |
333 | 348 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 Field(&EncodedImage::_encodedWidth, width), | 617 Field(&EncodedImage::_encodedWidth, width), |
603 Field(&EncodedImage::_encodedHeight, height)), | 618 Field(&EncodedImage::_encodedHeight, height)), |
604 _, _)) | 619 _, _)) |
605 .Times(1) | 620 .Times(1) |
606 .WillRepeatedly(Return( | 621 .WillRepeatedly(Return( |
607 EncodedImageCallback::Result(EncodedImageCallback::Result::OK, 0))); | 622 EncodedImageCallback::Result(EncodedImageCallback::Result::OK, 0))); |
608 EXPECT_EQ(0, encoder_->Encode(*input_frame_, NULL, &frame_types)); | 623 EXPECT_EQ(0, encoder_->Encode(*input_frame_, NULL, &frame_types)); |
609 | 624 |
610 // Switch back. | 625 // Switch back. |
611 DefaultSettings(&settings_, kDefaultTemporalLayerProfile); | 626 DefaultSettings(&settings_, kDefaultTemporalLayerProfile); |
627 settings_.codecSpecific.VP8.tl_factory = &tl_factory_; | |
612 // Start at the lowest bitrate for enabling base stream. | 628 // Start at the lowest bitrate for enabling base stream. |
613 settings_.startBitrate = kMinBitrates[0]; | 629 settings_.startBitrate = kMinBitrates[0]; |
614 EXPECT_EQ(0, encoder_->InitEncode(&settings_, 1, 1200)); | 630 EXPECT_EQ(0, encoder_->InitEncode(&settings_, 1, 1200)); |
615 encoder_->SetRates(settings_.startBitrate, 30); | 631 encoder_->SetRates(settings_.startBitrate, 30); |
616 ExpectStreams(kVideoFrameKey, 1); | 632 ExpectStreams(kVideoFrameKey, 1); |
617 // Resize |input_frame_| to the new resolution. | 633 // Resize |input_frame_| to the new resolution. |
618 half_width = (settings_.width + 1) / 2; | 634 half_width = (settings_.width + 1) / 2; |
619 input_buffer_ = I420Buffer::Create(settings_.width, settings_.height, | 635 input_buffer_ = I420Buffer::Create(settings_.width, settings_.height, |
620 settings_.width, half_width, half_width); | 636 settings_.width, half_width, half_width); |
621 input_buffer_->InitializeData(); | 637 input_buffer_->InitializeData(); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
965 } | 981 } |
966 } | 982 } |
967 | 983 |
968 std::unique_ptr<VP8Encoder> encoder_; | 984 std::unique_ptr<VP8Encoder> encoder_; |
969 MockEncodedImageCallback encoder_callback_; | 985 MockEncodedImageCallback encoder_callback_; |
970 std::unique_ptr<VP8Decoder> decoder_; | 986 std::unique_ptr<VP8Decoder> decoder_; |
971 MockDecodedImageCallback decoder_callback_; | 987 MockDecodedImageCallback decoder_callback_; |
972 VideoCodec settings_; | 988 VideoCodec settings_; |
973 rtc::scoped_refptr<I420Buffer> input_buffer_; | 989 rtc::scoped_refptr<I420Buffer> input_buffer_; |
974 std::unique_ptr<VideoFrame> input_frame_; | 990 std::unique_ptr<VideoFrame> input_frame_; |
991 TemporalLayersFactory tl_factory_; | |
975 }; | 992 }; |
976 | 993 |
977 } // namespace testing | 994 } // namespace testing |
978 } // namespace webrtc | 995 } // namespace webrtc |
979 | 996 |
980 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ | 997 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SIMULCAST_UNITTEST_H_ |
OLD | NEW |