| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 got_tl1 = true; | 119 got_tl1 = true; |
| 120 } | 120 } |
| 121 if (got_tl0 && got_tl1) | 121 if (got_tl0 && got_tl1) |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Adds frames until we get one in the specified temporal layer. The last | 127 // Adds frames until we get one in the specified temporal layer. The last |
| 128 // FrameEncoded() call will be omitted and needs to be done by the caller. | 128 // FrameEncoded() call will be omitted and needs to be done by the caller. |
| 129 void SkipUntilTl(int layer) { | 129 // Returns the flags for the last frame. |
| 130 for (int i = 0; i < 5; ++i) { | 130 int SkipUntilTl(int layer) { |
| 131 ConfigureFrame(false); | 131 return SkipUntilTlAndSync(layer, rtc::Optional<bool>()); |
| 132 } |
| 133 |
| 134 // Same as SkipUntilTl, but also waits until the sync bit condition is met. |
| 135 int SkipUntilTlAndSync(int layer, rtc::Optional<bool> sync) { |
| 136 int flags = 0; |
| 137 const int kMaxFramesToSkip = |
| 138 1 + (sync.value_or(false) ? kMaxSyncPeriodSeconds : 1) * kFrameRate; |
| 139 for (int i = 0; i < kMaxFramesToSkip; ++i) { |
| 140 flags = ConfigureFrame(false); |
| 132 timestamp_ += kTimestampDelta5Fps; | 141 timestamp_ += kTimestampDelta5Fps; |
| 133 if (vp8_info_.temporalIdx != layer) { | 142 if (vp8_info_.temporalIdx != layer || |
| 143 (sync && *sync != vp8_info_.layerSync)) { |
| 134 layers_->FrameEncoded(frame_size_, kDefaultQp); | 144 layers_->FrameEncoded(frame_size_, kDefaultQp); |
| 135 } else { | 145 } else { |
| 136 // Found frame form sought layer. | 146 // Found frame from sought after layer. |
| 137 return; | 147 return flags; |
| 138 } | 148 } |
| 139 } | 149 } |
| 140 ADD_FAILURE() << "Did not get a frame of TL" << layer << " in time."; | 150 ADD_FAILURE() << "Did not get a frame of TL" << layer << " in time."; |
| 151 return -1; |
| 141 } | 152 } |
| 142 | 153 |
| 143 int min_qp_; | 154 int min_qp_; |
| 144 int max_qp_; | 155 int max_qp_; |
| 145 int frame_size_; | 156 int frame_size_; |
| 146 SimulatedClock clock_; | 157 SimulatedClock clock_; |
| 147 std::unique_ptr<ScreenshareLayers> layers_; | 158 std::unique_ptr<ScreenshareLayers> layers_; |
| 148 | 159 |
| 149 uint32_t timestamp_; | 160 uint32_t timestamp_; |
| 150 TemporalLayers::FrameConfig tl_config_; | 161 TemporalLayers::FrameConfig tl_config_; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 layers_->FrameEncoded(frame_size_bytes, kDefaultQp); | 566 layers_->FrameEncoded(frame_size_bytes, kDefaultQp); |
| 556 } | 567 } |
| 557 timestamp += kFrameIntervalsMs * 90 / 2; | 568 timestamp += kFrameIntervalsMs * 90 / 2; |
| 558 clock_.AdvanceTimeMilliseconds(kFrameIntervalsMs / 2); | 569 clock_.AdvanceTimeMilliseconds(kFrameIntervalsMs / 2); |
| 559 ++num_input_frames; | 570 ++num_input_frames; |
| 560 } | 571 } |
| 561 | 572 |
| 562 // Allow for some rounding errors in the measurements. | 573 // Allow for some rounding errors in the measurements. |
| 563 EXPECT_NEAR(num_discarded_frames, num_input_frames / 2, 2); | 574 EXPECT_NEAR(num_discarded_frames, num_input_frames / 2, 2); |
| 564 } | 575 } |
| 576 |
| 577 TEST_F(ScreenshareLayerTest, 2LayersSyncAtOvershootDrop) { |
| 578 // Run grace period so we have existing frames in both TL0 and Tl1. |
| 579 EXPECT_TRUE(RunGracePeriod()); |
| 580 |
| 581 // Move ahead until we have a sync frame in TL1. |
| 582 EXPECT_EQ(kTl1SyncFlags, SkipUntilTlAndSync(1, rtc::Optional<bool>(true))); |
| 583 ASSERT_TRUE(vp8_info_.layerSync); |
| 584 |
| 585 // Simulate overshoot of this frame. |
| 586 layers_->FrameEncoded(0, -1); |
| 587 |
| 588 // Reencode, frame config, flags and codec specific info should remain the |
| 589 // same as for the dropped frame. |
| 590 timestamp_ -= kTimestampDelta5Fps; // Undo last timestamp increment. |
| 591 TemporalLayers::FrameConfig new_tl_config = |
| 592 layers_->UpdateLayerConfig(timestamp_); |
| 593 EXPECT_EQ(tl_config_, new_tl_config); |
| 594 |
| 595 config_updated_ = layers_->UpdateConfiguration(&cfg_); |
| 596 EXPECT_EQ(kTl1SyncFlags, VP8EncoderImpl::EncodeFlags(tl_config_)); |
| 597 |
| 598 CodecSpecificInfoVP8 new_vp8_info; |
| 599 layers_->PopulateCodecSpecific(false, tl_config_, &new_vp8_info, timestamp_); |
| 600 EXPECT_TRUE(new_vp8_info.layerSync); |
| 601 } |
| 602 |
| 565 } // namespace webrtc | 603 } // namespace webrtc |
| OLD | NEW |