blob: 267a8e063b4a4408b2b32a229dbc8bbf0b611725 [file] [log] [blame]
Sebastian Janssone92f93f2017-06-22 14:44:04 +02001/*
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 Titov46c4e602018-08-17 14:26:54 +020010
Mirko Bonadei317a1f02019-09-17 17:06:18 +020011#include <memory>
12
Artem Titov46c4e602018-08-17 14:26:54 +020013#include "api/test/simulated_network.h"
Danil Chapovalov99b71df2018-10-26 15:57:48 +020014#include "api/test/video/function_video_encoder_factory.h"
Artem Titov4e199e92018-08-20 13:30:39 +020015#include "call/fake_network_pipe.h"
16#include "call/simulated_network.h"
Steve Anton10542f22019-01-11 09:11:00 -080017#include "media/engine/internal_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "media/engine/simulcast_encoder_adapter.h"
19#include "modules/rtp_rtcp/source/rtp_format.h"
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020020#include "modules/video_coding/codecs/vp8/include/vp8.h"
Åsa Perssonad3c7a42017-11-29 10:24:27 +010021#include "modules/video_coding/codecs/vp9/include/vp9.h"
Oleh Prypina40f8242017-12-21 13:32:23 +010022#include "rtc_base/numerics/safe_conversions.h"
Bjorn Tereliusa194e582017-10-25 13:07:09 +020023#include "rtc_base/numerics/sequence_number_util.h"
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +020024#include "rtc_base/task_queue_for_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "test/call_test.h"
Sebastian Janssone92f93f2017-06-22 14:44:04 +020026
27namespace webrtc {
Åsa Persson4bece9a2017-10-06 10:04:04 +020028namespace {
Sebastian Janssone92f93f2017-06-22 14:44:04 +020029const int kFrameMaxWidth = 1280;
30const int kFrameMaxHeight = 720;
31const int kFrameRate = 30;
32const int kMaxSecondsLost = 5;
33const int kMaxFramesLost = kFrameRate * kMaxSecondsLost;
34const int kMinPacketsToObserve = 10;
Åsa Persson6a1b7ad2017-12-11 12:30:55 +010035const int kEncoderBitrateBps = 300000;
Sebastian Janssone92f93f2017-06-22 14:44:04 +020036const uint32_t kPictureIdWraparound = (1 << 15);
Åsa Persson71485ac2017-12-04 11:11:19 +010037const size_t kNumTemporalLayers[] = {1, 2, 3};
Sebastian Janssone92f93f2017-06-22 14:44:04 +020038
Åsa Persson4bece9a2017-10-06 10:04:04 +020039} // namespace
40
Sebastian Janssone92f93f2017-06-22 14:44:04 +020041class PictureIdObserver : public test::RtpRtcpObserver {
42 public:
Niels Möller520ca4e2018-06-04 11:14:38 +020043 explicit PictureIdObserver(VideoCodecType codec_type)
Sebastian Janssone92f93f2017-06-22 14:44:04 +020044 : test::RtpRtcpObserver(test::CallTest::kDefaultTimeoutMs),
Åsa Perssonad3c7a42017-11-29 10:24:27 +010045 codec_type_(codec_type),
Sebastian Janssone92f93f2017-06-22 14:44:04 +020046 max_expected_picture_id_gap_(0),
Åsa Persson71485ac2017-12-04 11:11:19 +010047 max_expected_tl0_idx_gap_(0),
Sebastian Janssone92f93f2017-06-22 14:44:04 +020048 num_ssrcs_to_observe_(1) {}
49
50 void SetExpectedSsrcs(size_t num_expected_ssrcs) {
51 rtc::CritScope lock(&crit_);
52 num_ssrcs_to_observe_ = num_expected_ssrcs;
53 }
54
55 void ResetObservedSsrcs() {
56 rtc::CritScope lock(&crit_);
57 // Do not clear the timestamp and picture_id, to ensure that we check
58 // consistency between reinits and recreations.
59 num_packets_sent_.clear();
60 observed_ssrcs_.clear();
61 }
62
63 void SetMaxExpectedPictureIdGap(int max_expected_picture_id_gap) {
64 rtc::CritScope lock(&crit_);
65 max_expected_picture_id_gap_ = max_expected_picture_id_gap;
Åsa Persson71485ac2017-12-04 11:11:19 +010066 // Expect smaller gap for |tl0_pic_idx| (running index for temporal_idx 0).
67 max_expected_tl0_idx_gap_ = max_expected_picture_id_gap_ / 2;
Sebastian Janssone92f93f2017-06-22 14:44:04 +020068 }
69
70 private:
Åsa Perssonad3c7a42017-11-29 10:24:27 +010071 struct ParsedPacket {
72 uint32_t timestamp;
73 uint32_t ssrc;
Åsa Persson71485ac2017-12-04 11:11:19 +010074 int16_t picture_id;
75 int16_t tl0_pic_idx;
76 uint8_t temporal_idx;
Niels Möller87e2d782019-03-07 10:18:23 +010077 VideoFrameType frame_type;
Åsa Perssonad3c7a42017-11-29 10:24:27 +010078 };
79
80 bool ParsePayload(const uint8_t* packet,
81 size_t length,
Åsa Persson71485ac2017-12-04 11:11:19 +010082 ParsedPacket* parsed) const {
Åsa Perssonad3c7a42017-11-29 10:24:27 +010083 RTPHeader header;
84 EXPECT_TRUE(parser_->Parse(packet, length, &header));
85 EXPECT_TRUE(header.ssrc == test::CallTest::kVideoSendSsrcs[0] ||
86 header.ssrc == test::CallTest::kVideoSendSsrcs[1] ||
87 header.ssrc == test::CallTest::kVideoSendSsrcs[2])
88 << "Unknown SSRC sent.";
89
90 EXPECT_GE(length, header.headerLength + header.paddingLength);
91 size_t payload_length = length - header.headerLength - header.paddingLength;
92 if (payload_length == 0) {
93 return false; // Padding packet.
94 }
95
Åsa Perssonad3c7a42017-11-29 10:24:27 +010096 parsed->timestamp = header.timestamp;
Åsa Persson71485ac2017-12-04 11:11:19 +010097 parsed->ssrc = header.ssrc;
Åsa Perssonad3c7a42017-11-29 10:24:27 +010098
99 std::unique_ptr<RtpDepacketizer> depacketizer(
100 RtpDepacketizer::Create(codec_type_));
101 RtpDepacketizer::ParsedPayload parsed_payload;
102 EXPECT_TRUE(depacketizer->Parse(
103 &parsed_payload, &packet[header.headerLength], payload_length));
104
105 switch (codec_type_) {
Philip Eliassond52a1a62018-09-07 13:03:55 +0000106 case kVideoCodecVP8: {
107 const auto& vp8_header = absl::get<RTPVideoHeaderVP8>(
108 parsed_payload.video_header().video_type_header);
109 parsed->picture_id = vp8_header.pictureId;
110 parsed->tl0_pic_idx = vp8_header.tl0PicIdx;
111 parsed->temporal_idx = vp8_header.temporalIdx;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100112 break;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000113 }
philipel29d88462018-08-08 14:26:00 +0200114 case kVideoCodecVP9: {
115 const auto& vp9_header = absl::get<RTPVideoHeaderVP9>(
116 parsed_payload.video_header().video_type_header);
117 parsed->picture_id = vp9_header.picture_id;
118 parsed->tl0_pic_idx = vp9_header.tl0_pic_idx;
119 parsed->temporal_idx = vp9_header.temporal_idx;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100120 break;
philipel29d88462018-08-08 14:26:00 +0200121 }
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100122 default:
123 RTC_NOTREACHED();
124 break;
125 }
126
Niels Möllerabbc50e2019-04-24 09:41:16 +0200127 parsed->frame_type = parsed_payload.video_header().frame_type;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100128 return true;
129 }
130
Åsa Persson71485ac2017-12-04 11:11:19 +0100131 // Verify continuity and monotonicity of picture_id sequence.
132 void VerifyPictureId(const ParsedPacket& current,
133 const ParsedPacket& last) const
134 RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
135 if (current.timestamp == last.timestamp) {
136 EXPECT_EQ(last.picture_id, current.picture_id);
137 return; // Same frame.
138 }
139
140 // Packet belongs to a new frame.
141 // Picture id should be increasing.
142 EXPECT_TRUE((AheadOf<uint16_t, kPictureIdWraparound>(current.picture_id,
143 last.picture_id)));
144
145 // Expect continuously increasing picture id.
146 int diff = ForwardDiff<uint16_t, kPictureIdWraparound>(last.picture_id,
147 current.picture_id);
148 if (diff > 1) {
149 // If the VideoSendStream is destroyed, any frames still in queue is lost.
150 // Gaps only possible for first frame after a recreation, i.e. key frames.
Niels Möller8f7ce222019-03-21 15:43:58 +0100151 EXPECT_EQ(VideoFrameType::kVideoFrameKey, current.frame_type);
Åsa Persson71485ac2017-12-04 11:11:19 +0100152 EXPECT_LE(diff - 1, max_expected_picture_id_gap_);
153 }
154 }
155
156 void VerifyTl0Idx(const ParsedPacket& current, const ParsedPacket& last) const
157 RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
158 if (current.tl0_pic_idx == kNoTl0PicIdx ||
159 current.temporal_idx == kNoTemporalIdx) {
160 return; // No temporal layers.
161 }
162
163 if (current.timestamp == last.timestamp || current.temporal_idx != 0) {
164 EXPECT_EQ(last.tl0_pic_idx, current.tl0_pic_idx);
165 return;
166 }
167
168 // New frame with |temporal_idx| 0.
169 // |tl0_pic_idx| should be increasing.
170 EXPECT_TRUE(AheadOf<uint8_t>(current.tl0_pic_idx, last.tl0_pic_idx));
171
172 // Expect continuously increasing idx.
173 int diff = ForwardDiff<uint8_t>(last.tl0_pic_idx, current.tl0_pic_idx);
174 if (diff > 1) {
175 // If the VideoSendStream is destroyed, any frames still in queue is lost.
176 // Gaps only possible for first frame after a recreation, i.e. key frames.
Niels Möller8f7ce222019-03-21 15:43:58 +0100177 EXPECT_EQ(VideoFrameType::kVideoFrameKey, current.frame_type);
Åsa Persson71485ac2017-12-04 11:11:19 +0100178 EXPECT_LE(diff - 1, max_expected_tl0_idx_gap_);
179 }
180 }
181
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200182 Action OnSendRtp(const uint8_t* packet, size_t length) override {
183 rtc::CritScope lock(&crit_);
184
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100185 ParsedPacket parsed;
Åsa Persson71485ac2017-12-04 11:11:19 +0100186 if (!ParsePayload(packet, length, &parsed))
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200187 return SEND_PACKET;
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200188
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100189 uint32_t ssrc = parsed.ssrc;
190 if (last_observed_packet_.find(ssrc) != last_observed_packet_.end()) {
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100191 // Compare to last packet.
Åsa Persson71485ac2017-12-04 11:11:19 +0100192 VerifyPictureId(parsed, last_observed_packet_[ssrc]);
193 VerifyTl0Idx(parsed, last_observed_packet_[ssrc]);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200194 }
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200195
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100196 last_observed_packet_[ssrc] = parsed;
197
198 // Pass the test when enough media packets have been received on all
199 // streams.
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200200 if (++num_packets_sent_[ssrc] >= kMinPacketsToObserve &&
201 observed_ssrcs_.find(ssrc) == observed_ssrcs_.end()) {
202 observed_ssrcs_.insert(ssrc);
203 if (observed_ssrcs_.size() == num_ssrcs_to_observe_) {
204 observation_complete_.Set();
205 }
206 }
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200207 return SEND_PACKET;
208 }
209
210 rtc::CriticalSection crit_;
Niels Möller520ca4e2018-06-04 11:14:38 +0200211 const VideoCodecType codec_type_;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100212 std::map<uint32_t, ParsedPacket> last_observed_packet_ RTC_GUARDED_BY(crit_);
danilchapa37de392017-09-09 04:17:22 -0700213 std::map<uint32_t, size_t> num_packets_sent_ RTC_GUARDED_BY(crit_);
214 int max_expected_picture_id_gap_ RTC_GUARDED_BY(crit_);
Åsa Persson71485ac2017-12-04 11:11:19 +0100215 int max_expected_tl0_idx_gap_ RTC_GUARDED_BY(crit_);
danilchapa37de392017-09-09 04:17:22 -0700216 size_t num_ssrcs_to_observe_ RTC_GUARDED_BY(crit_);
217 std::set<uint32_t> observed_ssrcs_ RTC_GUARDED_BY(crit_);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200218};
219
Åsa Persson4bece9a2017-10-06 10:04:04 +0200220class PictureIdTest : public test::CallTest,
Åsa Persson677f42c2018-03-16 13:09:17 +0100221 public ::testing::WithParamInterface<size_t> {
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200222 public:
Åsa Persson677f42c2018-03-16 13:09:17 +0100223 PictureIdTest() : num_temporal_layers_(GetParam()) {}
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200224
225 virtual ~PictureIdTest() {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200226 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700227 send_transport_.reset();
228 receive_transport_.reset();
229 DestroyCalls();
230 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200231 }
232
Niels Möller4db138e2018-04-19 09:04:13 +0200233 void SetupEncoder(VideoEncoderFactory* encoder_factory,
234 const std::string& payload_name);
Åsa Persson44327c32019-08-08 09:33:41 +0200235 void SetVideoEncoderConfig(int num_streams);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200236 void TestPictureIdContinuousAfterReconfigure(
237 const std::vector<int>& ssrc_counts);
238 void TestPictureIdIncreaseAfterRecreateStreams(
239 const std::vector<int>& ssrc_counts);
240
241 private:
Åsa Persson71485ac2017-12-04 11:11:19 +0100242 const size_t num_temporal_layers_;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100243 std::unique_ptr<PictureIdObserver> observer_;
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200244};
245
Mirko Bonadeic84f6612019-01-31 12:20:57 +0100246INSTANTIATE_TEST_SUITE_P(TemporalLayers,
247 PictureIdTest,
248 ::testing::ValuesIn(kNumTemporalLayers));
Åsa Persson4bece9a2017-10-06 10:04:04 +0200249
Niels Möller4db138e2018-04-19 09:04:13 +0200250void PictureIdTest::SetupEncoder(VideoEncoderFactory* encoder_factory,
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100251 const std::string& payload_name) {
252 observer_.reset(
Niels Möller520ca4e2018-06-04 11:14:38 +0200253 new PictureIdObserver(PayloadStringToCodecType(payload_name)));
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100254
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200255 SendTask(
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200256 RTC_FROM_HERE, task_queue(), [this, encoder_factory, payload_name]() {
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200257 CreateCalls();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200258
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200259 send_transport_.reset(new test::PacketTransport(
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200260 task_queue(), sender_call_.get(), observer_.get(),
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200261 test::PacketTransport::kSender, payload_type_map_,
262 std::make_unique<FakeNetworkPipe>(
263 Clock::GetRealTimeClock(),
264 std::make_unique<SimulatedNetwork>(
265 BuiltInNetworkBehaviorConfig()))));
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200266
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200267 CreateSendConfig(kNumSimulcastStreams, 0, 0, send_transport_.get());
268 GetVideoSendConfig()->encoder_settings.encoder_factory =
269 encoder_factory;
270 GetVideoSendConfig()->rtp.payload_name = payload_name;
271 GetVideoEncoderConfig()->codec_type =
272 PayloadStringToCodecType(payload_name);
273 SetVideoEncoderConfig(/* number_of_streams */ 1);
274 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200275}
276
Åsa Persson44327c32019-08-08 09:33:41 +0200277void PictureIdTest::SetVideoEncoderConfig(int num_streams) {
278 GetVideoEncoderConfig()->number_of_streams = num_streams;
279 GetVideoEncoderConfig()->max_bitrate_bps = kEncoderBitrateBps;
280
281 // Always divide the same total bitrate across all streams so that sending a
282 // single stream avoids lowering the bitrate estimate and requiring a
283 // subsequent rampup.
284 const int encoder_stream_bps = kEncoderBitrateBps / num_streams;
285 double scale_factor = 1.0;
286 for (int i = num_streams - 1; i >= 0; --i) {
287 VideoStream& stream = GetVideoEncoderConfig()->simulcast_layers[i];
288 // Reduce the min bitrate by 10% to account for overhead that might
289 // otherwise cause streams to not be enabled.
290 stream.min_bitrate_bps = static_cast<int>(encoder_stream_bps * 0.9);
291 stream.target_bitrate_bps = encoder_stream_bps;
292 stream.max_bitrate_bps = encoder_stream_bps;
293 stream.num_temporal_layers = num_temporal_layers_;
294 stream.scale_resolution_down_by = scale_factor;
295 scale_factor *= 2.0;
296 }
297}
298
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200299void PictureIdTest::TestPictureIdContinuousAfterReconfigure(
300 const std::vector<int>& ssrc_counts) {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200301 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700302 CreateVideoStreams();
303 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200304
eladalon413ee9a2017-08-22 04:02:52 -0700305 // Initial test with a single stream.
306 Start();
307 });
308
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100309 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200310
311 // Reconfigure VideoEncoder and test picture id increase.
Åsa Perssonae819752017-10-10 11:05:59 +0200312 // Expect continuously increasing picture id, equivalent to no gaps.
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100313 observer_->SetMaxExpectedPictureIdGap(0);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200314 for (int ssrc_count : ssrc_counts) {
Åsa Persson44327c32019-08-08 09:33:41 +0200315 SetVideoEncoderConfig(ssrc_count);
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100316 observer_->SetExpectedSsrcs(ssrc_count);
317 observer_->ResetObservedSsrcs();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200318 // Make sure the picture_id sequence is continuous on reinit and recreate.
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200319 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
Sebastian Janssonf33905d2018-07-13 09:49:00 +0200320 GetVideoSendStream()->ReconfigureVideoEncoder(
321 GetVideoEncoderConfig()->Copy());
eladalon413ee9a2017-08-22 04:02:52 -0700322 });
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100323 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200324 }
325
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200326 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700327 Stop();
328 DestroyStreams();
eladalon413ee9a2017-08-22 04:02:52 -0700329 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200330}
331
332void PictureIdTest::TestPictureIdIncreaseAfterRecreateStreams(
333 const std::vector<int>& ssrc_counts) {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200334 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700335 CreateVideoStreams();
336 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200337
eladalon413ee9a2017-08-22 04:02:52 -0700338 // Initial test with a single stream.
339 Start();
340 });
341
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100342 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200343
344 // Recreate VideoSendStream and test picture id increase.
345 // When the VideoSendStream is destroyed, any frames still in queue is lost
346 // with it, therefore it is expected that some frames might be lost.
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100347 observer_->SetMaxExpectedPictureIdGap(kMaxFramesLost);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200348 for (int ssrc_count : ssrc_counts) {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200349 SendTask(RTC_FROM_HERE, task_queue(), [this, &ssrc_count]() {
Sebastian Janssonf33905d2018-07-13 09:49:00 +0200350 DestroyVideoSendStreams();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200351
Åsa Persson44327c32019-08-08 09:33:41 +0200352 SetVideoEncoderConfig(ssrc_count);
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100353 observer_->SetExpectedSsrcs(ssrc_count);
354 observer_->ResetObservedSsrcs();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200355
Sebastian Janssonf33905d2018-07-13 09:49:00 +0200356 CreateVideoSendStreams();
357 GetVideoSendStream()->Start();
eladalon413ee9a2017-08-22 04:02:52 -0700358 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight);
eladalon413ee9a2017-08-22 04:02:52 -0700359 });
360
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100361 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200362 }
363
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200364 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700365 Stop();
366 DestroyStreams();
eladalon413ee9a2017-08-22 04:02:52 -0700367 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200368}
369
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100370TEST_P(PictureIdTest, ContinuousAfterReconfigureVp8) {
Niels Möller4db138e2018-04-19 09:04:13 +0200371 test::FunctionVideoEncoderFactory encoder_factory(
372 []() { return VP8Encoder::Create(); });
373 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200374 TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1});
375}
376
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100377TEST_P(PictureIdTest, IncreasingAfterRecreateStreamVp8) {
Niels Möller4db138e2018-04-19 09:04:13 +0200378 test::FunctionVideoEncoderFactory encoder_factory(
379 []() { return VP8Encoder::Create(); });
380 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200381 TestPictureIdIncreaseAfterRecreateStreams({1, 3, 3, 1, 1});
382}
383
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100384TEST_P(PictureIdTest, ContinuousAfterStreamCountChangeVp8) {
Niels Möller4db138e2018-04-19 09:04:13 +0200385 test::FunctionVideoEncoderFactory encoder_factory(
386 []() { return VP8Encoder::Create(); });
Åsa Persson71485ac2017-12-04 11:11:19 +0100387 // Make sure that the picture id is not reset if the stream count goes
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200388 // down and then up.
Niels Möller4db138e2018-04-19 09:04:13 +0200389 SetupEncoder(&encoder_factory, "VP8");
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100390 TestPictureIdContinuousAfterReconfigure({3, 1, 3});
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200391}
392
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100393TEST_P(PictureIdTest, ContinuousAfterReconfigureSimulcastEncoderAdapter) {
Magnus Jedvertdf4883d2017-11-17 14:44:55 +0100394 InternalEncoderFactory internal_encoder_factory;
Niels Möller4db138e2018-04-19 09:04:13 +0200395 test::FunctionVideoEncoderFactory encoder_factory(
396 [&internal_encoder_factory]() {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200397 return std::make_unique<SimulcastEncoderAdapter>(
Ilya Nikolaevskiy97b4ee52018-05-28 10:24:22 +0200398 &internal_encoder_factory, SdpVideoFormat("VP8"));
Niels Möller4db138e2018-04-19 09:04:13 +0200399 });
400 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200401 TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1});
402}
403
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100404TEST_P(PictureIdTest, IncreasingAfterRecreateStreamSimulcastEncoderAdapter) {
Magnus Jedvertdf4883d2017-11-17 14:44:55 +0100405 InternalEncoderFactory internal_encoder_factory;
Niels Möller4db138e2018-04-19 09:04:13 +0200406 test::FunctionVideoEncoderFactory encoder_factory(
407 [&internal_encoder_factory]() {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200408 return std::make_unique<SimulcastEncoderAdapter>(
Ilya Nikolaevskiy97b4ee52018-05-28 10:24:22 +0200409 &internal_encoder_factory, SdpVideoFormat("VP8"));
Niels Möller4db138e2018-04-19 09:04:13 +0200410 });
411 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200412 TestPictureIdIncreaseAfterRecreateStreams({1, 3, 3, 1, 1});
413}
414
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100415TEST_P(PictureIdTest, ContinuousAfterStreamCountChangeSimulcastEncoderAdapter) {
Åsa Persson677f42c2018-03-16 13:09:17 +0100416 InternalEncoderFactory internal_encoder_factory;
Niels Möller4db138e2018-04-19 09:04:13 +0200417 test::FunctionVideoEncoderFactory encoder_factory(
418 [&internal_encoder_factory]() {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200419 return std::make_unique<SimulcastEncoderAdapter>(
Ilya Nikolaevskiy97b4ee52018-05-28 10:24:22 +0200420 &internal_encoder_factory, SdpVideoFormat("VP8"));
Niels Möller4db138e2018-04-19 09:04:13 +0200421 });
Åsa Persson677f42c2018-03-16 13:09:17 +0100422 // Make sure that the picture id is not reset if the stream count goes
423 // down and then up.
Niels Möller4db138e2018-04-19 09:04:13 +0200424 SetupEncoder(&encoder_factory, "VP8");
Åsa Persson677f42c2018-03-16 13:09:17 +0100425 TestPictureIdContinuousAfterReconfigure({3, 1, 3});
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200426}
427
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100428TEST_P(PictureIdTest, IncreasingAfterRecreateStreamVp9) {
Niels Möller4db138e2018-04-19 09:04:13 +0200429 test::FunctionVideoEncoderFactory encoder_factory(
430 []() { return VP9Encoder::Create(); });
431 SetupEncoder(&encoder_factory, "VP9");
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100432 TestPictureIdIncreaseAfterRecreateStreams({1, 1});
433}
434
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200435} // namespace webrtc