Skip to content

Commit 2e1a9a4

Browse files
Sergey SilkinWebRTC LUCI CQ
authored andcommitted
Add video codec tester.
This tester is an improved version of VideoProcessor and VideoCodecTestFixture and will eventually replace them. The tester provides better separation between codecs and testing logic. Its knowledge about codecs is limited to frame encode/decode calls and frame ready callbacks. Instantiation and configuration of codecs are the test responsibilities. Other differences: - Run encoding and decoding in separate threads - Run quality analysis in a separate thread - Reference frame buffering is moved into video source (which re-read frames from the file). - Make it possible to run decode-only tests This CL is MVP implementation: it adds only 1 test (video_codec_test.cc, ConstantRate/EncodeDecodeTest) and the test is disabled for now. Bug: b/261160916 Change-Id: Ida24a2fca1b1496237fa695c812084877c76379f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/283525 Commit-Queue: Sergey Silkin <[email protected]> Reviewed-by: Rasmus Brandt <[email protected]> Reviewed-by: Mirko Bonadei <[email protected]> Cr-Commit-Position: refs/heads/main@{#38901}
1 parent aa5897d commit 2e1a9a4

16 files changed

+1836
-16
lines changed

api/BUILD.gn

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,22 +985,50 @@ if (rtc_include_tests) {
985985
]
986986
}
987987

988-
rtc_library("videocodec_test_fixture_api") {
988+
rtc_library("videocodec_test_stats_api") {
989989
visibility = [ "*" ]
990990
testonly = true
991991
sources = [
992-
"test/videocodec_test_fixture.h",
993992
"test/videocodec_test_stats.cc",
994993
"test/videocodec_test_stats.h",
995994
]
996995
deps = [
997-
"../modules/video_coding:video_codec_interface",
996+
"../api/units:data_rate",
997+
"../api/units:frequency",
998998
"../rtc_base:stringutils",
999999
"video:video_frame_type",
1000+
]
1001+
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
1002+
}
1003+
1004+
rtc_library("videocodec_test_fixture_api") {
1005+
visibility = [ "*" ]
1006+
testonly = true
1007+
sources = [ "test/videocodec_test_fixture.h" ]
1008+
deps = [
1009+
":videocodec_test_stats_api",
1010+
"../modules/video_coding:video_codec_interface",
10001011
"video_codecs:video_codecs_api",
10011012
]
10021013
}
10031014

1015+
rtc_library("video_codec_tester_api") {
1016+
visibility = [ "*" ]
1017+
testonly = true
1018+
sources = [ "test/video_codec_tester.h" ]
1019+
deps = [
1020+
":videocodec_test_stats_api",
1021+
"../modules/video_coding/svc:scalability_mode_util",
1022+
"video:encoded_image",
1023+
"video:resolution",
1024+
"video:video_frame",
1025+
]
1026+
absl_deps = [
1027+
"//third_party/abseil-cpp/absl/functional:any_invocable",
1028+
"//third_party/abseil-cpp/absl/types:optional",
1029+
]
1030+
}
1031+
10041032
rtc_library("create_videocodec_test_fixture_api") {
10051033
visibility = [ "*" ]
10061034
testonly = true
@@ -1016,6 +1044,19 @@ if (rtc_include_tests) {
10161044
]
10171045
}
10181046

1047+
rtc_library("create_video_codec_tester_api") {
1048+
visibility = [ "*" ]
1049+
testonly = true
1050+
sources = [
1051+
"test/create_video_codec_tester.cc",
1052+
"test/create_video_codec_tester.h",
1053+
]
1054+
deps = [
1055+
":video_codec_tester_api",
1056+
"../modules/video_coding:videocodec_test_impl",
1057+
]
1058+
}
1059+
10191060
rtc_source_set("mock_audio_mixer") {
10201061
visibility = [ "*" ]
10211062
testonly = true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2022 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+
11+
#include "api/test/create_video_codec_tester.h"
12+
13+
#include <memory>
14+
#include <utility>
15+
16+
#include "api/test/video_codec_tester.h"
17+
#include "modules/video_coding/codecs/test/video_codec_tester_impl.h"
18+
19+
namespace webrtc {
20+
namespace test {
21+
22+
std::unique_ptr<VideoCodecTester> CreateVideoCodecTester() {
23+
return std::make_unique<VideoCodecTesterImpl>();
24+
}
25+
26+
} // namespace test
27+
} // namespace webrtc
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2022 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+
11+
#ifndef API_TEST_CREATE_VIDEO_CODEC_TESTER_H_
12+
#define API_TEST_CREATE_VIDEO_CODEC_TESTER_H_
13+
14+
#include <memory>
15+
16+
#include "api/test/video_codec_tester.h"
17+
18+
namespace webrtc {
19+
namespace test {
20+
21+
std::unique_ptr<VideoCodecTester> CreateVideoCodecTester();
22+
23+
} // namespace test
24+
} // namespace webrtc
25+
26+
#endif // API_TEST_CREATE_VIDEO_CODEC_TESTER_H_

api/test/video_codec_tester.h

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2022 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+
11+
#ifndef API_TEST_VIDEO_CODEC_TESTER_H_
12+
#define API_TEST_VIDEO_CODEC_TESTER_H_
13+
14+
#include <memory>
15+
16+
#include "absl/functional/any_invocable.h"
17+
#include "api/test/videocodec_test_stats.h"
18+
#include "api/video/encoded_image.h"
19+
#include "api/video/resolution.h"
20+
#include "api/video/video_frame.h"
21+
22+
namespace webrtc {
23+
namespace test {
24+
25+
// Interface for a video codec tester. The interface provides minimalistic set
26+
// of data structures that enables implementation of decode-only, encode-only
27+
// and encode-decode tests.
28+
class VideoCodecTester {
29+
public:
30+
// Pacing settings for codec input.
31+
struct PacingSettings {
32+
enum PacingMode {
33+
// Pacing is not used. Frames are sent to codec back-to-back.
34+
kNoPacing,
35+
// Pace with the rate equal to the target video frame rate. Pacing time is
36+
// derived from RTP timestamp.
37+
kRealTime,
38+
// Pace with the explicitly provided rate.
39+
kConstantRate,
40+
};
41+
PacingMode mode = PacingMode::kNoPacing;
42+
// Pacing rate for `kConstantRate` mode.
43+
Frequency constant_rate = Frequency::Zero();
44+
};
45+
46+
struct DecoderSettings {
47+
PacingSettings pacing;
48+
};
49+
50+
struct EncoderSettings {
51+
PacingSettings pacing;
52+
};
53+
54+
virtual ~VideoCodecTester() = default;
55+
56+
// Interface for a raw video frames source.
57+
class RawVideoSource {
58+
public:
59+
virtual ~RawVideoSource() = default;
60+
61+
// Returns next frame. If no more frames to pull, returns `absl::nullopt`.
62+
// For analysis and pacing purposes, frame must have RTP timestamp set. The
63+
// timestamp must represent the target video frame rate and be unique.
64+
virtual absl::optional<VideoFrame> PullFrame() = 0;
65+
66+
// Returns early pulled frame with RTP timestamp equal to `timestamp_rtp`.
67+
virtual VideoFrame GetFrame(uint32_t timestamp_rtp,
68+
Resolution resolution) = 0;
69+
};
70+
71+
// Interface for a coded video frames source.
72+
class CodedVideoSource {
73+
public:
74+
virtual ~CodedVideoSource() = default;
75+
76+
// Returns next frame. If no more frames to pull, returns `absl::nullopt`.
77+
// For analysis and pacing purposes, frame must have RTP timestamp set. The
78+
// timestamp must represent the target video frame rate and be unique.
79+
virtual absl::optional<EncodedImage> PullFrame() = 0;
80+
};
81+
82+
// Interface for a video encoder.
83+
class Encoder {
84+
public:
85+
using EncodeCallback =
86+
absl::AnyInvocable<void(const EncodedImage& encoded_frame)>;
87+
88+
virtual ~Encoder() = default;
89+
90+
virtual void Encode(const VideoFrame& frame, EncodeCallback callback) = 0;
91+
};
92+
93+
// Interface for a video decoder.
94+
class Decoder {
95+
public:
96+
using DecodeCallback =
97+
absl::AnyInvocable<void(const VideoFrame& decoded_frame)>;
98+
99+
virtual ~Decoder() = default;
100+
101+
virtual void Decode(const EncodedImage& frame, DecodeCallback callback) = 0;
102+
};
103+
104+
// Pulls coded video frames from `video_source` and passes them to `decoder`.
105+
// Returns `VideoCodecTestStats` object that contains collected per-frame
106+
// metrics.
107+
virtual std::unique_ptr<VideoCodecTestStats> RunDecodeTest(
108+
std::unique_ptr<CodedVideoSource> video_source,
109+
std::unique_ptr<Decoder> decoder,
110+
const DecoderSettings& decoder_settings) = 0;
111+
112+
// Pulls raw video frames from `video_source` and passes them to `encoder`.
113+
// Returns `VideoCodecTestStats` object that contains collected per-frame
114+
// metrics.
115+
virtual std::unique_ptr<VideoCodecTestStats> RunEncodeTest(
116+
std::unique_ptr<RawVideoSource> video_source,
117+
std::unique_ptr<Encoder> encoder,
118+
const EncoderSettings& encoder_settings) = 0;
119+
120+
// Pulls raw video frames from `video_source`, passes them to `encoder` and
121+
// then passes encoded frames to `decoder`. Returns `VideoCodecTestStats`
122+
// object that contains collected per-frame metrics.
123+
virtual std::unique_ptr<VideoCodecTestStats> RunEncodeDecodeTest(
124+
std::unique_ptr<RawVideoSource> video_source,
125+
std::unique_ptr<Encoder> encoder,
126+
std::unique_ptr<Decoder> decoder,
127+
const EncoderSettings& encoder_settings,
128+
const DecoderSettings& decoder_settings) = 0;
129+
};
130+
131+
} // namespace test
132+
} // namespace webrtc
133+
134+
#endif // API_TEST_VIDEO_CODEC_TESTER_H_

api/test/videocodec_test_stats.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <string>
1919
#include <vector>
2020

21+
#include "absl/types/optional.h"
22+
#include "api/units/data_rate.h"
23+
#include "api/units/frequency.h"
2124
#include "api/video/video_frame_type.h"
2225

2326
namespace webrtc {
@@ -135,11 +138,16 @@ class VideoCodecTestStats {
135138

136139
virtual ~VideoCodecTestStats() = default;
137140

138-
virtual std::vector<FrameStatistics> GetFrameStatistics() = 0;
141+
virtual std::vector<FrameStatistics> GetFrameStatistics() const = 0;
139142

140143
virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
141144
size_t first_frame_num,
142145
size_t last_frame_num) = 0;
146+
147+
virtual VideoStatistics CalcVideoStatistic(size_t first_frame,
148+
size_t last_frame,
149+
DataRate target_bitrate,
150+
Frequency target_framerate) = 0;
143151
};
144152

145153
} // namespace test

0 commit comments

Comments
 (0)