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