Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: webrtc/video/vie_encoder_unittest.cc

Issue 2779163002: Use simulcast for screenshare only in conference mode (Closed)
Patch Set: Test fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 <algorithm>
11 #include <limits> 12 #include <limits>
12 #include <utility> 13 #include <utility>
13 14
14 #include "webrtc/api/video/i420_buffer.h" 15 #include "webrtc/api/video/i420_buffer.h"
15 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
16 #include "webrtc/media/base/videoadapter.h" 17 #include "webrtc/media/base/videoadapter.h"
18 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
17 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" 19 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h"
18 #include "webrtc/system_wrappers/include/metrics_default.h" 20 #include "webrtc/system_wrappers/include/metrics_default.h"
19 #include "webrtc/system_wrappers/include/sleep.h" 21 #include "webrtc/system_wrappers/include/sleep.h"
20 #include "webrtc/test/encoder_settings.h" 22 #include "webrtc/test/encoder_settings.h"
21 #include "webrtc/test/fake_encoder.h" 23 #include "webrtc/test/fake_encoder.h"
22 #include "webrtc/test/frame_generator.h" 24 #include "webrtc/test/frame_generator.h"
23 #include "webrtc/test/gmock.h" 25 #include "webrtc/test/gmock.h"
24 #include "webrtc/test/gtest.h" 26 #include "webrtc/test/gtest.h"
25 #include "webrtc/video/send_statistics_proxy.h" 27 #include "webrtc/video/send_statistics_proxy.h"
26 #include "webrtc/video/vie_encoder.h" 28 #include "webrtc/video/vie_encoder.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 rtc::CritScope lock(&local_crit_sect_); 277 rtc::CritScope lock(&local_crit_sect_);
276 EXPECT_EQ(timestamp_, timestamp); 278 EXPECT_EQ(timestamp_, timestamp);
277 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); 279 EXPECT_EQ(ntp_time_ms_, ntp_time_ms);
278 } 280 }
279 281
280 void SetQualityScaling(bool b) { 282 void SetQualityScaling(bool b) {
281 rtc::CritScope lock(&local_crit_sect_); 283 rtc::CritScope lock(&local_crit_sect_);
282 quality_scaling_ = b; 284 quality_scaling_ = b;
283 } 285 }
284 286
287 void ForceInitEncodeFailure(bool force_failure) {
288 rtc::CritScope lock(&local_crit_sect_);
289 force_init_encode_failed_ = force_failure;
290 }
291
285 private: 292 private:
286 int32_t Encode(const VideoFrame& input_image, 293 int32_t Encode(const VideoFrame& input_image,
287 const CodecSpecificInfo* codec_specific_info, 294 const CodecSpecificInfo* codec_specific_info,
288 const std::vector<FrameType>* frame_types) override { 295 const std::vector<FrameType>* frame_types) override {
289 bool block_encode; 296 bool block_encode;
290 { 297 {
291 rtc::CritScope lock(&local_crit_sect_); 298 rtc::CritScope lock(&local_crit_sect_);
292 EXPECT_GT(input_image.timestamp(), timestamp_); 299 EXPECT_GT(input_image.timestamp(), timestamp_);
293 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); 300 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_);
294 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); 301 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90);
295 302
296 timestamp_ = input_image.timestamp(); 303 timestamp_ = input_image.timestamp();
297 ntp_time_ms_ = input_image.ntp_time_ms(); 304 ntp_time_ms_ = input_image.ntp_time_ms();
298 last_input_width_ = input_image.width(); 305 last_input_width_ = input_image.width();
299 last_input_height_ = input_image.height(); 306 last_input_height_ = input_image.height();
300 block_encode = block_next_encode_; 307 block_encode = block_next_encode_;
301 block_next_encode_ = false; 308 block_next_encode_ = false;
302 } 309 }
303 int32_t result = 310 int32_t result =
304 FakeEncoder::Encode(input_image, codec_specific_info, frame_types); 311 FakeEncoder::Encode(input_image, codec_specific_info, frame_types);
305 if (block_encode) 312 if (block_encode)
306 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs)); 313 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs));
307 return result; 314 return result;
308 } 315 }
309 316
317 int32_t InitEncode(const VideoCodec* config,
318 int32_t number_of_cores,
319 size_t max_payload_size) override {
320 int res =
321 FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
322 rtc::CritScope lock(&local_crit_sect_);
323 if (config->codecType == kVideoCodecVP8 && config->VP8().tl_factory) {
324 // Simulate setting up temporal layers, in order to validate the life
325 // cycle of these objects.
326 int num_streams = std::max<int>(1, config->numberOfSimulcastStreams);
327 int num_temporal_layers =
328 std::max<int>(1, config->VP8().numberOfTemporalLayers);
329 for (int i = 0; i < num_streams; ++i) {
330 allocated_temporal_layers_.emplace_back(
331 config->VP8().tl_factory->Create(i, num_temporal_layers, 42));
332 }
333 }
334 if (force_init_encode_failed_)
335 return -1;
336 return res;
337 }
338
310 rtc::CriticalSection local_crit_sect_; 339 rtc::CriticalSection local_crit_sect_;
311 bool block_next_encode_ = false; 340 bool block_next_encode_ GUARDED_BY(local_crit_sect_) = false;
312 rtc::Event continue_encode_event_; 341 rtc::Event continue_encode_event_;
313 uint32_t timestamp_ = 0; 342 uint32_t timestamp_ GUARDED_BY(local_crit_sect_) = 0;
314 int64_t ntp_time_ms_ = 0; 343 int64_t ntp_time_ms_ GUARDED_BY(local_crit_sect_) = 0;
315 int last_input_width_ = 0; 344 int last_input_width_ GUARDED_BY(local_crit_sect_) = 0;
316 int last_input_height_ = 0; 345 int last_input_height_ GUARDED_BY(local_crit_sect_) = 0;
317 bool quality_scaling_ = true; 346 bool quality_scaling_ GUARDED_BY(local_crit_sect_) = true;
347 std::vector<std::unique_ptr<TemporalLayers>> allocated_temporal_layers_
348 GUARDED_BY(local_crit_sect_);
349 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false;
318 }; 350 };
319 351
320 class TestSink : public ViEEncoder::EncoderSink { 352 class TestSink : public ViEEncoder::EncoderSink {
321 public: 353 public:
322 explicit TestSink(TestEncoder* test_encoder) 354 explicit TestSink(TestEncoder* test_encoder)
323 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} 355 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {}
324 356
325 void WaitForEncodedFrame(int64_t expected_ntp_time) { 357 void WaitForEncodedFrame(int64_t expected_ntp_time) {
326 uint32_t timestamp = 0; 358 uint32_t timestamp = 0;
327 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); 359 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs));
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); 1268 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4);
1237 1269
1238 // Trigger CPU normal use, return to original resoluton; 1270 // Trigger CPU normal use, return to original resoluton;
1239 vie_encoder_->TriggerCpuNormalUsage(); 1271 vie_encoder_->TriggerCpuNormalUsage();
1240 video_source_.IncomingCapturedFrame( 1272 video_source_.IncomingCapturedFrame(
1241 CreateFrame(3, kFrameWidth, kFrameHeight)); 1273 CreateFrame(3, kFrameWidth, kFrameHeight));
1242 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); 1274 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight);
1243 1275
1244 vie_encoder_->Stop(); 1276 vie_encoder_->Stop();
1245 } 1277 }
1278
1279 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) {
1280 fake_encoder_.ForceInitEncodeFailure(true);
1281 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1282 ResetEncoder("VP8", 2, 1, true);
1283 const int kFrameWidth = 1280;
1284 const int kFrameHeight = 720;
1285 video_source_.IncomingCapturedFrame(
1286 CreateFrame(1, kFrameWidth, kFrameHeight));
1287 sink_.ExpectDroppedFrame();
1288 vie_encoder_->Stop();
1289 }
1246 } // namespace webrtc 1290 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698