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