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