Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Artem Titov | 46c4e60 | 2018-08-17 14:26:54 +0200 | [diff] [blame] | 10 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
Artem Titov | 46c4e60 | 2018-08-17 14:26:54 +0200 | [diff] [blame] | 13 | #include "api/test/simulated_network.h" |
Danil Chapovalov | 99b71df | 2018-10-26 15:57:48 +0200 | [diff] [blame] | 14 | #include "api/test/video/function_video_encoder_factory.h" |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 15 | #include "call/fake_network_pipe.h" |
| 16 | #include "call/simulated_network.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 17 | #include "media/engine/internal_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "media/engine/simulcast_encoder_adapter.h" |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 19 | #include "modules/rtp_rtcp/source/create_video_rtp_depacketizer.h" |
Danil Chapovalov | c347585 | 2019-12-05 13:51:32 +0100 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/rtp_packet.h" |
Sergio Garcia Murillo | 43800f9 | 2018-06-21 16:16:38 +0200 | [diff] [blame] | 21 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 22 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 23 | #include "rtc_base/numerics/safe_conversions.h" |
Bjorn Terelius | a194e58 | 2017-10-25 13:07:09 +0200 | [diff] [blame] | 24 | #include "rtc_base/numerics/sequence_number_util.h" |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 25 | #include "rtc_base/task_queue_for_test.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "test/call_test.h" |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 29 | namespace { |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 30 | const int kFrameMaxWidth = 1280; |
| 31 | const int kFrameMaxHeight = 720; |
| 32 | const int kFrameRate = 30; |
| 33 | const int kMaxSecondsLost = 5; |
| 34 | const int kMaxFramesLost = kFrameRate * kMaxSecondsLost; |
| 35 | const int kMinPacketsToObserve = 10; |
Åsa Persson | 6a1b7ad | 2017-12-11 12:30:55 +0100 | [diff] [blame] | 36 | const int kEncoderBitrateBps = 300000; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 37 | const uint32_t kPictureIdWraparound = (1 << 15); |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 38 | const size_t kNumTemporalLayers[] = {1, 2, 3}; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 39 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 40 | } // namespace |
| 41 | |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 42 | class PictureIdObserver : public test::RtpRtcpObserver { |
| 43 | public: |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 44 | explicit PictureIdObserver(VideoCodecType codec_type) |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 45 | : test::RtpRtcpObserver(test::CallTest::kDefaultTimeoutMs), |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 46 | depacketizer_(CreateVideoRtpDepacketizer(codec_type)), |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 47 | max_expected_picture_id_gap_(0), |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 48 | max_expected_tl0_idx_gap_(0), |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 49 | num_ssrcs_to_observe_(1) {} |
| 50 | |
| 51 | void SetExpectedSsrcs(size_t num_expected_ssrcs) { |
| 52 | rtc::CritScope lock(&crit_); |
| 53 | num_ssrcs_to_observe_ = num_expected_ssrcs; |
| 54 | } |
| 55 | |
| 56 | void ResetObservedSsrcs() { |
| 57 | rtc::CritScope lock(&crit_); |
| 58 | // Do not clear the timestamp and picture_id, to ensure that we check |
| 59 | // consistency between reinits and recreations. |
| 60 | num_packets_sent_.clear(); |
| 61 | observed_ssrcs_.clear(); |
| 62 | } |
| 63 | |
| 64 | void SetMaxExpectedPictureIdGap(int max_expected_picture_id_gap) { |
| 65 | rtc::CritScope lock(&crit_); |
| 66 | max_expected_picture_id_gap_ = max_expected_picture_id_gap; |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 67 | // Expect smaller gap for |tl0_pic_idx| (running index for temporal_idx 0). |
| 68 | max_expected_tl0_idx_gap_ = max_expected_picture_id_gap_ / 2; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | private: |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 72 | struct ParsedPacket { |
| 73 | uint32_t timestamp; |
| 74 | uint32_t ssrc; |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 75 | int16_t picture_id; |
| 76 | int16_t tl0_pic_idx; |
| 77 | uint8_t temporal_idx; |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 78 | VideoFrameType frame_type; |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | bool ParsePayload(const uint8_t* packet, |
| 82 | size_t length, |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 83 | ParsedPacket* parsed) const { |
Danil Chapovalov | c347585 | 2019-12-05 13:51:32 +0100 | [diff] [blame] | 84 | RtpPacket rtp_packet; |
| 85 | EXPECT_TRUE(rtp_packet.Parse(packet, length)); |
| 86 | EXPECT_TRUE(rtp_packet.Ssrc() == test::CallTest::kVideoSendSsrcs[0] || |
| 87 | rtp_packet.Ssrc() == test::CallTest::kVideoSendSsrcs[1] || |
| 88 | rtp_packet.Ssrc() == test::CallTest::kVideoSendSsrcs[2]) |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 89 | << "Unknown SSRC sent."; |
| 90 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 91 | if (rtp_packet.payload_size() == 0) { |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 92 | return false; // Padding packet. |
| 93 | } |
| 94 | |
Danil Chapovalov | c347585 | 2019-12-05 13:51:32 +0100 | [diff] [blame] | 95 | parsed->timestamp = rtp_packet.Timestamp(); |
| 96 | parsed->ssrc = rtp_packet.Ssrc(); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 97 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 98 | absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> parsed_payload = |
| 99 | depacketizer_->Parse(rtp_packet.PayloadBuffer()); |
| 100 | EXPECT_TRUE(parsed_payload); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 101 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 102 | if (const auto* vp8_header = absl::get_if<RTPVideoHeaderVP8>( |
| 103 | &parsed_payload->video_header.video_type_header)) { |
| 104 | parsed->picture_id = vp8_header->pictureId; |
| 105 | parsed->tl0_pic_idx = vp8_header->tl0PicIdx; |
| 106 | parsed->temporal_idx = vp8_header->temporalIdx; |
| 107 | } else if (const auto* vp9_header = absl::get_if<RTPVideoHeaderVP9>( |
| 108 | &parsed_payload->video_header.video_type_header)) { |
| 109 | parsed->picture_id = vp9_header->picture_id; |
| 110 | parsed->tl0_pic_idx = vp9_header->tl0_pic_idx; |
| 111 | parsed->temporal_idx = vp9_header->temporal_idx; |
| 112 | } else { |
| 113 | RTC_NOTREACHED(); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 116 | parsed->frame_type = parsed_payload->video_header.frame_type; |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 117 | return true; |
| 118 | } |
| 119 | |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 120 | // Verify continuity and monotonicity of picture_id sequence. |
| 121 | void VerifyPictureId(const ParsedPacket& current, |
| 122 | const ParsedPacket& last) const |
| 123 | RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
| 124 | if (current.timestamp == last.timestamp) { |
| 125 | EXPECT_EQ(last.picture_id, current.picture_id); |
| 126 | return; // Same frame. |
| 127 | } |
| 128 | |
| 129 | // Packet belongs to a new frame. |
| 130 | // Picture id should be increasing. |
| 131 | EXPECT_TRUE((AheadOf<uint16_t, kPictureIdWraparound>(current.picture_id, |
| 132 | last.picture_id))); |
| 133 | |
| 134 | // Expect continuously increasing picture id. |
| 135 | int diff = ForwardDiff<uint16_t, kPictureIdWraparound>(last.picture_id, |
| 136 | current.picture_id); |
| 137 | if (diff > 1) { |
| 138 | // If the VideoSendStream is destroyed, any frames still in queue is lost. |
| 139 | // Gaps only possible for first frame after a recreation, i.e. key frames. |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 140 | EXPECT_EQ(VideoFrameType::kVideoFrameKey, current.frame_type); |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 141 | EXPECT_LE(diff - 1, max_expected_picture_id_gap_); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void VerifyTl0Idx(const ParsedPacket& current, const ParsedPacket& last) const |
| 146 | RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
| 147 | if (current.tl0_pic_idx == kNoTl0PicIdx || |
| 148 | current.temporal_idx == kNoTemporalIdx) { |
| 149 | return; // No temporal layers. |
| 150 | } |
| 151 | |
| 152 | if (current.timestamp == last.timestamp || current.temporal_idx != 0) { |
| 153 | EXPECT_EQ(last.tl0_pic_idx, current.tl0_pic_idx); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | // New frame with |temporal_idx| 0. |
| 158 | // |tl0_pic_idx| should be increasing. |
| 159 | EXPECT_TRUE(AheadOf<uint8_t>(current.tl0_pic_idx, last.tl0_pic_idx)); |
| 160 | |
| 161 | // Expect continuously increasing idx. |
| 162 | int diff = ForwardDiff<uint8_t>(last.tl0_pic_idx, current.tl0_pic_idx); |
| 163 | if (diff > 1) { |
| 164 | // If the VideoSendStream is destroyed, any frames still in queue is lost. |
| 165 | // Gaps only possible for first frame after a recreation, i.e. key frames. |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 166 | EXPECT_EQ(VideoFrameType::kVideoFrameKey, current.frame_type); |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 167 | EXPECT_LE(diff - 1, max_expected_tl0_idx_gap_); |
| 168 | } |
| 169 | } |
| 170 | |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 171 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 172 | rtc::CritScope lock(&crit_); |
| 173 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 174 | ParsedPacket parsed; |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 175 | if (!ParsePayload(packet, length, &parsed)) |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 176 | return SEND_PACKET; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 177 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 178 | uint32_t ssrc = parsed.ssrc; |
| 179 | if (last_observed_packet_.find(ssrc) != last_observed_packet_.end()) { |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 180 | // Compare to last packet. |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 181 | VerifyPictureId(parsed, last_observed_packet_[ssrc]); |
| 182 | VerifyTl0Idx(parsed, last_observed_packet_[ssrc]); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 183 | } |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 184 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 185 | last_observed_packet_[ssrc] = parsed; |
| 186 | |
| 187 | // Pass the test when enough media packets have been received on all |
| 188 | // streams. |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 189 | if (++num_packets_sent_[ssrc] >= kMinPacketsToObserve && |
| 190 | observed_ssrcs_.find(ssrc) == observed_ssrcs_.end()) { |
| 191 | observed_ssrcs_.insert(ssrc); |
| 192 | if (observed_ssrcs_.size() == num_ssrcs_to_observe_) { |
| 193 | observation_complete_.Set(); |
| 194 | } |
| 195 | } |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 196 | return SEND_PACKET; |
| 197 | } |
| 198 | |
| 199 | rtc::CriticalSection crit_; |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 200 | const std::unique_ptr<VideoRtpDepacketizer> depacketizer_; |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 201 | std::map<uint32_t, ParsedPacket> last_observed_packet_ RTC_GUARDED_BY(crit_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 202 | std::map<uint32_t, size_t> num_packets_sent_ RTC_GUARDED_BY(crit_); |
| 203 | int max_expected_picture_id_gap_ RTC_GUARDED_BY(crit_); |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 204 | int max_expected_tl0_idx_gap_ RTC_GUARDED_BY(crit_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 205 | size_t num_ssrcs_to_observe_ RTC_GUARDED_BY(crit_); |
| 206 | std::set<uint32_t> observed_ssrcs_ RTC_GUARDED_BY(crit_); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 207 | }; |
| 208 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 209 | class PictureIdTest : public test::CallTest, |
Åsa Persson | 677f42c | 2018-03-16 13:09:17 +0100 | [diff] [blame] | 210 | public ::testing::WithParamInterface<size_t> { |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 211 | public: |
Åsa Persson | 677f42c | 2018-03-16 13:09:17 +0100 | [diff] [blame] | 212 | PictureIdTest() : num_temporal_layers_(GetParam()) {} |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 213 | |
| 214 | virtual ~PictureIdTest() { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 215 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 216 | send_transport_.reset(); |
| 217 | receive_transport_.reset(); |
| 218 | DestroyCalls(); |
| 219 | }); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 222 | void SetupEncoder(VideoEncoderFactory* encoder_factory, |
| 223 | const std::string& payload_name); |
Åsa Persson | 44327c3 | 2019-08-08 09:33:41 +0200 | [diff] [blame] | 224 | void SetVideoEncoderConfig(int num_streams); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 225 | void TestPictureIdContinuousAfterReconfigure( |
| 226 | const std::vector<int>& ssrc_counts); |
| 227 | void TestPictureIdIncreaseAfterRecreateStreams( |
| 228 | const std::vector<int>& ssrc_counts); |
| 229 | |
| 230 | private: |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 231 | const size_t num_temporal_layers_; |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 232 | std::unique_ptr<PictureIdObserver> observer_; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 233 | }; |
| 234 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 235 | INSTANTIATE_TEST_SUITE_P(TemporalLayers, |
| 236 | PictureIdTest, |
| 237 | ::testing::ValuesIn(kNumTemporalLayers)); |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 238 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 239 | void PictureIdTest::SetupEncoder(VideoEncoderFactory* encoder_factory, |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 240 | const std::string& payload_name) { |
| 241 | observer_.reset( |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 242 | new PictureIdObserver(PayloadStringToCodecType(payload_name))); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 243 | |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 244 | SendTask( |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 245 | RTC_FROM_HERE, task_queue(), [this, encoder_factory, payload_name]() { |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 246 | CreateCalls(); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 247 | |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 248 | send_transport_.reset(new test::PacketTransport( |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 249 | task_queue(), sender_call_.get(), observer_.get(), |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 250 | test::PacketTransport::kSender, payload_type_map_, |
| 251 | std::make_unique<FakeNetworkPipe>( |
| 252 | Clock::GetRealTimeClock(), |
| 253 | std::make_unique<SimulatedNetwork>( |
| 254 | BuiltInNetworkBehaviorConfig())))); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 255 | |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 256 | CreateSendConfig(kNumSimulcastStreams, 0, 0, send_transport_.get()); |
| 257 | GetVideoSendConfig()->encoder_settings.encoder_factory = |
| 258 | encoder_factory; |
| 259 | GetVideoSendConfig()->rtp.payload_name = payload_name; |
| 260 | GetVideoEncoderConfig()->codec_type = |
| 261 | PayloadStringToCodecType(payload_name); |
| 262 | SetVideoEncoderConfig(/* number_of_streams */ 1); |
| 263 | }); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Åsa Persson | 44327c3 | 2019-08-08 09:33:41 +0200 | [diff] [blame] | 266 | void PictureIdTest::SetVideoEncoderConfig(int num_streams) { |
| 267 | GetVideoEncoderConfig()->number_of_streams = num_streams; |
| 268 | GetVideoEncoderConfig()->max_bitrate_bps = kEncoderBitrateBps; |
| 269 | |
| 270 | // Always divide the same total bitrate across all streams so that sending a |
| 271 | // single stream avoids lowering the bitrate estimate and requiring a |
| 272 | // subsequent rampup. |
| 273 | const int encoder_stream_bps = kEncoderBitrateBps / num_streams; |
| 274 | double scale_factor = 1.0; |
| 275 | for (int i = num_streams - 1; i >= 0; --i) { |
| 276 | VideoStream& stream = GetVideoEncoderConfig()->simulcast_layers[i]; |
| 277 | // Reduce the min bitrate by 10% to account for overhead that might |
| 278 | // otherwise cause streams to not be enabled. |
| 279 | stream.min_bitrate_bps = static_cast<int>(encoder_stream_bps * 0.9); |
| 280 | stream.target_bitrate_bps = encoder_stream_bps; |
| 281 | stream.max_bitrate_bps = encoder_stream_bps; |
| 282 | stream.num_temporal_layers = num_temporal_layers_; |
| 283 | stream.scale_resolution_down_by = scale_factor; |
| 284 | scale_factor *= 2.0; |
| 285 | } |
| 286 | } |
| 287 | |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 288 | void PictureIdTest::TestPictureIdContinuousAfterReconfigure( |
| 289 | const std::vector<int>& ssrc_counts) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 290 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 291 | CreateVideoStreams(); |
| 292 | CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 293 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 294 | // Initial test with a single stream. |
| 295 | Start(); |
| 296 | }); |
| 297 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 298 | EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets."; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 299 | |
| 300 | // Reconfigure VideoEncoder and test picture id increase. |
Åsa Persson | ae81975 | 2017-10-10 11:05:59 +0200 | [diff] [blame] | 301 | // Expect continuously increasing picture id, equivalent to no gaps. |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 302 | observer_->SetMaxExpectedPictureIdGap(0); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 303 | for (int ssrc_count : ssrc_counts) { |
Åsa Persson | 44327c3 | 2019-08-08 09:33:41 +0200 | [diff] [blame] | 304 | SetVideoEncoderConfig(ssrc_count); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 305 | observer_->SetExpectedSsrcs(ssrc_count); |
| 306 | observer_->ResetObservedSsrcs(); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 307 | // Make sure the picture_id sequence is continuous on reinit and recreate. |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 308 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 309 | GetVideoSendStream()->ReconfigureVideoEncoder( |
| 310 | GetVideoEncoderConfig()->Copy()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 311 | }); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 312 | EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets."; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 315 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 316 | Stop(); |
| 317 | DestroyStreams(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 318 | }); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void PictureIdTest::TestPictureIdIncreaseAfterRecreateStreams( |
| 322 | const std::vector<int>& ssrc_counts) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 323 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 324 | CreateVideoStreams(); |
| 325 | CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 326 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 327 | // Initial test with a single stream. |
| 328 | Start(); |
| 329 | }); |
| 330 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 331 | EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets."; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 332 | |
| 333 | // Recreate VideoSendStream and test picture id increase. |
| 334 | // When the VideoSendStream is destroyed, any frames still in queue is lost |
| 335 | // with it, therefore it is expected that some frames might be lost. |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 336 | observer_->SetMaxExpectedPictureIdGap(kMaxFramesLost); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 337 | for (int ssrc_count : ssrc_counts) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 338 | SendTask(RTC_FROM_HERE, task_queue(), [this, &ssrc_count]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 339 | DestroyVideoSendStreams(); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 340 | |
Åsa Persson | 44327c3 | 2019-08-08 09:33:41 +0200 | [diff] [blame] | 341 | SetVideoEncoderConfig(ssrc_count); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 342 | observer_->SetExpectedSsrcs(ssrc_count); |
| 343 | observer_->ResetObservedSsrcs(); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 344 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 345 | CreateVideoSendStreams(); |
| 346 | GetVideoSendStream()->Start(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 347 | CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 348 | }); |
| 349 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 350 | EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets."; |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 353 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 354 | Stop(); |
| 355 | DestroyStreams(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 356 | }); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 359 | TEST_P(PictureIdTest, ContinuousAfterReconfigureVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 360 | test::FunctionVideoEncoderFactory encoder_factory( |
| 361 | []() { return VP8Encoder::Create(); }); |
| 362 | SetupEncoder(&encoder_factory, "VP8"); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 363 | TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1}); |
| 364 | } |
| 365 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 366 | TEST_P(PictureIdTest, IncreasingAfterRecreateStreamVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 367 | test::FunctionVideoEncoderFactory encoder_factory( |
| 368 | []() { return VP8Encoder::Create(); }); |
| 369 | SetupEncoder(&encoder_factory, "VP8"); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 370 | TestPictureIdIncreaseAfterRecreateStreams({1, 3, 3, 1, 1}); |
| 371 | } |
| 372 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 373 | TEST_P(PictureIdTest, ContinuousAfterStreamCountChangeVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 374 | test::FunctionVideoEncoderFactory encoder_factory( |
| 375 | []() { return VP8Encoder::Create(); }); |
Åsa Persson | 71485ac | 2017-12-04 11:11:19 +0100 | [diff] [blame] | 376 | // Make sure that the picture id is not reset if the stream count goes |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 377 | // down and then up. |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 378 | SetupEncoder(&encoder_factory, "VP8"); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 379 | TestPictureIdContinuousAfterReconfigure({3, 1, 3}); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 382 | TEST_P(PictureIdTest, ContinuousAfterReconfigureSimulcastEncoderAdapter) { |
Magnus Jedvert | df4883d | 2017-11-17 14:44:55 +0100 | [diff] [blame] | 383 | InternalEncoderFactory internal_encoder_factory; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 384 | test::FunctionVideoEncoderFactory encoder_factory( |
| 385 | [&internal_encoder_factory]() { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 386 | return std::make_unique<SimulcastEncoderAdapter>( |
Ilya Nikolaevskiy | 97b4ee5 | 2018-05-28 10:24:22 +0200 | [diff] [blame] | 387 | &internal_encoder_factory, SdpVideoFormat("VP8")); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 388 | }); |
| 389 | SetupEncoder(&encoder_factory, "VP8"); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 390 | TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1}); |
| 391 | } |
| 392 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 393 | TEST_P(PictureIdTest, IncreasingAfterRecreateStreamSimulcastEncoderAdapter) { |
Magnus Jedvert | df4883d | 2017-11-17 14:44:55 +0100 | [diff] [blame] | 394 | InternalEncoderFactory internal_encoder_factory; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 395 | test::FunctionVideoEncoderFactory encoder_factory( |
| 396 | [&internal_encoder_factory]() { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 397 | return std::make_unique<SimulcastEncoderAdapter>( |
Ilya Nikolaevskiy | 97b4ee5 | 2018-05-28 10:24:22 +0200 | [diff] [blame] | 398 | &internal_encoder_factory, SdpVideoFormat("VP8")); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 399 | }); |
| 400 | SetupEncoder(&encoder_factory, "VP8"); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 401 | TestPictureIdIncreaseAfterRecreateStreams({1, 3, 3, 1, 1}); |
| 402 | } |
| 403 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 404 | TEST_P(PictureIdTest, ContinuousAfterStreamCountChangeSimulcastEncoderAdapter) { |
Åsa Persson | 677f42c | 2018-03-16 13:09:17 +0100 | [diff] [blame] | 405 | InternalEncoderFactory internal_encoder_factory; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 406 | test::FunctionVideoEncoderFactory encoder_factory( |
| 407 | [&internal_encoder_factory]() { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 408 | return std::make_unique<SimulcastEncoderAdapter>( |
Ilya Nikolaevskiy | 97b4ee5 | 2018-05-28 10:24:22 +0200 | [diff] [blame] | 409 | &internal_encoder_factory, SdpVideoFormat("VP8")); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 410 | }); |
Åsa Persson | 677f42c | 2018-03-16 13:09:17 +0100 | [diff] [blame] | 411 | // Make sure that the picture id is not reset if the stream count goes |
| 412 | // down and then up. |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 413 | SetupEncoder(&encoder_factory, "VP8"); |
Åsa Persson | 677f42c | 2018-03-16 13:09:17 +0100 | [diff] [blame] | 414 | TestPictureIdContinuousAfterReconfigure({3, 1, 3}); |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 415 | } |
| 416 | |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 417 | TEST_P(PictureIdTest, IncreasingAfterRecreateStreamVp9) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 418 | test::FunctionVideoEncoderFactory encoder_factory( |
| 419 | []() { return VP9Encoder::Create(); }); |
| 420 | SetupEncoder(&encoder_factory, "VP9"); |
Åsa Persson | ad3c7a4 | 2017-11-29 10:24:27 +0100 | [diff] [blame] | 421 | TestPictureIdIncreaseAfterRecreateStreams({1, 1}); |
| 422 | } |
| 423 | |
Sebastian Jansson | e92f93f | 2017-06-22 14:44:04 +0200 | [diff] [blame] | 424 | } // namespace webrtc |