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