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

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

Issue 2795043004: Use simulcast for screenshare only in conference mode (Closed)
Patch Set: 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 262
261 void CheckLastTimeStampsMatch(int64_t ntp_time_ms, 263 void CheckLastTimeStampsMatch(int64_t ntp_time_ms,
262 uint32_t timestamp) const { 264 uint32_t timestamp) const {
263 rtc::CritScope lock(&local_crit_sect_); 265 rtc::CritScope lock(&local_crit_sect_);
264 EXPECT_EQ(timestamp_, timestamp); 266 EXPECT_EQ(timestamp_, timestamp);
265 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); 267 EXPECT_EQ(ntp_time_ms_, ntp_time_ms);
266 } 268 }
267 269
268 void SetQualityScaling(bool b) { quality_scaling_ = b; } 270 void SetQualityScaling(bool b) { quality_scaling_ = b; }
269 271
272 void ForceInitEncodeFailure(bool force_failure) {
273 rtc::CritScope lock(&local_crit_sect_);
274 force_init_encode_failed_ = force_failure;
275 }
276
270 private: 277 private:
271 int32_t Encode(const VideoFrame& input_image, 278 int32_t Encode(const VideoFrame& input_image,
272 const CodecSpecificInfo* codec_specific_info, 279 const CodecSpecificInfo* codec_specific_info,
273 const std::vector<FrameType>* frame_types) override { 280 const std::vector<FrameType>* frame_types) override {
274 bool block_encode; 281 bool block_encode;
275 { 282 {
276 rtc::CritScope lock(&local_crit_sect_); 283 rtc::CritScope lock(&local_crit_sect_);
277 EXPECT_GT(input_image.timestamp(), timestamp_); 284 EXPECT_GT(input_image.timestamp(), timestamp_);
278 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); 285 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_);
279 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); 286 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90);
280 287
281 timestamp_ = input_image.timestamp(); 288 timestamp_ = input_image.timestamp();
282 ntp_time_ms_ = input_image.ntp_time_ms(); 289 ntp_time_ms_ = input_image.ntp_time_ms();
283 last_input_width_ = input_image.width(); 290 last_input_width_ = input_image.width();
284 last_input_height_ = input_image.height(); 291 last_input_height_ = input_image.height();
285 block_encode = block_next_encode_; 292 block_encode = block_next_encode_;
286 block_next_encode_ = false; 293 block_next_encode_ = false;
287 } 294 }
288 int32_t result = 295 int32_t result =
289 FakeEncoder::Encode(input_image, codec_specific_info, frame_types); 296 FakeEncoder::Encode(input_image, codec_specific_info, frame_types);
290 if (block_encode) 297 if (block_encode)
291 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs)); 298 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs));
292 return result; 299 return result;
293 } 300 }
294 301
302 int32_t InitEncode(const VideoCodec* config,
303 int32_t number_of_cores,
304 size_t max_payload_size) override {
305 int res =
306 FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
307 rtc::CritScope lock(&local_crit_sect_);
308 if (config->codecType == kVideoCodecVP8 && config->VP8().tl_factory) {
309 // Simulate setting up temporal layers, in order to validate the life
310 // cycle of these objects.
311 int num_streams = std::max<int>(1, config->numberOfSimulcastStreams);
312 int num_temporal_layers =
313 std::max<int>(1, config->VP8().numberOfTemporalLayers);
314 for (int i = 0; i < num_streams; ++i) {
315 allocated_temporal_layers_.emplace_back(
316 config->VP8().tl_factory->Create(i, num_temporal_layers, 42));
317 }
318 }
319 if (force_init_encode_failed_)
320 return -1;
321 return res;
322 }
323
295 rtc::CriticalSection local_crit_sect_; 324 rtc::CriticalSection local_crit_sect_;
296 bool block_next_encode_ = false; 325 bool block_next_encode_ GUARDED_BY(local_crit_sect_) = false;
297 rtc::Event continue_encode_event_; 326 rtc::Event continue_encode_event_;
298 uint32_t timestamp_ = 0; 327 uint32_t timestamp_ GUARDED_BY(local_crit_sect_) = 0;
299 int64_t ntp_time_ms_ = 0; 328 int64_t ntp_time_ms_ GUARDED_BY(local_crit_sect_) = 0;
300 int last_input_width_ = 0; 329 int last_input_width_ GUARDED_BY(local_crit_sect_) = 0;
301 int last_input_height_ = 0; 330 int last_input_height_ GUARDED_BY(local_crit_sect_) = 0;
302 bool quality_scaling_ = true; 331 bool quality_scaling_ GUARDED_BY(local_crit_sect_) = true;
332 std::vector<std::unique_ptr<TemporalLayers>> allocated_temporal_layers_
333 GUARDED_BY(local_crit_sect_);
334 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false;
303 }; 335 };
304 336
305 class TestSink : public ViEEncoder::EncoderSink { 337 class TestSink : public ViEEncoder::EncoderSink {
306 public: 338 public:
307 explicit TestSink(TestEncoder* test_encoder) 339 explicit TestSink(TestEncoder* test_encoder)
308 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} 340 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {}
309 341
310 void WaitForEncodedFrame(int64_t expected_ntp_time) { 342 void WaitForEncodedFrame(int64_t expected_ntp_time) {
311 uint32_t timestamp = 0; 343 uint32_t timestamp = 0;
312 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); 344 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs));
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); 1267 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4);
1236 1268
1237 // Trigger CPU normal use, return to original resoluton; 1269 // Trigger CPU normal use, return to original resoluton;
1238 vie_encoder_->TriggerCpuNormalUsage(); 1270 vie_encoder_->TriggerCpuNormalUsage();
1239 video_source_.IncomingCapturedFrame( 1271 video_source_.IncomingCapturedFrame(
1240 CreateFrame(3, kFrameWidth, kFrameHeight)); 1272 CreateFrame(3, kFrameWidth, kFrameHeight));
1241 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); 1273 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight);
1242 1274
1243 vie_encoder_->Stop(); 1275 vie_encoder_->Stop();
1244 } 1276 }
1277
1278 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) {
1279 fake_encoder_.ForceInitEncodeFailure(true);
1280 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1281 ResetEncoder("VP8", 2, 1, true);
1282 const int kFrameWidth = 1280;
1283 const int kFrameHeight = 720;
1284 video_source_.IncomingCapturedFrame(
1285 CreateFrame(1, kFrameWidth, kFrameHeight));
1286 sink_.ExpectDroppedFrame();
1287 vie_encoder_->Stop();
1288 }
1245 } // namespace webrtc 1289 } // 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