blob: 60a0bc8a15a259f42b625a8e84a72912b5a0b163 [file] [log] [blame]
Sebastian Janssonc5017132018-02-02 15:24:161/*
2 * Copyright 2018 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 */
10
Mirko Bonadei317a1f02019-09-17 15:06:1811#include <memory>
Artem Titov8a9f3a82023-04-25 07:56:4912
Johannes Kronf7f13e02018-12-12 10:17:4313#include "absl/types/optional.h"
Danil Chapovalov99b71df2018-10-26 13:57:4814#include "api/test/video/function_video_encoder_factory.h"
Johannes Kronf7f13e02018-12-12 10:17:4315#include "api/video/color_space.h"
16#include "api/video/video_rotation.h"
Johannes Kronf1ab9b92018-12-14 09:14:0717#include "common_video/test/utilities.h"
Florent Castelli5278b392023-05-31 12:44:3218#include "media/base/codec.h"
19#include "media/base/media_constants.h"
Steve Anton10542f22019-01-11 17:11:0020#include "media/engine/internal_decoder_factory.h"
21#include "media/engine/internal_encoder_factory.h"
Sebastian Janssonc5017132018-02-02 15:24:1622#include "modules/video_coding/codecs/h264/include/h264.h"
Emircan Uysaleref76e5a2018-02-12 21:36:4123#include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h"
24#include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h"
Sebastian Janssonc5017132018-02-02 15:24:1625#include "modules/video_coding/codecs/vp8/include/vp8.h"
26#include "modules/video_coding/codecs/vp9/include/vp9.h"
27#include "test/call_test.h"
28#include "test/encoder_settings.h"
29#include "test/field_trial.h"
30#include "test/gtest.h"
Artem Titov8a9f3a82023-04-25 07:56:4931#include "test/video_test_constants.h"
Sebastian Janssonc5017132018-02-02 15:24:1632
33namespace webrtc {
Elad Alond8d32482019-02-18 22:45:5734namespace {
35enum : int { // The first valid value is 1.
36 kColorSpaceExtensionId = 1,
37 kVideoRotationExtensionId,
38};
39} // namespace
Sebastian Janssonc5017132018-02-02 15:24:1640
Danil Chapovalov636865e2020-06-03 12:11:2641class CodecEndToEndTest : public test::CallTest {
Sebastian Janssonc5017132018-02-02 15:24:1642 public:
Danil Chapovalov636865e2020-06-03 12:11:2643 CodecEndToEndTest() {
Elad Alond8d32482019-02-18 22:45:5744 RegisterRtpExtension(
45 RtpExtension(RtpExtension::kColorSpaceUri, kColorSpaceExtensionId));
46 RegisterRtpExtension(RtpExtension(RtpExtension::kVideoRotationUri,
47 kVideoRotationExtensionId));
48 }
Sebastian Janssonc5017132018-02-02 15:24:1649};
50
Sebastian Janssonc5017132018-02-02 15:24:1651class CodecObserver : public test::EndToEndTest,
52 public rtc::VideoSinkInterface<VideoFrame> {
53 public:
54 CodecObserver(int no_frames_to_wait_for,
55 VideoRotation rotation_to_test,
Johannes Kronf7f13e02018-12-12 10:17:4356 absl::optional<ColorSpace> color_space_to_test,
Sebastian Janssonc5017132018-02-02 15:24:1657 const std::string& payload_name,
Niels Möller4db138e2018-04-19 07:04:1358 VideoEncoderFactory* encoder_factory,
Niels Möllercbcbc222018-09-28 07:07:2459 VideoDecoderFactory* decoder_factory)
Artem Titov8a9f3a82023-04-25 07:56:4960 : EndToEndTest(4 * test::VideoTestConstants::kDefaultTimeout),
Sebastian Janssonc5017132018-02-02 15:24:1661 // TODO(hta): This timeout (120 seconds) is excessive.
62 // https://bugs.webrtc.org/6830
63 no_frames_to_wait_for_(no_frames_to_wait_for),
64 expected_rotation_(rotation_to_test),
Johannes Kronf7f13e02018-12-12 10:17:4365 expected_color_space_(color_space_to_test),
Sebastian Janssonc5017132018-02-02 15:24:1666 payload_name_(payload_name),
Niels Möller4db138e2018-04-19 07:04:1367 encoder_factory_(encoder_factory),
Niels Möllercbcbc222018-09-28 07:07:2468 decoder_factory_(decoder_factory),
Sebastian Janssonc5017132018-02-02 15:24:1669 frame_counter_(0) {}
70
71 void PerformTest() override {
72 EXPECT_TRUE(Wait())
73 << "Timed out while waiting for enough frames to be decoded.";
74 }
75
76 void ModifyVideoConfigs(
77 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:2078 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
Sebastian Janssonc5017132018-02-02 15:24:1679 VideoEncoderConfig* encoder_config) override {
Niels Möller259a4972018-04-05 13:36:5180 encoder_config->codec_type = PayloadStringToCodecType(payload_name_);
Niels Möller4db138e2018-04-19 07:04:1381 send_config->encoder_settings.encoder_factory = encoder_factory_;
Niels Möller259a4972018-04-05 13:36:5182 send_config->rtp.payload_name = payload_name_;
Artem Titov8a9f3a82023-04-25 07:56:4983 send_config->rtp.payload_type =
84 test::VideoTestConstants::kVideoSendPayloadType;
Sebastian Janssonc5017132018-02-02 15:24:1685
86 (*receive_configs)[0].renderer = this;
87 (*receive_configs)[0].decoders.resize(1);
88 (*receive_configs)[0].decoders[0].payload_type =
Niels Möller259a4972018-04-05 13:36:5189 send_config->rtp.payload_type;
Niels Möllercb7e1d22018-09-11 13:56:0490 (*receive_configs)[0].decoders[0].video_format =
91 SdpVideoFormat(send_config->rtp.payload_name);
Philip Eliasson2b068ce2020-08-03 15:55:1092 (*receive_configs)[0].decoder_factory = decoder_factory_;
Sebastian Janssonc5017132018-02-02 15:24:1693 }
94
95 void OnFrame(const VideoFrame& video_frame) override {
96 EXPECT_EQ(expected_rotation_, video_frame.rotation());
Johannes Kronf7f13e02018-12-12 10:17:4397 // Test only if explicit color space has been specified since otherwise the
98 // color space is codec dependent.
99 if (expected_color_space_) {
100 EXPECT_EQ(expected_color_space_,
101 video_frame.color_space()
102 ? absl::make_optional(*video_frame.color_space())
103 : absl::nullopt);
104 }
Sebastian Janssonc5017132018-02-02 15:24:16105 if (++frame_counter_ == no_frames_to_wait_for_)
106 observation_complete_.Set();
107 }
108
109 void OnFrameGeneratorCapturerCreated(
110 test::FrameGeneratorCapturer* frame_generator_capturer) override {
111 frame_generator_capturer->SetFakeRotation(expected_rotation_);
Johannes Kronf7f13e02018-12-12 10:17:43112 frame_generator_capturer->SetFakeColorSpace(expected_color_space_);
Sebastian Janssonc5017132018-02-02 15:24:16113 }
114
115 private:
116 int no_frames_to_wait_for_;
117 VideoRotation expected_rotation_;
Johannes Kronf7f13e02018-12-12 10:17:43118 absl::optional<ColorSpace> expected_color_space_;
Sebastian Janssonc5017132018-02-02 15:24:16119 std::string payload_name_;
Niels Möller4db138e2018-04-19 07:04:13120 VideoEncoderFactory* encoder_factory_;
Niels Möllercbcbc222018-09-28 07:07:24121 VideoDecoderFactory* decoder_factory_;
Sebastian Janssonc5017132018-02-02 15:24:16122 int frame_counter_;
123};
124
Danil Chapovalov636865e2020-06-03 12:11:26125TEST_F(CodecEndToEndTest, SendsAndReceivesVP8) {
Niels Möller4db138e2018-04-19 07:04:13126 test::FunctionVideoEncoderFactory encoder_factory(
127 []() { return VP8Encoder::Create(); });
Niels Möllercbcbc222018-09-28 07:07:24128 test::FunctionVideoDecoderFactory decoder_factory(
129 []() { return VP8Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43130 CodecObserver test(5, kVideoRotation_0, absl::nullopt, "VP8",
131 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16132 RunBaseTest(&test);
133}
134
Danil Chapovalov636865e2020-06-03 12:11:26135TEST_F(CodecEndToEndTest, SendsAndReceivesVP8Rotation90) {
Niels Möller4db138e2018-04-19 07:04:13136 test::FunctionVideoEncoderFactory encoder_factory(
137 []() { return VP8Encoder::Create(); });
Niels Möllercbcbc222018-09-28 07:07:24138 test::FunctionVideoDecoderFactory decoder_factory(
139 []() { return VP8Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43140 CodecObserver test(5, kVideoRotation_90, absl::nullopt, "VP8",
141 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16142 RunBaseTest(&test);
143}
144
Mirko Bonadei8ef57932018-11-16 13:38:03145#if defined(RTC_ENABLE_VP9)
Danil Chapovalov636865e2020-06-03 12:11:26146TEST_F(CodecEndToEndTest, SendsAndReceivesVP9) {
Niels Möller4db138e2018-04-19 07:04:13147 test::FunctionVideoEncoderFactory encoder_factory(
148 []() { return VP9Encoder::Create(); });
Niels Möllercbcbc222018-09-28 07:07:24149 test::FunctionVideoDecoderFactory decoder_factory(
150 []() { return VP9Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43151 CodecObserver test(500, kVideoRotation_0, absl::nullopt, "VP9",
152 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16153 RunBaseTest(&test);
154}
155
Danil Chapovalov636865e2020-06-03 12:11:26156TEST_F(CodecEndToEndTest, SendsAndReceivesVP9VideoRotation90) {
Niels Möller4db138e2018-04-19 07:04:13157 test::FunctionVideoEncoderFactory encoder_factory(
158 []() { return VP9Encoder::Create(); });
Niels Möllercbcbc222018-09-28 07:07:24159 test::FunctionVideoDecoderFactory decoder_factory(
160 []() { return VP9Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43161 CodecObserver test(5, kVideoRotation_90, absl::nullopt, "VP9",
162 &encoder_factory, &decoder_factory);
163 RunBaseTest(&test);
164}
165
Danil Chapovalov636865e2020-06-03 12:11:26166TEST_F(CodecEndToEndTest, SendsAndReceivesVP9ExplicitColorSpace) {
Johannes Kronf7f13e02018-12-12 10:17:43167 test::FunctionVideoEncoderFactory encoder_factory(
168 []() { return VP9Encoder::Create(); });
169 test::FunctionVideoDecoderFactory decoder_factory(
170 []() { return VP9Decoder::Create(); });
171 CodecObserver test(5, kVideoRotation_90,
172 CreateTestColorSpace(/*with_hdr_metadata=*/false), "VP9",
173 &encoder_factory, &decoder_factory);
174 RunBaseTest(&test);
175}
176
Danil Chapovalov636865e2020-06-03 12:11:26177TEST_F(CodecEndToEndTest,
Johannes Kronf7f13e02018-12-12 10:17:43178 SendsAndReceivesVP9ExplicitColorSpaceWithHdrMetadata) {
179 test::FunctionVideoEncoderFactory encoder_factory(
180 []() { return VP9Encoder::Create(); });
181 test::FunctionVideoDecoderFactory decoder_factory(
182 []() { return VP9Decoder::Create(); });
183 CodecObserver test(5, kVideoRotation_90,
184 CreateTestColorSpace(/*with_hdr_metadata=*/true), "VP9",
185 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16186 RunBaseTest(&test);
187}
Emircan Uysaleref76e5a2018-02-12 21:36:41188
189// Mutiplex tests are using VP9 as the underlying implementation.
Danil Chapovalov636865e2020-06-03 12:11:26190TEST_F(CodecEndToEndTest, SendsAndReceivesMultiplex) {
Niels Möller4db138e2018-04-19 07:04:13191 InternalEncoderFactory internal_encoder_factory;
Niels Möllercbcbc222018-09-28 07:07:24192 InternalDecoderFactory internal_decoder_factory;
Niels Möller4db138e2018-04-19 07:04:13193 test::FunctionVideoEncoderFactory encoder_factory(
194 [&internal_encoder_factory]() {
Mirko Bonadei317a1f02019-09-17 15:06:18195 return std::make_unique<MultiplexEncoderAdapter>(
Niels Möller4db138e2018-04-19 07:04:13196 &internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName));
197 });
Niels Möllercbcbc222018-09-28 07:07:24198 test::FunctionVideoDecoderFactory decoder_factory(
199 [&internal_decoder_factory]() {
Mirko Bonadei317a1f02019-09-17 15:06:18200 return std::make_unique<MultiplexDecoderAdapter>(
Niels Möllercbcbc222018-09-28 07:07:24201 &internal_decoder_factory, SdpVideoFormat(cricket::kVp9CodecName));
202 });
203
Johannes Kronf7f13e02018-12-12 10:17:43204 CodecObserver test(5, kVideoRotation_0, absl::nullopt, "multiplex",
205 &encoder_factory, &decoder_factory);
Emircan Uysaleref76e5a2018-02-12 21:36:41206 RunBaseTest(&test);
207}
208
Danil Chapovalov636865e2020-06-03 12:11:26209TEST_F(CodecEndToEndTest, SendsAndReceivesMultiplexVideoRotation90) {
Niels Möller4db138e2018-04-19 07:04:13210 InternalEncoderFactory internal_encoder_factory;
Niels Möllercbcbc222018-09-28 07:07:24211 InternalDecoderFactory internal_decoder_factory;
Niels Möller4db138e2018-04-19 07:04:13212 test::FunctionVideoEncoderFactory encoder_factory(
213 [&internal_encoder_factory]() {
Mirko Bonadei317a1f02019-09-17 15:06:18214 return std::make_unique<MultiplexEncoderAdapter>(
Niels Möller4db138e2018-04-19 07:04:13215 &internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName));
216 });
Niels Möllercbcbc222018-09-28 07:07:24217 test::FunctionVideoDecoderFactory decoder_factory(
218 [&internal_decoder_factory]() {
Mirko Bonadei317a1f02019-09-17 15:06:18219 return std::make_unique<MultiplexDecoderAdapter>(
Niels Möllercbcbc222018-09-28 07:07:24220 &internal_decoder_factory, SdpVideoFormat(cricket::kVp9CodecName));
221 });
Johannes Kronf7f13e02018-12-12 10:17:43222 CodecObserver test(5, kVideoRotation_90, absl::nullopt, "multiplex",
223 &encoder_factory, &decoder_factory);
Emircan Uysaleref76e5a2018-02-12 21:36:41224 RunBaseTest(&test);
225}
226
Mirko Bonadei8ef57932018-11-16 13:38:03227#endif // defined(RTC_ENABLE_VP9)
Sebastian Janssonc5017132018-02-02 15:24:16228
229#if defined(WEBRTC_USE_H264)
Ilya Nikolaevskiycb960622018-09-04 09:07:31230class EndToEndTestH264 : public test::CallTest,
Mirko Bonadei6a489f22019-04-09 13:11:12231 public ::testing::WithParamInterface<std::string> {
Ilya Nikolaevskiycb960622018-09-04 09:07:31232 public:
Erik Språngeb3307f2022-08-22 09:06:06233 EndToEndTestH264() : field_trial_(GetParam()) {
Elad Alond8d32482019-02-18 22:45:57234 RegisterRtpExtension(RtpExtension(RtpExtension::kVideoRotationUri,
235 kVideoRotationExtensionId));
236 }
Erik Språngeb3307f2022-08-22 09:06:06237
238 private:
239 test::ScopedFieldTrials field_trial_;
Ilya Nikolaevskiycb960622018-09-04 09:07:31240};
241
Erik Språngeb3307f2022-08-22 09:06:06242INSTANTIATE_TEST_SUITE_P(
243 SpsPpsIdrIsKeyframe,
244 EndToEndTestH264,
245 ::testing::Values("WebRTC-SpsPpsIdrIsH264Keyframe/Disabled/",
246 "WebRTC-SpsPpsIdrIsH264Keyframe/Enabled/"));
247
248TEST_P(EndToEndTestH264, SendsAndReceivesH264) {
Niels Möller4db138e2018-04-19 07:04:13249 test::FunctionVideoEncoderFactory encoder_factory(
Florent Castelli5278b392023-05-31 12:44:32250 []() { return H264Encoder::Create(); });
Niels Möllercbcbc222018-09-28 07:07:24251 test::FunctionVideoDecoderFactory decoder_factory(
252 []() { return H264Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43253 CodecObserver test(500, kVideoRotation_0, absl::nullopt, "H264",
254 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16255 RunBaseTest(&test);
256}
257
Erik Språngeb3307f2022-08-22 09:06:06258TEST_P(EndToEndTestH264, SendsAndReceivesH264VideoRotation90) {
Niels Möller4db138e2018-04-19 07:04:13259 test::FunctionVideoEncoderFactory encoder_factory(
Florent Castelli5278b392023-05-31 12:44:32260 []() { return H264Encoder::Create(); });
Niels Möllercbcbc222018-09-28 07:07:24261 test::FunctionVideoDecoderFactory decoder_factory(
262 []() { return H264Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43263 CodecObserver test(5, kVideoRotation_90, absl::nullopt, "H264",
264 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16265 RunBaseTest(&test);
266}
267
Erik Språngeb3307f2022-08-22 09:06:06268TEST_P(EndToEndTestH264, SendsAndReceivesH264PacketizationMode0) {
Florent Castelli5278b392023-05-31 12:44:32269 cricket::VideoCodec codec =
270 cricket::CreateVideoCodec(cricket::kH264CodecName);
Sebastian Janssonc5017132018-02-02 15:24:16271 codec.SetParam(cricket::kH264FmtpPacketizationMode, "0");
Niels Möller4db138e2018-04-19 07:04:13272 test::FunctionVideoEncoderFactory encoder_factory(
273 [codec]() { return H264Encoder::Create(codec); });
Niels Möllercbcbc222018-09-28 07:07:24274 test::FunctionVideoDecoderFactory decoder_factory(
275 []() { return H264Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43276 CodecObserver test(500, kVideoRotation_0, absl::nullopt, "H264",
277 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16278 RunBaseTest(&test);
279}
280
Erik Språngeb3307f2022-08-22 09:06:06281TEST_P(EndToEndTestH264, SendsAndReceivesH264PacketizationMode1) {
Florent Castelli5278b392023-05-31 12:44:32282 cricket::VideoCodec codec =
283 cricket::CreateVideoCodec(cricket::kH264CodecName);
Sebastian Janssonc5017132018-02-02 15:24:16284 codec.SetParam(cricket::kH264FmtpPacketizationMode, "1");
Niels Möller4db138e2018-04-19 07:04:13285 test::FunctionVideoEncoderFactory encoder_factory(
286 [codec]() { return H264Encoder::Create(codec); });
Niels Möllercbcbc222018-09-28 07:07:24287 test::FunctionVideoDecoderFactory decoder_factory(
288 []() { return H264Decoder::Create(); });
Johannes Kronf7f13e02018-12-12 10:17:43289 CodecObserver test(500, kVideoRotation_0, absl::nullopt, "H264",
290 &encoder_factory, &decoder_factory);
Sebastian Janssonc5017132018-02-02 15:24:16291 RunBaseTest(&test);
292}
293#endif // defined(WEBRTC_USE_H264)
294
295} // namespace webrtc