blob: 19c1141b0a0fdc21e861904f5c65c5a644df1ad2 [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"
Danil Chapovalovb57fe172019-12-11 09:38:44 +010019#include "modules/rtp_rtcp/source/create_video_rtp_depacketizer.h"
Danil Chapovalovc3475852019-12-05 13:51:32 +010020#include "modules/rtp_rtcp/source/rtp_packet.h"
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020021#include "modules/video_coding/codecs/vp8/include/vp8.h"
Åsa Perssonad3c7a42017-11-29 10:24:27 +010022#include "modules/video_coding/codecs/vp9/include/vp9.h"
Oleh Prypina40f8242017-12-21 13:32:23 +010023#include "rtc_base/numerics/safe_conversions.h"
Bjorn Tereliusa194e582017-10-25 13:07:09 +020024#include "rtc_base/numerics/sequence_number_util.h"
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +020025#include "rtc_base/task_queue_for_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "test/call_test.h"
Sebastian Janssone92f93f2017-06-22 14:44:04 +020027
28namespace webrtc {
Åsa Persson4bece9a2017-10-06 10:04:04 +020029namespace {
Sebastian Janssone92f93f2017-06-22 14:44:04 +020030const int kFrameMaxWidth = 1280;
31const int kFrameMaxHeight = 720;
32const int kFrameRate = 30;
33const int kMaxSecondsLost = 5;
34const int kMaxFramesLost = kFrameRate * kMaxSecondsLost;
35const int kMinPacketsToObserve = 10;
Åsa Persson6a1b7ad2017-12-11 12:30:55 +010036const int kEncoderBitrateBps = 300000;
Sebastian Janssone92f93f2017-06-22 14:44:04 +020037const uint32_t kPictureIdWraparound = (1 << 15);
Åsa Persson71485ac2017-12-04 11:11:19 +010038const size_t kNumTemporalLayers[] = {1, 2, 3};
Sebastian Janssone92f93f2017-06-22 14:44:04 +020039
Åsa Persson4bece9a2017-10-06 10:04:04 +020040} // namespace
41
Sebastian Janssone92f93f2017-06-22 14:44:04 +020042class PictureIdObserver : public test::RtpRtcpObserver {
43 public:
Niels Möller520ca4e2018-06-04 11:14:38 +020044 explicit PictureIdObserver(VideoCodecType codec_type)
Sebastian Janssone92f93f2017-06-22 14:44:04 +020045 : test::RtpRtcpObserver(test::CallTest::kDefaultTimeoutMs),
Danil Chapovalovb57fe172019-12-11 09:38:44 +010046 depacketizer_(CreateVideoRtpDepacketizer(codec_type)),
Sebastian Janssone92f93f2017-06-22 14:44:04 +020047 max_expected_picture_id_gap_(0),
Åsa Persson71485ac2017-12-04 11:11:19 +010048 max_expected_tl0_idx_gap_(0),
Sebastian Janssone92f93f2017-06-22 14:44:04 +020049 num_ssrcs_to_observe_(1) {}
50
51 void SetExpectedSsrcs(size_t num_expected_ssrcs) {
52 rtc::CritScope lock(&crit_);
53 num_ssrcs_to_observe_ = num_expected_ssrcs;
54 }
55
56 void ResetObservedSsrcs() {
57 rtc::CritScope lock(&crit_);
58 // Do not clear the timestamp and picture_id, to ensure that we check
59 // consistency between reinits and recreations.
60 num_packets_sent_.clear();
61 observed_ssrcs_.clear();
62 }
63
64 void SetMaxExpectedPictureIdGap(int max_expected_picture_id_gap) {
65 rtc::CritScope lock(&crit_);
66 max_expected_picture_id_gap_ = max_expected_picture_id_gap;
Åsa Persson71485ac2017-12-04 11:11:19 +010067 // Expect smaller gap for |tl0_pic_idx| (running index for temporal_idx 0).
68 max_expected_tl0_idx_gap_ = max_expected_picture_id_gap_ / 2;
Sebastian Janssone92f93f2017-06-22 14:44:04 +020069 }
70
71 private:
Åsa Perssonad3c7a42017-11-29 10:24:27 +010072 struct ParsedPacket {
73 uint32_t timestamp;
74 uint32_t ssrc;
Åsa Persson71485ac2017-12-04 11:11:19 +010075 int16_t picture_id;
76 int16_t tl0_pic_idx;
77 uint8_t temporal_idx;
Niels Möller87e2d782019-03-07 10:18:23 +010078 VideoFrameType frame_type;
Åsa Perssonad3c7a42017-11-29 10:24:27 +010079 };
80
81 bool ParsePayload(const uint8_t* packet,
82 size_t length,
Åsa Persson71485ac2017-12-04 11:11:19 +010083 ParsedPacket* parsed) const {
Danil Chapovalovc3475852019-12-05 13:51:32 +010084 RtpPacket rtp_packet;
85 EXPECT_TRUE(rtp_packet.Parse(packet, length));
86 EXPECT_TRUE(rtp_packet.Ssrc() == test::CallTest::kVideoSendSsrcs[0] ||
87 rtp_packet.Ssrc() == test::CallTest::kVideoSendSsrcs[1] ||
88 rtp_packet.Ssrc() == test::CallTest::kVideoSendSsrcs[2])
Åsa Perssonad3c7a42017-11-29 10:24:27 +010089 << "Unknown SSRC sent.";
90
Danil Chapovalovb57fe172019-12-11 09:38:44 +010091 if (rtp_packet.payload_size() == 0) {
Åsa Perssonad3c7a42017-11-29 10:24:27 +010092 return false; // Padding packet.
93 }
94
Danil Chapovalovc3475852019-12-05 13:51:32 +010095 parsed->timestamp = rtp_packet.Timestamp();
96 parsed->ssrc = rtp_packet.Ssrc();
Åsa Perssonad3c7a42017-11-29 10:24:27 +010097
Danil Chapovalovb57fe172019-12-11 09:38:44 +010098 absl::optional<VideoRtpDepacketizer::ParsedRtpPayload> parsed_payload =
99 depacketizer_->Parse(rtp_packet.PayloadBuffer());
100 EXPECT_TRUE(parsed_payload);
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100101
Danil Chapovalovb57fe172019-12-11 09:38:44 +0100102 if (const auto* vp8_header = absl::get_if<RTPVideoHeaderVP8>(
103 &parsed_payload->video_header.video_type_header)) {
104 parsed->picture_id = vp8_header->pictureId;
105 parsed->tl0_pic_idx = vp8_header->tl0PicIdx;
106 parsed->temporal_idx = vp8_header->temporalIdx;
107 } else if (const auto* vp9_header = absl::get_if<RTPVideoHeaderVP9>(
108 &parsed_payload->video_header.video_type_header)) {
109 parsed->picture_id = vp9_header->picture_id;
110 parsed->tl0_pic_idx = vp9_header->tl0_pic_idx;
111 parsed->temporal_idx = vp9_header->temporal_idx;
112 } else {
113 RTC_NOTREACHED();
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100114 }
115
Danil Chapovalovb57fe172019-12-11 09:38:44 +0100116 parsed->frame_type = parsed_payload->video_header.frame_type;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100117 return true;
118 }
119
Åsa Persson71485ac2017-12-04 11:11:19 +0100120 // Verify continuity and monotonicity of picture_id sequence.
121 void VerifyPictureId(const ParsedPacket& current,
122 const ParsedPacket& last) const
123 RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
124 if (current.timestamp == last.timestamp) {
125 EXPECT_EQ(last.picture_id, current.picture_id);
126 return; // Same frame.
127 }
128
129 // Packet belongs to a new frame.
130 // Picture id should be increasing.
131 EXPECT_TRUE((AheadOf<uint16_t, kPictureIdWraparound>(current.picture_id,
132 last.picture_id)));
133
134 // Expect continuously increasing picture id.
135 int diff = ForwardDiff<uint16_t, kPictureIdWraparound>(last.picture_id,
136 current.picture_id);
137 if (diff > 1) {
138 // If the VideoSendStream is destroyed, any frames still in queue is lost.
139 // Gaps only possible for first frame after a recreation, i.e. key frames.
Niels Möller8f7ce222019-03-21 15:43:58 +0100140 EXPECT_EQ(VideoFrameType::kVideoFrameKey, current.frame_type);
Åsa Persson71485ac2017-12-04 11:11:19 +0100141 EXPECT_LE(diff - 1, max_expected_picture_id_gap_);
142 }
143 }
144
145 void VerifyTl0Idx(const ParsedPacket& current, const ParsedPacket& last) const
146 RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
147 if (current.tl0_pic_idx == kNoTl0PicIdx ||
148 current.temporal_idx == kNoTemporalIdx) {
149 return; // No temporal layers.
150 }
151
152 if (current.timestamp == last.timestamp || current.temporal_idx != 0) {
153 EXPECT_EQ(last.tl0_pic_idx, current.tl0_pic_idx);
154 return;
155 }
156
157 // New frame with |temporal_idx| 0.
158 // |tl0_pic_idx| should be increasing.
159 EXPECT_TRUE(AheadOf<uint8_t>(current.tl0_pic_idx, last.tl0_pic_idx));
160
161 // Expect continuously increasing idx.
162 int diff = ForwardDiff<uint8_t>(last.tl0_pic_idx, current.tl0_pic_idx);
163 if (diff > 1) {
164 // If the VideoSendStream is destroyed, any frames still in queue is lost.
165 // Gaps only possible for first frame after a recreation, i.e. key frames.
Niels Möller8f7ce222019-03-21 15:43:58 +0100166 EXPECT_EQ(VideoFrameType::kVideoFrameKey, current.frame_type);
Åsa Persson71485ac2017-12-04 11:11:19 +0100167 EXPECT_LE(diff - 1, max_expected_tl0_idx_gap_);
168 }
169 }
170
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200171 Action OnSendRtp(const uint8_t* packet, size_t length) override {
172 rtc::CritScope lock(&crit_);
173
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100174 ParsedPacket parsed;
Åsa Persson71485ac2017-12-04 11:11:19 +0100175 if (!ParsePayload(packet, length, &parsed))
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200176 return SEND_PACKET;
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200177
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100178 uint32_t ssrc = parsed.ssrc;
179 if (last_observed_packet_.find(ssrc) != last_observed_packet_.end()) {
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100180 // Compare to last packet.
Åsa Persson71485ac2017-12-04 11:11:19 +0100181 VerifyPictureId(parsed, last_observed_packet_[ssrc]);
182 VerifyTl0Idx(parsed, last_observed_packet_[ssrc]);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200183 }
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200184
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100185 last_observed_packet_[ssrc] = parsed;
186
187 // Pass the test when enough media packets have been received on all
188 // streams.
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200189 if (++num_packets_sent_[ssrc] >= kMinPacketsToObserve &&
190 observed_ssrcs_.find(ssrc) == observed_ssrcs_.end()) {
191 observed_ssrcs_.insert(ssrc);
192 if (observed_ssrcs_.size() == num_ssrcs_to_observe_) {
193 observation_complete_.Set();
194 }
195 }
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200196 return SEND_PACKET;
197 }
198
199 rtc::CriticalSection crit_;
Danil Chapovalovb57fe172019-12-11 09:38:44 +0100200 const std::unique_ptr<VideoRtpDepacketizer> depacketizer_;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100201 std::map<uint32_t, ParsedPacket> last_observed_packet_ RTC_GUARDED_BY(crit_);
danilchapa37de392017-09-09 04:17:22 -0700202 std::map<uint32_t, size_t> num_packets_sent_ RTC_GUARDED_BY(crit_);
203 int max_expected_picture_id_gap_ RTC_GUARDED_BY(crit_);
Åsa Persson71485ac2017-12-04 11:11:19 +0100204 int max_expected_tl0_idx_gap_ RTC_GUARDED_BY(crit_);
danilchapa37de392017-09-09 04:17:22 -0700205 size_t num_ssrcs_to_observe_ RTC_GUARDED_BY(crit_);
206 std::set<uint32_t> observed_ssrcs_ RTC_GUARDED_BY(crit_);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200207};
208
Åsa Persson4bece9a2017-10-06 10:04:04 +0200209class PictureIdTest : public test::CallTest,
Åsa Persson677f42c2018-03-16 13:09:17 +0100210 public ::testing::WithParamInterface<size_t> {
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200211 public:
Åsa Persson677f42c2018-03-16 13:09:17 +0100212 PictureIdTest() : num_temporal_layers_(GetParam()) {}
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200213
214 virtual ~PictureIdTest() {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200215 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700216 send_transport_.reset();
217 receive_transport_.reset();
218 DestroyCalls();
219 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200220 }
221
Niels Möller4db138e2018-04-19 09:04:13 +0200222 void SetupEncoder(VideoEncoderFactory* encoder_factory,
223 const std::string& payload_name);
Åsa Persson44327c32019-08-08 09:33:41 +0200224 void SetVideoEncoderConfig(int num_streams);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200225 void TestPictureIdContinuousAfterReconfigure(
226 const std::vector<int>& ssrc_counts);
227 void TestPictureIdIncreaseAfterRecreateStreams(
228 const std::vector<int>& ssrc_counts);
229
230 private:
Åsa Persson71485ac2017-12-04 11:11:19 +0100231 const size_t num_temporal_layers_;
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100232 std::unique_ptr<PictureIdObserver> observer_;
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200233};
234
Mirko Bonadeic84f6612019-01-31 12:20:57 +0100235INSTANTIATE_TEST_SUITE_P(TemporalLayers,
236 PictureIdTest,
237 ::testing::ValuesIn(kNumTemporalLayers));
Åsa Persson4bece9a2017-10-06 10:04:04 +0200238
Niels Möller4db138e2018-04-19 09:04:13 +0200239void PictureIdTest::SetupEncoder(VideoEncoderFactory* encoder_factory,
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100240 const std::string& payload_name) {
241 observer_.reset(
Niels Möller520ca4e2018-06-04 11:14:38 +0200242 new PictureIdObserver(PayloadStringToCodecType(payload_name)));
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100243
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200244 SendTask(
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200245 RTC_FROM_HERE, task_queue(), [this, encoder_factory, payload_name]() {
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200246 CreateCalls();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200247
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200248 send_transport_.reset(new test::PacketTransport(
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200249 task_queue(), sender_call_.get(), observer_.get(),
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200250 test::PacketTransport::kSender, payload_type_map_,
251 std::make_unique<FakeNetworkPipe>(
252 Clock::GetRealTimeClock(),
253 std::make_unique<SimulatedNetwork>(
254 BuiltInNetworkBehaviorConfig()))));
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200255
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +0200256 CreateSendConfig(kNumSimulcastStreams, 0, 0, send_transport_.get());
257 GetVideoSendConfig()->encoder_settings.encoder_factory =
258 encoder_factory;
259 GetVideoSendConfig()->rtp.payload_name = payload_name;
260 GetVideoEncoderConfig()->codec_type =
261 PayloadStringToCodecType(payload_name);
262 SetVideoEncoderConfig(/* number_of_streams */ 1);
263 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200264}
265
Åsa Persson44327c32019-08-08 09:33:41 +0200266void PictureIdTest::SetVideoEncoderConfig(int num_streams) {
267 GetVideoEncoderConfig()->number_of_streams = num_streams;
268 GetVideoEncoderConfig()->max_bitrate_bps = kEncoderBitrateBps;
269
270 // Always divide the same total bitrate across all streams so that sending a
271 // single stream avoids lowering the bitrate estimate and requiring a
272 // subsequent rampup.
273 const int encoder_stream_bps = kEncoderBitrateBps / num_streams;
274 double scale_factor = 1.0;
275 for (int i = num_streams - 1; i >= 0; --i) {
276 VideoStream& stream = GetVideoEncoderConfig()->simulcast_layers[i];
277 // Reduce the min bitrate by 10% to account for overhead that might
278 // otherwise cause streams to not be enabled.
279 stream.min_bitrate_bps = static_cast<int>(encoder_stream_bps * 0.9);
280 stream.target_bitrate_bps = encoder_stream_bps;
281 stream.max_bitrate_bps = encoder_stream_bps;
282 stream.num_temporal_layers = num_temporal_layers_;
283 stream.scale_resolution_down_by = scale_factor;
284 scale_factor *= 2.0;
285 }
286}
287
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200288void PictureIdTest::TestPictureIdContinuousAfterReconfigure(
289 const std::vector<int>& ssrc_counts) {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200290 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700291 CreateVideoStreams();
292 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200293
eladalon413ee9a2017-08-22 04:02:52 -0700294 // Initial test with a single stream.
295 Start();
296 });
297
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100298 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200299
300 // Reconfigure VideoEncoder and test picture id increase.
Åsa Perssonae819752017-10-10 11:05:59 +0200301 // Expect continuously increasing picture id, equivalent to no gaps.
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100302 observer_->SetMaxExpectedPictureIdGap(0);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200303 for (int ssrc_count : ssrc_counts) {
Åsa Persson44327c32019-08-08 09:33:41 +0200304 SetVideoEncoderConfig(ssrc_count);
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100305 observer_->SetExpectedSsrcs(ssrc_count);
306 observer_->ResetObservedSsrcs();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200307 // Make sure the picture_id sequence is continuous on reinit and recreate.
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200308 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
Sebastian Janssonf33905d2018-07-13 09:49:00 +0200309 GetVideoSendStream()->ReconfigureVideoEncoder(
310 GetVideoEncoderConfig()->Copy());
eladalon413ee9a2017-08-22 04:02:52 -0700311 });
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100312 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200313 }
314
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200315 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700316 Stop();
317 DestroyStreams();
eladalon413ee9a2017-08-22 04:02:52 -0700318 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200319}
320
321void PictureIdTest::TestPictureIdIncreaseAfterRecreateStreams(
322 const std::vector<int>& ssrc_counts) {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200323 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700324 CreateVideoStreams();
325 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200326
eladalon413ee9a2017-08-22 04:02:52 -0700327 // Initial test with a single stream.
328 Start();
329 });
330
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100331 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200332
333 // Recreate VideoSendStream and test picture id increase.
334 // When the VideoSendStream is destroyed, any frames still in queue is lost
335 // with it, therefore it is expected that some frames might be lost.
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100336 observer_->SetMaxExpectedPictureIdGap(kMaxFramesLost);
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200337 for (int ssrc_count : ssrc_counts) {
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200338 SendTask(RTC_FROM_HERE, task_queue(), [this, &ssrc_count]() {
Sebastian Janssonf33905d2018-07-13 09:49:00 +0200339 DestroyVideoSendStreams();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200340
Åsa Persson44327c32019-08-08 09:33:41 +0200341 SetVideoEncoderConfig(ssrc_count);
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100342 observer_->SetExpectedSsrcs(ssrc_count);
343 observer_->ResetObservedSsrcs();
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200344
Sebastian Janssonf33905d2018-07-13 09:49:00 +0200345 CreateVideoSendStreams();
346 GetVideoSendStream()->Start();
eladalon413ee9a2017-08-22 04:02:52 -0700347 CreateFrameGeneratorCapturer(kFrameRate, kFrameMaxWidth, kFrameMaxHeight);
eladalon413ee9a2017-08-22 04:02:52 -0700348 });
349
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100350 EXPECT_TRUE(observer_->Wait()) << "Timed out waiting for packets.";
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200351 }
352
Danil Chapovalovd15a0282019-10-22 10:48:17 +0200353 SendTask(RTC_FROM_HERE, task_queue(), [this]() {
eladalon413ee9a2017-08-22 04:02:52 -0700354 Stop();
355 DestroyStreams();
eladalon413ee9a2017-08-22 04:02:52 -0700356 });
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200357}
358
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100359TEST_P(PictureIdTest, ContinuousAfterReconfigureVp8) {
Niels Möller4db138e2018-04-19 09:04:13 +0200360 test::FunctionVideoEncoderFactory encoder_factory(
361 []() { return VP8Encoder::Create(); });
362 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200363 TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1});
364}
365
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100366TEST_P(PictureIdTest, IncreasingAfterRecreateStreamVp8) {
Niels Möller4db138e2018-04-19 09:04:13 +0200367 test::FunctionVideoEncoderFactory encoder_factory(
368 []() { return VP8Encoder::Create(); });
369 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200370 TestPictureIdIncreaseAfterRecreateStreams({1, 3, 3, 1, 1});
371}
372
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100373TEST_P(PictureIdTest, ContinuousAfterStreamCountChangeVp8) {
Niels Möller4db138e2018-04-19 09:04:13 +0200374 test::FunctionVideoEncoderFactory encoder_factory(
375 []() { return VP8Encoder::Create(); });
Åsa Persson71485ac2017-12-04 11:11:19 +0100376 // Make sure that the picture id is not reset if the stream count goes
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200377 // down and then up.
Niels Möller4db138e2018-04-19 09:04:13 +0200378 SetupEncoder(&encoder_factory, "VP8");
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100379 TestPictureIdContinuousAfterReconfigure({3, 1, 3});
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200380}
381
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100382TEST_P(PictureIdTest, ContinuousAfterReconfigureSimulcastEncoderAdapter) {
Magnus Jedvertdf4883d2017-11-17 14:44:55 +0100383 InternalEncoderFactory internal_encoder_factory;
Niels Möller4db138e2018-04-19 09:04:13 +0200384 test::FunctionVideoEncoderFactory encoder_factory(
385 [&internal_encoder_factory]() {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200386 return std::make_unique<SimulcastEncoderAdapter>(
Ilya Nikolaevskiy97b4ee52018-05-28 10:24:22 +0200387 &internal_encoder_factory, SdpVideoFormat("VP8"));
Niels Möller4db138e2018-04-19 09:04:13 +0200388 });
389 SetupEncoder(&encoder_factory, "VP8");
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200390 TestPictureIdContinuousAfterReconfigure({1, 3, 3, 1, 1});
391}
392
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100393TEST_P(PictureIdTest, IncreasingAfterRecreateStreamSimulcastEncoderAdapter) {
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 TestPictureIdIncreaseAfterRecreateStreams({1, 3, 3, 1, 1});
402}
403
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100404TEST_P(PictureIdTest, ContinuousAfterStreamCountChangeSimulcastEncoderAdapter) {
Åsa Persson677f42c2018-03-16 13:09:17 +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 });
Åsa Persson677f42c2018-03-16 13:09:17 +0100411 // Make sure that the picture id is not reset if the stream count goes
412 // down and then up.
Niels Möller4db138e2018-04-19 09:04:13 +0200413 SetupEncoder(&encoder_factory, "VP8");
Åsa Persson677f42c2018-03-16 13:09:17 +0100414 TestPictureIdContinuousAfterReconfigure({3, 1, 3});
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200415}
416
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100417TEST_P(PictureIdTest, IncreasingAfterRecreateStreamVp9) {
Niels Möller4db138e2018-04-19 09:04:13 +0200418 test::FunctionVideoEncoderFactory encoder_factory(
419 []() { return VP9Encoder::Create(); });
420 SetupEncoder(&encoder_factory, "VP9");
Åsa Perssonad3c7a42017-11-29 10:24:27 +0100421 TestPictureIdIncreaseAfterRecreateStreams({1, 1});
422}
423
Sebastian Janssone92f93f2017-06-22 14:44:04 +0200424} // namespace webrtc