OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (vp8_info.temporalIdx != layer) { | 101 if (vp8_info.temporalIdx != layer) { |
102 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); | 102 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); |
103 } else { | 103 } else { |
104 return timestamp; | 104 return timestamp; |
105 } | 105 } |
106 } | 106 } |
107 ADD_FAILURE() << "Did not get a frame of TL" << layer << " in time."; | 107 ADD_FAILURE() << "Did not get a frame of TL" << layer << " in time."; |
108 return 0; | 108 return 0; |
109 } | 109 } |
110 | 110 |
| 111 vpx_codec_enc_cfg_t GetConfig() { |
| 112 vpx_codec_enc_cfg_t cfg; |
| 113 memset(&cfg, 0, sizeof(cfg)); |
| 114 cfg.rc_min_quantizer = 2; |
| 115 cfg.rc_max_quantizer = kDefaultQp; |
| 116 return cfg; |
| 117 } |
| 118 |
111 int min_qp_; | 119 int min_qp_; |
112 int max_qp_; | 120 int max_qp_; |
113 int frame_size_; | 121 int frame_size_; |
114 SimulatedClock clock_; | 122 SimulatedClock clock_; |
115 std::unique_ptr<ScreenshareLayers> layers_; | 123 std::unique_ptr<ScreenshareLayers> layers_; |
116 }; | 124 }; |
117 | 125 |
118 TEST_F(ScreenshareLayerTest, 1Layer) { | 126 TEST_F(ScreenshareLayerTest, 1Layer) { |
119 layers_.reset(new ScreenshareLayers(1, 0, &clock_)); | 127 layers_.reset(new ScreenshareLayers(1, 0, &clock_)); |
120 ConfigureBitrates(); | 128 ConfigureBitrates(); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 break; | 360 break; |
353 case 1: | 361 case 1: |
354 ++tl1_frames; | 362 ++tl1_frames; |
355 break; | 363 break; |
356 default: | 364 default: |
357 abort(); | 365 abort(); |
358 } | 366 } |
359 } | 367 } |
360 } | 368 } |
361 | 369 |
362 EXPECT_EQ(5, tl0_frames); | 370 EXPECT_EQ(50, tl0_frames + tl1_frames); |
363 EXPECT_EQ(45, tl1_frames); | |
364 EXPECT_EQ(50, dropped_frames); | 371 EXPECT_EQ(50, dropped_frames); |
365 } | 372 } |
366 | 373 |
367 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL0) { | 374 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL0) { |
368 vpx_codec_enc_cfg_t cfg; | 375 vpx_codec_enc_cfg_t cfg = GetConfig(); |
369 layers_->ConfigureBitrates(100, 1000, 5, &cfg); | 376 layers_->ConfigureBitrates(100, 1000, 5, &cfg); |
370 | 377 |
371 EXPECT_EQ(static_cast<unsigned int>( | 378 EXPECT_EQ(static_cast<unsigned int>( |
372 ScreenshareLayers::kMaxTL0FpsReduction * 100 + 0.5), | 379 ScreenshareLayers::kMaxTL0FpsReduction * 100 + 0.5), |
373 cfg.rc_target_bitrate); | 380 cfg.rc_target_bitrate); |
374 } | 381 } |
375 | 382 |
376 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL1) { | 383 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL1) { |
377 vpx_codec_enc_cfg_t cfg; | 384 vpx_codec_enc_cfg_t cfg = GetConfig(); |
378 layers_->ConfigureBitrates(100, 450, 5, &cfg); | 385 layers_->ConfigureBitrates(100, 450, 5, &cfg); |
379 | 386 |
380 EXPECT_EQ(static_cast<unsigned int>( | 387 EXPECT_EQ(static_cast<unsigned int>( |
381 450 / ScreenshareLayers::kAcceptableTargetOvershoot), | 388 450 / ScreenshareLayers::kAcceptableTargetOvershoot), |
382 cfg.rc_target_bitrate); | 389 cfg.rc_target_bitrate); |
383 } | 390 } |
384 | 391 |
385 TEST_F(ScreenshareLayerTest, TargetBitrateBelowTL0) { | 392 TEST_F(ScreenshareLayerTest, TargetBitrateBelowTL0) { |
386 vpx_codec_enc_cfg_t cfg; | 393 vpx_codec_enc_cfg_t cfg = GetConfig(); |
387 layers_->ConfigureBitrates(100, 100, 5, &cfg); | 394 layers_->ConfigureBitrates(100, 100, 5, &cfg); |
388 | 395 |
389 EXPECT_EQ(100U, cfg.rc_target_bitrate); | 396 EXPECT_EQ(100U, cfg.rc_target_bitrate); |
390 } | 397 } |
391 | 398 |
392 TEST_F(ScreenshareLayerTest, EncoderDrop) { | 399 TEST_F(ScreenshareLayerTest, EncoderDrop) { |
393 ConfigureBitrates(); | 400 ConfigureBitrates(); |
394 CodecSpecificInfoVP8 vp8_info; | 401 CodecSpecificInfoVP8 vp8_info; |
395 vpx_codec_enc_cfg_t cfg; | 402 vpx_codec_enc_cfg_t cfg = GetConfig(); |
396 cfg.rc_max_quantizer = kDefaultQp; | |
397 | 403 |
398 uint32_t timestamp = RunGracePeriod(); | 404 uint32_t timestamp = RunGracePeriod(); |
399 timestamp = SkipUntilTl(0, timestamp); | 405 timestamp = SkipUntilTl(0, timestamp); |
400 | 406 |
401 // Size 0 indicates dropped frame. | 407 // Size 0 indicates dropped frame. |
402 layers_->FrameEncoded(0, timestamp, kDefaultQp); | 408 layers_->FrameEncoded(0, timestamp, kDefaultQp); |
403 timestamp += kTimestampDelta5Fps; | 409 timestamp += kTimestampDelta5Fps; |
404 EXPECT_FALSE(layers_->UpdateConfiguration(&cfg)); | 410 EXPECT_FALSE(layers_->UpdateConfiguration(&cfg)); |
405 EXPECT_EQ(ScreenshareLayers::kTl0Flags, layers_->EncodeFlags(timestamp)); | 411 EXPECT_EQ(ScreenshareLayers::kTl0Flags, layers_->EncodeFlags(timestamp)); |
406 layers_->PopulateCodecSpecific(false, &vp8_info, timestamp); | 412 layers_->PopulateCodecSpecific(false, &vp8_info, timestamp); |
(...skipping 27 matching lines...) Expand all Loading... |
434 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); | 440 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); |
435 | 441 |
436 layers_->EncodeFlags(timestamp); | 442 layers_->EncodeFlags(timestamp); |
437 timestamp += kTimestampDelta5Fps; | 443 timestamp += kTimestampDelta5Fps; |
438 EXPECT_TRUE(layers_->UpdateConfiguration(&cfg)); | 444 EXPECT_TRUE(layers_->UpdateConfiguration(&cfg)); |
439 layers_->PopulateCodecSpecific(false, &vp8_info, timestamp); | 445 layers_->PopulateCodecSpecific(false, &vp8_info, timestamp); |
440 EXPECT_EQ(cfg.rc_max_quantizer, static_cast<unsigned int>(kDefaultQp)); | 446 EXPECT_EQ(cfg.rc_max_quantizer, static_cast<unsigned int>(kDefaultQp)); |
441 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); | 447 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); |
442 } | 448 } |
443 | 449 |
| 450 TEST_F(ScreenshareLayerTest, RespectsMaxIntervalBetweenFrames) { |
| 451 const int kLowBitrateKbps = 50; |
| 452 const int kLargeFrameSizeBytes = 100000; |
| 453 const uint32_t kStartTimestamp = 1234; |
| 454 |
| 455 vpx_codec_enc_cfg_t cfg = GetConfig(); |
| 456 layers_->ConfigureBitrates(kLowBitrateKbps, kLowBitrateKbps, 5, &cfg); |
| 457 |
| 458 EXPECT_EQ(ScreenshareLayers::kTl0Flags, |
| 459 layers_->EncodeFlags(kStartTimestamp)); |
| 460 layers_->FrameEncoded(kLargeFrameSizeBytes, kStartTimestamp, kDefaultQp); |
| 461 |
| 462 const uint32_t kTwoSecondsLater = |
| 463 kStartTimestamp + (ScreenshareLayers::kMaxFrameIntervalMs * 90); |
| 464 |
| 465 // Sanity check, repayment time should exceed kMaxFrameIntervalMs. |
| 466 ASSERT_GT(kStartTimestamp + 90 * (kLargeFrameSizeBytes * 8) / kLowBitrateKbps, |
| 467 kStartTimestamp + (ScreenshareLayers::kMaxFrameIntervalMs * 90)); |
| 468 |
| 469 EXPECT_EQ(-1, layers_->EncodeFlags(kTwoSecondsLater)); |
| 470 // More than two seconds has passed since last frame, one should be emitted |
| 471 // even if bitrate target is then exceeded. |
| 472 EXPECT_EQ(ScreenshareLayers::kTl0Flags, |
| 473 layers_->EncodeFlags(kTwoSecondsLater + 90)); |
| 474 } |
| 475 |
444 TEST_F(ScreenshareLayerTest, UpdatesHistograms) { | 476 TEST_F(ScreenshareLayerTest, UpdatesHistograms) { |
445 ConfigureBitrates(); | 477 ConfigureBitrates(); |
446 vpx_codec_enc_cfg_t cfg; | 478 vpx_codec_enc_cfg_t cfg = GetConfig(); |
447 cfg.rc_max_quantizer = kDefaultQp; | |
448 bool trigger_drop = false; | 479 bool trigger_drop = false; |
449 bool dropped_frame = false; | 480 bool dropped_frame = false; |
450 bool overshoot = false; | 481 bool overshoot = false; |
451 const int kTl0Qp = 35; | 482 const int kTl0Qp = 35; |
452 const int kTl1Qp = 30; | 483 const int kTl1Qp = 30; |
453 for (int64_t timestamp = 0; | 484 for (int64_t timestamp = 0; |
454 timestamp < kTimestampDelta5Fps * 5 * metrics::kMinRunTimeInSeconds; | 485 timestamp < kTimestampDelta5Fps * 5 * metrics::kMinRunTimeInSeconds; |
455 timestamp += kTimestampDelta5Fps) { | 486 timestamp += kTimestampDelta5Fps) { |
456 int flags = layers_->EncodeFlags(timestamp); | 487 int flags = layers_->EncodeFlags(timestamp); |
457 if (flags != -1) | 488 if (flags != -1) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 test::LastHistogramSample("WebRTC.Video.Screenshare.Layer1.Qp")); | 551 test::LastHistogramSample("WebRTC.Video.Screenshare.Layer1.Qp")); |
521 EXPECT_EQ(kDefaultTl0BitrateKbps, | 552 EXPECT_EQ(kDefaultTl0BitrateKbps, |
522 test::LastHistogramSample( | 553 test::LastHistogramSample( |
523 "WebRTC.Video.Screenshare.Layer0.TargetBitrate")); | 554 "WebRTC.Video.Screenshare.Layer0.TargetBitrate")); |
524 EXPECT_EQ(kDefaultTl1BitrateKbps, | 555 EXPECT_EQ(kDefaultTl1BitrateKbps, |
525 test::LastHistogramSample( | 556 test::LastHistogramSample( |
526 "WebRTC.Video.Screenshare.Layer1.TargetBitrate")); | 557 "WebRTC.Video.Screenshare.Layer1.TargetBitrate")); |
527 } | 558 } |
528 | 559 |
529 } // namespace webrtc | 560 } // namespace webrtc |
OLD | NEW |